From: Aron Roberts Date: Thu, 24 May 2012 21:06:47 +0000 (-0700) Subject: CSPACE-5012: Made XPath expression evaluator a class variable; added multiple FIXME... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ad772899457df97288e7e6d1e7855f85755e87dc;p=tmp%2Fjakarta-migration.git CSPACE-5012: Made XPath expression evaluator a class variable; added multiple FIXME comments. --- diff --git a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java index 3f609e7d6..ca7b5cb71 100644 --- a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java +++ b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java @@ -57,6 +57,7 @@ import org.xml.sax.InputSource; public class TemplateExpander { private static Map docTypeSvcNameRegistry = new HashMap(); + private static XPath xpath = XPathFactory.newInstance().newXPath(); private static final String IN_AUTHORITY_XPATH = "//inAuthority"; protected static String var(String theVar){ @@ -179,8 +180,15 @@ public class TemplateExpander { return uri; } - // Stub / mock of a registry of authority document types and their - // associated parent authority service names + // FIXME: This is a quick hack; a stub / mock of a registry of + // authority document types and their associated parent authority + // service names. This MUST be replaced by a more general mechanism + // in v2.5. + // + // Per Patrick, this registry needs to be available system-wide, not + // just here in the Imports service; extend to all relevant record types; + // and be automatically built via per-resource registration, from + // configuration, etc. - ADR 2012-05-24 private static Map getDocTypeSvcNameRegistry() { if (docTypeSvcNameRegistry.isEmpty()) { docTypeSvcNameRegistry.put("Concept", "Conceptauthorities"); @@ -209,15 +217,25 @@ public class TemplateExpander { + '/' + docID; } + // FIXME: Create equivalent getUri-type method(s) for sub-resources, such as contacts + private static String getInAuthorityValue(String xmlFragment) { + // We may also want to explicitly validate the format of CSID + // values provided in fields such as inAuthority, and perhaps later, + // their uniqueness against those already present in a running system. + // - ADR 2012-05-24 return getXpathValueFromXmlFragment(IN_AUTHORITY_XPATH, xmlFragment); } private static String getXpathValueFromXmlFragment(String xpathExpr, String xmlFragment) { String xpathValue = ""; try { - XPath xpath = XPathFactory.newInstance().newXPath(); InputSource input = new InputSource(new StringReader(xmlFragment)); + // FIXME: Need to handle cases where the xmlFragment may contain more + // than one matching expression, and thus a non-CSID value may be + // obtained. (Simply matching on instance [0] within the XPath expr + // might not be reasonable, as we won't always know which value is + // pertinent.) - ADR 2012-05-24 xpathValue = xpath.evaluate(xpathExpr, input); } catch (XPathExpressionException e) { // Do nothing here. @@ -226,8 +244,6 @@ public class TemplateExpander { } - // FIXME: Create equivalent getUri-type method(s) for sub-resources, such as contacts - /** This inner class is the callback target for calls to XmlSaxFragmenter, for example: * FragmentHandlerImpl callback = new FragmentHandlerImpl(); * XmlSaxFragmenter.parse(filename, "/imports/import", callback, false);