From: <lh...@us...> - 2008-11-23 14:50:31
|
Revision: 232 http://tinytim.svn.sourceforge.net/tinytim/?rev=232&view=rev Author: lheuer Date: 2008-11-23 14:50:27 +0000 (Sun, 23 Nov 2008) Log Message: ----------- - Added JSON Topic Maps (JTM) writer - Made prettifying XML configurable - Updated MIO XTM lib Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/CHANGES.txt 2008-11-23 14:50:27 UTC (rev 232) @@ -17,8 +17,9 @@ - Snello - LTM 1.3 * Moved CXTMWriter into .mio package, implements TopicMapWriter -* XTM 1.0 writer -* XTM 2.0 writer +* JSON Topic Maps (JTM) writer +* XML Topic Maps (XTM) 1.0 writer +* XML Topic Maps (XTM) 2.0 writer * Deprecated some TopicMapImporter methods which take a sax.InputSource as argument * Added docs to TopicMapImporter that it may become deprecated Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/build-15.xml 2008-11-23 14:50:27 UTC (rev 232) @@ -123,7 +123,7 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter*" + excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM* org/tinytim/mio/JSON*" includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" target="1.5"> <classpath> Modified: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -29,7 +29,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class AbstractXTMWriter extends AbstractTopicMapWriter { +abstract class AbstractXTMTopicMapWriter extends AbstractTopicMapWriter { protected final AttributesImpl _attrs; @@ -42,7 +42,7 @@ * @param baseIRI The base IRI. * @throws IOException If an error occurs. */ - protected AbstractXTMWriter(final OutputStream out, final String baseIRI) + protected AbstractXTMTopicMapWriter(final OutputStream out, final String baseIRI) throws IOException { this(out, baseIRI, "utf-8"); } @@ -59,14 +59,34 @@ * @throws IOException * If an error occurs. */ - protected AbstractXTMWriter(final OutputStream out, final String baseIRI, + protected AbstractXTMTopicMapWriter(final OutputStream out, final String baseIRI, final String encoding) throws IOException { super(baseIRI); if (encoding == null) { throw new IOException("The encoding must not be null"); } _out = new XMLWriter(out, encoding); + _out.setPrettify(true); _attrs = new AttributesImpl(); } + /** + * Enables / disables newlines and indentation of XML elements. + * (newlines and indentation is enabled by default) + * + * @param prettify <tt>true</tt> to enable prettified XML, otherwise <tt>false</tt>. + */ + public void setPrettify(boolean prettify) { + _out.setPrettify(prettify); + } + + /** + * Returns if newlines and indentation are enabled. + * + * @return <tt>true</tt> if prettified XML is enabled, otherwise <tt>false</tt>. + */ + public boolean getPrettify() { + return _out.getPrettify(); + } + } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -29,6 +29,7 @@ import java.util.Set; import java.util.logging.Logger; +import org.tinytim.internal.api.IIndexManagerAware; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.DuplicateRemovalUtils; import org.tinytim.voc.TMDM; @@ -143,7 +144,7 @@ */ public void write(TopicMap topicMap) throws IOException { DuplicateRemovalUtils.removeDuplicates(topicMap); - TypeInstanceIndex typeInstanceIndex = topicMap.getIndex(TypeInstanceIndex.class); + TypeInstanceIndex typeInstanceIndex = ((IIndexManagerAware)topicMap).getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); } Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -0,0 +1,217 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +/** + * Simple JSON serializer. This class is not usable as a generic JSON writer + * since it is possible to create an invalid JSON representation, but + * it is good enough to support JTM. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class JSONWriter { + + private OutputStreamWriter _out; + private boolean _wantComma; + private int _depth; + private boolean _prettify; + + public JSONWriter(OutputStream out) throws IOException { + _out = new OutputStreamWriter(out, "utf-8"); + } + + public void setPrettify(boolean prettify) { + _prettify = prettify; + } + + public boolean getPrettify() { + return _prettify; + } + + public void startDocument() { + _depth = 0; + } + + public void endDocument() throws IOException { + _out.write('\n'); + _out.flush(); + } + + private void _indent() throws IOException { + if (!_prettify) { + return; + } + if (_depth > 0) { + _out.write('\n'); + } + int indent = _depth*2; + char[] chars = new char[indent]; + for (int i=0; i<indent; i++) { + chars[i] = ' '; + } + _out.write(chars); + } + + public void startObject() throws IOException { + if (_wantComma) { + _out.write(','); + } + _indent(); + _out.write('{'); + _depth++; + _wantComma = false; + } + + public void endObject() throws IOException { + _out.write('}'); + _depth--; + _wantComma = true; + } + + public void startArray() throws IOException { + _out.write('['); + _depth++; + _wantComma = false; + } + + public void endArray() throws IOException { + _out.write(']'); + _depth--; + _wantComma = true; + } + + /** + * Writes the key of a <tt>"key": value</tt> pair. + * The writer assumes that the key is a valid JSON string (ensured by + * by JTM) so the keys are not escaped! + * + * @param key + * @throws IOException + */ + public void key(String key) throws IOException { + if (_wantComma) { + _out.write(','); + _indent(); + } + _out.write('"'); + _out.write(key); + _out.write('"'); + _out.write(':'); + _wantComma = false; + } + + public void value(String value) throws IOException { + if (_wantComma) { + _out.write(','); + } + _out.write(escape(value)); + _wantComma = true; + } + + /** + * + * + * @param value + * @return + */ + public static String escape(String value) { + // Code adapted from JSON.org (JSONObject.quote(String)) + // Copyrighted by JSON.org licensed under a BSD-license, see + // complete copyright notice at the end of this file. + char b; + char c = 0; + char[] chars = value.toCharArray(); + StringBuilder sb = new StringBuilder(chars.length + 4); + String t; + sb.append('"'); + for (int i = 0; i < chars.length; i += 1) { + b = c; + c = chars[i]; + switch (chars[i]) { + case '\\': + case '"': + sb.append('\\'); + sb.append(c); + break; + case '/': + if (b == '<') { + sb.append('\\'); + } + sb.append(c); + break; + case '\b': + sb.append("\\b"); + break; + case '\t': + sb.append("\\t"); + break; + case '\n': + sb.append("\\n"); + break; + case '\f': + sb.append("\\f"); + break; + case '\r': + sb.append("\\r"); + break; + default: + if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || + (c >= '\u2000' && c < '\u2100')) { + t = "000" + Integer.toHexString(c); + sb.append("\\u" + t.substring(t.length() - 4)); + } else { + sb.append(c); + } + } + } + sb.append('"'); + return sb.toString(); + } + + /* + =========================================================================== + Copyright of the JSONObject code which was used to implement the "escape" + function. + =========================================================================== + + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -0,0 +1,347 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Set; + +import org.tinytim.internal.api.IIndexManagerAware; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.IScoped; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XSD; + +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.DatatypeAware; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Role; +import org.tmapi.core.Scoped; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; +import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; + +/** + * A {@link TopicMapWriter} implementation that serializes a topic map into + * a <a href="http://www.cerny-online.com/topincs/">JSON Topic Maps</a> + * representation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class JTMTopicMapWriter implements TopicMapWriter { + + private static final String _TMDM_TYPE_INSTANCE = TMDM.TYPE_INSTANCE.getReference(); + private static final String _TMDM_TYPE = TMDM.TYPE.getReference(); + private static final String _TMDM_INSTANCE = TMDM.INSTANCE.getReference(); + + private JSONWriter _out; + private String _baseIRI; + private Topic _defaultNameType; + + /** + * Creates a JTM writer. + * + * @param out The stream the JTM is written onto. + * @param baseIRI The base IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public JTMTopicMapWriter(OutputStream out, String baseIRI) throws IOException { + _baseIRI = baseIRI; + _out = new JSONWriter(out); + _out.setPrettify(true); + } + + /** + * Enables / disables newlines and indentation of JSON elements. + * (newlines and indentation is enabled by default) + * + * @param prettify <tt>true</tt> to enable prettified JSON, otherwise <tt>false</tt>. + */ + public void setPrettify(boolean prettify) { + _out.setPrettify(prettify); + } + + /** + * Returns if newlines and indentation are enabled. + * + * @return <tt>true</tt> if prettified JSON is enabled, otherwise <tt>false</tt>. + */ + public boolean getPrettify() { + return _out.getPrettify(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.TopicMapWriter#write(org.tmapi.core.TopicMap) + */ + public void write(TopicMap topicMap) throws IOException { + _defaultNameType = topicMap.getTopicBySubjectIdentifier(TMDM.TOPIC_NAME); + _out.startDocument(); + _out.startObject(); + _writeReifier(topicMap); + _writeItemIdentifiers(topicMap); + _out.key("topics"); + _out.startArray(); + for (Topic topic: topicMap.getTopics()) { + _writeTopic(topic); + } + _out.endArray(); + _out.key("associations"); + _out.startArray(); + for (Association assoc: topicMap.getAssociations()) { + _writeAssociation(assoc); + } + // Write type-instance relationships + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + for (Topic type: tiIdx.getTopicTypes()) { + for (Topic instance: tiIdx.getTopics(type)) { + _writeTypeInstance(type, instance); + } + } + tiIdx.close(); + _out.endArray(); + _out.endObject(); + _out.endDocument(); + } + + private void _writeTopic(Topic topic) throws IOException { + // Ignore the topic if it is the default name type and it has no further + // characteristics + if (_isDefaultNameType(topic) + && topic.getReified() == null + && topic.getSubjectIdentifiers().size() == 1 + && topic.getSubjectLocators().isEmpty() + && topic.getItemIdentifiers().isEmpty() + && topic.getRolesPlayed().isEmpty() + && topic.getTypes().isEmpty() + && topic.getNames().isEmpty() + && topic.getOccurrences().isEmpty()) { + return; + } + _out.startObject(); + _writeItemIdentifiers(topic); + _writeLocators("subject_identifiers", topic.getSubjectIdentifiers()); + _writeLocators("subject_locators", topic.getSubjectLocators()); + Set<Name> names = topic.getNames(); + if (!names.isEmpty()) { + _out.key("names"); + _out.startArray(); + for (Name name: names) { + _writeName(name); + } + _out.endArray(); + } + Set<Occurrence> occs = topic.getOccurrences(); + if (!occs.isEmpty()) { + _out.key("occurrences"); + _out.startArray(); + for (Occurrence occ: occs) { + _writeOccurrence(occ); + } + _out.endArray(); + } + _out.endObject(); + } + + private void _writeName(Name name) throws IOException { + _out.startObject(); + _writeReifier(name); + _writeItemIdentifiers(name); + if (!_isDefaultNameType(name.getType())) { + _writeType(name); + } + _writeScope(name); + _writeKeyValue("value", name.getValue()); + Set<Variant> variants = name.getVariants(); + if (!variants.isEmpty()) { + _out.key("variants"); + _out.startArray(); + for (Variant variant: variants) { + _writeVariant(variant); + } + _out.endArray(); + } + _out.endObject(); + } + + private void _writeVariant(Variant variant) throws IOException { + _out.startObject(); + _writeReifier(variant); + _writeItemIdentifiers(variant); + _writeScope(variant); + _writeDatatypeAware(variant); + _out.endObject(); + } + + private void _writeOccurrence(Occurrence occ) throws IOException { + _out.startObject(); + _writeReifier(occ); + _writeItemIdentifiers(occ); + _writeType(occ); + _writeScope(occ); + _writeDatatypeAware(occ); + _out.endObject(); + } + + private void _writeDatatypeAware(DatatypeAware datatyped) throws IOException { + Locator datatype = datatyped.getDatatype(); + String value = XSD.ANY_URI.equals(datatype) ? datatyped.locatorValue().toExternalForm() + : datatyped.getValue(); + _writeKeyValue("value", value); + _writeKeyValue("datatype", datatype.toExternalForm()); + } + + private void _writeItemIdentifiers(Construct construct) throws IOException { + _writeLocators("item_identifiers", construct.getItemIdentifiers()); + } + + private void _writeLocators(String name, Set<Locator> locators) throws IOException { + if (locators.isEmpty()) { + return; + } + _out.key(name); + _out.startArray(); + for (Locator loc: locators) { + _out.value(loc.toExternalForm()); + } + _out.endArray(); + } + + private void _writeAssociation(Association assoc) throws IOException { + Set<Role> roles = assoc.getRoles(); + if (roles.isEmpty()) { + return; + } + _out.startObject(); + _writeReifier(assoc); + _writeItemIdentifiers(assoc); + _writeType(assoc); + _writeScope(assoc); + _out.key("roles"); + _out.startArray(); + for (Role role: roles) { + _writeRole(role); + } + _out.endArray(); + _out.endObject(); + } + + private void _writeRole(Role role) throws IOException { + _out.startObject(); + _writeReifier(role); + _writeItemIdentifiers(role); + _writeType(role); + _writeKeyValue("player", _topicRef(role.getPlayer())); + _out.endObject(); + } + + private void _writeType(Typed typed) throws IOException { + _writeKeyValue("type", _topicRef(typed.getType())); + } + + private void _writeScope(Scoped scoped) throws IOException { + IScope scope = ((IScoped) scoped).getScopeObject(); + if (scope.isUnconstrained()) { + return; + } + _out.key("scope"); + _out.startArray(); + for (Topic theme: scope) { + _out.value(_topicRef(theme)); + } + _out.endArray(); + } + + /** + * Writes a type-instance association. + * <p> + * JTM provides no shortcut like "instanceOf" at the topic level to indicate + * that a topic is an instance of another topic, all type-instance + * relationships must be encoded as associations. + * </p> + * + * @param type The topic which plays the <tt>tmdm:type</tt> role. + * @param instance The topic which plays the <tt>tmdm:instance</tt> role. + * @throws IOException If an error occurs. + */ + private void _writeTypeInstance(Topic type, Topic instance) throws IOException { + _out.startObject(); + _writeKeyValue("type", _TMDM_TYPE_INSTANCE); + _out.key("roles"); + _out.startArray(); + _out.startObject(); + _writeKeyValue("type", _TMDM_TYPE); + _writeKeyValue("player", _topicRef(type)); + _out.endObject(); + _out.startObject(); + _writeKeyValue("type", _TMDM_INSTANCE); + _writeKeyValue("player", _topicRef(instance)); + _out.endObject(); + _out.endArray(); + _out.endObject(); + } + + private void _writeReifier(Reifiable reifiable) throws IOException { + Topic reifier = reifiable.getReifier(); + if (reifier == null) { + return; + } + _writeKeyValue("reifier", _topicRef(reifier)); + } + + private void _writeKeyValue(String key, String value) throws IOException { + _out.key(key); + _out.value(value); + } + + /** + * Returns an IRI which is usable to as reference to the specified topic. + * + * @param topic The topic. + * @return An IRI. + */ + private String _topicRef(Topic topic) { + Set<Locator> locs = topic.getItemIdentifiers(); + if (!locs.isEmpty()) { + return locs.iterator().next().toExternalForm(); + } + locs = topic.getSubjectIdentifiers(); + if (!locs.isEmpty()) { + return locs.iterator().next().toExternalForm(); + } + return _baseIRI + "#" + topic.getId(); + } + + /** + * Checks if the specified <tt>topic</tt> is the default TMDM name type. + * + * @param topic The topic to check, not <tt>null</tt>. + * @return <tt>true</tt> if the topic is the default name type, otherwise <tt>false</tt>. + */ + private boolean _isDefaultNameType(final Topic topic) { + return topic.equals(_defaultNameType); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -39,6 +39,7 @@ private final String _encoding; private int _depth; + private boolean _prettify; public XMLWriter(OutputStream out) throws IOException { this(out, "utf-8"); @@ -49,6 +50,14 @@ _encoding = encoding; } + public void setPrettify(boolean prettify) { + _prettify = prettify; + } + + public boolean getPrettify() { + return _prettify; + } + /** * @see org.xml.sax.DocumentHandler#startDocument() */ @@ -83,9 +92,6 @@ * @see org.xml.sax.DocumentHandler#startElement(java.lang.String, org.xml.sax.AttributeList) */ public void startElement(String name, Attributes attrs) throws IOException { - if (_depth > 0) { - _newline(); - } _indent(); _out.write('<'); _out.write(name); @@ -106,8 +112,7 @@ */ public void _endElement(String name, boolean indent) throws IOException { _depth--; - if (indent && _depth >= 0) { - _newline(); + if (indent) { _indent(); } _out.write("</"); @@ -116,9 +121,6 @@ } public void emptyElement(String name, Attributes attrs) throws IOException { - if (_depth > 0) { - _newline(); - } _indent(); _out.write('<'); _out.write(name); @@ -158,6 +160,12 @@ } private void _indent() throws IOException { + if (!_prettify) { + return; + } + if (_depth > 0) { + _newline(); + } int indent = _depth*2; char[] chars = new char[indent]; for (int i=0; i<indent; i++) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -49,7 +49,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class XTM10TopicMapWriter extends AbstractXTMWriter { +public class XTM10TopicMapWriter extends AbstractXTMTopicMapWriter { private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -58,7 +58,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class XTM20TopicMapWriter extends AbstractXTMWriter { +public class XTM20TopicMapWriter extends AbstractXTMTopicMapWriter { private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |