From: <lh...@us...> - 2008-11-12 14:23:25
|
Revision: 176 http://tinytim.svn.sourceforge.net/tinytim/?rev=176&view=rev Author: lheuer Date: 2008-11-12 14:23:22 +0000 (Wed, 12 Nov 2008) Log Message: ----------- Added latest version of the *experimental* XTM writers Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java 2008-11-12 14:03:27 UTC (rev 175) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java 2008-11-12 14:23:22 UTC (rev 176) @@ -22,7 +22,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractTopicMapWriter implements TopicMapWriter { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java 2008-11-12 14:03:27 UTC (rev 175) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java 2008-11-12 14:23:22 UTC (rev 176) @@ -15,6 +15,10 @@ */ package org.tinytim.mio; +import java.io.IOException; +import java.io.OutputStream; + +import org.tmapi.core.TMAPIRuntimeException; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; @@ -22,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractXTMWriter extends AbstractTopicMapWriter { @@ -30,13 +34,15 @@ protected AttributesImpl _attrs; protected XMLWriter _out; - /** - * - * - * @param baseIRI - */ - public AbstractXTMWriter(String baseIRI) { + + public AbstractXTMWriter(final OutputStream out, final String baseIRI) { super(baseIRI); + try { + _out = new XMLWriter(out); + } + catch (IOException ex) { + throw new TMAPIRuntimeException(ex); + } } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java 2008-11-12 14:03:27 UTC (rev 175) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java 2008-11-12 14:23:22 UTC (rev 176) @@ -16,6 +16,7 @@ package org.tinytim.mio; import java.io.IOException; +import java.io.OutputStream; import java.util.Set; import org.tinytim.voc.Namespace; @@ -41,7 +42,7 @@ * a <a href="http://www.topicmaps.org/xtm/1.0/">XTM 1.0</a> representation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class XTM10Writer extends AbstractXTMWriter { @@ -55,8 +56,8 @@ * * @param baseIRI */ - public XTM10Writer(String baseIRI) { - super(baseIRI); + public XTM10Writer(final OutputStream out, final String baseIRI) { + super(out, baseIRI); } private String _getId(Reifiable reifiable) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java 2008-11-12 14:03:27 UTC (rev 175) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java 2008-11-12 14:23:22 UTC (rev 176) @@ -16,6 +16,7 @@ package org.tinytim.mio; import java.io.IOException; +import java.io.OutputStream; import java.util.Set; import org.tinytim.core.IConstruct; @@ -46,7 +47,7 @@ * representation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class XTM20Writer extends AbstractXTMWriter { @@ -55,8 +56,8 @@ * * @param baseIRI */ - public XTM20Writer(String baseIRI) { - super(baseIRI); + public XTM20Writer(final OutputStream out, final String baseIRI) { + super(out, baseIRI); } /* (non-Javadoc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-14 13:39:26
|
Revision: 190 http://tinytim.svn.sourceforge.net/tinytim/?rev=190&view=rev Author: lheuer Date: 2008-11-14 13:39:21 +0000 (Fri, 14 Nov 2008) Log Message: ----------- - Fixed #2276392 -- Prettify XML (XTM) output - XTM10Writer didn't used xlink:href for topicRefs. Fixed. - Added logger to XTM10Writer / XTM20Writer - Associations with no roles are omitted now (1.0 and 2.0) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java 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-14 13:35:18 UTC (rev 189) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-14 13:39:21 UTC (rev 190) @@ -39,6 +39,9 @@ private final String _encoding; + private int _depth; + + public XMLWriter(OutputStream out) throws IOException { this(out, "utf-8"); } @@ -55,18 +58,18 @@ _out.write("<?xml version=\"1.0\" encoding=\""); _out.write(_encoding); _out.write("\" standalone=\"yes\"?>"); - newline(); + _newline(); _out.write("<!-- Generated by tinyTiM v"); _out.write(Version.RELEASE); _out.write(" - http://tinytim.sourceforge.net/ -->"); - newline(); + _newline(); } /** * @see org.xml.sax.DocumentHandler#endDocument() */ public void endDocument() throws IOException { - newline(); + _newline(); try { _out.flush(); } @@ -83,22 +86,43 @@ * @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); _writeAttributes(attrs); _out.write('>'); + _depth++; } /** * @see org.xml.sax.DocumentHandler#endElement(java.lang.String) */ public void endElement(String name) throws IOException { + _endElement(name, true); + } + + /** + * @see org.xml.sax.DocumentHandler#endElement(java.lang.String) + */ + public void _endElement(String name, boolean indent) throws IOException { + _depth--; + if (indent && _depth >= 0) { + _newline(); + _indent(); + } _out.write("</"); _out.write(name); _out.write('>'); } public void emptyElement(String name, Attributes attrs) throws IOException { + if (_depth > 0) { + _newline(); + } + _indent(); _out.write('<'); _out.write(name); _writeAttributes(attrs); @@ -112,7 +136,7 @@ public void dataElement(String name, Attributes attrs, String data) throws IOException { startElement(name, attrs); characters(data); - endElement(name); + _endElement(name, false); } public void _writeAttributes(Attributes attrs) throws IOException { @@ -132,10 +156,18 @@ * * @throws IOException If an error occurs. */ - public void newline() throws IOException { + private void _newline() throws IOException { _out.write(_NL); } + private void _indent() throws IOException { + char[] indent = new char[_depth*2]; + for (int i=0; i<indent.length; i++) { + indent[i] = ' '; + } + _out.write(indent); + } + /** * Writes the specified characters to the output. * Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java 2008-11-14 13:35:18 UTC (rev 189) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java 2008-11-14 13:39:21 UTC (rev 190) @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.logging.Logger; import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; @@ -48,8 +49,9 @@ */ public class XTM10Writer extends AbstractXTMWriter { + private static final Logger LOG = Logger.getLogger(XTM10Writer.class.getName()); + //TODO: Export iids, - // warn if len(slos) > 1, // warn if name.type != default name type, // warn if datatype not in (xsd:string, xsd:anyURI) @@ -120,50 +122,45 @@ _out.startElement("topic", _attrs); _writeIdentities(topic); for (Topic type: topic.getTypes()) { - _out.newline(); _out.startElement("instanceOf"); _writeTopicRef(type); _out.endElement("instanceOf"); - _out.newline(); } for (Name name: topic.getNames()) { - _out.newline(); _writeName(name); - _out.newline(); } for (Occurrence occ: topic.getOccurrences()) { - _out.newline(); _writeOccurrence(occ); - _out.newline(); } _out.endElement("topic"); - _out.newline(); } protected void _writeAssociation(final Association assoc) throws IOException { + Set<Role> roles = assoc.getRoles(); + if (roles.isEmpty()) { + LOG.info("Omitting association id " + assoc.getId() + " since it has no roles"); + return; + } _attrs.clear(); _addId(_attrs, assoc); _out.startElement("association", _attrs); _writeType(assoc); _writeScope(assoc); - for (Role role: assoc.getRoles()) { + for (Role role: roles) { _writeRole(role); } _out.endElement("association"); - _out.newline(); } protected void _writeRole(final Role role) throws IOException { _attrs.clear(); _addId(_attrs, role); - _out.newline(); _out.startElement("member", _attrs); _out.startElement("roleSpec"); _writeTopicRef(role.getType()); _out.endElement("roleSpec"); _writeTopicRef(role.getPlayer()); _out.endElement("member"); - _out.newline(); } protected void _writeName(final Name name) throws IOException { @@ -173,9 +170,7 @@ _writeScope(name); _out.dataElement("baseNameString", name.getValue()); for (Variant variant: name.getVariants()) { - _out.newline(); _writeVariant(variant); - _out.newline(); } _out.endElement("baseName"); } @@ -184,13 +179,11 @@ _attrs.clear(); _addId(_attrs, variant); _out.startElement("variant", _attrs); - _out.newline(); _out.startElement("parameters"); for (Topic theme: variant.getScope()) { _writeTopicRef(theme); } _out.endElement("parameters"); - _out.newline(); _writeDatatypeAware(variant); _out.endElement("variant"); } @@ -218,18 +211,14 @@ private void _writeTopicRef(final Topic topic) throws IOException { _attrs.clear(); - _attrs.addAttribute("", "href", "", "CDATA", "#" + _getId(topic)); - _out.newline(); + _attrs.addAttribute("", "xlink:href", "", "CDATA", "#" + _getId(topic)); _out.emptyElement("topicRef", _attrs); - _out.newline(); } private void _writeType(final Typed typed) throws IOException { - _out.newline(); _out.startElement("type"); _writeTopicRef(typed.getType()); _out.endElement("type"); - _out.newline(); } private void _writeScope(final Scoped scoped) throws IOException { @@ -237,13 +226,11 @@ if (scope.isUnconstrained()) { return; } - _out.newline(); _out.startElement("scope"); for (Topic theme: scope) { _writeTopicRef(theme); } _out.endElement("scope"); - _out.newline(); } protected void _writeIdentities(final Topic topic) throws IOException { @@ -256,8 +243,10 @@ return; } _out.startElement("subjectIdentity"); - _out.newline(); if (!slos.isEmpty()) { + if (slos.size() > 1) { + LOG.warning("The topic " + topic.getId() + " has more than one subject locator, exporting just one"); + } // Choose one subject locator Locator slo = slos.iterator().next(); _attrs.clear(); @@ -275,7 +264,6 @@ _out.emptyElement("subjectIndicatorRef", _attrs); } _out.endElement("subjectIdentity"); - _out.newline(); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java 2008-11-14 13:35:18 UTC (rev 189) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java 2008-11-14 13:39:21 UTC (rev 190) @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.logging.Logger; import org.tinytim.internal.api.IConstruct; import org.tinytim.internal.api.IScope; @@ -53,6 +54,8 @@ */ public class XTM20Writer extends AbstractXTMWriter { + private static final Logger LOG = Logger.getLogger(XTM20Writer.class.getName()); + /** * Creates a XTM 2.0 writer using "utf-8" encoding. * @@ -92,11 +95,9 @@ _writeItemIdentifiers(topicMap); for (Topic topic: topicMap.getTopics()) { _writeTopic(topic); - _out.newline(); } for (Association assoc: topicMap.getAssociations()) { _writeAssociation(assoc); - _out.newline(); } _out.endElement("topicMap"); _out.endDocument(); @@ -116,23 +117,25 @@ } for (Name name: topic.getNames()) { _writeName(name); - _out.newline(); } for (Occurrence occ: topic.getOccurrences()) { _writeOccurrence(occ); - _out.newline(); } _out.endElement("topic"); } protected void _writeAssociation(final Association assoc) throws IOException { + Set<Role> roles = assoc.getRoles(); + if (roles.isEmpty()) { + LOG.info("Omitting association id " + assoc.getId() + " since it has no roles"); + return; + } _out.startElement("association", _reifier(assoc)); _writeItemIdentifiers(assoc); _writeType(assoc); _writeScope(assoc); - for (Role role: assoc.getRoles()) { + for (Role role: roles) { _writeRole(role); - _out.newline(); } _out.endElement("association"); } @@ -142,7 +145,6 @@ _writeItemIdentifiers(role); _writeType(role); _writeTopicRef(role.getPlayer()); - _out.newline(); _out.endElement("role"); } @@ -154,7 +156,6 @@ _out.dataElement("value", name.getValue()); for (Variant variant: name.getVariants()) { _writeVariant(variant); - _out.newline(); } _out.endElement("name"); } @@ -178,7 +179,6 @@ private void _writeDatatypeAware(final DatatypeAware datatyped) throws IOException { _attrs.clear(); - _out.newline(); if (XSD.ANY_URI.equals(datatyped.getDatatype())) { _attrs.addAttribute("", "href", "", "CDATA", datatyped.locatorValue().toExternalForm()); _out.emptyElement("resourceRef", _attrs); @@ -190,7 +190,6 @@ } _out.dataElement("resourceData", _attrs, datatyped.getValue()); } - _out.newline(); } /** @@ -226,11 +225,9 @@ && type.getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)) { return; } - _out.newline(); _out.startElement("type"); _writeTopicRef(type); _out.endElement("type"); - _out.newline(); } private void _writeScope(final Scoped scoped) throws IOException { @@ -238,13 +235,11 @@ if (scope.isUnconstrained()) { return; } - _out.newline(); _out.startElement("scope"); for (Topic theme: scope) { _writeTopicRef(theme); } _out.endElement("scope"); - _out.newline(); } private void _writeItemIdentifiers(final Construct construct) throws IOException { @@ -255,9 +250,7 @@ for (Locator loc: locs) { _attrs.clear(); _attrs.addAttribute("", "href", "", "CDATA", loc.toExternalForm()); - _out.newline(); _out.emptyElement(name, _attrs); - _out.newline(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-15 13:09:11
|
Revision: 198 http://tinytim.svn.sourceforge.net/tinytim/?rev=198&view=rev Author: lheuer Date: 2008-11-15 13:09:09 +0000 (Sat, 15 Nov 2008) Log Message: ----------- - Better naming scheme: * <Syntax>Reader -> <Syntax>TopicMapReader * <Syntax>Writer -> <Syntax>TopicMapWriter - XTM20TopicMapWriter ignores the tmdm:topic-name iff it consists just of the subject identifier Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMTopicMapReader.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Reader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10Writer.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Reader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20Writer.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-11-15 13:02:58 UTC (rev 197) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-11-15 13:09:09 UTC (rev 198) @@ -1,90 +0,0 @@ -/* - * 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.File; -import java.io.IOException; -import java.io.InputStream; - -import org.tmapi.core.TopicMap; - -import com.semagia.mio.Source; -import com.semagia.mio.Syntax; - -/** - * {@link TopicMapReader} implementation that is able to deserialize - * <a href="http://www.isotopicmaps.org/ctm/">Compact Topic Maps (CTM) 1.0</a>. - * <p> - * Note that this reader implements the CTM draft dtd. 2008-05-15. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class CTMReader extends AbstractTopicMapReader { - - /** - * Constructs a new instance. - * - * @param topicMap The topic map to which the content is added to. - * @param source The source to read the topic map from. - * @param docIRI The document IRI which is used to resolve IRIs against. - * @throws IOException If an error occurs. - */ - public CTMReader(final TopicMap topicMap, final File source, - final String docIRI) throws IOException { - super(topicMap, Syntax.CTM, source, docIRI); - } - - /** - * Constructs a new instance. - * <p> - * The <tt>source</tt> is converted into an absolute IRI which will be - * utilised as document IRI - * </p> - * - * @param topicMap The topic map to which the content is added to. - * @param source The source to read the topic map from. - * @throws IOException If an error occurs. - */ - public CTMReader(final TopicMap topicMap, final File source) - throws IOException { - super(topicMap, Syntax.CTM, source); - } - - /** - * Constructs a new instance. - * - * @param topicMap The topic map to which the content is added to. - * @param source The source to read the topic map from. - * @param docIRI The document IRI which is used to resolve IRIs against. - */ - public CTMReader(final TopicMap topicMap, final InputStream source, - final String docIRI) { - super(topicMap, Syntax.CTM, source, docIRI); - } - - /** - * Constructs a new instance. - * - * @param topicMap The topic map to which the content is added to. - * @param source The source to read the serialized topic map from. - */ - public CTMReader(final TopicMap topicMap, final Source source) { - super(topicMap, Syntax.CTM, source); - } - -} Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapReader.java 2008-11-15 13:09:09 UTC (rev 198) @@ -0,0 +1,90 @@ +/* + * 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.File; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.Source; +import com.semagia.mio.Syntax; + +/** + * {@link TopicMapReader} implementation that is able to deserialize + * <a href="http://www.isotopicmaps.org/ctm/">Compact Topic Maps (CTM) 1.0</a>. + * <p> + * Note that this reader implements the CTM draft dtd. 2008-05-15. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class CTMTopicMapReader extends AbstractTopicMapReader { + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public CTMTopicMapReader(final TopicMap topicMap, final File source, + final String docIRI) throws IOException { + super(topicMap, Syntax.CTM, source, docIRI); + } + + /** + * Constructs a new instance. + * <p> + * The <tt>source</tt> is converted into an absolute IRI which will be + * utilised as document IRI + * </p> + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @throws IOException If an error occurs. + */ + public CTMTopicMapReader(final TopicMap topicMap, final File source) + throws IOException { + super(topicMap, Syntax.CTM, source); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + */ + public CTMTopicMapReader(final TopicMap topicMap, final InputStream source, + final String docIRI) { + super(topicMap, Syntax.CTM, source, docIRI); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the serialized topic map from. + */ + public CTMTopicMapReader(final TopicMap topicMap, final Source source) { + super(topicMap, Syntax.CTM, source); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-15 13:09:09 UTC (rev 198) @@ -0,0 +1,1230 @@ +/* + * 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.AbstractSet; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.logging.Logger; + +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.DuplicateRemovalUtils; +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.TopicInUseException; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; +import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Provides serialization of topic maps into Canonical XTM (CXTM). + * <p> + * CXTM is a format that guarantees that two equivalent Topic Maps Data Model + * instances [ISO/IEC 13250-2] will always produce byte-by-byte identical + * serializations, and that non-equivalent instances will always produce + * different serializations. + * </p> + * <p> + * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> + * for details. + * </p> + * <p> + * <em>CAUTION</em>: This class implements the + * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, + * the output may change in the future. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class CXTMTopicMapWriter implements TopicMapWriter { + + private static final Logger LOG = Logger.getLogger(CXTMTopicMapWriter.class.getName()); + + private static final Role[] _EMPTY_ROLES = new Role[0]; + + private final AttributesImpl _attrs; + + private Topic _type; + private Topic _instance; + private Topic _typeInstance; + + private final XMLC14NWriter _out; + private final String _normBase; + private final Map<Construct, Integer> _construct2Id; + private final Map<Topic, List<Role>> _topic2Roles; + private final Map<Locator, String> _locator2Norm; + private final Map<Association, Role[]> _assoc2Roles; + + private final Comparator<Topic> _topicComparator; + private final Comparator<Association> _assocComparator; + private final Comparator<Role> _roleComparator; + private final Comparator<Occurrence> _occComparator; + private final Comparator<Name> _nameComparator; + private final Comparator<Variant> _variantComparator; + private final Comparator<Set<Locator>> _locSetComparator; + private final Comparator<Locator> _locComparator; + private final Comparator<Set<Topic>> _scopeComparator; + + /** + * Creates a canonicalizer. + * + * @param out The stream the CXTM is written onto. + * @param baseLocator The base locator which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public CXTMTopicMapWriter(OutputStream out, String baseLocator) throws IOException { + if (baseLocator == null) { + throw new IllegalArgumentException("The base locator must not be null"); + } + _out = new XMLC14NWriter(out); + _attrs = new AttributesImpl(); + _normBase = _normalizeBaseLocator(baseLocator); + _construct2Id = CollectionFactory.createIdentityMap(); + _locator2Norm = CollectionFactory.createIdentityMap(); + _assoc2Roles = CollectionFactory.createIdentityMap(); + _topic2Roles = CollectionFactory.createIdentityMap(); + _topicComparator = new TopicComparator(); + _assocComparator = new AssociationComparator(); + _roleComparator = new RoleComparator(); + _occComparator = new OccurrenceComparator(); + _nameComparator = new NameComparator(); + _variantComparator = new VariantComparator(); + _locSetComparator = new LocatorSetComparator(); + _locComparator = new LocatorComparator(); + _scopeComparator = new ScopeComparator(); + } + + /** + * Serializes the specified <tt>topicMap</tt> into the CXTM format. + * <p> + * <em>CAUTION</em>: This method MAY modify the topic map since duplicate + * Topic Maps constructs (if any) are removed in advance. + * </p> + * + * @param topicMap The topic map to serialize. + * @throws IOException If an error occurs. + */ + public void write(TopicMap topicMap) throws IOException { + DuplicateRemovalUtils.removeDuplicates(topicMap); + TypeInstanceIndex typeInstanceIndex = topicMap.getIndex(TypeInstanceIndex.class); + if (!typeInstanceIndex.isAutoUpdated()) { + typeInstanceIndex.reindex(); + } + Topic[] topics = _fetchTopics(topicMap, typeInstanceIndex); + Association[] assocs = _fetchAssociations(topicMap, typeInstanceIndex); + typeInstanceIndex.close(); + _createIndex(topics, assocs); + _out.startDocument(); + _attrs.clear(); + _addReifier(_attrs, topicMap); + _out.startElement("topicMap", _attrs); + _out.newline(); + _writeItemIdentifiers(topicMap); + for (Topic topic: topics) { + _writeTopic(topic); + } + for (Association assoc: assocs) { + _writeAssociation(assoc); + } + _out.endElement("topicMap"); + _out.newline(); + _out.endDocument(); + _attrs.clear(); + _construct2Id.clear(); + _topic2Roles.clear(); + _locator2Norm.clear(); + _assoc2Roles.clear(); + } + + /** + * Returns an unsorted array of topics which should be included into + * the output. + * <p> + * This method may return more topics than {@link TopicMap#getTopics()} + * since this method creates virtual topics to model type-instance + * relationships properly. + * </p> + * + * @param topicMap The topic map from which the topic should be serialized. + * @param idx A (upto date) type instance index. + * @return All topics which must be included into the output. + */ + private Topic[] _fetchTopics(final TopicMap topicMap, final TypeInstanceIndex idx) { + Collection<Topic> types = idx.getTopicTypes(); + if (types.isEmpty()) { + Set<Topic> topics = topicMap.getTopics(); + return topics.toArray(new Topic[topics.size()]); + } + else { + List<Topic> topics = CollectionFactory.createList(topicMap.getTopics()); + _typeInstance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE_INSTANCE); + _type = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE); + _instance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.INSTANCE); + return topics.toArray(new Topic[topics.size()]); + } + } + + /** + * Returns a topic by its subject identifier. If the topic is null, a + * {@link TypeInstanceTopic} is created, added to the <tt>topics</tt> + * and returned. + * + * @param tm The topic map to fetch the topic from. + * @param topics A modifiable collection of topics. + * @param sid The subject identifier. + * @return A topic with the specified subject identifier. + */ + private Topic _getTopicBySubjectIdentifier(TopicMap tm, Collection<Topic> topics, Locator sid) { + Topic topic = tm.getTopicBySubjectIdentifier(sid); + if (topic == null) { + topic = new TypeInstanceTopic(sid); + topics.add(topic); + } + return topic; + } + + /** + * Returns an unsorted array of associations which should be serialized. + * + * This method may return more association than {@link TopicMap#getAssociations()} + * since this method may create virtual associations which are used to + * model type-instance relationships properly. + * + * @param tm The topic map from which the associations should be serialized. + * @param idx A (upto date) type instance index. + * @return An unsorted array of associations which must be included into the output. + */ + private Association[] _fetchAssociations(final TopicMap tm, final TypeInstanceIndex idx) { + Collection<Topic> types = idx.getTopicTypes(); + if (types.isEmpty()) { + Set<Association> assocs = tm.getAssociations(); + return assocs.toArray(new Association[assocs.size()]); + } + else { + List<Association> assocs = CollectionFactory.createList(tm.getAssociations()); + for (Topic type: types) { + for (Topic instance: idx.getTopics(type)) { + assocs.add(new TypeInstanceAssociation(type, instance)); + } + } + return assocs.toArray(new Association[assocs.size()]); + } + } + + /** + * Creates the index on which the canonicalizer operates. + * + * As sideeffect, the provided topic and association arrays get sorted. + * + * @param topics An array of topics. + * @param assocs An array of associations. + */ + private void _createIndex(Topic[] topics, Association[] assocs) { + Arrays.sort(topics, _topicComparator); + Topic topic = null; + for (int i=0; i < topics.length; i++) { + topic = topics[i]; + _construct2Id.put(topic, Integer.valueOf(i+1)); + } + Arrays.sort(assocs, _assocComparator); + Association assoc = null; + for (int i=0; i < assocs.length; i++) { + assoc = assocs[i]; + _construct2Id.put(assoc, Integer.valueOf(i+1)); + Set<Role> roles_ = assoc.getRoles(); + Role[] roles = roles_.toArray(new Role[roles_.size()]); + Arrays.sort(roles, _roleComparator); + _assoc2Roles.put(assoc, roles); + for (int j=0; j < roles.length; j++) { + _construct2Id.put(roles[j], Integer.valueOf(j+1)); + } + } + } + + /** + * Returns a sorted array of roles of the provided association. + * + * @param assoc The association to retrieve the roles from. + * @return A (maybe empty) sorted array of roles. + */ + private Role[] _getRoles(final Association assoc) { + Role[] roles = _assoc2Roles.get(assoc); + return roles != null ? roles : _EMPTY_ROLES; + } + + /** + * Returns a sorted array of names of the provided topic. + * + * @param topic The topic to retrieve the names from. + * @return A (maybe empty) sorted array of names. + */ + private Name[] _getNames(final Topic topic) { + Set<Name> names_ = topic.getNames(); + Name[] names = names_.toArray(new Name[names_.size()]); + Arrays.sort(names, _nameComparator); + return names; + } + + /** + * Returs a sorted array of variants of the provided name. + * + * @param name The name to retrieve the variants from. + * @return A (maybe empty) sorted array of variants. + */ + private Variant[] _getVariants(final Name name) { + Set<Variant> variants_ = name.getVariants(); + Variant[] variants = variants_.toArray(new Variant[variants_.size()]); + Arrays.sort(variants, _variantComparator); + return variants; + } + + /** + * Returns a sorted array of occurrences of the provided topic. + * + * @param topic The topic to retrieve the occurrences from. + * @return A (maybe emtpy) sorted array of occurrences. + */ + private Occurrence[] _getOccurrences(final Topic topic) { + Set<Occurrence> occs_ = topic.getOccurrences(); + Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); + Arrays.sort(occs, _occComparator); + return occs; + } + + /** + * Returns the index of the provided Topic Maps construct. + * + * The "index" is <cite>"[...] the string encoding of the position of this + * information item in the canonically ordered list of the values from + * that set".</cite> (CXTM 3.20 Constructing the number attribute). + * + * @param tmo The Topic Maps construct to return the index of. + * @return The index of the Topic Maps construct. + */ + private int _indexOf(final Construct tmo) { + return _construct2Id.get(tmo).intValue(); + } + + /** + * Serializes the <tt>topic</tt>. + * + * @param topic The topic to serialize. + * @throws IOException If an error occurs. + */ + private void _writeTopic(final Topic topic) throws IOException { + _attrs.clear(); + _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(_indexOf(topic))); + _out.startElement("topic", _attrs); + _out.newline(); + _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); + _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); + _writeItemIdentifiers(topic); + Name[] names = _getNames(topic); + for (int i=0; i < names.length; i++) { + _writeName(names[i], i+1); + } + Occurrence[] occs = _getOccurrences(topic); + for (int i=0; i < occs.length; i++) { + _writeOccurrence(occs[i], i+1); + } + List<Role> roles_ = CollectionFactory.createList(topic.getRolesPlayed()); + List<Role> alienRoles = _topic2Roles.get(topic); + if (alienRoles != null) { + roles_.addAll(alienRoles); + } + Role[] roles = roles_.toArray(new Role[roles_.size()]); + Arrays.sort(roles, _roleComparator); + StringBuilder sb = new StringBuilder(20); + for (int i=0; i < roles.length; i++) { + sb.append("association.") + .append(_indexOf(roles[i].getParent())) + .append(".role.") + .append(_indexOf(roles[i])); + _attrs.clear(); + _attrs.addAttribute("", "ref", "", "CDATA", sb.toString()); + _out.startElement("rolePlayed", _attrs); + _out.endElement("rolePlayed"); + _out.newline(); + sb.setLength(0); + } + _out.endElement("topic"); + _out.newline(); + } + + /** + * Serializes an association. + * + * @param assoc The association to serialize. + * @throws IOException If an error occurs. + */ + private void _writeAssociation(final Association assoc) throws IOException { + _out.startElement("association", _attributes(assoc, _indexOf(assoc))); + _out.newline(); + _writeType(assoc); + for (Role role: _getRoles(assoc)) { + _out.startElement("role", _attributes(role, _indexOf(role))); + _out.newline(); + _out.startElement("player", _topicRef(role.getPlayer())); + _out.endElement("player"); + _out.newline(); + _writeType(role); + _writeItemIdentifiers(role); + _out.endElement("role"); + _out.newline(); + } + _writeScope(assoc); + _writeItemIdentifiers(assoc); + _out.endElement("association"); + _out.newline(); + } + + /** + * Serializes an occurrence. + * + * @param occ The occurrence to serialize. + * @param pos The position of the occurrence within the parent container. + * @throws IOException If an error occurs. + */ + private void _writeOccurrence(final Occurrence occ, int pos) throws IOException { + _out.startElement("occurrence", _attributes(occ, pos)); + _out.newline(); + _writeDatatyped(occ); + _writeType(occ); + _writeScope(occ); + _writeItemIdentifiers(occ); + _out.endElement("occurrence"); + _out.newline(); + } + + /** + * Writes the value/datatype pair of an occurrence or variant. + * + * @param obj The construct to serialize. + * @throws IOException If an error occurs. + */ + private void _writeDatatyped(final DatatypeAware obj) throws IOException { + final String value = XSD.ANY_URI.equals(obj.getDatatype()) + ? _normalizeLocator(obj.locatorValue()) + : obj.getValue(); + _out.startElement("value"); + _out.characters(value); + _out.endElement("value"); + _out.newline(); + _out.startElement("datatype"); + _out.characters(_normalizeLocator(obj.getDatatype())); + _out.endElement("datatype"); + _out.newline(); + } + + /** + * Serializes a topic name. + * + * @param name The name to serialize. + * @param pos The position of the name within the parent container. + * @throws IOException If an error occurs. + */ + private void _writeName(final Name name, int pos) throws IOException { + _out.startElement("name", _attributes(name, pos)); + _out.newline(); + _out.startElement("value"); + _out.characters(name.getValue()); + _out.endElement("value"); + _out.newline(); + _writeType(name); + _writeScope(name); + Variant[] variants = _getVariants(name); + Variant variant = null; + for (int i=0; i<variants.length; i++) { + variant = variants[i]; + _out.startElement("variant", _attributes(variant, i+1)); + _out.newline(); + _writeDatatyped(variant); + _writeScope(variant); + _writeItemIdentifiers(variant); + _out.endElement("variant"); + _out.newline(); + } + _writeItemIdentifiers(name); + _out.endElement("name"); + _out.newline(); + } + + /** + * Serializes the type of a typed Topic Maps construct. + * + * @param typed The typed Topic Maps construct from which the type should be + * serialized. + * @throws IOException If an error occurs. + */ + private void _writeType(final Typed typed) throws IOException { + _out.startElement("type", _topicRef(typed.getType())); + _out.endElement("type"); + _out.newline(); + } + + /** + * Serializes the scope of a scoped Topic Maps construct. + * + * If the scope is unconstrained, this method does nothing. + * + * @param scoped The scoped Topic Maps construct. + * @throws IOException If an error occurs. + */ + private void _writeScope(final Scoped scoped) throws IOException { + Set<Topic> scope = scoped.getScope(); + if (scope.isEmpty()) { + return; + } + _out.startElement("scope"); + _out.newline(); + Topic[] themes = scope.toArray(new Topic[scope.size()]); + Arrays.sort(themes, _topicComparator); + for (int i=0; i < themes.length; i++) { + _out.startElement("scopingTopic", _topicRef(themes[i])); + _out.endElement("scopingTopic"); + _out.newline(); + } + _out.endElement("scope"); + _out.newline(); + } + + /** + * Serializes a locator. + * + * A normalized locator value is created which is serialized. + * + * @param loc The locator to serialize. + * @throws IOException If an error occurs. + */ + private void _writeLocator(final Locator loc) throws IOException { + _out.startElement("locator"); + _out.characters(_normalizeLocator(loc)); + _out.endElement("locator"); + _out.newline(); + } + + /** + * Serializes the item identifiers of the specified Topic Maps construct. + * + * @param tmo The Topic Maps construct to take the item identifiers from. + * @throws IOException If an error occurs. + */ + private void _writeItemIdentifiers(final Construct tmo) throws IOException { + _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); + } + + /** + * Serializes the <tt>locators</tt> using the <tt>localName</tt> as + * element name. + * <p> + * If the set of <tt>locators</tt> is empty, this method does nothing. + * </p> + * + * @param localName The element's name. + * @param locators The locators to serialize. + * @throws IOException If an error occurs. + */ + private void _writeLocatorSet(final String localName, final Set<Locator> locators) throws IOException { + if (locators.isEmpty()) { + return; + } + Locator[] locs = locators.toArray(new Locator[locators.size()]); + Arrays.sort(locs, _locComparator); + _out.startElement(localName); + _out.newline(); + for (int i=0; i < locs.length; i++) { + _writeLocator(locs[i]); + } + _out.endElement(localName); + _out.newline(); + } + + /** + * Returns attributes which contains a reference to the provided topic. + * + * @param topic The topic to which the reference should point to. + * @return Attributes with a topic reference. + */ + private Attributes _topicRef(final Topic topic) { + if (topic == null) { + _reportInvalid("The topic reference is null"); + return XMLC14NWriter.EMPTY_ATTRS; + } + _attrs.clear(); + _attrs.addAttribute("", "topicref", "", "CDATA", Integer.toString(_indexOf(topic))); + return _attrs; + } + + /** + * Returns attributes which contain the reifier (if any) and the number + * of the provided Topic Maps construct (not a topic). + * + * @param reifiable The Topic Maps construct. + * @param pos The position of the reifiable within the parent container. + * @return Attributes which contain a reference to the reifier (if any) and + * the number of the provided Topic Maps construct. + */ + private Attributes _attributes(final Reifiable reifiable, int pos) { + _attrs.clear(); + _addReifier(_attrs, reifiable); + _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(pos)); + return _attrs; + } + + /** + * Adds a reference to the reifier of the Topic Maps construct to the + * provided attributes. If the Topic Maps construct has no reifier, the + * provided attributes are not modified. + * + * @param attrs The attributes. + * @param reifiable The reifiable Topic Maps construct. + */ + private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { + Topic reifier = reifiable.getReifier(); + if (reifier != null) { + attrs.addAttribute("", "reifier", "", "CDATA", Integer.toString(_indexOf(reifier))); + } + } + + /** + * Normalizes the locator according to CXTM 3.19. + * + * @param locator The locator to normalize. + * @return A normalized representation of the locator. + */ + private String _normalizeLocator(final Locator locator) { + String normLoc = _locator2Norm.get(locator); + if (normLoc != null) { + return normLoc; + } + normLoc = locator.getReference(); + if (normLoc.startsWith(_normBase)) { + normLoc = normLoc.substring(_normBase.length()); + } + else { + int i = 0; + int slashPos = -1; + final int max = Math.min(_normBase.length(), normLoc.length()); + while(i < max && _normBase.charAt(i) == normLoc.charAt(i)) { + if (_normBase.charAt(i) == '/') { + slashPos = i; + } + i++; + } + if (slashPos > -1) { + normLoc = normLoc.substring(slashPos); + } + } + if (normLoc.startsWith("/")) { + normLoc = normLoc.substring(1); + } + _locator2Norm.put(locator, normLoc); + return normLoc; + } + + /** + * Normalizes the base locator according to the following procedure + * (CXTM 3.19 - 1.): + * <cite>[...] the base locator with any fragment identifier and query + * removed and any trailing "/" character removed.[...]</cite> + * + * @param baseLocator + * @return + */ + private static String _normalizeBaseLocator(final String baseLocator) { + String loc = baseLocator; + int i = loc.indexOf('#'); + if (i > 0) { + loc = loc.substring(0, i); + } + i = loc.indexOf('?'); + if (i > 0) { + loc = loc.substring(0, i); + } + if (loc.endsWith("/")) { + loc = loc.substring(0, loc.length()-1); + } + return loc; + } + + /** + * Writes a warning msg to the log. + * + * This method is used to inform the user that the serialized topic map + * is not valid acc. to CXTM. + * + * @param msg The warning message. + */ + private static void _reportInvalid(final String msg) { + LOG.warning("Invalid CXTM: '" + msg + "'"); + } + + + /* + * Comparators. + */ + + private final class TopicComparator implements Comparator<Topic> { + + public int compare(Topic o1, Topic o2) { + if (o1 == o2) { + return 0; + } + if (o1 != null && o2 == null) { + _reportInvalid("Comparing topics where one topic is null"); + return +1; + } + else if (o1 == null && o2 != null) { + _reportInvalid("Comparing topics where one topic is null"); + return -1; + } + int res = _locSetComparator.compare(o1.getSubjectIdentifiers(), o2.getSubjectIdentifiers()); + if (res == 0) { + res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators()); + if (res == 0) { + res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers()); + } + } + return res; + } + } + + /** + * Abstract comparator that provides some utility methods which handle common + * comparisons. + */ + private abstract class AbstractComparator<T> implements Comparator<T> { + int compareString(String o1, String o2) { + if (o1 == null && o2 != null) { + _reportInvalid("The first string value is null"); + return -1; + } + if (o1 != null && o2 == null) { + _reportInvalid("The second string value is null"); + return +1; + } + return o1.compareTo(o2); + } + /** + * Extracts the type of the typed Topic Maps constructs and compares + * the topics. + * + * @param o1 The first typed Topic Maps construct. + * @param o2 The second typed Topic Maps construct. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int compareType(Typed o1, Typed o2) { + return _topicComparator.compare(o1.getType(), o2.getType()); + } + /** + * Extracts the scope of the scoped Topic Maps constructs and compares + * them. + * + * @param o1 The first scoped Topic Maps construct. + * @param o2 The second scoped Topic Maps construct. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int compareScope(Scoped o1, Scoped o2) { + return _scopeComparator.compare(o1.getScope(), o2.getScope()); + } + } + + /** + * Enhances the {@link AbstractComparator} with a method to compare the + * value and datatype of an occurrence or variant. + */ + private abstract class AbstractDatatypeAwareComparator<T> extends AbstractComparator<T> { + /** + * Compares the value and datatype of the occurrences / variants. + * + * @param o1 The first occurrence / variant. + * @param o2 The second occurrence / variant. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) { + int res = compareString(o1.getValue(), o2.getValue()); + if (res == 0) { + res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference()); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [type] + * 2. [roles] + * 3. [scope] + * 4. [parent] + */ + private final class AssociationComparator extends AbstractComparator<Association> { + + private Comparator<Set<Role>> _roleSetComparator; + + AssociationComparator() { + _roleSetComparator = new RoleSetComparator(); + } + + public int compare(Association o1, Association o2) { + if (o1 == o2) { + return 0; + } + int res = compareType(o1, o2); + if (res == 0) { + res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles()); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + } + + /** + * Role comparator which ignores the parent association. This comparator + * is meant to be used for roles where the parent is known to be equal or + * unequal. + */ + private class RoleIgnoreParentComparator extends AbstractComparator<Role> { + + public int compare(Role o1, Role o2) { + if (o1 == o2) { + return 0; + } + int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); + if (res == 0) { + res = compareType(o1, o2); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [player] + * 2. [type] + * 3. [parent] + */ + private final class RoleComparator extends RoleIgnoreParentComparator { + + public int compare(Role o1, Role o2) { + if (o1 == o2) { + return 0; + } + int res = super.compare(o1, o2); + if (res == 0) { + res = _assocComparator.compare(o1.getParent(), o2.getParent()); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [type] + * 4. [scope] + * 5. [parent] + */ + private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { + + public int compare(Occurrence o1, Occurrence o2) { + if (o1 == o2) { + return 0; + } + int res = _compareValueDatatype(o1, o2); + if (res == 0) { + res = compareType(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [type] + * 3. [scope] + * 4. [parent] + */ + private final class NameComparator extends AbstractComparator<Name> { + + public int compare(Name o1, Name o2) { + if (o1 == o2) { + return 0; + } + int res = compareString(o1.getValue(), o2.getValue()); + if (res == 0) { + res = compareType(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [scope] + * 4. [parent] + */ + private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { + + public int compare(Variant o1, Variant o2) { + if (o1 == o2) { + return 0; + } + int res = _compareValueDatatype(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + return res; + } + } + + /** + * Comparator which compares the size of the provided set. + * + * Iff the size of the sets are equal, another comparison method is used + * to compare the content of the sets. + */ + private abstract class AbstractSetComparator<T> implements Comparator<Set<T>> { + + public int compare(Set<T> o1, Set<T> o2) { + int s1 = o1.size(); + int s2 = o2.size(); + int res = s1 - s2; + if (res == 0) { + res = compareContent(o1, o2, s1); + } + return res; + } + + /** + * Called iff the size of the sets is equal. + * + * This method is used to compare the content of the sets. + * + * @param o1 The first set. + * @param o2 The second set. + * @param size The size of the set(s). + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + abstract int compareContent(Set<T> o1, Set<T> o2, int size); + } + + /** + * Compares role sets. The parent of the roles is ignored! + */ + private final class RoleSetComparator extends AbstractSetComparator<Role> { + + private RoleIgnoreParentComparator _roleCmp; + + RoleSetComparator() { + _roleCmp = new RoleIgnoreParentComparator(); + } + + @Override + int compareContent(Set<Role> o1, Set<Role> o2, + int size) { + int res = 0; + Role[] roles1 = o1.toArray(new Role[size]); + Role[] roles2 = o2.toArray(new Role[size]); + Arrays.sort(roles1, _roleCmp); + Arrays.sort(roles2, _roleCmp); + for (int i=0; i < size && res == 0; i++) { + res = _roleCmp.compare(roles1[i], roles2[i]); + } + return res; + } + + } + + /** + * Compares the scope of two scoped Topic Maps constructs. + */ + private final class ScopeComparator extends AbstractSetComparator<Topic> { + + @Override + int compareContent(Set<Topic> o1, Set<Topic> o2, int size) { + int res = 0 ; + Topic[] topics1 = o1.toArray(new Topic[size]); + Topic[] topics2 = o2.toArray(new Topic[size]); + Arrays.sort(topics1, _topicComparator); + Arrays.sort(topics2, _topicComparator); + for (int i=0; i < size && res == 0; i++) { + res = _topicComparator.compare(topics1[i], topics2[i]); + } + return res; + } + + } + + /** + * Comparator for sets of {@link org.tmapi.core.Locator}s. + */ + private final class LocatorSetComparator extends AbstractSetComparator<Locator> { + + @Override + int compareContent(Set<Locator> o1, Set<Locator> o2, int size) { + int res = 0; + Locator[] locs1 = o1.toArray(new Locator[size]); + Locator[] locs2 = o2.toArray(new Locator[size]); + Arrays.sort(locs1, _locComparator); + Arrays.sort(locs2, _locComparator); + for (int i=0; i < size && res == 0; i++) { + res = _locComparator.compare(locs1[i], locs2[i]); + } + return res; + } + } + + /** + * Compares {@link org.tmapi.core.Locator}s. + */ + private final class LocatorComparator implements Comparator<Locator> { + + public int compare(Locator o1, Locator o2) { + if (o1 == o2) { + return 0; + } + return _normalizeLocator(o1).compareTo(_normalizeLocator(o2)); + } + + } + + + /* + * Helper classes to treat type-instance relationships, modelled as property + * of a topic, as associations. + */ + + private final class TypeInstanceTopic implements Topic { + + private final Set<Locator> _sids; + + TypeInstanceTopic(Locator sid) { + _sids = Collections.singleton(sid); + } + + public Set<Locator> getSubjectIdentifiers() { + return _sids; + } + + public void addItemIdentifier(Locator arg0) { } + public void addSubjectIdentifier(Locator arg0) {} + public void addSubjectLocator(Locator arg0) {} + public void addType(Topic arg0) {} + public Set<Occurrence> getOccurrences() { return Collections.emptySet(); } + public Reifiable getReified() { return null; } + public Set<Role> getRolesPlayed() { return Collections.emptySet(); } + public Set<Locator> getSubjectLocators() { return Collections.emptySet(); } + public Set<Name> getNames() { return Collections.emptySet(); } + public Set<Topic> getTypes() { return null; } + public void mergeIn(Topic arg0) { } + public void remove() throws TopicInUseException { } + public void removeSubjectIdentifier(Locator arg0) { } + public void removeSubjectLocator(Locator arg0) { } + public void removeType(Topic arg0) { } + public String getId() { return null; } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public TopicMap getTopicMap() { return null; } + public void removeItemIdentifier(Locator arg0) { } + public Name createName(String value, Collection<Topic> scope) { return null; } + public Name createName(String value, Topic... scope) {return null;} + public Name createName(Topic type, String value, Collection<Topic> scope) { return null; } + public Name createName(Topic type, String value, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { return null;} + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) {return null;} + public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Topic... scope) { return null; } + public Set<Name> getNames(Topic type) { return null; } + public Set<Occurrence> getOccurrences(Topic type) { return null;} + public TopicMap getParent() { return null; } + public Set<Role> getRolesPlayed(Topic type, Topic assocType) { return null; } + public Set<Role> getRolesPlayed(Topic type) { return null; } + + } + + /** + * Used to represent type-instance relationships which are modelled as + * [type] property of topics. + */ + private final class TypeInstanceAssociation implements Association { + + final Set<Role> _roles; + + TypeInstanceAssociation(Topic type, Topic instance) { + Role typeRole = new TypeInstanceRole(this, _type, type); + Role instanceRole = new TypeInstanceRole(this, _instance, instance); + _roles = new TypeInstanceRoleSet(typeRole, instanceRole); + } + + public Set<Role> getRoles() { + return _roles; + } + + public Topic getType() { + return _typeInstance; + } + + public Set<Topic> getRoleTypes() { return null; } + public Set<Role> getRoles(Topic type) { return null; } + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public TopicMap getParent() { return null; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public Role createRole(Topic arg0, Topic arg1) { return null; } + public Topic getReifier() { return null; } + public void remove() {} + public void setType(Topic arg0) {} + public void addTheme(Topic arg0) {} + public Set<Topic> getScope() { return Collections.emptySet(); } + public void removeTheme(Topic arg0) {} + public String getId() { return null; } + public TopicMap getTopicMap() { return null; } + } + + /** + * Immutable association role. + */ + private class TypeInstanceRole implements Role { + private final Topic _type; + private final Topic _player; + private final Association _parent; + + TypeInstanceRole(Association parent, Topic type, Topic player) { + _type = type; + _player = player; + _parent = parent; + List<Role> roles = _topic2Roles.get(player); + if (roles == null) { + roles = CollectionFactory.createList(); + _topic2Roles.put(player, roles); + } + roles.add(this); + } + + public Topic getType() { + return _type; + } + + public Topic getPlayer() { + return _player; + } + + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public Association getParent() { return _parent; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public Association getAssociation() { return _parent; } + public Topic getReifier() { return null; } + public void remove() {} + public void setPlayer(Topic arg0) {} + public void setType(Topic arg0) {} + public String getId() { return null; } + public TopicMap getTopicMap() { return null; } + } + + /** + * Immutable 'set' of two roles. + */ + private static class TypeInstanceRoleSet extends AbstractSet<Role> { + + private final Role _role1; + private final Role _role2; + + TypeInstanceRoleSet(Role role1, Role role2) { + _role1 = role1; + _role2 = role2; + } + + @Override + public Iterator<Role> iterator() { + return new TypeInstanceRoleSetIterator(); + } + + @Override + public int size() { + return 2; + } + + private class TypeInstanceRoleSetIterator implements Iterator<Role> { + + private int _idx; + + public boolean hasNext() { + return _idx < 2; + } + + public Role next() { + if (_idx > 1) { + throw new NoSuchElementException(); + } + return 0 == _idx++ ? _role1 : _role2; + } + + public void remove() { + new UnsupportedOperationException(); + } + } + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-11-15 13:02:58 UTC (rev 197) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-11-15 13:09:09 UTC (rev 198) @@ -1,1230 +0,0 @@ -/* - * 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.AbstractSet; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.logging.Logger; - -import org.tinytim.internal.utils.CollectionFactory; -import org.tinytim.utils.DuplicateRemovalUtils; -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.TopicInUseException; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; -import org.tmapi.core.Variant; -import org.tmapi.index.TypeInstanceIndex; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Provides serialization of topic maps into Canonical XTM (CXTM). - * <p> - * CXTM is a format that guarantees that two equivalent Topic Maps Data Model - * instances [ISO/IEC 13250-2] will always produce byte-by-byte identical - * serializations, and that non-equivalent instances will always produce - * different serializations. - * </p> - * <p> - * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> - * for details. - * </p> - * <p> - * <em>CAUTION</em>: This class implements the - * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, - * the output may change in the future. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class CXTMWriter implements TopicMapWriter { - - private static final Logger LOG = Logger.getLogger(CXTMWriter.class.getName()); - - private static final Role[] _EMPTY_ROLES = new Role[0]; - - private final AttributesImpl _attrs; - - private Topic _type; - private Topic _instance; - private Topic _typeInstance; - - private final XMLC14NWriter _out; - private final String _normBase; - private final Map<Construct, Integer> _construct2Id; - private final Map<Topic, List<Role>> _topic2Roles; - private final Map<Locator, String> _locator2Norm; - private final Map<Association, Role[]> _assoc2Roles; - - private final Comparator<Topic> _topicComparator; - private final Comparator<Association> _assocComparator; - private final Comparator<Role> _roleComparator; - private final Comparator<Occurrence> _occComparator; - private final Comparator<Name> _nameComparator; - private final Comparator<Variant> _variantComparator; - private final Comparator<Set<Locator>> _locSetComparator; - private final Comparator<Locator> _locComparator; - private final Comparator<Set<Topic>> _scopeComparator; - - /** - * Creates a canonicalizer. - * - * @param out The stream the CXTM is written onto. - * @param baseLocator The base locator which is used to resolve IRIs against. - * @throws IOException If an error occurs. - */ - public CXTMWriter(OutputStream out, String baseLocator) throws IOException { - if (baseLocator == null) { - throw new IllegalArgumentException("The base locator must not be null"); - } - _out = new XMLC14NWriter(out); - _attrs = new AttributesImpl(); - _normBase = _normalizeBaseLocator(baseLocator); - _construct2Id = CollectionFactory.createIdentityMap(); - _locator2Norm = CollectionFactory.createIdentityMap(); - _assoc2Roles = CollectionFactory.createIdentityMap(); - _topic2Roles = CollectionFactory.createIdentityMap(); - _topicComparator = new TopicComparator(); - _assocComparator = new AssociationComparator(); - _roleComparator = new RoleComparator(); - _occComparator = new OccurrenceComparator(); - _nameComparator = new NameComparator(); - _variantComparator = new VariantComparator(); - _locSetComparator = new LocatorSetComparator(); - _locComparator = new LocatorComparator(); - _scopeComparator = new ScopeComparator(); - } - - /** - * Serializes the specified <tt>topicMap</tt> into the CXTM format. - * <p> - * <em>CAUTION</em>: This method MAY modify the topic map since duplicate - * Topic Maps constructs (if any) are removed in advance. - * </p> - * - * @param topicMap The topic map to serialize. - * @throws IOException If an error occurs. - */ - public void write(TopicMap topicMap) throws IOException { - DuplicateRemovalUtils.removeDuplicates(topicMap); - TypeInstanceIndex typeInstanceIndex = topicMap.getIndex(TypeInstanceIndex.class); - if (!typeInstanceIndex.isAutoUpdated()) { - ... [truncated message content] |
From: <lh...@us...> - 2008-11-18 14:08:00
|
Revision: 200 http://tinytim.svn.sourceforge.net/tinytim/?rev=200&view=rev Author: lheuer Date: 2008-11-18 14:07:47 +0000 (Tue, 18 Nov 2008) Log Message: ----------- - CXTMTopicMapWriter: Datatype locators are not normalized anymore (not yet in the draft dtd. 2008-05-15) - XTM20TopicMapWriter: iids are taken into account - AbstractTopicMapReader: Did wrongly checked if field _deserializer is null and not against the argument "deserializer") - TinyTimMapInputHandler: * Tried to set an element outside the array to null. Fixed * Using construct.equals(other) instead of construct == other (since that may only work for the memory impl of tinyTiM) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-11-18 14:07:47 UTC (rev 200) @@ -71,7 +71,7 @@ protected AbstractTopicMapReader(final TopicMap topicMap, final Syntax syntax, final File source, final String docIRI) throws IOException { - this(topicMap, syntax, new Source(new FileInputStream(source), docIRI)); + this(topicMap, syntax, new FileInputStream(source), docIRI); } /** @@ -82,8 +82,8 @@ * @param source * @param docIRI */ - protected AbstractTopicMapReader(TopicMap topicMap, Syntax syntax, - InputStream source, String docIRI) { + protected AbstractTopicMapReader(final TopicMap topicMap, final Syntax syntax, + final InputStream source, final String docIRI) { this(topicMap, syntax, new Source(source, docIRI)); } @@ -108,14 +108,15 @@ */ protected AbstractTopicMapReader(final IMapHandler handler, final Syntax syntax, final Source source) { - this(handler, DeserializerRegistry.createDeserializer(syntax), source); + this(handler, DeserializerRegistry.createDeserializer(syntax), source, syntax); } protected AbstractTopicMapReader(final IMapHandler handler, - final IDeserializer deserializer, final Source source) { - if (_deserializer == null) { - throw new IllegalArgumentException("Deserializer not found"); + final IDeserializer deserializer, final Source source, final Syntax syntax) { + if (deserializer == null) { + throw new IllegalArgumentException("Deserializer for " + syntax.getName() + " not found"); } + _deserializer = deserializer; _deserializer.setProperty(Property.VALIDATE, Boolean.FALSE); _deserializer.setMapHandler(handler); _source = source; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapWriter.java 2008-11-18 14:07:47 UTC (rev 200) @@ -56,7 +56,8 @@ continue; } id = reference.substring(fragIdx+1); - if (id.startsWith("id")) { + System.out.println("Id: " + id); + if (id.startsWith("id-")) { id = null; } if (id != null) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2008-11-18 14:07:47 UTC (rev 200) @@ -33,7 +33,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class AbstractXTMTopicMapReader extends AbstractTopicMapReader { +public abstract class AbstractXTMTopicMapReader extends AbstractTopicMapReader { public AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, File source) throws IOException { 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-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-18 14:07:47 UTC (rev 200) @@ -448,7 +448,7 @@ _out.endElement("value"); _out.newline(); _out.startElement("datatype"); - _out.characters(_normalizeLocator(obj.getDatatype())); + _out.characters(obj.getDatatype().getReference()); _out.endElement("datatype"); _out.newline(); } @@ -652,7 +652,7 @@ normLoc = normLoc.substring(slashPos); } } - if (normLoc.startsWith("/")) { + if (normLoc.charAt(0) == '/') { normLoc = normLoc.substring(1); } _locator2Norm.put(locator, normLoc); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-11-18 14:07:47 UTC (rev 200) @@ -435,7 +435,7 @@ private IConstruct _leaveStatePopConstruct(int state) throws MIOException { _leaveState(state); final IConstruct construct = _peekConstruct(); - _constructStack[_constructSize] = null; + _constructStack[_constructSize-1] = null; _constructSize--; return construct; } @@ -494,7 +494,7 @@ */ private void _merge(Topic source, ITopic target) { for (int i=0; i <_constructSize; i++) { - if (_constructStack[i] == source) { + if (_constructStack[i].equals(source)) { _constructStack[i] = target; } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2008-11-18 14:07:47 UTC (rev 200) @@ -138,7 +138,6 @@ protected void _writeAssociation(final Association assoc) throws IOException { Set<Role> roles = assoc.getRoles(); if (roles.isEmpty()) { - LOG.info("Omitting association id " + assoc.getId() + " since it has no roles"); return; } _attrs.clear(); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java 2008-11-15 13:17:29 UTC (rev 199) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java 2008-11-18 14:07:47 UTC (rev 200) @@ -18,7 +18,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Set; -import java.util.logging.Logger; import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; @@ -53,8 +52,6 @@ */ public class XTM20TopicMapWriter extends AbstractXTMWriter { - private static final Logger LOG = Logger.getLogger(XTM20TopicMapWriter.class.getName()); - private Topic _defaultNameType; /** @@ -108,11 +105,12 @@ protected void _writeTopic(final Topic topic) throws IOException { // Ignore the topic if it is the default name type and it has no further - // characteristics (iids do not count) + // 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() @@ -142,7 +140,6 @@ protected void _writeAssociation(final Association assoc) throws IOException { Set<Role> roles = assoc.getRoles(); if (roles.isEmpty()) { - LOG.info("Omitting association id " + assoc.getId() + " since it has no roles"); return; } _out.startElement("association", _reifier(assoc)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-23 14:42:07
|
Revision: 231 http://tinytim.svn.sourceforge.net/tinytim/?rev=231&view=rev Author: lheuer Date: 2008-11-23 14:42:02 +0000 (Sun, 23 Nov 2008) Log Message: ----------- Aligned naming Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java Copied: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java (from rev 230, tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java) =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) @@ -0,0 +1,72 @@ +/* + * 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 org.xml.sax.helpers.AttributesImpl; + +/** + * Abstract superclass for XTM serializers. + * <p> + * Provides a XML writer and takes care about the encoding. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class AbstractXTMWriter extends AbstractTopicMapWriter { + + protected final AttributesImpl _attrs; + + protected final XMLWriter _out; + + /** + * Creates a new instance using "utf-8" encoding. + * + * @param out The output stream to write onto. + * @param baseIRI The base IRI. + * @throws IOException If an error occurs. + */ + protected AbstractXTMWriter(final OutputStream out, final String baseIRI) + throws IOException { + this(out, baseIRI, "utf-8"); + } + + /** + * Creates a new instance. + * + * @param out + * The output stream to write onto. + * @param baseIRI + * The base IRI. + * @param encoding + * The encoding to use. + * @throws IOException + * If an error occurs. + */ + protected AbstractXTMWriter(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); + _attrs = new AttributesImpl(); + } + +} Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java 2008-11-22 16:59:38 UTC (rev 230) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMWriter.java 2008-11-23 14:42:02 UTC (rev 231) @@ -1,72 +0,0 @@ -/* - * 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 org.xml.sax.helpers.AttributesImpl; - -/** - * Abstract superclass for XTM serializers. - * <p> - * Provides a XML writer and takes care about the encoding. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -abstract class AbstractXTMWriter extends AbstractTopicMapWriter { - - protected final AttributesImpl _attrs; - - protected final XMLWriter _out; - - /** - * Creates a new instance using "utf-8" encoding. - * - * @param out The output stream to write onto. - * @param baseIRI The base IRI. - * @throws IOException If an error occurs. - */ - protected AbstractXTMWriter(final OutputStream out, final String baseIRI) - throws IOException { - this(out, baseIRI, "utf-8"); - } - - /** - * Creates a new instance. - * - * @param out - * The output stream to write onto. - * @param baseIRI - * The base IRI. - * @param encoding - * The encoding to use. - * @throws IOException - * If an error occurs. - */ - protected AbstractXTMWriter(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); - _attrs = new AttributesImpl(); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-24 15:35:49
|
Revision: 234 http://tinytim.svn.sourceforge.net/tinytim/?rev=234&view=rev Author: lheuer Date: 2008-11-24 15:35:42 +0000 (Mon, 24 Nov 2008) Log Message: ----------- - Added a constructor to JTMTopicMapWriter to specify the encoding (default: utf-8) - Minor changes, mostly docs Modified 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/src/main/java/org/tinytim/mio/JSONWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java 2008-11-23 18:17:48 UTC (rev 233) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java 2008-11-24 15:35:42 UTC (rev 234) @@ -25,7 +25,7 @@ * 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:$ + * @version $Rev$ - $Date$ */ final class JSONWriter { @@ -34,27 +34,51 @@ private int _depth; private boolean _prettify; - public JSONWriter(OutputStream out) throws IOException { - _out = new OutputStreamWriter(out, "utf-8"); + public JSONWriter(OutputStream out, String encoding) throws IOException { + _out = new OutputStreamWriter(out, encoding); } + /** + * 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) { _prettify = 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 _prettify; } + /** + * Indicates the start of the serialization. + */ public void startDocument() { _depth = 0; } + /** + * Indicates the end of the serialization. + * + * @throws IOException If an error occurs. + */ public void endDocument() throws IOException { _out.write('\n'); _out.flush(); } + /** + * Indents a line, iff {@link #getPrettify()} is enabled. + * + * @throws IOException If an error occurs. + */ private void _indent() throws IOException { if (!_prettify) { return; @@ -70,6 +94,11 @@ _out.write(chars); } + /** + * Start of a JSON object. + * + * @throws IOException If an error occurs. + */ public void startObject() throws IOException { if (_wantComma) { _out.write(','); @@ -80,18 +109,33 @@ _wantComma = false; } + /** + * End of a JSON object. + * + * @throws IOException If an error occurs. + */ public void endObject() throws IOException { _out.write('}'); _depth--; _wantComma = true; } + /** + * Start of a JSON array. + * + * @throws IOException If an error occurs. + */ public void startArray() throws IOException { _out.write('['); _depth++; _wantComma = false; } + /** + * End of a JSON array. + * + * @throws IOException If an error occurs. + */ public void endArray() throws IOException { _out.write(']'); _depth--; @@ -103,8 +147,8 @@ * 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 + * @param key The key to write. + * @throws IOException If an error occurs. */ public void key(String key) throws IOException { if (_wantComma) { @@ -118,6 +162,12 @@ _wantComma = false; } + /** + * The value to write. The value is written in an escaped form. + * + * @param value The value to write. + * @throws IOException If an error occurs. + */ public void value(String value) throws IOException { if (_wantComma) { _out.write(','); @@ -127,10 +177,10 @@ } /** - * + * Escapes a string value. * - * @param value - * @return + * @param value The string to escape. + * @return An escaped string, usable as JSON value. */ public static String escape(String value) { // Code adapted from JSON.org (JSONObject.quote(String)) @@ -140,12 +190,11 @@ 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) { + for (int i=0; i<chars.length; i++) { b = c; c = chars[i]; - switch (chars[i]) { + switch (c) { case '\\': case '"': sb.append('\\'); @@ -175,9 +224,10 @@ 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("\\u000") + .append(Integer.toHexString(c)); + } + else { sb.append(c); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-23 18:17:48 UTC (rev 233) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-24 15:35:42 UTC (rev 234) @@ -59,15 +59,30 @@ private Topic _defaultNameType; /** + * Creates a JTM writer, using "utf-8" encoding. + * + * @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 { + this(out, baseIRI, "utf-8"); + } + + /** * 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. + * @param encoding The encoding to use. * @throws IOException If an error occurs. */ - public JTMTopicMapWriter(OutputStream out, String baseIRI) throws IOException { + public JTMTopicMapWriter(OutputStream out, String baseIRI, String encoding) throws IOException { + if (encoding == null) { + throw new IOException("The encoding must not be null"); + } _baseIRI = baseIRI; - _out = new JSONWriter(out); + _out = new JSONWriter(out, encoding); _out.setPrettify(true); } @@ -126,6 +141,16 @@ _out.endDocument(); } + /** + * Serializes the specified topic. + * <p> + * The default name type topic is omitted in case it carries no further + * characteristics. + * </p> + * + * @param topic The topic to serialize. + * @throws IOException If an error occurs. + */ private void _writeTopic(Topic topic) throws IOException { // Ignore the topic if it is the default name type and it has no further // characteristics @@ -165,6 +190,12 @@ _out.endObject(); } + /** + * Serializes the specified name. + * + * @param name The name to serialize. + * @throws IOException If an error occurs. + */ private void _writeName(Name name) throws IOException { _out.startObject(); _writeReifier(name); @@ -186,6 +217,12 @@ _out.endObject(); } + /** + * Serializes the specified variant. + * + * @param variant The variant to serialize. + * @throws IOException If an error occurs. + */ private void _writeVariant(Variant variant) throws IOException { _out.startObject(); _writeReifier(variant); @@ -195,6 +232,12 @@ _out.endObject(); } + /** + * Serializes the specifed occurrence. + * + * @param occ The occurrence. + * @throws IOException If an error occurs. + */ private void _writeOccurrence(Occurrence occ) throws IOException { _out.startObject(); _writeReifier(occ); @@ -205,6 +248,12 @@ _out.endObject(); } + /** + * Writes the value and datatype of an occurrence or variant. + * + * @param datatyped The datatype-aware construct. + * @throws IOException If an error occurs. + */ private void _writeDatatypeAware(DatatypeAware datatyped) throws IOException { Locator datatype = datatyped.getDatatype(); String value = XSD.ANY_URI.equals(datatype) ? datatyped.locatorValue().toExternalForm() @@ -213,10 +262,24 @@ _writeKeyValue("datatype", datatype.toExternalForm()); } + /** + * Serializes the item identifiers of the specified construct. + * + * @param construct The construct to serialize the iids from. + * @throws IOException If an error occurs. + */ private void _writeItemIdentifiers(Construct construct) throws IOException { _writeLocators("item_identifiers", construct.getItemIdentifiers()); } + /** + * Writes a set of locators under the specified name. If the set is + * empty, this method does nothing. + * + * @param name The name (item_identifiers, subject_identifiers, subject_locators) + * @param locators A (maybe empty) set of locators. + * @throws IOException If an error occurs. + */ private void _writeLocators(String name, Set<Locator> locators) throws IOException { if (locators.isEmpty()) { return; @@ -229,6 +292,12 @@ _out.endArray(); } + /** + * Serializes the specified asssociation. + * + * @param assoc The association to serialize. + * @throws IOException If an error occurs. + */ private void _writeAssociation(Association assoc) throws IOException { Set<Role> roles = assoc.getRoles(); if (roles.isEmpty()) { @@ -248,6 +317,12 @@ _out.endObject(); } + /** + * Serializes the specified role. + * + * @param role The role to serialize. + * @throws IOException If an error occurs. + */ private void _writeRole(Role role) throws IOException { _out.startObject(); _writeReifier(role); @@ -257,10 +332,22 @@ _out.endObject(); } + /** + * Writes the type of a typed construct. + * + * @param typed The typed construct. + * @throws IOException If an error occurs. + */ private void _writeType(Typed typed) throws IOException { _writeKeyValue("type", _topicRef(typed.getType())); } + /** + * Writes the scope. + * + * @param scoped The scoped construct to retrieve the scope from. + * @throws IOException If an error occurs. + */ private void _writeScope(Scoped scoped) throws IOException { IScope scope = ((IScoped) scoped).getScopeObject(); if (scope.isUnconstrained()) { @@ -303,6 +390,12 @@ _out.endObject(); } + /** + * Serializes the reifier iff the reifier is not <tt>null</tt>. + * + * @param reifiable The reifiable construct to retrieve the reifier from. + * @throws IOException If an error occurs. + */ private void _writeReifier(Reifiable reifiable) throws IOException { Topic reifier = reifiable.getReifier(); if (reifier == null) { @@ -311,6 +404,13 @@ _writeKeyValue("reifier", _topicRef(reifier)); } + /** + * Writes a key/value pair. + * + * @param key The key to write. + * @param value The value to write. + * @throws IOException If an error occurs. + */ private void _writeKeyValue(String key, String value) throws IOException { _out.key(key); _out.value(value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-25 14:18:15
|
Revision: 236 http://tinytim.svn.sourceforge.net/tinytim/?rev=236&view=rev Author: lheuer Date: 2008-11-25 14:18:12 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2008-11-25 14:11:21 UTC (rev 235) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2008-11-25 14:18:12 UTC (rev 236) @@ -47,7 +47,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 Logger LOG = Logger.getLogger(XTM10TopicMapWriter.class.getName()); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java 2008-11-25 14:11:21 UTC (rev 235) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM20TopicMapWriter.java 2008-11-25 14:18:12 UTC (rev 236) @@ -50,7 +50,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 Topic _defaultNameType; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-26 16:26:30
|
Revision: 238 http://tinytim.svn.sourceforge.net/tinytim/?rev=238&view=rev Author: lheuer Date: 2008-11-26 16:26:07 +0000 (Wed, 26 Nov 2008) Log Message: ----------- - Changed JTM links to the new (non-existing) JTM homepage - Added links to the RDF syntax specs Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFXMLTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrigTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrixTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TurtleTopicMapReader.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -30,7 +30,7 @@ /** * {@link TopicMapReader} implementation that deserializes - * <a href="http://www.cerny-online.com/topincs/technical-whitepaper">JSON Topic Maps (JTM)</a>. + * <a href="http://www.cerny-online.com/jtm/">JSON Topic Maps (JTM)</a>. * <p> * The reader does not accept fragments, i.e. only a topic in a JSON document; * each JTM instance must start with a topic map container, i.e. Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-26 16:26:07 UTC (rev 238) @@ -42,7 +42,7 @@ /** * A {@link TopicMapWriter} implementation that serializes a topic map into - * a <a href="http://www.cerny-online.com/topincs/technical-whitepaper">JSON Topic Maps (JTM)</a> + * a <a href="http://www.cerny-online.com/jtm/">JSON Topic Maps (JTM)</a> * representation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> @@ -83,12 +83,12 @@ } _baseIRI = baseIRI; _out = new JSONWriter(out, encoding); - _out.setPrettify(true); + _out.setPrettify(false); } /** - * Enables / disables newlines and indentation of JSON elements. - * (newlines and indentation is enabled by default) + * Enables / disables newlines and indentation of the JSON output. + * (disabled by default) * * @param prettify <tt>true</tt> to enable prettified JSON, otherwise <tt>false</tt>. */ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -25,7 +25,8 @@ import com.semagia.mio.Syntax; /** - * {@link RDFTopicMapReader} implementation that is able to deserialize RDF N3. + * {@link RDFTopicMapReader} implementation that is able to deserialize RDF + * <a href="http://www.w3c.org/2000/10/swap/Primer.html">N3</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -26,7 +26,7 @@ /** * {@link RDFTopicMapReader} implementation that is able to deserialize RDF - * N-Triples. + * <a href="http://www.w3.org/TR/rdf-testcases/#ntriples">N-Triples</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFXMLTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFXMLTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFXMLTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -25,7 +25,8 @@ import com.semagia.mio.Syntax; /** - * {@link RDFTopicMapReader} implementation that is able to deserialize RDF/XML. + * {@link RDFTopicMapReader} implementation that is able to deserialize + * <a href="http://www.w3.org/TR/rdf-syntax-grammar/">RDF/XML</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrigTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrigTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrigTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -25,7 +25,8 @@ import com.semagia.mio.Syntax; /** - * {@link RDFTopicMapReader} implementation that is able to deserialize RDF TriG. + * {@link RDFTopicMapReader} implementation that is able to deserialize RDF + * <a href="http://www.wiwiss.fu-berlin.de/suhl/bizer/TriG/Spec/">TriG</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrixTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrixTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrixTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -25,7 +25,8 @@ import com.semagia.mio.Syntax; /** - * {@link RDFTopicMapReader} implementation that is able to deserialize RDF TriX. + * {@link RDFTopicMapReader} implementation that is able to deserialize RDF + * <a href="http://swdev.nokia.com/trix/TriX.html">TriX</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TurtleTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TurtleTopicMapReader.java 2008-11-25 14:24:19 UTC (rev 237) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TurtleTopicMapReader.java 2008-11-26 16:26:07 UTC (rev 238) @@ -26,7 +26,7 @@ /** * {@link RDFTopicMapReader} implementation that is able to deserialize RDF - * Turtle. + * <a href="http://www.dajobe.org/2004/01/turtle/">Turtle</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-02-03 13:39:42
|
Revision: 258 http://tinytim.svn.sourceforge.net/tinytim/?rev=258&view=rev Author: lheuer Date: 2009-02-03 13:39:34 +0000 (Tue, 03 Feb 2009) Log Message: ----------- Fixed XTM 1.0 writer bug #2560821 -- "XTM 1.0 serializer uses wrong element for type" Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-01-28 15:28:36 UTC (rev 257) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-02-03 13:39:34 UTC (rev 258) @@ -215,9 +215,9 @@ } private void _writeType(final Typed typed) throws IOException { - _out.startElement("type"); + _out.startElement("instanceOf"); _writeTopicRef(typed.getType()); - _out.endElement("type"); + _out.endElement("instanceOf"); } private void _writeScope(final Scoped scoped) throws IOException { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-01-28 15:28:36 UTC (rev 257) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-02-03 13:39:34 UTC (rev 258) @@ -234,9 +234,9 @@ } private void _writeType(final ITyped typed) throws IOException { - _out.startElement("type"); + _out.startElement("instanceOf"); _writeTopicRef(typed.getType()); - _out.endElement("type"); + _out.endElement("instanceOf"); } private void _writeScope(final ScopedObject scoped) throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-02-26 15:31:43
|
Revision: 273 http://tinytim.svn.sourceforge.net/tinytim/?rev=273&view=rev Author: lheuer Date: 2009-02-26 15:31:30 +0000 (Thu, 26 Feb 2009) Log Message: ----------- Removed the hint that the CXTM writers implement a draft of CXTM. The output is compatible to the published version of ISO/IEC 13250-4 Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2009-02-26 14:29:35 UTC (rev 272) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2009-02-26 15:31:30 UTC (rev 273) @@ -65,11 +65,6 @@ * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> * for details. * </p> - * <p> - * <em>CAUTION</em>: This class implements the - * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, - * the output may change in the future. - * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java 2009-02-26 14:29:35 UTC (rev 272) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java 2009-02-26 15:31:30 UTC (rev 273) @@ -73,11 +73,6 @@ * for details. * </p> * <p> - * <em>CAUTION</em>: This class implements the - * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, - * the output may change in the future. - * </p> - * <p> * The canonicalizer IS NOT a generic TMAPI-compatible implementation. It * requires tinyTiM. The canonicalizer requires that the property * {@link org.tinytim.Property#XTM10_REIFICATION} is set to <tt>false</tt> and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-05-11 12:34:28
|
Revision: 297 http://tinytim.svn.sourceforge.net/tinytim/?rev=297&view=rev Author: lheuer Date: 2009-05-11 12:34:25 +0000 (Mon, 11 May 2009) Log Message: ----------- Fixed wrong imports in XTM10TopicMapWriter (tinyTiM 2.0) and fixed the XTM 1.0 writer of tinyTiM 1.5 (<variantName/> element was forgotten) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-05-10 15:17:05 UTC (rev 296) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-05-11 12:34:25 UTC (rev 297) @@ -33,10 +33,10 @@ import org.tmapi.core.TopicMap; import org.tmapi.core.Typed; import org.tmapi.core.Variant; -import org.topicmap.internal.api.IScope; -import org.topicmap.internal.api.IScoped; -import org.topicmap.voc.Namespace; -import org.topicmap.voc.XSD; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.IScoped; +import org.tinytim.voc.Namespace; +import org.tinytim.voc.XSD; import org.xml.sax.helpers.AttributesImpl; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-05-10 15:17:05 UTC (rev 296) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-05-11 12:34:25 UTC (rev 297) @@ -193,7 +193,9 @@ _writeTopicRef(theme); } _out.endElement("parameters"); + _out.startElement("variantName"); _writeDatatypeAware(variant); + _out.endElement("variantName"); _out.endElement("variant"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-07-23 12:21:29
|
Revision: 328 http://tinytim.svn.sourceforge.net/tinytim/?rev=328&view=rev Author: bosso Date: 2009-07-23 12:21:03 +0000 (Thu, 23 Jul 2009) Log Message: ----------- updated other-role-constraint tmcl changes Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-23 12:16:14 UTC (rev 327) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-23 12:21:03 UTC (rev 328) @@ -564,7 +564,8 @@ TMCL.ROLE_PLAYER_CONSTRAINT, TMCL.SCOPE_CONSTRAINT, TMCL.REIFIER_CONSTRAINT, TMCL.ASSOCIATION_ROLE_CONSTRAINT, - TMCL.OTHER_ROLE_CONSTRAINT, + TMCL.ROLE_COMBINATION_CONSTRAINT, + TMCL.TOPIC_REIFIES_CONSTRAINT, TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, TMCL.UNIQUE_VALUE_CONSTRAINT, TMCL.REGULAR_EXPRESSION_CONSTRAINT Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-23 12:16:14 UTC (rev 327) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-23 12:21:03 UTC (rev 328) @@ -48,6 +48,8 @@ */ public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { + @SuppressWarnings("unused") + // TODO can we remove it, if we don't use it? private static final Logger LOG = Logger .getLogger(DefaultTMCLPreprocessor.class.getName()); @@ -109,7 +111,6 @@ */ @Override public Set<Locator> getSuppressableSubjectIdentifiers() { - // TODO Auto-generated method stub return null; } @@ -150,7 +151,7 @@ _processOverlapConstraints(topicMap, tiIdx, topics, assocs); _processAssociationRoleConstraints(topicMap, tiIdx, topics, assocs); _processRolePlayerConstraints(topicMap, tiIdx, topics, assocs); - _processOtherRoleConstraints(topicMap, tiIdx, topics, assocs); + _processRoleCombinationConstraints(topicMap, tiIdx, topics, assocs); _processOccurrenceConstraints(topicMap, tiIdx, topics, assocs); _processNameConstraints(topicMap, tiIdx, topics, assocs); _processScopeConstraints(topicMap, tiIdx, topics, assocs); @@ -408,17 +409,17 @@ removeConstraint(constraint, topics, occCounter); } - private void _processOtherRoleConstraints(TopicMap topicMap, + private void _processRoleCombinationConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, - TMCL.OTHER_ROLE_CONSTRAINT)) { - _processOtherRoleConstraint(constraint, topics, assocs); + TMCL.ROLE_COMBINATION_CONSTRAINT)) { + _processRoleCombinationConstraint(constraint, topics, assocs); } } - private void _processOtherRoleConstraint(Topic constraint, + private void _processRoleCombinationConstraint(Topic constraint, Collection<Topic> topics, Collection<Association> assocs) { Topic type = _getConstrainedTopicTypePlayer(constraint, assocs); Topic assocType = _getConstrainedStatementPlayer(constraint, assocs); @@ -427,7 +428,7 @@ Topic otherPlayer = _getOtherConstrainedTopicTypePlayer(constraint, assocs); - DefaultTemplate tpl = new DefaultTemplate("other-role"); + DefaultTemplate tpl = new DefaultTemplate("role-combination"); tpl.addParameter(roleType); tpl.addParameter(type); tpl.addParameter(otherRole); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-08-17 10:56:25
|
Revision: 350 http://tinytim.svn.sourceforge.net/tinytim/?rev=350&view=rev Author: bosso Date: 2009-08-17 10:56:16 +0000 (Mon, 17 Aug 2009) Log Message: ----------- minor bugfix Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-17 10:43:24 UTC (rev 349) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-17 10:56:16 UTC (rev 350) @@ -561,7 +561,8 @@ TMCL.SUBJECT_LOCATOR_CONSTRAINT, TMCL.TOPIC_NAME_CONSTRAINT, TMCL.TOPIC_OCCURRENCE_CONSTRAINT, - TMCL.ROLE_PLAYER_CONSTRAINT, TMCL.SCOPE_CONSTRAINT, + TMCL.TOPIC_ROLE_CONSTRAINT, + TMCL.SCOPE_CONSTRAINT, TMCL.REIFIER_CONSTRAINT, TMCL.ASSOCIATION_ROLE_CONSTRAINT, TMCL.ROLE_COMBINATION_CONSTRAINT, Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-17 10:43:24 UTC (rev 349) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-17 10:56:16 UTC (rev 350) @@ -150,6 +150,7 @@ _processNameConstraints(topicMap, tiIdx, topics, assocs); _processScopeConstraints(topicMap, tiIdx, topics, assocs); _processReifierConstraints(topicMap, tiIdx, topics, assocs); + _processTopicReifiesConstraints(topicMap, tiIdx, topics, assocs); _processBelongsToSchema(topicMap, tiIdx, topics, assocs); } @@ -345,17 +346,17 @@ TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, - TMCL.BELONGS_TO_SCHEMA)) { + TMCL.REIFIER_CONSTRAINT)) { _processReifierConstraint(constraint, topics, assocs); } } - + private void _processReifierConstraint(Topic constraint, Collection<Topic> topics, Collection<Association> assocs) { - Topic reifierType = _getConstrainedStatementPlayer(constraint, assocs); - Topic reifiableType = _getAllowedReifierPlayer(constraint, assocs); - + Topic reifiableType = _getConstrainedStatementPlayer(constraint, assocs); + Topic reifierType = _getAllowedReifierPlayer(constraint, assocs); + ILiteral cardMin = _getCardMin(constraint); ILiteral cardMax = _getCardMax(constraint); DefaultTemplate tpl = null; @@ -371,10 +372,47 @@ else { tpl = new DefaultTemplate("may-have-reifier"); tpl.addParameter(reifierType); + + } + + _registerTemplate(reifiableType, tpl); + removeConstraint(constraint, topics, 2); + } + private void _processTopicReifiesConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.TOPIC_REIFIES_CONSTRAINT)) { + _processTopicReifiesConstraint(constraint, topics, assocs); } - _registerTemplate(reifiableType, tpl); + } + + private void _processTopicReifiesConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic reifiableType = _getConstrainedStatementPlayer(constraint, assocs); + Topic reifierType = _getConstrainedTopicTypePlayer(constraint, assocs); + + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + DefaultTemplate tpl = null; + if (cardMin.getValue().equals(cardMax.getValue())) { + if (cardMin.getValue().equals("0")) { + tpl = new DefaultTemplate("cannot-reify"); + } + else { + tpl = new DefaultTemplate("must-reify"); + tpl.addParameter(reifiableType); + } + } + else { + tpl = new DefaultTemplate("may"); + tpl.addParameter(reifiableType); + + } + + _registerTemplate(reifierType, tpl); removeConstraint(constraint, topics, 2); } @@ -382,7 +420,7 @@ TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, - TMCL.ROLE_PLAYER_CONSTRAINT)) { + TMCL.TOPIC_ROLE_CONSTRAINT)) { _processRolePlayerConstraint(constraint, topics, assocs); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2009-08-18 12:54:58
|
Revision: 355 http://tinytim.svn.sourceforge.net/tinytim/?rev=355&view=rev Author: bosso Date: 2009-08-18 12:54:43 +0000 (Tue, 18 Aug 2009) Log Message: ----------- * bugfix in TemplateProcessor * removed TMDM.Subject removal Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-18 11:37:46 UTC (rev 354) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-18 12:54:43 UTC (rev 355) @@ -469,12 +469,6 @@ _newline(); _writeSection("INSTANCES"); _writeSection("Topics"); - // remove tmdm:subject, because filter below doesn't work. tmdm:subject plays a role, so - // _omitTopic returns false - we definitly don't want "tmdm:subject ." in our ctm file, do we? - Topic topic = topicMap.getTopicBySubjectIdentifier(TMDM.SUBJECT); - if (topic != null) { - topics.remove(topic); - } _writeTopics(topics); if (!assocs.isEmpty()) { Association[] assocArray = assocs.toArray(new Association[assocs.size()]); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-18 11:37:46 UTC (rev 354) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-18 12:54:43 UTC (rev 355) @@ -602,9 +602,10 @@ } DefaultTemplate tpl = new DefaultTemplate(templateName); + occCounter = _assignCardinality(constraint, tpl, occCounter); tpl.addParameter(regEx); - occCounter = _assignCardinality(constraint, tpl, occCounter); + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); _registerTemplate(player, tpl); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |