Coverage Report - org.kuali.rice.krad.workflow.attribute.KualiXmlAttributeHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiXmlAttributeHelper
0%
0/195
0%
0/98
7.6
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.workflow.attribute;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 import org.kuali.rice.core.util.KeyValue;
 22  
 import org.kuali.rice.core.util.xml.XmlJotter;
 23  
 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
 24  
 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
 25  
 import org.kuali.rice.krad.service.DataDictionaryService;
 26  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 27  
 import org.w3c.dom.Element;
 28  
 import org.w3c.dom.NamedNodeMap;
 29  
 import org.w3c.dom.Node;
 30  
 import org.w3c.dom.NodeList;
 31  
 
 32  
 import javax.xml.transform.Result;
 33  
 import javax.xml.transform.Source;
 34  
 import javax.xml.transform.TransformerFactory;
 35  
 import javax.xml.transform.dom.DOMSource;
 36  
 import javax.xml.transform.stream.StreamResult;
 37  
 import javax.xml.xpath.XPath;
 38  
 import javax.xml.xpath.XPathConstants;
 39  
 import javax.xml.xpath.XPathExpressionException;
 40  
 import java.io.StringWriter;
 41  
 import java.util.ArrayList;
 42  
 import java.util.Iterator;
 43  
 import java.util.List;
 44  
 import java.util.regex.Matcher;
 45  
 import java.util.regex.Pattern;
 46  
 
 47  
 
 48  0
 public class KualiXmlAttributeHelper {
 49  0
     private static Log LOG = LogFactory.getLog(KualiXmlAttributeHelper.class);
 50  0
     private static XPath xpath = XPathHelper.newXPath();
 51  
     private static final String testVal = "\'/[^\']*\'";// get the individual xpath tests.
 52  
     private static final String testVal2 = "/[^/]+/" + "*";// have to do this or the compiler gets confused by end comment.
 53  
     private static final String cleanVal = "[^/\']+";// get rid of / and ' in the resulting term.
 54  
     private static final String ruledataVal = "ruledata[^\']*\'([^\']*)";
 55  
     // TODO - enter JIRA
 56  
     // below removes wf:xstreamsafe( and )
 57  
     // below separates each wf:xstreamsafe() section into separate 'finds'
 58  0
     private static final Pattern xPathPattern = Pattern.compile(testVal);
 59  0
     private static final Pattern termPattern = Pattern.compile(testVal2);
 60  0
     private static final Pattern cleanPattern = Pattern.compile(cleanVal);
 61  0
     private static final Pattern targetPattern = Pattern.compile(ruledataVal);
 62  
 
 63  
     public static final String ATTRIBUTE_LABEL_BO_REFERENCE_PREFIX = "kuali_dd_label(";
 64  
     public static final String ATTRIBUTE_LABEL_BO_REFERENCE_SUFFIX = ")";
 65  
     public static final String ATTRIBUTE_SHORT_LABEL_BO_REFERENCE_PREFIX = "kuali_dd_short_label(";
 66  
     public static final String ATTRIBUTE_SHORT_LABEL_BO_REFERENCE_SUFFIX = ")";
 67  
     private static final String KUALI_VALUES_FINDER_REFERENCE_PREFIX = "kuali_values_finder_class(";
 68  
     private static final String KUALI_VALUES_FINDER_REFERENCE_SUFFIX = ")";
 69  
     public static final String notFound = "Label Not Found";
 70  
 
 71  0
     private String lastXPath = "";
 72  
 
 73  
     /**
 74  
      * This method overrides the super class and modifies the XML that it operates on to put the name and the title in the place
 75  
      * where the super class expects to see them, even though they may no longer exist in the original XML.
 76  
      *
 77  
      * @see org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute#getConfigXML()
 78  
      */
 79  
 
 80  
     public Element processConfigXML(Element root) {
 81  0
         return this.processConfigXML(root, null);
 82  
     }
 83  
 
 84  
     /**
 85  
      * This method overrides the super class and modifies the XML that it operates on to put the name and the title in the place
 86  
      * where the super class expects to see them, overwriting the original title in the XML.
 87  
      *
 88  
      * @see org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute#getConfigXML()
 89  
      */
 90  
 
 91  
     public Element processConfigXML(Element root, String[] xpathExpressionElements) {
 92  
 
 93  0
         NodeList fields = root.getElementsByTagName("fieldDef");
 94  0
         Element theTag = null;
 95  0
         String docContent = "";
 96  
 
 97  
 
 98  
         /**
 99  
          * This section will check to see if document content has been defined in the configXML for the document type, by running an
 100  
          * XPath. If this is an empty list the xpath expression in the fieldDef is used to define the xml document content that is
 101  
          * added to the configXML. The xmldocument content is of this form, when in the document configXML. <xmlDocumentContent>
 102  
          * <org.kuali.rice.krad.bo.SourceAccountingLine> <amount> <value>%totaldollarAmount%</value> </amount>
 103  
          * </org.kuali.rice.krad.bo.SourceAccountingLine> </xmlDocumentContent> This class generates this on the fly, by creating an XML
 104  
          * element for each term in the XPath expression. When this doesn't apply XML can be coded in the configXML for the
 105  
          * ruleAttribute.
 106  
          *
 107  
          * @see org.kuali.rice.kew.plugin.attributes.WorkflowAttribute#getDocContent()
 108  
          */
 109  
 
 110  
 
 111  0
         org.w3c.dom.Document xmlDoc = null;
 112  0
         if (!xmlDocumentContentExists(root)) { // XML Document content is given because the xpath is non standard
 113  0
             fields = root.getElementsByTagName("fieldDef");
 114  0
             xmlDoc = root.getOwnerDocument();
 115  
         }
 116  0
         for (int i = 0; i < fields.getLength(); i++) { // loop over each fieldDef
 117  0
             String name = null;
 118  0
             if (!xmlDocumentContentExists(root)) {
 119  0
                 theTag = (Element) fields.item(i);
 120  
 
 121  
                 /*
 122  
                  * Even though there may be multiple xpath test, for example one for source lines and one for target lines, the
 123  
                  * xmlDocumentContent only needs one, since it is used for formatting. The first one is arbitrarily selected, since
 124  
                  * they are virtually equivalent in structure, most of the time.
 125  
                  */
 126  
 
 127  0
                 List<String> xPathTerms = getXPathTerms(theTag);
 128  0
                 if (xPathTerms.size() != 0) {
 129  0
                     Node iterNode = xmlDoc.createElement("xmlDocumentContent");
 130  
 
 131  
 
 132  0
                     xmlDoc.normalize();
 133  
 
 134  0
                     iterNode.normalize();
 135  
 
 136  
                     /*
 137  
                      * Since this method is run once per attribute and there may be multiple fieldDefs, the first fieldDef is used
 138  
                      * to create the configXML.
 139  
                      */
 140  0
                     for (int j = 0; j < xPathTerms.size(); j++) {// build the configXML based on the Xpath
 141  
                         // TODO - Fix the document content element generation
 142  0
                         iterNode.appendChild(xmlDoc.createElement(xPathTerms.get(j)));
 143  0
                         xmlDoc.normalize();
 144  
 
 145  0
                         iterNode = iterNode.getFirstChild();
 146  0
                         iterNode.normalize();
 147  
 
 148  
                     }
 149  0
                     iterNode.setTextContent("%" + xPathTerms.get(xPathTerms.size() - 1) + "%");
 150  0
                     root.appendChild(iterNode);
 151  
                 }
 152  
             }
 153  0
             theTag = (Element) fields.item(i);
 154  
             // check to see if a values finder is being used to set valid values for a field
 155  0
             NodeList displayTagElements = theTag.getElementsByTagName("display");
 156  0
             if (displayTagElements.getLength() == 1) {
 157  0
                 Element displayTag = (Element) displayTagElements.item(0);
 158  0
                 List valuesElementsToAdd = new ArrayList();
 159  0
                 for (int w = 0; w < displayTag.getChildNodes().getLength(); w++) {
 160  0
                     Node displayTagChildNode = (Node) displayTag.getChildNodes().item(w);
 161  0
                     if ((displayTagChildNode != null) && ("values".equals(displayTagChildNode.getNodeName()))) {
 162  0
                         if (displayTagChildNode.getChildNodes().getLength() > 0) {
 163  0
                             String valuesNodeText = displayTagChildNode.getFirstChild().getNodeValue();
 164  0
                             String potentialClassName = getPotentialKualiClassName(valuesNodeText, KUALI_VALUES_FINDER_REFERENCE_PREFIX, KUALI_VALUES_FINDER_REFERENCE_SUFFIX);
 165  0
                             if (StringUtils.isNotBlank(potentialClassName)) {
 166  
                                 try {
 167  0
                                     Class finderClass = Class.forName((String) potentialClassName);
 168  0
                                     KeyValuesFinder finder = (KeyValuesFinder) finderClass.newInstance();
 169  0
                                     NamedNodeMap valuesNodeAttributes = displayTagChildNode.getAttributes();
 170  0
                                     Node potentialSelectedAttribute = (valuesNodeAttributes != null) ? valuesNodeAttributes.getNamedItem("selected") : null;
 171  0
                                     for (Iterator iter = finder.getKeyValues().iterator(); iter.hasNext();) {
 172  0
                                         KeyValue keyValue = (KeyValue) iter.next();
 173  0
                                         Element newValuesElement = root.getOwnerDocument().createElement("values");
 174  0
                                         newValuesElement.appendChild(root.getOwnerDocument().createTextNode(keyValue.getKey()));
 175  
                                         // newValuesElement.setNodeValue(KeyValue.getKey().toString());
 176  0
                                         newValuesElement.setAttribute("title", keyValue.getValue());
 177  0
                                         if (potentialSelectedAttribute != null) {
 178  0
                                             newValuesElement.setAttribute("selected", potentialSelectedAttribute.getNodeValue());
 179  
                                         }
 180  0
                                         valuesElementsToAdd.add(newValuesElement);
 181  0
                                     }
 182  0
                                 } catch (ClassNotFoundException cnfe) {
 183  0
                                     String errorMessage = "Caught an exception trying to find class '" + potentialClassName + "'";
 184  0
                                     LOG.error(errorMessage, cnfe);
 185  0
                                     throw new RuntimeException(errorMessage, cnfe);
 186  0
                                 } catch (InstantiationException ie) {
 187  0
                                     String errorMessage = "Caught an exception trying to instantiate class '" + potentialClassName + "'";
 188  0
                                     LOG.error(errorMessage, ie);
 189  0
                                     throw new RuntimeException(errorMessage, ie);
 190  0
                                 } catch (IllegalAccessException iae) {
 191  0
                                     String errorMessage = "Caught an access exception trying to instantiate class '" + potentialClassName + "'";
 192  0
                                     LOG.error(errorMessage, iae);
 193  0
                                     throw new RuntimeException(errorMessage, iae);
 194  0
                                 }
 195  
                             } else {
 196  0
                                 valuesElementsToAdd.add(displayTagChildNode.cloneNode(true));
 197  
                             }
 198  0
                             displayTag.removeChild(displayTagChildNode);
 199  
                         }
 200  
                     }
 201  
                 }
 202  0
                 for (Iterator iter = valuesElementsToAdd.iterator(); iter.hasNext();) {
 203  0
                     Element valuesElementToAdd = (Element) iter.next();
 204  0
                     displayTag.appendChild(valuesElementToAdd);
 205  0
                 }
 206  
             }
 207  0
             if ((xpathExpressionElements != null) && (xpathExpressionElements.length > 0)) {
 208  0
                 NodeList fieldEvaluationElements = theTag.getElementsByTagName("fieldEvaluation");
 209  0
                 if (fieldEvaluationElements.getLength() == 1) {
 210  0
                     Element fieldEvaluationTag = (Element) fieldEvaluationElements.item(0);
 211  0
                     List tagsToAdd = new ArrayList();
 212  0
                     for (int w = 0; w < fieldEvaluationTag.getChildNodes().getLength(); w++) {
 213  0
                         Node fieldEvaluationChildNode = (Node) fieldEvaluationTag.getChildNodes().item(w);
 214  0
                         Element newTagToAdd = null;
 215  0
                         if ((fieldEvaluationChildNode != null) && ("xpathexpression".equals(fieldEvaluationChildNode.getNodeName()))) {
 216  0
                             newTagToAdd = root.getOwnerDocument().createElement("xpathexpression");
 217  0
                             newTagToAdd.appendChild(root.getOwnerDocument().createTextNode(generateNewXpathExpression(fieldEvaluationChildNode.getFirstChild().getNodeValue(), xpathExpressionElements)));
 218  0
                             tagsToAdd.add(newTagToAdd);
 219  0
                             fieldEvaluationTag.removeChild(fieldEvaluationChildNode);
 220  
                         }
 221  
                     }
 222  0
                     for (Iterator iter = tagsToAdd.iterator(); iter.hasNext();) {
 223  0
                         Element elementToAdd = (Element) iter.next();
 224  0
                         fieldEvaluationTag.appendChild(elementToAdd);
 225  0
                     }
 226  
                 }
 227  
             }
 228  0
             theTag.setAttribute("title", getBusinessObjectTitle(theTag));
 229  
 
 230  
         }
 231  0
         if (LOG.isDebugEnabled()) {
 232  0
             LOG.debug(XmlJotter.jotNode(root));
 233  0
             StringWriter xmlBuffer = new StringWriter();
 234  
             try {
 235  
 
 236  0
                 root.normalize();
 237  0
                 Source source = new DOMSource(root);
 238  0
                 Result result = new StreamResult(xmlBuffer);
 239  0
                 TransformerFactory.newInstance().newTransformer().transform(source, result);
 240  0
             } catch (Exception e) {
 241  0
                 LOG.debug(" Exception when printing debug XML output " + e);
 242  0
             }
 243  0
             LOG.debug(xmlBuffer.getBuffer());
 244  
         }
 245  
 
 246  0
         return root;
 247  
     }
 248  
 
 249  
     private String generateNewXpathExpression(String currentXpathExpression, String[] newXpathExpressionElements) {
 250  0
         StringBuffer returnableString = new StringBuffer();
 251  0
         for (int i = 0; i < newXpathExpressionElements.length; i++) {
 252  0
             String newXpathElement = newXpathExpressionElements[i];
 253  0
             returnableString.append(newXpathElement);
 254  
 
 255  
             /*
 256  
              * Append the given xpath expression onto the end of the stringbuffer only in the following cases - if there is only one
 257  
              * element in the string array - if there is more than one element in the string array and if the current element is not
 258  
              * the last element
 259  
              */
 260  0
             if (((i + 1) != newXpathExpressionElements.length) || (newXpathExpressionElements.length == 1)) {
 261  0
                 returnableString.append(currentXpathExpression);
 262  
             }
 263  
         }
 264  0
         return returnableString.toString();
 265  
     }
 266  
 
 267  
     /**
 268  
      * This method gets all of the text from the xpathexpression element.
 269  
      *
 270  
      * @param root
 271  
      * @return
 272  
      */
 273  
     private String getXPathText(Element root) {
 274  
         try {
 275  0
             String textContent = null;
 276  0
             Node node = (Node) xpath.evaluate(".//xpathexpression", root, XPathConstants.NODE);
 277  0
             if (node != null) {
 278  0
                 textContent = node.getTextContent();
 279  
             }
 280  0
             return textContent;
 281  0
         } catch (XPathExpressionException e) {
 282  0
             LOG.error("No XPath expression text found in element xpathexpression of configXML for document. " + e);
 283  0
             return null;
 284  
             // throw e; Just writing labels or doing routing report.
 285  
         }
 286  
     }
 287  
 
 288  
     /**
 289  
      * This method uses an XPath expression to determine if the content of the xmlDocumentContent is empty
 290  
      *
 291  
      * @param root
 292  
      * @return
 293  
      */
 294  
     private boolean xmlDocumentContentExists(Element root) {
 295  
         try {
 296  0
             if (((NodeList) xpath.evaluate("//xmlDocumentContent", root, XPathConstants.NODESET)).getLength() == 0) {
 297  0
                 return false;
 298  
             }
 299  0
         } catch (XPathExpressionException e) {
 300  0
             LOG.error("Error parsing xmlDocumentConfig.  " + e);
 301  0
             return false;
 302  0
         }
 303  0
         return true;
 304  
     }
 305  
 
 306  
     public static String getPotentialKualiClassName(String testString, String prefixIndicator, String suffixIndicator) {
 307  0
         if ((StringUtils.isNotBlank(testString)) && (testString.startsWith(prefixIndicator)) && (testString.endsWith(suffixIndicator))) {
 308  0
             return testString.substring(prefixIndicator.length(), testString.lastIndexOf(suffixIndicator));
 309  
         }
 310  0
         return null;
 311  
     }
 312  
 
 313  
     /**
 314  
      * Method to look up the title of each fieldDef tag in the RuleAttribute xml. This method checks the following items in the
 315  
      * following order:
 316  
      * <ol>
 317  
      * <li>Check for the business object name from {@link #getBusinessObjectName(Element)}. If it is not found or blank and the
 318  
      * 'title' attribute of the fieldDef tag is specified then return the value of the 'title' attribute.
 319  
      * <li>Check for the business object name from {@link #getBusinessObjectName(Element)}. If it is found try getting the data
 320  
      * dictionary label related to the business object name and the attribute name (found in the xpath expression)
 321  
      * <li>Check for the data dictionary title value using the attribute name (found in the xpath expression) and the KFS stand in
 322  
      * business object for attributes (see {@link KFSConstants#STAND_IN_BUSINESS_OBJECT_FOR_ATTRIBUTES}
 323  
      * <li>Check for the data dictionary title value using the xpath attribute name found in the xpath expression section. Use that
 324  
      * attribute name to get the label out of the KFS stand in business object for attributes (see
 325  
      * {@link KFSConstants#STAND_IN_BUSINESS_OBJECT_FOR_ATTRIBUTES}
 326  
      * <li>Check for the data dictionary title value using the xpath attribute name found in the xpath expression in the
 327  
      * wf:ruledata() section. Use that attribute name to get the label out of the KFS stand in business object for attributes (see
 328  
      * {@link KFSConstants#STAND_IN_BUSINESS_OBJECT_FOR_ATTRIBUTES}
 329  
      * </ol>
 330  
      *
 331  
      * @param root - the element of the fieldDef tag
 332  
      */
 333  
     private String getBusinessObjectTitle(Element root) {
 334  0
         String businessObjectName = null;
 335  0
         String businessObjectText = root.getAttribute("title");
 336  0
         String potentialClassNameLongLabel = getPotentialKualiClassName(businessObjectText, ATTRIBUTE_LABEL_BO_REFERENCE_PREFIX, ATTRIBUTE_LABEL_BO_REFERENCE_SUFFIX);
 337  0
         String potentialClassNameShortLabel = getPotentialKualiClassName(businessObjectText, ATTRIBUTE_SHORT_LABEL_BO_REFERENCE_PREFIX, ATTRIBUTE_SHORT_LABEL_BO_REFERENCE_SUFFIX);
 338  
         // we assume they want the long label... but allow for the short label
 339  0
         boolean requestedShortLabel = false;
 340  
 
 341  0
         if (StringUtils.isNotBlank(potentialClassNameLongLabel)) {
 342  0
             businessObjectName = potentialClassNameLongLabel;
 343  0
         } else if (StringUtils.isNotBlank(potentialClassNameShortLabel)) {
 344  0
             businessObjectName = potentialClassNameShortLabel;
 345  0
             requestedShortLabel = true;
 346  
         }
 347  0
         if (StringUtils.isNotBlank(businessObjectName)) {
 348  0
             DataDictionaryService DDService = KRADServiceLocatorWeb.getDataDictionaryService();
 349  
 
 350  0
             String title = null;
 351  0
             String targetVal = lastXPath; // Assume the attribute is the last term in the XPath expression
 352  
 
 353  0
             if (LOG.isErrorEnabled()) {
 354  0
                 LOG.debug("Finding title in BO=" + businessObjectName + " ObjectName=" + targetVal);
 355  
             }
 356  
 
 357  0
             if (StringUtils.isNotBlank(targetVal)) {
 358  
                 // try to get the label based on the bo name and xpath attribute
 359  0
                 if (requestedShortLabel) {
 360  0
                     title = DDService.getAttributeShortLabel(businessObjectName, targetVal);
 361  
                 } else {
 362  0
                     title = DDService.getAttributeLabel(businessObjectName, targetVal);
 363  
                 }
 364  0
                 if (StringUtils.isNotBlank(title)) {
 365  0
                     return title;
 366  
                 }
 367  
             }
 368  
             // try to get the label based on the business object and xpath ruledata section
 369  0
             targetVal = getRuleData(root);
 370  0
             if (LOG.isErrorEnabled()) {
 371  0
                 LOG.debug("Finding title in BO=" + businessObjectName + " ObjectName=" + targetVal);
 372  
             }
 373  0
             if (StringUtils.isNotBlank(targetVal)) {
 374  0
                 title = DDService.getAttributeLabel(businessObjectName, targetVal);
 375  0
                 if (StringUtils.isNotBlank(title)) {
 376  0
                     return title;
 377  
                 }
 378  
             }
 379  
             // If haven't found a label yet, its probably because there is no xpath. Use the name attribute to determine the BO
 380  
             // attribute to use.
 381  0
             targetVal = root.getAttribute("name");
 382  0
             if (LOG.isErrorEnabled()) {
 383  0
                 LOG.debug("Finding title in BO=" + businessObjectName + " ObjectName=" + targetVal);
 384  
             }
 385  0
             title = DDService.getAttributeLabel(businessObjectName, targetVal);
 386  
 
 387  0
             if (StringUtils.isNotBlank(title)) {
 388  0
                 return title;
 389  
             }
 390  0
         }
 391  
         // return any potentially hard coded title info
 392  0
         else if ((StringUtils.isNotBlank(businessObjectText)) && (StringUtils.isBlank(businessObjectName))) {
 393  0
             return businessObjectText;
 394  
         }
 395  0
         return notFound;
 396  
 
 397  
     }
 398  
 
 399  
     /**
 400  
      * This method gets the contents of the ruledata function in the xpath statement in the XML
 401  
      *
 402  
      * @param root
 403  
      * @return
 404  
      */
 405  
     private String getRuleData(Element root) {
 406  0
         String xPathRuleTarget = getXPathText(root);
 407  
 
 408  
         // This pattern may need to change to get the last stanza of the xpath
 409  0
         if (StringUtils.isNotBlank(xPathRuleTarget)) {
 410  0
             Matcher ruleTarget = targetPattern.matcher(xPathRuleTarget);
 411  0
             if (ruleTarget.find()) {
 412  0
                 xPathRuleTarget = ruleTarget.group(1);
 413  
             }
 414  
         }
 415  0
         return xPathRuleTarget;
 416  
     }
 417  
 
 418  
     private List<String> getXPathTerms(Element myTag) {
 419  
 
 420  
         Matcher xPathTarget;
 421  
         String firstMatch;
 422  0
         List<String> xPathTerms = new ArrayList();
 423  0
         String allText = getXPathText(myTag);// grab the whole xpath expression
 424  0
         if (StringUtils.isNotBlank(allText)) {
 425  0
             xPathTarget = xPathPattern.matcher(allText);
 426  
             Matcher termTarget;
 427  
             Matcher cleanTarget;
 428  0
             int theEnd = 0;// Have to define this or the / gets used up with the match and every other term is returned.
 429  
 
 430  0
             xPathTarget.find(theEnd);
 431  0
             theEnd = xPathTarget.end() - 1;
 432  0
             firstMatch = xPathTarget.group();
 433  
 
 434  
 
 435  0
             termTarget = termPattern.matcher(firstMatch);
 436  0
             int theEnd2 = 0;
 437  0
             while (termTarget.find(theEnd2)) { // get each term, clean them up, and add to the list.
 438  0
                 theEnd2 = termTarget.end() - 1;
 439  0
                 cleanTarget = cleanPattern.matcher(termTarget.group());
 440  0
                 cleanTarget.find();
 441  0
                 lastXPath = cleanTarget.group();
 442  0
                 xPathTerms.add(lastXPath);
 443  
 
 444  
             }
 445  
         }
 446  0
         return xPathTerms;
 447  
     }
 448  
 
 449  
     private String getLastXPath(Element root) {
 450  0
         List<String> tempList = getXPathTerms(root);
 451  0
         return tempList.get(tempList.size());
 452  
     }
 453  
 }