From: <lh...@us...> - 2008-08-17 10:03:00
|
Revision: 130 http://tinytim.svn.sourceforge.net/tinytim/?rev=130&view=rev Author: lheuer Date: 2008-08-17 10:03:04 +0000 (Sun, 17 Aug 2008) Log Message: ----------- - Renamed MapInputHandler into TinyTimMapInputHandler (again) :/ - CXTMWriter creates valid sax.Attributes (no null for QName and type) - XMLC14NWriter avoids creating StringBuilder and emits escaped characters directly Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 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/ITopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.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/XMLC14NWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.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-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -41,7 +41,7 @@ * the discovery of an appropriate deserializer transparently. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractTopicMapReader implements ITopicMapReader { @@ -52,7 +52,7 @@ if (_deserializer == null) { throw new TMAPIRuntimeException("Appropriate deserializer not found for syntax " + syntax.getName()); } - _deserializer.setMapHandler(new MapInputHandler(topicMap)); + _deserializer.setMapHandler(new TinyTimMapInputHandler(topicMap)); } /* (non-Javadoc) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.semagia.com/tr/btm/1.0/">Binary Topic Maps (BTM) 1.0</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class BTMReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -32,7 +32,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class CTMReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -85,6 +85,8 @@ private static final Role[] _EMPTY_ROLES = new Role[0]; + private AttributesImpl _attrs; + private Topic _type; private Topic _instance; private Topic _typeInstance; @@ -119,6 +121,7 @@ throw new IllegalArgumentException("The base locator must not be null"); } _out = new XMLC14NWriter(out); + _attrs = new AttributesImpl(); _normBase = _normalizeBaseLocator(baseLocator); _topicComparator = new TopicComparator(); _assocComparator = new AssociationComparator(); @@ -353,7 +356,7 @@ */ private void _writeTopic(final Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); + attrs.addAttribute("", "number", "", "CDATA", "" +_indexOf(topic)); _out.startElement("topic", attrs); _out.newline(); _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); @@ -381,7 +384,7 @@ .append(_indexOf(roles[i].getParent())) .append(".role.") .append(_indexOf(roles[i])); - roleAttrs.addAttribute("", "ref", null, null, sb.toString()); + roleAttrs.addAttribute("", "ref", "", "CDATA", sb.toString()); _out.startElement("rolePlayed", roleAttrs); _out.endElement("rolePlayed"); _out.newline(); @@ -591,7 +594,7 @@ return XMLC14NWriter.EMPTY_ATTRS; } AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", null, null, "" + _indexOf(topic)); + attrs.addAttribute("", "topicref", "", "CDATA", "" + _indexOf(topic)); return attrs; } @@ -605,10 +608,10 @@ * the number of the provided Topic Maps construct. */ private Attributes _attributes(final Reifiable reifiable, int i) { - AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, reifiable); - attrs.addAttribute("", "number", null, null, "" + i); - return attrs; + _attrs.clear(); + _addReifier(_attrs, reifiable); + _attrs.addAttribute("", "number", "", "CDATA", "" + i); + return _attrs; } /** @@ -622,7 +625,7 @@ private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { - attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); + attrs.addAttribute("", "reifier", "", "CDATA", "" + _indexOf(reifier)); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -34,7 +34,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ITopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ITopicMapWriter { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.ontopia.net/download/ltm.html">Linear Topic Map Notation (LTM) 1.3</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class LTMReader extends AbstractTopicMapReader { Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -1,44 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.mio; - -import org.tinytim.core.AbstractMapInputHandler; -import org.tmapi.core.TopicMap; - -/** - * {@link com.semagia.mio.IMapHandler} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class MapInputHandler extends AbstractMapInputHandler { - - /** - * Intitializes a new <tt>MapInputHandler</tt> instance with the specified - * <tt>topicMap</tt>. - * - * @param topicMap The {@link TopicMap} instance. - */ - public MapInputHandler(final TopicMap topicMap) { - super(topicMap); - } - -} Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.semagia.com/tr/snello/1.0/">Snello Topic Maps (STM) 1.0</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class SnelloReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class TMXMLReader extends AbstractTopicMapReader { Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tinytim.core.AbstractMapInputHandler; +import org.tmapi.core.TopicMap; + +/** + * {@link com.semagia.mio.IMapHandler} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class TinyTimMapInputHandler extends AbstractMapInputHandler { + + /** + * Intitializes a new <tt>MapInputHandler</tt> instance with the specified + * <tt>topicMap</tt>. + * + * @param topicMap The {@link TopicMap} instance. + */ + public TinyTimMapInputHandler(final TopicMap topicMap) { + super(topicMap); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -100,7 +100,7 @@ _out.write(' '); _out.write(names[i]); _out.write("=\""); - _out.write(_escapeAttributeValue(attrs.getValue("", names[i]))); + _writeEscapedAttributeValue(attrs.getValue("", names[i])); _out.write('"'); } _out.write('>'); @@ -136,7 +136,7 @@ * @throws IOException If an error occurs. */ public void characters(String data) throws IOException { - _out.write(_escapeTextContent(data)); + _writeEscapedTextContent(data); } /** @@ -144,29 +144,28 @@ * * @param value The value. * @return The escaped value. + * @throws IOException */ - private String _escapeTextContent(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i < data.length; i++) { - char c = data[i]; - if (c == '\r') { - sb.append("
"); + private void _writeEscapedTextContent(String value) throws IOException { + char[] ch = value.toCharArray(); + for (int i=0; i < ch.length; i++) { + switch(ch[i]) { + case '\r': + _out.write("
"); + break; + case '&': + _out.write("&"); + break; + case '<': + _out.write("<"); + break; + case '>': + _out.write(">"); + break; + default: + _out.write(ch[i]); } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else if (c == '>') { - sb.append(">"); - } - else { - sb.append(c); - } } - return sb.toString(); } /** @@ -174,34 +173,33 @@ * * @param value The value to escape. * @return The escaped value. + * @throws IOException */ - private String _escapeAttributeValue(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i<data.length; i++) { - char c = data[i]; - if (c == '\t') { - sb.append("	"); + private void _writeEscapedAttributeValue(String value) throws IOException { + char[] ch = value.toCharArray(); + for (int i=0; i<ch.length; i++) { + switch(ch[i]) { + case '\t': + _out.write("	"); + break; + case '\n': + _out.write("
"); + break; + case '\r': + _out.write("
"); + break; + case '\"': + _out.write("""); + break; + case '&': + _out.write("&"); + break; + case '<': + _out.write("<"); + break; + default: + _out.write(ch[i]); } - else if (c == '\n') { - sb.append("
"); - } - else if (c == '\r') { - sb.append("
"); - } - else if (c == '\"') { - sb.append("""); - } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else { - sb.append(c); - } } - return sb.toString(); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -33,7 +33,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class XTMReader extends AbstractTopicMapReader { Deleted: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -1,324 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.mio; - -import org.tinytim.core.TinyTimTestCase; -import org.tinytim.voc.TMDM; -import org.tinytim.voc.XSD; -import org.tmapi.core.Locator; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; - -import com.semagia.mio.MIOException; -import com.semagia.mio.helpers.Ref; - -/** - * Tests against the {@link org.tinytim.core.AbstractMapInputHandler}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestMapInputHandler extends TinyTimTestCase { - - private static final String _XSD_STRING = XSD.STRING.getReference(); - private static final String _XSD_ANY_URI = XSD.ANY_URI.getReference(); - - private MapInputHandler _handler; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - _handler = new MapInputHandler(_tm); - } - - /** - * Simple startTopicMap, followed by an endTopicMap event. - */ - public void testEmpty() throws Exception { - assertEquals(0, _tm.getTopics().size()); - assertEquals(0, _tm.getAssociations().size()); - _handler.startTopicMap(); - _handler.endTopicMap(); - assertEquals(0, _tm.getTopics().size()); - assertEquals(0, _tm.getAssociations().size()); - } - - /** - * Tests reifying a topic map. - */ - public void testTMReifier() throws Exception { - String itemIdent = "http://sf.net/projects/tinytim/test#1"; - assertEquals(0, _tm.getTopics().size()); - assertEquals(0, _tm.getAssociations().size()); - _handler.startTopicMap(); - _handler.startReifier(); - _handler.startTopic(Ref.createItemIdentifier(itemIdent)); - _handler.endTopic(); - _handler.endReifier(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - assertEquals(0, _tm.getAssociations().size()); - Topic topic = (Topic) _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent)); - assertNotNull(topic); - assertNotNull(_tm.getReifier()); - assertEquals(topic, _tm.getReifier()); - } - - /** - * Tests topic creation with an item identifier. - */ - public void testTopicIdentityItemIdentifier() throws Exception { - String itemIdent = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createItemIdentifier(itemIdent)); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Topic topic = (Topic) _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent)); - assertNotNull(topic); - } - - /** - * Tests topic creation with a subject identifier. - */ - public void testTopicIdentitySubjectIdentifier() throws Exception { - String subjIdent = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(subjIdent)); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(subjIdent)); - assertNotNull(topic); - } - - /** - * Tests topic creation with a subject locator. - */ - public void testTopicIdentitySubjectLocator() throws Exception { - String subjLoc = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectLocator(subjLoc)); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Topic topic = _tm.getTopicBySubjectLocator(_tm.createLocator(subjLoc)); - assertNotNull(topic); - } - - /** - * Tests transparent merging. - */ - public void testTopicMerging() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String itemIdent = "http://example.org/1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - // Topic in topic event - _handler.startTopic(Ref.createItemIdentifier(itemIdent)); - _handler.itemIdentifier(ref); - _handler.endTopic(); - _handler.startOccurrence(); - _handler.value("tinyTiM", _XSD_STRING); - _handler.endOccurrence(); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); - assertNotNull(topic); - assertEquals(topic, _tm.getConstructByItemIdentifier(_tm.createLocator(ref))); - assertEquals(topic, _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent))); - assertEquals(1, topic.getOccurrences().size()); - Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); - assertEquals("tinyTiM", occ.getValue()); - } - - /** - * Tests assigning identities to a topic. - */ - public void testTopicIdentities1() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.itemIdentifier(ref); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Locator loc = _tm.createLocator(ref); - Topic topic = _tm.getTopicBySubjectIdentifier(loc); - assertNotNull(topic); - assertEquals(topic, _tm.getConstructByItemIdentifier(loc)); - } - - /** - * Tests assigning identities to a topic. - */ - public void testTopicIdentities2() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createItemIdentifier(ref)); - _handler.subjectIdentifier(ref); - _handler.endTopic(); - _handler.endTopicMap(); - assertEquals(1, _tm.getTopics().size()); - Locator loc = _tm.createLocator(ref); - Topic topic = _tm.getTopicBySubjectIdentifier(loc); - assertNotNull(topic); - assertEquals(topic, _tm.getConstructByItemIdentifier(loc)); - } - - /** - * Tests reifying the topic map. - */ - public void testTopicMapReifier() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - _handler.startTopicMap(); - _handler.startReifier(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.endTopic(); - _handler.endReifier(); - _handler.endTopicMap(); - assertNotNull(_tm.getReifier()); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); - assertNotNull(topic); - assertEquals(topic, _tm.getReifier()); - } - - /** - * Tests occurrence creation with a value of datatype xsd:string. - */ - public void testOccurrenceValueString() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String val = "tinyTiM"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.startOccurrence(); - _handler.value(val, _XSD_STRING); - _handler.endOccurrence(); - _handler.endTopic(); - _handler.endTopicMap(); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); - assertNotNull(topic); - Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); - assertEquals(val, occ.getValue()); - assertEquals(XSD.STRING, occ.getDatatype()); - } - - /** - * Tests occurrence creation with a value of datatype xsd:anyURI. - */ - public void testOccurrenceValueURI() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String val = "http://sf.net/projects/tinytim"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.startOccurrence(); - _handler.value(val, _XSD_ANY_URI); - _handler.endOccurrence(); - _handler.endTopic(); - _handler.endTopicMap(); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); - assertNotNull(topic); - Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); - assertEquals(val, occ.getValue()); - assertEquals(XSD.ANY_URI, occ.getDatatype()); - } - - /** - * Tests if the name type is automatically set. - */ - public void testDefaultNameType() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String val = "tinyTiM"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.startName(); - _handler.value(val); - _handler.endName(); - _handler.endTopic(); - _handler.endTopicMap(); - Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); - assertNotNull(topic); - Name name = topic.getNames().iterator().next(); - assertEquals(val, name.getValue()); - assertNotNull(name.getType()); - assertTrue(name.getType().getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)); - } - - /** - * Tests if a variant with no scope is reported as error. - */ - public void testVariantNoScopeError() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String val = "tinyTiM"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.startName(); - _handler.value(val); - _handler.startVariant(); - _handler.value(val, _XSD_STRING); - try { - _handler.endVariant(); - fail("A variant with no scope shouldn't be allowed"); - } - catch (MIOException ex) { - // noop. - } - } - - /** - * Tests if a variant with a scope equals to the parent's scope is rejected. - */ - public void testVariantNoScopeError2() throws Exception { - String ref = "http://sf.net/projects/tinytim/test#1"; - String theme = "http://sf.net/projects/tinytim/test#theme"; - String val = "tinyTiM"; - _handler.startTopicMap(); - _handler.startTopic(Ref.createSubjectIdentifier(ref)); - _handler.startName(); - _handler.startScope(); - _handler.startTheme(); - _handler.topicRef(Ref.createItemIdentifier(theme)); - _handler.endTheme(); - _handler.endScope(); - _handler.value(val); - - _handler.startVariant(); - _handler.value(val, _XSD_STRING); - _handler.startScope(); - _handler.startTheme(); - _handler.topicRef(Ref.createItemIdentifier(theme)); - _handler.endTheme(); - _handler.endScope(); - try { - _handler.endVariant(); - fail("A variant with a scope equals to the parent's scope shouldn't be allowed"); - } - catch (MIOException ex) { - // noop. - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |