import org.jdom.Document;\r
import org.jdom.Element;\r
import org.jdom.JDOMException;\r
+import org.jdom.Namespace;\r
import org.jdom.input.SAXBuilder;\r
import org.jaxen.XPath;\r
import org.jaxen.jdom.JDOMXPath;\r
}\r
\r
public static TreeWalkResults compareParts(String expectedContent, String leftID, String actualPartContent, String rightID){\r
+\r
+ System.out.println("expected: \r\n"+expectedContent+"\r\n\r\n");\r
+ System.out.println("ACTUAL: \r\n"+actualPartContent);\r
+\r
TreeWalkResults list = new TreeWalkResults();\r
try {\r
\r
return list;\r
}\r
\r
- public static List select(Element element, String xpathExpression) throws Exception {\r
+ public static List select(Element element, String xpathExpression, Namespace namespace) throws Exception {\r
XPath xpath = new JDOMXPath(xpathExpression);\r
+ String prefix = namespace.getPrefix();\r
+ String uri = namespace.getURI();\r
+ xpath.addNamespace(prefix, uri);\r
return xpath.selectNodes(element);\r
}\r
\r
- public static Object selectSingleNode(Element element, String xpathExpression) throws Exception {\r
+ public static Object selectSingleNode(Element element, String xpathExpression, Namespace namespace) throws Exception {\r
XPath xpath = new JDOMXPath(xpathExpression);\r
+ if (namespace != null) {\r
+ String prefix = namespace.getPrefix();\r
+ String uri = namespace.getURI();\r
+ xpath.addNamespace(prefix, uri);\r
+ }\r
return xpath.selectSingleNode(element);\r
}\r
\r
- public static Object selectSingleNode(String docSource, String xpathExpression) throws Exception {\r
+ public static Object selectSingleNode(String docSource, String xpathExpression, Namespace namespace) throws Exception {\r
Document doc = getDocumentFromContent(docSource);\r
Element element = doc.getRootElement();\r
XPath xpath = new JDOMXPath(xpathExpression);\r
+ if (namespace != null) {\r
+ String prefix = namespace.getPrefix();\r
+ String uri = namespace.getURI();\r
+ xpath.addNamespace(prefix, uri);\r
+ }\r
return xpath.selectSingleNode(element);\r
}\r
\r
-\r
public static boolean treeWalk(Document left, Document right, TreeWalkResults list) throws Exception {\r
boolean res = treeWalk(left.getRootElement(), right.getRootElement(), "/", list);\r
return res;\r
continue;\r
}\r
Element leftChild = (Element)o;\r
- String leftChildName = leftChild.getName();\r
+ //String leftChildName = leftChild.getName();\r
+ String leftChildName = leftChild.getQualifiedName();\r
if (Tools.isEmpty(leftChildName)){\r
continue;\r
}\r
+\r
+ Namespace namespace = leftChild.getNamespace();\r
+\r
String leftChildPath = Tools.glue(parentPath, "/", leftChildName);\r
\r
if (foundRepeatingList.indexOf(leftChildPath)>=0){\r
continue;\r
}\r
- List leftlist = select(left, leftChildName);\r
+ List leftlist = select(left, leftChildName, namespace);\r
if (leftlist != null && leftlist.size() > 1){\r
//System.out.println("-----------------doRepeating------"+leftChildPath);\r
foundRepeatingList.add(leftChildPath);\r
boolean repeatingIdentical =\r
- doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList) ; //todo: deal with foundRightMap in this repeating field block.\r
+ doRepeatingFieldComparison(leftlist, leftChildPath, leftChildName, left, right, msgList, namespace) ; //todo: deal with foundRightMap in this repeating field block.\r
if ( ! repeatingIdentical ){\r
//System.out.println("\r\n\r\n\r\n*****************************\r\nOne repeating field failed: "+msgList);\r
return false;\r
}\r
foundRightMap.put(leftChildName, "OK");\r
} else {\r
- Element rightChild = (Element)selectSingleNode(right,leftChildName);\r
+ Element rightChild = (Element)selectSingleNode(right,leftChildName, namespace);\r
if (rightChild == null){\r
TreeWalkEntry entry = new TreeWalkEntry();\r
- entry.lpath = leftChildPath;\r
+ entry.lpath = leftChildPath; //this works, but is questionable: selectSingleNode(right, "//*[local-name() = \"objectexit_common\"]")\r
entry.status = TreeWalkEntry.STATUS.R_MISSING;\r
msgList.add(entry);\r
continue;\r
continue;\r
}\r
Element rightChild = (Element)r;\r
- String rname = rightChild.getName();\r
+ String rname = rightChild.getQualifiedName();\r
if (null==foundRightMap.get(rname)){\r
String rightChildPath = Tools.glue(parentPath, "/", rname);\r
\r
return outputter.outputString(el);\r
}\r
\r
- public static boolean doRepeatingFieldComparison(List leftList, String leftChildPath, String leftChildName, Element left, Element right, TreeWalkResults msgList)\r
+ public static boolean doRepeatingFieldComparison(List leftList, String leftChildPath, String leftChildName, Element left, Element right, TreeWalkResults msgList, Namespace namespace)\r
throws Exception {\r
//todo: deal with foundRightMap in this repeating field block.\r
- List rightList = select(right, leftChildName);\r
+ List rightList = select(right, leftChildName, namespace);\r
if (rightList == null || rightList.size() == 0 || rightList.size() < leftList.size()){\r
TreeWalkEntry twe = new TreeWalkEntry();\r
twe.lpath = leftChildPath;\r
}\r
\r
private static void pl(String name, Element el) throws Exception {\r
- Object lobid = selectSingleNode(el, "@ID");\r
+ Namespace namespace = el.getNamespace();\r
+ Object lobid = selectSingleNode(el, "@ID", namespace);\r
String lid = "";\r
if (lobid!=null){\r
lid = lobid.toString();\r
// addedRight,missingRight,textMismatches,strictMatch,treesMatch\r
}\r
\r
-\r
// ============ expected part, will be used as LEFT tree ==========================================================\r
private static String exHEAD ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"\r
+ +"<document name=\"objectexit\">"\r
+"<ns2:objectexit_common \r\n"\r
+" xmlns:ns2=\"http://collectionspace.org/services/objectexit\" \r\n"\r
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \r\n"\r
+" </first>\r\n";\r
private static String exDEP =" <depositor>urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'</depositor>\r\n";\r
private static String exNEW =" <newField>objectexitNumber-1290026472360</newField>\r\n";\r
- private static String exFOOT ="</ns2:objectexit_common>";\r
+ private static String exFOOT ="</ns2:objectexit_common>"\r
+ +"</document>";\r
\r
private static String expectedPartContent = exHEAD + exEN + exDEP + exFOOT;\r
\r
// ============ from-server part, will be used as RIGHT tree ==========================================================\r
\r
private static String srvHEAD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"\r
+ +"<document name=\"objectexit\">"\r
+"<ns2:objectexit_common xmlns:ns2=\"http://collectionspace.org/services/objectexit\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://collectionspace.org/services/objectexit http://services.collectionspace.org/objectexit/objectexit_common.xsd\">\r\n";\r
+\r
private static String srvEN = "<exitNumber>objectexitNumber-1290026472360</exitNumber>\r\n";\r
private static String srvEN2 = "<exitNumber>objectexitNumber-9999999999999</exitNumber>\r\n";\r
private static String srvDEPOSITOR = "<depositor>urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'</depositor>\r\n";\r
- private static String srvFOOT = "</ns2:objectexit_common>\r\n";\r
+ private static String srvFOOT = "</ns2:objectexit_common>\r\n"\r
+ +"</document>";\r
\r
private static String partFromServer = srvHEAD+srvEN+srvDEPOSITOR+srvFOOT;\r
\r