From: Lars H. <lh...@us...> - 2005-07-08 16:27:48
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm Modified Files: AssociationComparator.java AssociationRoleComparator.java Canonicalize.java ComparisonException.java Driver.java LocatorComparator.java OccurrenceComparator.java SetComparator.java TopicComparator.java TopicNameComparator.java VariantComparator.java XTMCanonicalizer.java Log Message: Tabs -> Whitespaces Index: XTMCanonicalizer.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/XTMCanonicalizer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XTMCanonicalizer.java 5 Mar 2005 17:09:38 -0000 1.1 --- XTMCanonicalizer.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,593 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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 [...1157 lines suppressed...] ! } else if (tmo instanceof TopicMap) { ! reifier = ((TopicMap)tmo).getReifier(); ! } ! if (reifier != null) { ! atts.addAttribute(null, "reifier", "reifier", "CDATA", String.valueOf(m_topicRefMap.get(reifier.getObjectId()))); ! } ! } ! ! public boolean isReifiable(TopicMapObject tmo) { ! return (!(tmo instanceof Topic)); ! } ! ! /** ! * @param b ! */ ! public void setOptWriteSourceLocators(boolean b) { ! m_optWriteSourceLocators = b; ! } ! ! } Index: LocatorComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/LocatorComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LocatorComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- LocatorComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,37 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! import org.tmapi.core.Locator; ! ! /** ! * Compares to Locator instances according to the canonical ! * sort rules of the CXTM standard. ! */ ! public class LocatorComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! return ((Locator)o1).getReference().compareTo(((Locator)o2).getReference()); ! } ! ! } --- 1,37 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! import org.tmapi.core.Locator; ! ! /** ! * Compares to Locator instances according to the canonical ! * sort rules of the CXTM standard. ! */ ! public class LocatorComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! return ((Locator)o1).getReference().compareTo(((Locator)o2).getReference()); ! } ! ! } Index: AssociationComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/AssociationComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationComparator.java 5 Mar 2005 17:09:37 -0000 1.1 --- AssociationComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,56 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Association; ! ! /** ! * A Comparator that compares two Association instances ! * according to the canonical sort order defined by ! * the CXTM standard. ! */ ! public class AssociationComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! private static final Comparator rolesComp = new AssociationRoleComparator(); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Association a1 = (Association)o1; ! Association a2 = (Association)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(a1.getType(), a2.getType()); ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getAssociationRoles(), a2.getAssociationRoles()); ! } ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getScope(), a2.getScope()); ! } ! return 0; ! } ! ! } --- 1,56 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Association; ! ! /** ! * A Comparator that compares two Association instances ! * according to the canonical sort order defined by ! * the CXTM standard. ! */ ! public class AssociationComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! private static final Comparator rolesComp = new AssociationRoleComparator(); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Association a1 = (Association)o1; ! Association a2 = (Association)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(a1.getType(), a2.getType()); ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getAssociationRoles(), a2.getAssociationRoles()); ! } ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getScope(), a2.getScope()); ! } ! return 0; ! } ! ! } Index: VariantComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/VariantComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VariantComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- VariantComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,66 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Variant; ! ! /** ! * A Comparator implementation which compares TMAPI Variant ! * instances according to the comparison rules of ! * CXTM (ISO 13250-4). ! */ ! public class VariantComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Variant var1 = (Variant)o1; ! Variant var2 = (Variant)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (var1.getValue() != null && var2.getValue() == null) { ! ret = 1; ! } else if (var1.getValue() == null && var2.getValue() != null) { ! ret = -1; ! } else if (var1.getValue() != null && var2.getValue() != null) { ! ret = var1.getValue().compareTo(var2.getValue()); ! } else { ! ret = locComp.compare(var1.getResource(), var2.getResource()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(var1.getScope(), var2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(var1.getTopicName(), var2.getTopicName()); ! } ! ! return ret; ! } ! ! } --- 1,66 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Variant; ! ! /** ! * A Comparator implementation which compares TMAPI Variant ! * instances according to the comparison rules of ! * CXTM (ISO 13250-4). ! */ ! public class VariantComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Variant var1 = (Variant)o1; ! Variant var2 = (Variant)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (var1.getValue() != null && var2.getValue() == null) { ! ret = 1; ! } else if (var1.getValue() == null && var2.getValue() != null) { ! ret = -1; ! } else if (var1.getValue() != null && var2.getValue() != null) { ! ret = var1.getValue().compareTo(var2.getValue()); ! } else { ! ret = locComp.compare(var1.getResource(), var2.getResource()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(var1.getScope(), var2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(var1.getTopicName(), var2.getTopicName()); ! } ! ! return ret; ! } ! ! } Index: TopicNameComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/TopicNameComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicNameComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- TopicNameComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,53 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.TopicName; ! ! /** ! * Compares two TopicName instances according to the ! * canonical sorting rules defined by the CXTM standard. ! */ ! public class TopicNameComparator implements Comparator { ! ! static final Comparator topicComp = new TopicComparator(); ! static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! TopicName bn1 = (TopicName)o1; ! TopicName bn2 = (TopicName)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = bn1.getValue().compareTo(bn2.getValue()); ! if (ret == 0) { ! // TODO: Type comparison ! ret = scopeComp.compare(bn1.getScope(), bn2.getScope()); ! } ! if (ret == 0) { ! return topicComp.compare(bn1.getTopic(), bn2.getTopic()); ! } ! return ret; ! } ! ! } --- 1,53 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.TopicName; ! ! /** ! * Compares two TopicName instances according to the ! * canonical sorting rules defined by the CXTM standard. ! */ ! public class TopicNameComparator implements Comparator { ! ! static final Comparator topicComp = new TopicComparator(); ! static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! TopicName bn1 = (TopicName)o1; ! TopicName bn2 = (TopicName)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = bn1.getValue().compareTo(bn2.getValue()); ! if (ret == 0) { ! // TODO: Type comparison ! ret = scopeComp.compare(bn1.getScope(), bn2.getScope()); ! } ! if (ret == 0) { ! return topicComp.compare(bn1.getTopic(), bn2.getTopic()); ! } ! return ret; ! } ! ! } Index: Canonicalize.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/Canonicalize.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Canonicalize.java 5 Mar 2005 17:30:08 -0000 1.2 --- Canonicalize.java 8 Jul 2005 16:27:22 -0000 1.3 *************** *** 1,211 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import jargs.gnu.CmdLineParser; ! import jargs.gnu.CmdLineParser.IllegalOptionValueException; ! import jargs.gnu.CmdLineParser.UnknownOptionException; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.io.UnsupportedEncodingException; ! ! import org.tmapi.core.TopicMap; ! import org.xml.sax.SAXException; ! ! import org.tmapiutils.impexp.cxtm.utils.SimpleXMLC14N; ! ! /** ! * The command-line driver for CXTMP. ! */ ! public class Canonicalize { ! ! private File m_compareSrc; ! private String m_baseURI; ! private String m_tmFileName; ! private boolean m_insertLinefeeds; ! ! private static CmdLineParser.Option m_driverClassOpt; ! private static CmdLineParser.Option m_baseURIOpt; ! private static CmdLineParser.Option m_compareOpt; ! private Driver m_driver; ! ! ! public static void main(String[] args) { ! Canonicalize theApp = new Canonicalize(args); ! theApp.run(); ! } ! ! public Canonicalize(Driver dr) { ! m_driver = dr; ! } ! ! public Canonicalize(String [] args) { ! CmdLineParser parser = new CmdLineParser(); ! m_driverClassOpt = parser.addStringOption('d', "driver-class"); ! m_baseURIOpt = parser.addStringOption('b', "baseuri"); ! m_compareOpt = parser.addStringOption('c', "compare-to"); ! try { ! parser.parse(args); ! } catch (IllegalOptionValueException e) { ! e.printStackTrace(); ! usage(); ! } catch (UnknownOptionException e) { ! e.printStackTrace(); ! usage(); ! } ! ! if (parser.getOptionValue(m_compareOpt) != null){ ! m_compareSrc = new File((String)parser.getOptionValue(m_compareOpt)); ! if (!m_compareSrc.exists() || !m_compareSrc.canRead()) { ! System.err.println("Cannot read file " + m_compareSrc.getAbsolutePath()); ! System.exit(-1); ! } ! } ! ! // Initialise the TMAPI implementation ! String driverClassName = (String) parser.getOptionValue(m_driverClassOpt); ! System.out.println("Driver class: " + driverClassName); ! try { ! Class driverClass = Class.forName(driverClassName); ! m_driver = (Driver)driverClass.newInstance(); ! m_driver.initialise(System.getProperties()); ! } catch (Exception ex) { ! System.err.println("Error initialising topic map system."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! ! m_baseURI = (String) parser.getOptionValue(m_baseURIOpt); ! ! String[] rem = parser.getRemainingArgs(); ! if (rem == null) { ! System.out.println("No input topic map file name specified."); ! usage(); ! } ! ! m_tmFileName = parser.getRemainingArgs()[0]; ! } ! ! public void run() { ! try { ! // TODO: If src locator is a URL, use a URL stream ! File f = new File(m_tmFileName); ! InputStream in = new FileInputStream(f); ! if (m_baseURI == null) { ! m_baseURI = f.toURL().toString(); ! } ! if (m_compareSrc == null) { ! canonicalize(in, m_baseURI, System.out); ! } else { ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! int tmp; ! InputStream expectedStr = new FileInputStream(m_compareSrc); ! while ((tmp = expectedStr.read()) != -1) { ! expected.write(tmp); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = canonicalize(in, m_baseURI, expected.toByteArray(), actual); ! if (mismatchAt < 0) { ! System.exit(0); ! } else { ! System.err.println("Canonicalized form of input does not match expected value."); ! System.err.println("Expected: " + expected.toString("UTF-8")); ! System.err.println("Actual: " + actual.toString()); ! System.exit(-1); ! } ! } ! } catch (Exception ex) { ! System.err.println("Error caught during canonicalization: "+ ex.getMessage()); ! ex.printStackTrace(); ! System.exit(-1); ! } ! } ! ! private int compare(byte[] expected, byte[] actual) ! throws IOException, ComparisonException ! { ! int lineCount = 1; ! int charCount = 1; ! if (expected.length > actual.length) return actual.length; ! for (int ix = 0; ix < expected.length; ix++) { ! if (ix > actual.length) { ! throw new ComparisonException("Output shorter than expected.", lineCount, charCount); ! } ! if (expected[ix] != actual[ix]) { ! throw new ComparisonException("Expected " + (char)expected[ix] + " found " + (char)actual[ix], lineCount, charCount); ! } ! if (expected[ix] == 10) { ! lineCount++; ! charCount = 1; ! } else { ! charCount++; ! } ! } ! return -1; ! } ! ! public void canonicalize(InputStream in, String baseURI, OutputStream out) { ! TopicMap tm = null; ! try { ! tm = m_driver.importXTM(in, baseURI); ! } catch (Exception ex) { ! System.err.println("Error importing source XTM."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! try { ! SimpleXMLC14N xmlCanonicalizer = new SimpleXMLC14N(out); ! xmlCanonicalizer.setInsertLinefeeds(m_insertLinefeeds); ! XTMCanonicalizer c = new XTMCanonicalizer(xmlCanonicalizer); ! c.canonicalize(tm); ! } catch (SAXException ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } catch (UnsupportedEncodingException ex) { ! System.out.println("Cannot write canonical output. " + ex.toString()); ! } catch (Exception ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } ! } ! ! public int canonicalize(InputStream in, String baseURI, byte[] expected, StringBuffer actual) throws IOException, ComparisonException { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(); ! canonicalize(in, baseURI, bos); ! if (actual != null) { ! actual.append(bos.toString()); ! } ! return compare(expected, bos.toByteArray()); ! } ! ! private void usage() { ! System.out.println("Usage: java org.tmapiutils.impexp.cxtm.Canonicalize -d <driver class name> [-b <base uri>] [-c <cxtm comparison file>] topicmap_filename"); ! System.exit(-1); ! } ! ! public void setDriver(Driver dr) { ! m_driver = dr; ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! } --- 1,211 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import jargs.gnu.CmdLineParser; ! import jargs.gnu.CmdLineParser.IllegalOptionValueException; ! import jargs.gnu.CmdLineParser.UnknownOptionException; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.io.UnsupportedEncodingException; ! ! import org.tmapi.core.TopicMap; ! import org.xml.sax.SAXException; ! ! import org.tmapiutils.impexp.cxtm.utils.SimpleXMLC14N; ! ! /** ! * The command-line driver for CXTMP. ! */ ! public class Canonicalize { ! ! private File m_compareSrc; ! private String m_baseURI; ! private String m_tmFileName; ! private boolean m_insertLinefeeds; ! ! private static CmdLineParser.Option m_driverClassOpt; ! private static CmdLineParser.Option m_baseURIOpt; ! private static CmdLineParser.Option m_compareOpt; ! private Driver m_driver; ! ! ! public static void main(String[] args) { ! Canonicalize theApp = new Canonicalize(args); ! theApp.run(); ! } ! ! public Canonicalize(Driver dr) { ! m_driver = dr; ! } ! ! public Canonicalize(String [] args) { ! CmdLineParser parser = new CmdLineParser(); ! m_driverClassOpt = parser.addStringOption('d', "driver-class"); ! m_baseURIOpt = parser.addStringOption('b', "baseuri"); ! m_compareOpt = parser.addStringOption('c', "compare-to"); ! try { ! parser.parse(args); ! } catch (IllegalOptionValueException e) { ! e.printStackTrace(); ! usage(); ! } catch (UnknownOptionException e) { ! e.printStackTrace(); ! usage(); ! } ! ! if (parser.getOptionValue(m_compareOpt) != null){ ! m_compareSrc = new File((String)parser.getOptionValue(m_compareOpt)); ! if (!m_compareSrc.exists() || !m_compareSrc.canRead()) { ! System.err.println("Cannot read file " + m_compareSrc.getAbsolutePath()); ! System.exit(-1); ! } ! } ! ! // Initialise the TMAPI implementation ! String driverClassName = (String) parser.getOptionValue(m_driverClassOpt); ! System.out.println("Driver class: " + driverClassName); ! try { ! Class driverClass = Class.forName(driverClassName); ! m_driver = (Driver)driverClass.newInstance(); ! m_driver.initialise(System.getProperties()); ! } catch (Exception ex) { ! System.err.println("Error initialising topic map system."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! ! m_baseURI = (String) parser.getOptionValue(m_baseURIOpt); ! ! String[] rem = parser.getRemainingArgs(); ! if (rem == null) { ! System.out.println("No input topic map file name specified."); ! usage(); ! } ! ! m_tmFileName = parser.getRemainingArgs()[0]; ! } ! ! public void run() { ! try { ! // TODO: If src locator is a URL, use a URL stream ! File f = new File(m_tmFileName); ! InputStream in = new FileInputStream(f); ! if (m_baseURI == null) { ! m_baseURI = f.toURL().toString(); ! } ! if (m_compareSrc == null) { ! canonicalize(in, m_baseURI, System.out); ! } else { ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! int tmp; ! InputStream expectedStr = new FileInputStream(m_compareSrc); ! while ((tmp = expectedStr.read()) != -1) { ! expected.write(tmp); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = canonicalize(in, m_baseURI, expected.toByteArray(), actual); ! if (mismatchAt < 0) { ! System.exit(0); ! } else { ! System.err.println("Canonicalized form of input does not match expected value."); ! System.err.println("Expected: " + expected.toString("UTF-8")); ! System.err.println("Actual: " + actual.toString()); ! System.exit(-1); ! } ! } ! } catch (Exception ex) { ! System.err.println("Error caught during canonicalization: "+ ex.getMessage()); ! ex.printStackTrace(); ! System.exit(-1); ! } ! } ! ! private int compare(byte[] expected, byte[] actual) ! throws IOException, ComparisonException ! { ! int lineCount = 1; ! int charCount = 1; ! if (expected.length > actual.length) return actual.length; ! for (int ix = 0; ix < expected.length; ix++) { ! if (ix > actual.length) { ! throw new ComparisonException("Output shorter than expected.", lineCount, charCount); ! } ! if (expected[ix] != actual[ix]) { ! throw new ComparisonException("Expected " + (char)expected[ix] + " found " + (char)actual[ix], lineCount, charCount); ! } ! if (expected[ix] == 10) { ! lineCount++; ! charCount = 1; ! } else { ! charCount++; ! } ! } ! return -1; ! } ! ! public void canonicalize(InputStream in, String baseURI, OutputStream out) { ! TopicMap tm = null; ! try { ! tm = m_driver.importXTM(in, baseURI); ! } catch (Exception ex) { ! System.err.println("Error importing source XTM."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! try { ! SimpleXMLC14N xmlCanonicalizer = new SimpleXMLC14N(out); ! xmlCanonicalizer.setInsertLinefeeds(m_insertLinefeeds); ! XTMCanonicalizer c = new XTMCanonicalizer(xmlCanonicalizer); ! c.canonicalize(tm); ! } catch (SAXException ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } catch (UnsupportedEncodingException ex) { ! System.out.println("Cannot write canonical output. " + ex.toString()); ! } catch (Exception ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } ! } ! ! public int canonicalize(InputStream in, String baseURI, byte[] expected, StringBuffer actual) throws IOException, ComparisonException { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(); ! canonicalize(in, baseURI, bos); ! if (actual != null) { ! actual.append(bos.toString()); ! } ! return compare(expected, bos.toByteArray()); ! } ! ! private void usage() { ! System.out.println("Usage: java org.tmapiutils.impexp.cxtm.Canonicalize -d <driver class name> [-b <base uri>] [-c <cxtm comparison file>] topicmap_filename"); ! System.exit(-1); ! } ! ! public void setDriver(Driver dr) { ! m_driver = dr; ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! } Index: ComparisonException.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/ComparisonException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ComparisonException.java 5 Mar 2005 17:09:38 -0000 1.1 --- ComparisonException.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,34 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! /** ! * Exception raised when comparison of generated CXTM output ! * and expected CXTM output fails. ! */ ! public class ComparisonException extends Exception { ! private String m_msg; ! private int m_line; ! private int m_ch; ! ! public ComparisonException(String msg, int lineCount, int charCount) { ! super(String.valueOf(lineCount) + "," + String.valueOf(charCount) + ": " + msg); ! m_msg = msg; ! m_line =lineCount; ! m_ch = charCount; ! } ! ! } --- 1,34 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! /** ! * Exception raised when comparison of generated CXTM output ! * and expected CXTM output fails. ! */ ! public class ComparisonException extends Exception { ! private String m_msg; ! private int m_line; ! private int m_ch; ! ! public ComparisonException(String msg, int lineCount, int charCount) { ! super(String.valueOf(lineCount) + "," + String.valueOf(charCount) + ": " + msg); ! m_msg = msg; ! m_line =lineCount; ! m_ch = charCount; ! } ! ! } Index: SetComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/SetComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SetComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- SetComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,57 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Collection; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! /** ! * Compares two sets of objects according to the collection ! * comparison algorithm specified by the CXTM standard. ! */ ! public class SetComparator implements Comparator { ! ! private Comparator m_ic; ! ! public SetComparator(Comparator instanceComparator) { ! m_ic = instanceComparator; ! } ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Collection) || !(o2 instanceof Collection)) { ! throw new RuntimeException("CollectionComparator invoked with a parameter that is not a Collection"); ! } ! int ret = ((Collection)o2).size() - ((Collection)o1).size(); ! if (ret == 0) { ! TreeSet ts1 = new TreeSet(m_ic); ! ts1.addAll((Collection)o1); ! TreeSet ts2 = new TreeSet(m_ic); ! ts2.addAll((Collection)o2); ! Iterator it1 = ts1.iterator(); ! Iterator it2 = ts2.iterator(); ! while ((ret == 0) && (it1.hasNext())) { ! ret = m_ic.compare(it1.next(), it2.next()); ! } ! } ! return ret; ! } ! ! } --- 1,57 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Collection; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! /** ! * Compares two sets of objects according to the collection ! * comparison algorithm specified by the CXTM standard. ! */ ! public class SetComparator implements Comparator { ! ! private Comparator m_ic; ! ! public SetComparator(Comparator instanceComparator) { ! m_ic = instanceComparator; ! } ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Collection) || !(o2 instanceof Collection)) { ! throw new RuntimeException("CollectionComparator invoked with a parameter that is not a Collection"); ! } ! int ret = ((Collection)o2).size() - ((Collection)o1).size(); ! if (ret == 0) { ! TreeSet ts1 = new TreeSet(m_ic); ! ts1.addAll((Collection)o1); ! TreeSet ts2 = new TreeSet(m_ic); ! ts2.addAll((Collection)o2); ! Iterator it1 = ts1.iterator(); ! Iterator it2 = ts2.iterator(); ! while ((ret == 0) && (it1.hasNext())) { ! ret = m_ic.compare(it1.next(), it2.next()); ! } ! } ! return ret; ! } ! ! } Index: AssociationRoleComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/AssociationRoleComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationRoleComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- AssociationRoleComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,53 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.AssociationRole; ! ! /** ! * Compares two AssociationRole instances according to the ! * canonical sorting algorithm of CXTM. ! */ ! public class AssociationRoleComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! AssociationRole m1 = (AssociationRole)o1; ! AssociationRole m2 = (AssociationRole)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(m1.getPlayer(), m2.getPlayer()); ! if (ret == 0) { ! ret = topicComp.compare(m1.getType(), m2.getType()); ! } ! if (ret == 0) { ! // TODO: Need to rework the spec here. ! ret = new AssociationComparator().compare(m1.getAssociation(), m2.getAssociation()); ! } ! return ret; ! } ! ! } --- 1,53 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.AssociationRole; ! ! /** ! * Compares two AssociationRole instances according to the ! * canonical sorting algorithm of CXTM. ! */ ! public class AssociationRoleComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! AssociationRole m1 = (AssociationRole)o1; ! AssociationRole m2 = (AssociationRole)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(m1.getPlayer(), m2.getPlayer()); ! if (ret == 0) { ! ret = topicComp.compare(m1.getType(), m2.getType()); ! } ! if (ret == 0) { ! // TODO: Need to rework the spec here. ! ret = new AssociationComparator().compare(m1.getAssociation(), m2.getAssociation()); ! } ! return ret; ! } ! ! } Index: OccurrenceComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/OccurrenceComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OccurrenceComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- OccurrenceComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,69 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Occurrence; ! ! /** ! * Compares two Occurrence instances according to the ! * canonical sorting rules of the CXTM standard. ! */ ! public class OccurrenceComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Occurrence occ1 = (Occurrence)o1; ! Occurrence occ2 = (Occurrence)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (occ1.getValue() != null && occ2.getValue() == null) { ! ret = 1; ! } else if (occ1.getValue() == null && occ2.getValue() != null) { ! ret = -1; ! } else if (occ1.getValue() != null && occ2.getValue() != null) { ! ret = occ1.getValue().compareTo(occ2.getValue()); ! } else { ! ret = locComp.compare(occ1.getResource(), occ2.getResource()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getType(), occ2.getType()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(occ1.getScope(), occ2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getTopic(), occ2.getTopic()); ! } ! ! return ret; ! } ! ! } --- 1,69 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Occurrence; ! ! /** ! * Compares two Occurrence instances according to the ! * canonical sorting rules of the CXTM standard. ! */ ! public class OccurrenceComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Occurrence occ1 = (Occurrence)o1; ! Occurrence occ2 = (Occurrence)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (occ1.getValue() != null && occ2.getValue() == null) { ! ret = 1; ! } else if (occ1.getValue() == null && occ2.getValue() != null) { ! ret = -1; ! } else if (occ1.getValue() != null && occ2.getValue() != null) { ! ret = occ1.getValue().compareTo(occ2.getValue()); ! } else { ! ret = locComp.compare(occ1.getResource(), occ2.getResource()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getType(), occ2.getType()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(occ1.getScope(), occ2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getTopic(), occ2.getTopic()); ! } ! ! return ret; ! } ! ! } Index: Driver.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/Driver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Driver.java 5 Mar 2005 17:09:38 -0000 1.1 --- Driver.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,51 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tmapi.core.TopicMap; ! ! /** ! * The interface to be implemented by the Driver that ! * enables CXTMP to talk to a topic map processor. ! */ ! public interface Driver { ! ! /** ! * This method is invoked by the CXTMP processor after ! * loading the Driver class and before any calls to ! * the importXTM method. ! * @param props configuration properties that the Driver can ! * use to initialise the underlying topic map processor ! * @throws Exception if the initialisation of the topic map ! * processor fails for any reason. ! */ ! public void initialise(Properties props) throws Exception; ! ! /** ! * This method is invoked by CXTMP to load a topic map ! * into the topic map processor. ! * @param src the input stream from which the topic map can be read ! * @param baseURI a hint to the base URI to be assigned to the topic map on import. ! * A Driver implementation may choose to ignore this value. ! * @return the TMAPI TopicMap instance that represents the topic map processor's ! * fully merged model of the parsed input ! * @throws Exception if the import fails for any reason. ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception; ! } --- 1,51 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tmapi.core.TopicMap; ! ! /** ! * The interface to be implemented by the Driver that ! * enables CXTMP to talk to a topic map processor. ! */ ! public interface Driver { ! ! /** ! * This method is invoked by the CXTMP processor after ! * loading the Driver class and before any calls to ! * the importXTM method. ! * @param props configuration properties that the Driver can ! * use to initialise the underlying topic map processor ! * @throws Exception if the initialisation of the topic map ! * processor fails for any reason. ! */ ! public void initialise(Properties props) throws Exception; ! ! /** ! * This method is invoked by CXTMP to load a topic map ! * into the topic map processor. ! * @param src the input stream from which the topic map can be read ! * @param baseURI a hint to the base URI to be assigned to the topic map on import. ! * A Driver implementation may choose to ignore this value. ! * @return the TMAPI TopicMap instance that represents the topic map processor's ! * fully merged model of the parsed input ! * @throws Exception if the import fails for any reason. ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception; ! } Index: TopicComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/TopicComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- TopicComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,61 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.Topic; ! ! /** ! * Implements the topic comparison algorithm defined by ! * the CXTM specification. ! */ ! public class TopicComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Topic) || !(o2 instanceof Topic)) { ! throw new IllegalArgumentException("TopicComparator invoked with parameter that is not a Topic."); ! } ! ! Topic t1 = (Topic)o1; ! Topic t2 = (Topic)o2; ! Comparator locatorSetComparator = new SetComparator(new LocatorComparator()); ! int ret = locatorSetComparator.compare(t1.getSourceLocators(), t2.getSourceLocators()); ! if (ret == 0) { ! ret = locatorSetComparator.compare(t1.getSubjectIdentifiers(), t2.getSubjectIdentifiers()); ! } ! if (ret == 0) { ! Locator l1 = t1.getSubjectLocator(); ! Locator l2 =t2.getSubjectLocator(); ! if (l1 == null && l2 != null) { ! return -1; ! } else if (l1 != null && l2 == null) { ! return 1; ! } else { ! return new LocatorComparator().compare(l1, l2); ! } ! } ! if (ret == 0) { ! throw new RuntimeException("Unable to compare topics - perhaps they are the same ?"); ! } ! return ret; ! } ! ! } --- 1,61 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.Topic; ! ! /** ! * Implements the topic comparison algorithm defined by ! * the CXTM specification. ! */ ! public class TopicComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Topic) || !(o2 instanceof Topic)) { ! throw new IllegalArgumentException("TopicComparator invoked with parameter that is not a Topic."); ! } ! ! Topic t1 = (Topic)o1; ! Topic t2 = (Topic)o2; ! Comparator locatorSetComparator = new SetComparator(new LocatorComparator()); ! int ret = locatorSetComparator.compare(t1.getSourceLocators(), t2.getSourceLocators()); ! if (ret == 0) { ! ret = locatorSetComparator.compare(t1.getSubjectIdentifiers(), t2.getSubjectIdentifiers()); ! } ! if (ret == 0) { ! Locator l1 = t1.getSubjectLocator(); ! Locator l2 =t2.getSubjectLocator(); ! if (l1 == null && l2 != null) { ! return -1; ! } else if (l1 != null && l2 == null) { ! return 1; ! } else { ! return new LocatorComparator().compare(l1, l2); ! } ! } ! if (ret == 0) { ! throw new RuntimeException("Unable to compare topics - perhaps they are the same ?"); ! } ! return ret; ! } ! ! } |