List of usage examples for javax.xml.xpath XPathConstants NODE
QName NODE
To view the source code for javax.xml.xpath XPathConstants NODE.
Click Source Link
The XPath 1.0 NodeSet data type.
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private RouteNode makeRouteNodePrototype(String nodeTypeName, String nodeName, String nodeExpression, Node routeNodesNode, DocumentType documentType, RoutePathContext context) throws XPathExpressionException, GroupNotFoundException, XmlException { NodeList nodeList;/* ww w . j a v a2 s. co m*/ try { nodeList = (NodeList) getXPath().evaluate(nodeExpression, routeNodesNode, XPathConstants.NODESET); } catch (XPathExpressionException xpee) { LOG.error("Error evaluating node expression: '" + nodeExpression + "'"); throw xpee; } if (nodeList.getLength() > 1) { throw new XmlException("More than one node under routeNodes has the same name of '" + nodeName + "'"); } if (nodeList.getLength() == 0) { throw new XmlException("No node definition was found with the name '" + nodeName + "'"); } Node node = nodeList.item(0); RouteNode routeNode = new RouteNode(); // set fields that all route nodes of all types should have defined routeNode.setDocumentType(documentType); routeNode.setRouteNodeName((String) getXPath().evaluate("./@name", node, XPathConstants.STRING)); routeNode.setContentFragment(XmlJotter.jotNode(node)); if (XmlHelper.pathExists(xpath, "./activationType", node)) { routeNode.setActivationType(ActivationTypeEnum .parse((String) getXPath().evaluate("./activationType", node, XPathConstants.STRING)) .getCode()); } else { routeNode.setActivationType(DEFAULT_ACTIVATION_TYPE); } Group exceptionWorkgroup = defaultExceptionWorkgroup; String exceptionWg = null; String exceptionWorkgroupName = null; String exceptionWorkgroupNamespace = null; if (XmlHelper.pathExists(xpath, "./" + EXCEPTION_GROUP_NAME, node)) { exceptionWorkgroupName = Utilities .substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_GROUP_NAME, node, XPathConstants.STRING)) .trim(); exceptionWorkgroupNamespace = Utilities .substituteConfigParameters((String) getXPath() .evaluate("./" + EXCEPTION_GROUP_NAME + "/@" + NAMESPACE, node, XPathConstants.STRING)) .trim(); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName) && XmlHelper.pathExists(xpath, "./" + EXCEPTION_WORKGROUP_NAME, node)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(EXCEPTION_WORKGROUP_NAME).append("', please use '").append(EXCEPTION_GROUP_NAME) .append("' instead.").toString()); // for backward compatibility we also need to be able to support exceptionWorkgroupName exceptionWg = Utilities.substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_WORKGROUP_NAME, node, XPathConstants.STRING)); exceptionWorkgroupName = Utilities.parseGroupName(exceptionWg); exceptionWorkgroupNamespace = Utilities.parseGroupNamespaceCode(exceptionWg); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName) && XmlHelper.pathExists(xpath, "./" + EXCEPTION_WORKGROUP, node)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(EXCEPTION_WORKGROUP).append("', please use '").append(EXCEPTION_GROUP_NAME) .append("' instead.").toString()); // for backward compatibility we also need to be able to support exceptionWorkgroup exceptionWg = Utilities.substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_WORKGROUP, node, XPathConstants.STRING)); exceptionWorkgroupName = Utilities.parseGroupName(exceptionWg); exceptionWorkgroupNamespace = Utilities.parseGroupNamespaceCode(exceptionWg); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName)) { if (routeNode.getDocumentType().getDefaultExceptionWorkgroup() != null) { exceptionWorkgroupName = routeNode.getDocumentType().getDefaultExceptionWorkgroup().getName(); exceptionWorkgroupNamespace = routeNode.getDocumentType().getDefaultExceptionWorkgroup() .getNamespaceCode(); } } if (org.apache.commons.lang.StringUtils.isNotEmpty(exceptionWorkgroupName) && org.apache.commons.lang.StringUtils.isNotEmpty(exceptionWorkgroupNamespace)) { exceptionWorkgroup = getGroupService().getGroupByNamespaceCodeAndName(exceptionWorkgroupNamespace, exceptionWorkgroupName); if (exceptionWorkgroup == null) { throw new GroupNotFoundException("Could not locate exception workgroup with namespace '" + exceptionWorkgroupNamespace + "' and name '" + exceptionWorkgroupName + "'"); } } else { if (StringUtils.isEmpty(exceptionWorkgroupName) ^ StringUtils.isEmpty(exceptionWorkgroupNamespace)) { throw new GroupNotFoundException("Could not locate exception workgroup with namespace '" + exceptionWorkgroupNamespace + "' and name '" + exceptionWorkgroupName + "'"); } } if (exceptionWorkgroup != null) { routeNode.setExceptionWorkgroupName(exceptionWorkgroup.getName()); routeNode.setExceptionWorkgroupId(exceptionWorkgroup.getId()); } if (((Boolean) getXPath().evaluate("./mandatoryRoute", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setMandatoryRouteInd( Boolean.valueOf((String) getXPath().evaluate("./mandatoryRoute", node, XPathConstants.STRING))); } else { routeNode.setMandatoryRouteInd(Boolean.FALSE); } if (((Boolean) getXPath().evaluate("./finalApproval", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setFinalApprovalInd( Boolean.valueOf((String) getXPath().evaluate("./finalApproval", node, XPathConstants.STRING))); } else { routeNode.setFinalApprovalInd(Boolean.FALSE); } // for every simple child element of the node, store a config parameter of the element name and text content NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n instanceof Element) { Element e = (Element) n; String name = e.getNodeName(); String content = getTextContent(e); routeNode.getConfigParams().add(new RouteNodeConfigParam(routeNode, name, content)); } } // make sure a default rule selector is set Map<String, String> cfgMap = Utilities.getKeyValueCollectionAsMap(routeNode.getConfigParams()); if (!cfgMap.containsKey(RouteNode.RULE_SELECTOR_CFG_KEY)) { routeNode.getConfigParams().add(new RouteNodeConfigParam(routeNode, RouteNode.RULE_SELECTOR_CFG_KEY, FlexRM.DEFAULT_RULE_SELECTOR)); } if (((Boolean) getXPath().evaluate("./ruleTemplate", node, XPathConstants.BOOLEAN)).booleanValue()) { String ruleTemplateName = (String) getXPath().evaluate("./ruleTemplate", node, XPathConstants.STRING); RuleTemplateBo ruleTemplate = KEWServiceLocator.getRuleTemplateService() .findByRuleTemplateName(ruleTemplateName); if (ruleTemplate == null) { throw new XmlException("Rule template for node '" + routeNode.getRouteNodeName() + "' not found: " + ruleTemplateName); } routeNode.setRouteMethodName(ruleTemplateName); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_FLEX_RM); } else if (((Boolean) getXPath().evaluate("./routeModule", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode .setRouteMethodName((String) getXPath().evaluate("./routeModule", node, XPathConstants.STRING)); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_ROUTE_MODULE); } else if (((Boolean) getXPath().evaluate("./peopleFlows", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_PEOPLE_FLOW); } else if (((Boolean) getXPath().evaluate("./rulesEngine", node, XPathConstants.BOOLEAN)).booleanValue()) { // validate that the element has at least one of the two required attributes, XML schema does not provide a way for us to // check this so we must do so programatically Element rulesEngineElement = (Element) getXPath().evaluate("./rulesEngine", node, XPathConstants.NODE); String executorName = rulesEngineElement.getAttribute("executorName"); String executorClass = rulesEngineElement.getAttribute("executorClass"); if (StringUtils.isBlank(executorName) && StringUtils.isBlank(executorClass)) { throw new XmlException( "The rulesEngine declaration must have at least one of 'executorName' or 'executorClass' attributes."); } else if (StringUtils.isNotBlank(executorName) && StringUtils.isNotBlank(executorClass)) { throw new XmlException( "Only one of 'executorName' or 'executorClass' may be declared on rulesEngine configuration, but both were declared."); } routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_RULES_ENGINE); } String nodeType = null; if (((Boolean) getXPath().evaluate("./type", node, XPathConstants.BOOLEAN)).booleanValue()) { nodeType = (String) getXPath().evaluate("./type", node, XPathConstants.STRING); } else { String localName = (String) getXPath().evaluate("local-name(.)", node, XPathConstants.STRING); if ("start".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.InitialNode"; } else if ("split".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleSplitNode"; } else if ("join".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleJoinNode"; } else if ("requests".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.RequestsNode"; } else if ("process".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleSubProcessNode"; } else if (NodeType.ROLE.getName().equalsIgnoreCase(localName)) { nodeType = RoleNode.class.getName(); } } if (org.apache.commons.lang.StringUtils.isEmpty(nodeType)) { throw new XmlException( "Could not determine node type for the node named '" + routeNode.getRouteNodeName() + "'"); } routeNode.setNodeType(nodeType); String localName = (String) getXPath().evaluate("local-name(.)", node, XPathConstants.STRING); if ("split".equalsIgnoreCase(localName)) { context.splitNodeStack.addFirst(routeNode); } else if ("join".equalsIgnoreCase(localName) && context.splitNodeStack.size() != 0) { // join node should have same branch prototype as split node RouteNode splitNode = (RouteNode) context.splitNodeStack.removeFirst(); context.branch = splitNode.getBranch(); } else if (NodeType.ROLE.getName().equalsIgnoreCase(localName)) { routeNode.setRouteMethodName(RoleRouteModule.class.getName()); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_ROUTE_MODULE); } routeNode.setBranch(context.branch); return routeNode; }
From source file:org.kuali.rice.kew.xml.xstream.XStreamSafeEvaluator.java
/** * Resolves the reference to a Node by checking for a "reference" attribute and returning the resolved node if * it's there. The resolution happens by grabbing the value of the reference and evaluation it as an XPath * expression against the given Node. If there is no reference attribute, the node passed in is returned. * The method is recursive in the fact that it will continue to follow XStream "reference" attributes until it * reaches a resolved node./*from www . j av a 2 s.c o m*/ */ private Node resolveNodeReference(XPath xpath, Node node) throws XPathExpressionException { NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node referenceNode = attributes.getNamedItem(XSTREAM_REFERENCE_ATTRIBUTE); if (referenceNode != null) { node = (Node) xpath.evaluate(referenceNode.getNodeValue(), node, XPathConstants.NODE); if (node != null) { node = resolveNodeReference(xpath, node); } else { throw new XPathExpressionException( "Could not locate the node for the given XStream references expression: '" + referenceNode.getNodeValue() + "'"); } } } return node; }
From source file:org.kuali.rice.kns.workflow.attribute.KualiXmlAttributeHelper.java
/** * This method gets all of the text from the xpathexpression element. * * @param root//from w ww. jav a 2 s . c o m * @return */ private String getXPathText(Element root) { try { String textContent = null; Node node = (Node) xpath.evaluate(".//xpathexpression", root, XPathConstants.NODE); if (node != null) { textContent = node.getTextContent(); } return textContent; } catch (XPathExpressionException e) { LOG.error("No XPath expression text found in element xpathexpression of configXML for document. " + e); return null; // throw e; Just writing labels or doing routing report. } }
From source file:org.kuali.rice.kns.workflow.KualiXMLAttributeImplTest.java
/** * compares the label from the test to the expected, or not expected, value for all of the rule attributes in the file * * <p>The inputSource file should be as close to the production version as possible, as described by the class comments. It * accepts the string to test against as a parameter.</p> * /*ww w .j ava 2 s.com*/ * @param testString * @param attributeXml * @param configNodeName */ private boolean confirmLabels(String testString, String attributeXml, String configNodeName) { boolean testFailed = false; String theTitle = ""; String theName = ""; String attributeName = ""; try { NodeList tempList = (NodeList) myXPath.evaluate("//ruleAttribute", new InputSource(new StringReader(attributeXml)), XPathConstants.NODESET); for (int i = 0; i < tempList.getLength(); i++) { // loop over ruleattributes Node originalNode = tempList.item(i); Set ruleAttributeFieldDefNames = new HashSet(); Set ruleAttributeFieldDefTitles = new HashSet(); attributeName = (String) myXPath.evaluate(WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "name", originalNode, XPathConstants.STRING); Node classNameNode = (Node) myXPath.evaluate( WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "className", originalNode, XPathConstants.NODE); if ((classNameNode != null) && (classNameNode.getFirstChild() != null)) { if (LOG.isInfoEnabled()) { LOG.info("Checking attribute with name '" + attributeName + "'"); } KualiXmlAttribute myAttribute = (KualiXmlAttribute) GlobalResourceLoader .getObject(new ObjectDefinition(classNameNode.getFirstChild().getNodeValue())); Node xmlNode = configureRuleAttribute(originalNode, myAttribute); NamedNodeMap fieldDefAttributes = null; String potentialFailMessage = ""; try { NodeList xmlNodeList = (NodeList) myXPath.evaluate("//fieldDef", xmlNode, XPathConstants.NODESET); for (int j = 0; j < xmlNodeList.getLength(); j++) { Node fieldDefXmlNode = xmlNodeList.item(j); fieldDefAttributes = fieldDefXmlNode.getAttributes(); theTitle = fieldDefAttributes.getNamedItem("title").getNodeValue();// Making sure they are clean theName = fieldDefAttributes.getNamedItem("name").getNodeValue(); if (LOG.isDebugEnabled()) { LOG.debug(attributeName); LOG.debug("name=" + theName + " title=" + theTitle); } if (ruleAttributeFieldDefNames.contains(theName)) { // names of fieldDefs inside a single attribute must be unique potentialFailMessage = "Each fieldDef name on a single attribute must be unique and the fieldDef name '" + theName + "' already exists on the attribute '" + attributeName + "'"; Assert.fail(potentialFailMessage); } else { ruleAttributeFieldDefNames.add(theName); } if (testString.equals(KualiXmlAttributeHelper.notFound)) { potentialFailMessage = "Each fieldDef title should be a valid value and currently the title for attribute '" + attributeName + "' is '" + theTitle + "'"; Assert.assertFalse(potentialFailMessage, theTitle.equals(testString)); if (ruleAttributeFieldDefTitles.contains(theTitle)) { /* * Titles of fieldDefs inside a single attribute should be unique in the normal case. Having two * fields with the same label would certainly confuse the user. However, due to the way the * confirmSource test works, all the titles/labels must be the same. So only run this check when * not in the confirmSource test. */ potentialFailMessage = "Each fieldDef title on a single attribute must be unique and the fieldDef title '" + theTitle + "' already exists on the attribute '" + attributeName + "'"; Assert.fail(potentialFailMessage); } else { ruleAttributeFieldDefTitles.add(theTitle); } } else { potentialFailMessage = "For attribute '" + attributeName + "' the title should have been '" + testString + "' but was actually '" + theTitle + "'"; Assert.assertEquals(potentialFailMessage, testString, theTitle); } } } catch (AssertionError afe) { LOG.warn("Assertion Failed for attribute '" + attributeName + "' with error " + potentialFailMessage, afe); testFailed = true; } finally { attributeName = ""; } } else { throw new RuntimeException("Could not find class for attribute named '" + attributeName + "'"); } } } catch (Exception e) { LOG.error("General Exception thrown for attribute '" + attributeName + "'", e); testFailed = true; } return testFailed; }
From source file:org.kuali.rice.krad.demo.uif.library.fields.DemoFieldsActionAft.java
protected void testActionFieldImages() throws Exception { WebElement exampleDiv = navigateToExample("Demo-ActionField-Example5"); List<WebElement> fields = exampleDiv.findElements(By.cssSelector("a.uif-actionLink")); assertEquals(2, fields.size());/* w w w . ja v a2 s . c o m*/ WebElement leftField = fields.get(0); WebElement rightField = fields.get(1); String leftFieldId = leftField.getAttribute("id"); String rightFieldId = rightField.getAttribute("id"); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); XPath xPathFactory = XPathFactory.newInstance().newXPath(); Document document = builder.parse(IOUtils.toInputStream(driver.getPageSource())); Node leftFieldImg = (Node) xPathFactory.evaluate("//a[@id='" + leftFieldId + "']/img", document, XPathConstants.NODE); Node leftFieldImgNextSibling = leftFieldImg.getNextSibling(); if (!leftFieldImgNextSibling.getTextContent().contains("Action Link with left image")) { fail("Image is not on the left of the link"); } Node rightFieldText = (Node) xPathFactory.evaluate( "//a[@id='" + rightFieldId + "']/text()[contains(., 'Action Link with right image')]", document, XPathConstants.NODE); Node rightFieldTextNextSibling = rightFieldText.getNextSibling(); if (!rightFieldTextNextSibling.getNodeName().equals("img")) { fail("Image is not on the right of the link"); } }
From source file:org.kuali.rice.krad.demo.uif.library.fields.DemoFieldsActionAft.java
protected void testActionFieldButtons() throws Exception { WebElement exampleDiv = navigateToExample("Demo-ActionField-Example6"); List<WebElement> fields = exampleDiv.findElements(By.cssSelector("button.btn-primary")); assertEquals(7, fields.size());/*from ww w. j a va2s. co m*/ String buttonFieldId = fields.get(0).getAttribute("id"); String imageBottomFieldId = fields.get(1).getAttribute("id"); String imageTopFieldId = fields.get(2).getAttribute("id"); String imageLeftFieldId = fields.get(3).getAttribute("id"); String imageRightFieldId = fields.get(4).getAttribute("id"); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); XPath xPathFactory = XPathFactory.newInstance().newXPath(); Document document = builder.parse(IOUtils.toInputStream(driver.getPageSource())); assertIsVisible("#" + buttonFieldId); waitAndClickButtonByText(fields.get(0).getText()); assertTrue(driver.switchTo().alert().getText().contains("You clicked a button")); alertAccept(); assertElementPresent("#" + imageBottomFieldId + " span.topBottomSpan img[src*='searchicon.png']"); Node topFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageBottomFieldId + "']/text()[contains(., 'Image BOTTOM')]", document, XPathConstants.NODE); Node topFieldTextNextSibling = topFieldText.getNextSibling(); if (!topFieldTextNextSibling.getNodeName().equals("span")) { fail("Image is not on the bottom of the text"); } assertElementPresent("#" + imageTopFieldId + " span.topBottomSpan img[src*='searchicon.png']"); Node bottomFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageTopFieldId + "']/text()[contains(., 'Image TOP')]", document, XPathConstants.NODE); Node bottomFieldImgNextSibling = bottomFieldText.getPreviousSibling(); if (!bottomFieldImgNextSibling.getNodeName().contains("span")) { fail("Image is not on the top of the text"); } Node leftFieldImg = (Node) xPathFactory.evaluate("//button[@id='" + imageLeftFieldId + "']/img", document, XPathConstants.NODE); Node leftFieldImgNextSibling = leftFieldImg.getNextSibling(); if (!leftFieldImgNextSibling.getTextContent().contains("Image LEFT")) { fail("Image is not on the left of the text"); } Node rightFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageRightFieldId + "']/text()[contains(., 'Image RIGHT')]", document, XPathConstants.NODE); Node rightFieldTextNextSibling = rightFieldText.getNextSibling(); if (!rightFieldTextNextSibling.getNodeName().equals("img")) { fail("Image is not on the right of the text"); } driver.findElement(By .xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img")); driver.findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]")); driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]")); }
From source file:org.kuali.rice.krad.workflow.KualiXMLAttributeImplTest.java
/** * This method compares the label from the test to the expected, or not expected, value for all of the rule attributes in the * file. The inputSource file should be as close to the production version as possible, as described by the class comments. It * accepts the string to test against as a parameter. * /*from w ww . j a va2 s . c o m*/ * @param testString */ private boolean confirmLabels(String testString, String attributeXml, String configNodeName) { boolean testFailed = false; String theTitle = ""; String theName = ""; String attributeName = ""; try { NodeList tempList = (NodeList) myXPath.evaluate("//ruleAttribute", new InputSource(new StringReader(attributeXml)), XPathConstants.NODESET); for (int i = 0; i < tempList.getLength(); i++) { // loop over ruleattributes Node originalNode = tempList.item(i); Set ruleAttributeFieldDefNames = new HashSet(); Set ruleAttributeFieldDefTitles = new HashSet(); attributeName = (String) myXPath.evaluate(WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "name", originalNode, XPathConstants.STRING); Node classNameNode = (Node) myXPath.evaluate( WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "className", originalNode, XPathConstants.NODE); if ((classNameNode != null) && (classNameNode.getFirstChild() != null)) { if (LOG.isInfoEnabled()) { LOG.info("Checking attribute with name '" + attributeName + "'"); } KualiXmlAttribute myAttribute = (KualiXmlAttribute) GlobalResourceLoader .getObject(new ObjectDefinition(classNameNode.getFirstChild().getNodeValue())); Node xmlNode = configureRuleAttribute(originalNode, myAttribute); NamedNodeMap fieldDefAttributes = null; String potentialFailMessage = ""; try { NodeList xmlNodeList = (NodeList) myXPath.evaluate("//fieldDef", xmlNode, XPathConstants.NODESET); for (int j = 0; j < xmlNodeList.getLength(); j++) { Node fieldDefXmlNode = xmlNodeList.item(j); fieldDefAttributes = fieldDefXmlNode.getAttributes(); theTitle = fieldDefAttributes.getNamedItem("title").getNodeValue();// Making sure they are clean theName = fieldDefAttributes.getNamedItem("name").getNodeValue(); if (LOG.isDebugEnabled()) { LOG.debug(attributeName); LOG.debug("name=" + theName + " title=" + theTitle); } if (ruleAttributeFieldDefNames.contains(theName)) { // names of fieldDefs inside a single attribute must be unique potentialFailMessage = "Each fieldDef name on a single attribute must be unique and the fieldDef name '" + theName + "' already exists on the attribute '" + attributeName + "'"; fail(potentialFailMessage); } else { ruleAttributeFieldDefNames.add(theName); } if (testString.equals(KualiXmlAttributeHelper.notFound)) { potentialFailMessage = "Each fieldDef title should be a valid value and currently the title for attribute '" + attributeName + "' is '" + theTitle + "'"; assertFalse(potentialFailMessage, theTitle.equals(testString)); if (ruleAttributeFieldDefTitles.contains(theTitle)) { /* * Titles of fieldDefs inside a single attribute should be unique in the normal case. Having two * fields with the same label would certainly confuse the user. However, due to the way the * confirmSource test works, all the titles/labels must be the same. So only run this check when * not in the confirmSource test. */ potentialFailMessage = "Each fieldDef title on a single attribute must be unique and the fieldDef title '" + theTitle + "' already exists on the attribute '" + attributeName + "'"; fail(potentialFailMessage); } else { ruleAttributeFieldDefTitles.add(theTitle); } } else { potentialFailMessage = "For attribute '" + attributeName + "' the title should have been '" + testString + "' but was actually '" + theTitle + "'"; assertEquals(potentialFailMessage, testString, theTitle); } } } catch (AssertionError afe) { LOG.warn("Assertion Failed for attribute '" + attributeName + "' with error " + potentialFailMessage, afe); testFailed = true; } finally { attributeName = ""; } } else { throw new RuntimeException("Could not find class for attribute named '" + attributeName + "'"); } } } catch (Exception e) { LOG.error("General Exception thrown for attribute '" + attributeName + "'", e); testFailed = true; } return testFailed; }
From source file:org.linguafranca.pwdb.kdbx.dom.DomHelper.java
@Nullable @Contract("_,_,true -> !null") static Element getElement(String elementPath, Element parentElement, boolean create) { try {/* w w w . j ava2 s . c o m*/ Element result = (Element) xpath.evaluate(elementPath, parentElement, XPathConstants.NODE); if (result == null && create) { result = createHierarchically(elementPath, parentElement); } return result; } catch (XPathExpressionException e) { throw new IllegalStateException(e); } }
From source file:org.linguafranca.pwdb.kdbx.dom.DomHelper.java
private static Element createHierarchically(String elementPath, Element startElement) { Element currentElement = startElement; for (String elementName : elementPath.split("/")) { try {//from w w w . j av a 2 s .com Element nextElement = (Element) xpath.evaluate(elementName, currentElement, XPathConstants.NODE); if (nextElement == null) { nextElement = (Element) currentElement .appendChild(currentElement.getOwnerDocument().createElement(elementName)); } currentElement = nextElement; } catch (XPathExpressionException e) { throw new IllegalStateException(e); } } return currentElement; }
From source file:org.linguafranca.pwdb.kdbx.dom.DomSerializableDatabase.java
public static DomSerializableDatabase createEmptyDatabase() throws IOException { DomSerializableDatabase result = new DomSerializableDatabase(); // read in the template KeePass XML database result.load(result.getClass().getClassLoader().getResourceAsStream("base.kdbx.xml")); try {/*from w ww . j a v a 2 s . com*/ // replace all placeholder dates with now String now = DomHelper.dateFormatter.format(new Date()); NodeList list = (NodeList) DomHelper.xpath.evaluate("//*[contains(text(),'${creationDate}')]", result.doc.getDocumentElement(), XPathConstants.NODESET); for (int i = 0; i < list.getLength(); i++) { list.item(i).setTextContent(now); } // set the root group UUID Node uuid = (Node) DomHelper.xpath.evaluate("//" + DomHelper.UUID_ELEMENT_NAME, result.doc.getDocumentElement(), XPathConstants.NODE); uuid.setTextContent(DomHelper.base64RandomUuid()); } catch (XPathExpressionException e) { throw new IllegalStateException(e); } result.setEncryption(new Salsa20StreamEncryptor(SecureRandom.getSeed(32))); return result; }