From: Xuan B. <med...@us...> - 2007-04-12 12:57:56
|
Update of /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv3702/src/org/tm4j/topicmap/utils Modified Files: TopicMapHandler.java XTMBuilder.java XTMParser.java Log Message: Some XTM 2.0 reading support, applying to the current data model. Some XTM 2.0 features are still unsupported. This change should be very compatible, thus applying this change before branching into a release 1.0 branch and a more advanced branch. Index: XTMBuilder.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils/XTMBuilder.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** XTMBuilder.java 27 Sep 2004 19:14:24 -0000 1.72 --- XTMBuilder.java 12 Apr 2007 12:57:48 -0000 1.73 *************** *** 94,97 **** --- 94,98 ---- * @author <a href="mailto:ka...@te...">Kal Ahmed</a> * @author <a href="har...@we...">Harald Kuhn</a> (support for Reader) + * @author <a href="mailto:xua...@ba...">Xuan Baldauf</a> (some XTM2 support) */ public class XTMBuilder implements TopicMapHandler, TopicMapBuilder { *************** *** 985,988 **** --- 986,990 ---- case REFTYPE_SUBJECTINDICATOR: + case REFTYPE_SUBJECTIDENTIFIER: if (purpose != SUBJECTIDENTITY) { *************** *** 993,997 **** case REFTYPE_TOPIC: ! refTopic = getTopicBySourceLocator(expandedRef); break; --- 995,1003 ---- case REFTYPE_TOPIC: ! if (purpose != SUBJECTIDENTITY) { // This has side-effects for XTM 1.0, but this is considered correct. ! refTopic = getTopicBySubjectIndicator(expandedRef.getAddress()); ! } else { ! refTopic = getTopicBySourceLocator(expandedRef); ! } break; *************** *** 1092,1095 **** --- 1098,1106 ---- m_currScope.add(refTopic); + case 0: + if (refType == REFTYPE_SUBJECTIDENTIFIER) { + m_currTopic.addSubjectIndicator(m_locatorFactory.createLocator("URI", expandedRef.getAddress())); + } + break; } *************** *** 1748,1751 **** --- 1759,1765 ---- /* * $Log$ + * Revision 1.73 2007/04/12 12:57:48 mediumnet + * Some XTM 2.0 reading support, applying to the current data model. Some XTM 2.0 features are still unsupported. This change should be very compatible, thus applying this change before branching into a release 1.0 branch and a more advanced branch. + * * Revision 1.72 2004/09/27 19:14:24 kal_ahmed * Builder now handles out-of-order scope elements better. Index: XTMParser.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils/XTMParser.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** XTMParser.java 7 Oct 2004 16:29:33 -0000 1.19 --- XTMParser.java 12 Apr 2007 12:57:48 -0000 1.20 *************** *** 25,28 **** --- 25,32 ---- + /** + * @author unknown <!-- please fix --> + * @author <a href="mailto:xua...@ba...">Xuan Baldauf</a> (some XTM2 support) + */ public class XTMParser extends DefaultHandler implements ContentHandler, ErrorHandler { *************** *** 51,54 **** --- 55,73 ---- public static final String XTM_NS_URI = "http://www.topicmaps.org/xtm/1.0/"; public static final String XLINK_NS_URI = "http://www.w3.org/1999/xlink"; + + public static final String XTM2_NS_URI = "http://www.topicmaps.org/xtm/"; + public static final String SUBJECTIDENTIFIER = "subjectIdentifier"; + public static final String NAME = "name"; + public static final String VALUE = "value"; + public static final String TYPE = "type"; + public static final String ROLE = "role"; + + /** + XTM 2.0 support is a quick&dirty kludge and it is incomplete. + Shall it be replaced by something better. + But as long nothing better is there... + */ + protected final static boolean enableXTM2support = true; + private static Stack m_classStack; private static Stack m_xmlBaseStack; *************** *** 58,63 **** private TopicMapHandler m_builder; ! private Log m_log = LogFactory.getLog(XTMParser.class); ! // optional XML catalog resolver private CatalogResolver m_catalogResolver = null; --- 77,82 ---- private TopicMapHandler m_builder; ! private Log m_log = LogFactory.getLog(XTMParser.class); ! // optional XML catalog resolver private CatalogResolver m_catalogResolver = null; *************** *** 163,166 **** --- 182,195 ---- } else if (xtmClass.equals(MERGEMAP)) { parseMergeMap(atts); + } else if (enableXTM2support&&xtmClass.equals(SUBJECTIDENTIFIER)) { + parseSubjectIdentifier(atts); + } else if (enableXTM2support&&xtmClass.equals(NAME)) { + parseNameStart(atts); + } else if (enableXTM2support&&xtmClass.equals(VALUE)) { + parseValueStart(atts); + } else if (enableXTM2support&&xtmClass.equals(TYPE)) { + parseTypeStart(atts); + } else if (enableXTM2support&&xtmClass.equals(ROLE)) { + parseRoleStart(atts); } else if (nsURI.equals(XTM_NS_URI)) { throw new TopicMapProcessingException( *************** *** 220,223 **** --- 249,264 ---- } else if (xtmClass.equals(MERGEMAP)) { m_builder.endMergeMap(); + } else if (xtmClass.equals(SUBJECTIDENTITY)) { + m_builder.endSubjectIdentity(); + } else if (enableXTM2support&&xtmClass.equals(SUBJECTIDENTIFIER)) { + /* do nothing special */ + } else if (enableXTM2support&&xtmClass.equals(NAME)) { + parseNameEnd(); + } else if (enableXTM2support&&xtmClass.equals(VALUE)) { + parseValueEnd(); + } else if (enableXTM2support&&xtmClass.equals(TYPE)) { + parseTypeEnd(); + } else if (enableXTM2support&&xtmClass.equals(ROLE)) { + parseRoleEnd(); } } catch (TopicMapProcessingException ex) { *************** *** 274,278 **** (String) m_xmlBaseStack.peek()); } else { ! warn("Encoutered topicRef element with no xlink:href attribute value. This element will be ignored."); } } --- 315,319 ---- (String) m_xmlBaseStack.peek()); } else { ! warn("Encoutered topicRef element with no xlink:href attribute value. This element will be ignored."); } } *************** *** 287,291 **** (String) m_xmlBaseStack.peek()); } else { ! warn("Encoutered resourceRef element with no xlink:href attribute value. This element will be ignored."); } } --- 328,332 ---- (String) m_xmlBaseStack.peek()); } else { ! warn("Encoutered resourceRef element with no xlink:href attribute value. This element will be ignored."); } } *************** *** 300,304 **** (String) m_xmlBaseStack.peek()); } else { ! warn("Encountered a subjectIndicatorRef element with no xlink:href attribute. This element will be ignored."); } } --- 341,345 ---- (String) m_xmlBaseStack.peek()); } else { ! warn("Encountered a subjectIndicatorRef element with no xlink:href attribute. This element will be ignored."); } } *************** *** 374,378 **** --- 415,485 ---- m_builder.startMergeMap(id, ref, (String) m_xmlBaseStack.peek()); } + + + + + public void parseSubjectIdentifier(Attributes atts) + throws TopicMapProcessingException { + String id = getXTMAttribute(ID, atts); + String ref = getXTMAttribute(HREF, atts); + if (ref != null) { + m_builder.ref(id, TopicMapHandler.REFTYPE_SUBJECTIDENTIFIER, ref, (String) m_xmlBaseStack.peek()); + } else { + warn("Encountered a subjectIdentifier element with no href attribute. This element will be ignored."); + } + } + + public void parseNameStart(Attributes atts) throws TopicMapProcessingException { + // FIXME: need to process type + parseBaseName(atts); + } + + public void parseValueStart(Attributes atts) throws TopicMapProcessingException { + // FIXME: need to process type + parseBaseNameString(atts); + } + + public void parseValueEnd() throws TopicMapProcessingException { + m_builder.baseNameString(m_id, m_data.toString()); + m_data = null; + m_getData = false; + } + + public void parseNameEnd() throws TopicMapProcessingException { + m_builder.endBaseName(); + } + + public void parseTypeStart(Attributes atts) throws TopicMapProcessingException { + switch (((XTMBuilder) m_builder).peekPurpose()) { + case XTMBuilder.MEMBER: + parseRoleSpec(atts); + break; + default: + parseInstanceOf(atts); + } + } + + public void parseTypeEnd() throws TopicMapProcessingException { + switch (((XTMBuilder) m_builder).peekPurpose()) { + case XTMBuilder.ROLESPEC: + m_builder.endRoleSpec(); + break; + case XTMBuilder.INSTANCEOF: + m_builder.endInstanceOf(); + break; + default: + throw new UnsupportedOperationException(); + } + } + + public void parseRoleStart(Attributes atts) throws TopicMapProcessingException { + parseMember(atts); + } + + public void parseRoleEnd() throws TopicMapProcessingException { + m_builder.endMember(); + } + protected String getXTMAttribute(String localName, Attributes atts) { String ret = atts.getValue(XTM_NS_URI, localName); *************** *** 403,407 **** protected String getXLinkAttribute(String localName, Attributes atts) { ! return atts.getValue(XLINK_NS_URI, localName); } --- 510,524 ---- protected String getXLinkAttribute(String localName, Attributes atts) { ! String ret = atts.getValue(XLINK_NS_URI, localName); ! ! if (enableXTM2support&&(ret==null)) { ! ret = atts.getValue(XTM2_NS_URI, localName); ! ! if (ret==null) { ! ret = atts.getValue(localName); ! } ! } ! ! return ret; } Index: TopicMapHandler.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils/TopicMapHandler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TopicMapHandler.java 26 Feb 2004 21:33:50 -0000 1.9 --- TopicMapHandler.java 12 Apr 2007 12:57:48 -0000 1.10 *************** *** 16,19 **** --- 16,21 ---- public static final int REFTYPE_TOPIC = 2; + public static final int REFTYPE_SUBJECTIDENTIFIER = 3; + public void startTopicMap(String id, String xmlBase) throws TopicMapProcessingException; |