Refine search
public void testHandleServiceExceptionNullMessages() throws Exception { // create a stack of three exceptions NullPointerException npe = new NullPointerException(); ServiceException serviceException = new ServiceException("hello service exception"); serviceException.setCode("helloCode"); serviceException.setLocator("helloLocator"); serviceException.getExceptionText().add("NullPointerException"); serviceException.initCause(npe); handler.handleServiceException(serviceException, requestInfo); InputStream input = new ByteArrayInputStream(response.getContentAsString().getBytes()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); Document doc = docBuilderFactory.newDocumentBuilder().parse(input); Node exceptionTextNode = XPathAPI.selectSingleNode( doc, "ows:ExceptionReport/ows:Exception/ows:ExceptionText/text()"); assertNotNull(exceptionTextNode); // normalise whitespace String exceptionText = exceptionTextNode.getNodeValue().replaceAll("\\s+", " "); // used to contain an extra " null" at the end assertEquals("hello service exception NullPointerException", exceptionText); } }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the contextNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public static NodeList selectNodeList(Node contextNode, String str) throws TransformerException { return selectNodeList(contextNode, str, contextNode); }
/** * Evaluate XPath string to an XObject. Using this method, * XPath namespace prefixes will be resolved from the namespaceNode. * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see org.apache.xpath.objects.XObject * @see org.apache.xpath.objects.XNull * @see org.apache.xpath.objects.XBoolean * @see org.apache.xpath.objects.XNumber * @see org.apache.xpath.objects.XString * @see org.apache.xpath.objects.XRTreeFrag * * @throws TransformerException */ public static XObject eval(Node contextNode, String str) throws TransformerException { return eval(contextNode, str, contextNode); }
nscontext.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS); Element sigElement = (Element) XPathAPI.selectSingleNode(doc, "//ds:Signature[1]", nscontext); if((childNode.getNodeName().equals("Assertion")) && (childNode.getNodeType() == Node.ELEMENT_NODE)){ SAMLAssertion assertion = new SAMLAssertion((Element)childNode); return assertion;
protected void loadDublinCore(Context c, Item myitem, String filename) throws SQLException, IOException, ParserConfigurationException, SAXException, TransformerException, AuthorizeException { Document document = loadXML(filename); // Get the schema, for backward compatibility we will default to the // dublin core schema if the schema name is not available in the import // file String schema; NodeList metadata = XPathAPI.selectNodeList(document, "/dublin_core"); Node schemaAttr = metadata.item(0).getAttributes().getNamedItem( "schema"); if (schemaAttr == null) { schema = MetadataSchema.DC_SCHEMA; } else { schema = schemaAttr.getNodeValue(); } // Get the nodes corresponding to formats NodeList dcNodes = XPathAPI.selectNodeList(document, "/dublin_core/dcvalue"); if (!isQuiet) { System.out.println("\tLoading dublin core from " + filename); } // Add each one as a new format to the registry for (int i = 0; i < dcNodes.getLength(); i++) { Node n = dcNodes.item(i); addDCValue(c, myitem, schema, n); } }
private static List<String> getStepActionConfigs(Node stepNode) throws TransformerException { NodeList actionConfigNodes = XPathAPI.selectNodeList(stepNode, "actions/action"); List<String> actionConfigIDs = new ArrayList<String>(); for (int i = 0; i < actionConfigNodes.getLength(); i++) { actionConfigIDs.add(actionConfigNodes.item(i).getAttributes().getNamedItem("id").getTextContent()); } return actionConfigIDs; }
throws TransformerException { Node childNode = XPathAPI.selectSingleNode(parentElement, childName); Node dataNode = childNode.getFirstChild(); String value = dataNode.getNodeValue().trim();
String childName) throws TransformerException { NodeList childNodes = XPathAPI.selectNodeList(parentElement, childName); Node dataNode = childNodes.item(i).getFirstChild(); data[i] = dataNode.getNodeValue().trim();
/** * Constructor. * * @param filename selenese script file. (Don't use to open a file. It is used as a label and is used to generate filenames based on it) * @param document Test case DOM. * @param baseURL base URL. * @throws InvalidSeleneseException invalid selenese exception. */ public SeleneseCommandIterator(String filename, Document document, String baseURL) throws InvalidSeleneseException { super(filename); setId(filename); this.baseURL = baseURL; String name = ParserUtils.getNameFromFilename(filename); try { name = XPathAPI.selectSingleNode(document, "//THEAD/TR/TD").getTextContent(); Node tbody = XPathAPI.selectSingleNode(document, "//TBODY"); NodeList trList = tbody.getChildNodes(); this.nodeIterator = new NodeIterator(trList); } catch (DOMException | TransformerException e) { throw new InvalidSeleneseException(e, filename, getName()); } setName(name); this.next = nextImpl(); }
protected Step createFirstStep(Workflow workflow, Node workflowNode) throws TransformerException, WorkflowConfigurationException { String firstStepID = workflowNode.getAttributes().getNamedItem("start").getTextContent(); Node stepNode = XPathAPI.selectSingleNode(workflowNode, "step[@id='" + firstStepID + "']"); if (stepNode == null) { throw new WorkflowConfigurationException( "First step does not exist for workflow: " + workflowNode.getAttributes().getNamedItem("id") .getTextContent()); } Node roleNode = stepNode.getAttributes().getNamedItem("role"); Role role = null; if (roleNode != null) { role = workflow.getRoles().get(roleNode.getTextContent()); } String userSelectionActionID = stepNode.getAttributes().getNamedItem("userSelectionMethod").getTextContent(); UserSelectionActionConfig userSelection = createUserAssignmentActionConfig(userSelectionActionID); return new Step(firstStepID, workflow, role, userSelection, getStepActionConfigs(stepNode), getStepOutcomes(stepNode), getNbRequiredUser(stepNode)); }
XNodeSet result = (XNodeSet) XPathAPI.eval(doc, xPathString); final int nodeId = iterator.getCurrentNode(); Node resultNode = iterator.getDTM(nodeId).getNode(nodeId); String className = resultNode.getAttributes().getNamedItem("class").getTextContent(); String methodName = resultNode.getAttributes().getNamedItem("method").getTextContent(); String packageName = resultNode.getAttributes().getNamedItem("package").getTextContent(); int line = Integer.valueOf(resultNode.getAttributes().getNamedItem("line").getTextContent());
Element nsElement = parentNode.getOwnerDocument().createElement("ns"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi", nodeList = XPathAPI.selectNodeList(parentNode, "mdssi:RelationshipReference/@SourceId", nsElement); } catch (TransformerException e) { LOG.error("transformer exception: " + e.getMessage(), e); String sourceId = node.getTextContent(); LOG.debug("sourceId: " + sourceId); this.sourceIds.add(sourceId); nodeList = XPathAPI.selectNodeList(parentNode, "mdssi:RelationshipsGroupReference/@SourceType", nsElement); } catch (TransformerException e) { LOG.error("transformer exception: " + e.getMessage(), e); String sourceType = node.getTextContent(); LOG.debug("sourceType: " + sourceType); this.sourceTypes.add(sourceType);
public void testHandleServiceExceptionEncoding() throws Exception { String message = "foo & <foo> \"foo's\""; ServiceException exception = new ServiceException(message); exception.setLocator("test-locator"); handler.handleServiceException(exception, requestInfo); InputStream input = new ByteArrayInputStream(response.getContentAsString().getBytes()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); Document doc = docBuilderFactory.newDocumentBuilder().parse(input); Node exceptionText = XPathAPI.selectSingleNode( doc, "ows:ExceptionReport/ows:Exception/ows:ExceptionText/text()"); assertNotNull(exceptionText); assertEquals( "round-tripped through character entities", message, exceptionText.getTextContent()); }
private Map<String, String> getResources(byte[] document) throws IOException, ParserConfigurationException, SAXException, TransformerException { Map<String, String> signatureResources = new HashMap<String, String>(); ByteArrayInputStream bais = new ByteArrayInputStream(document); ZipInputStream zipInputStream = new ZipInputStream(bais); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (!"[Content_Types].xml".equals(zipEntry.getName())) { continue; } Document contentTypesDocument = OOXMLSignatureFacet.loadDocument(zipInputStream); Element nsElement = contentTypesDocument.createElement("ns"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns", "http://schemas.openxmlformats.org/package/2006/content-types"); for (String contentType : OOXMLSignatureFacet.contentTypes) { NodeList nodeList = XPathAPI.selectNodeList(contentTypesDocument, "/tns:Types/tns:Override[@ContentType='" + contentType + "']/@PartName", nsElement); for (int nodeIdx = 0; nodeIdx < nodeList.getLength(); nodeIdx++) { String partName = nodeList.item(nodeIdx).getTextContent(); LOG.debug("part name: " + partName); partName = partName.substring(1); // remove '/' signatureResources.put(partName, contentType); } } break; } return signatureResources; }
/** * Use an XPath string to select a single node. XPath namespace * prefixes are resolved from the context node, which may not * be what you want (see the next method). * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return The first node found that matches the XPath, or null. * * @throws TransformerException */ public static Node selectSingleNode(Node contextNode, String str) throws TransformerException { return selectSingleNode(contextNode, str, contextNode); }
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the contextNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public static NodeIterator selectNodeIterator(Node contextNode, String str) throws TransformerException { return selectNodeIterator(contextNode, str, contextNode); }
nscontext.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS); Element sigElement = (Element) XPathAPI.selectSingleNode(doc, "//ds:Signature[1]", nscontext); if((childNode.getNodeName().equals("Assertion")) && (childNode.getNodeType() == Node.ELEMENT_NODE)){ SAMLAssertion assertion = new SAMLAssertion((Element)childNode); return assertion;
Node idNode = node.getAttributes().getNamedItem("id"); String id = null; if (idNode != null) { id = idNode.getNodeValue(); Node labelNode = node.getAttributes().getNamedItem("label"); String label = null; if (labelNode != null) { value = label; NodeList subNodes = XPathAPI.selectNodeList(node, "isComposedBy/node");
protected Map<Integer, String> getStepOutcomes(Node stepNode) throws TransformerException, WorkflowConfigurationException { try { NodeList outcomesNodeList = XPathAPI.selectNodeList(stepNode, "outcomes/step"); Map<Integer, String> outcomes = new HashMap<Integer, String>(); //Add our outcome, should it be null it will be interpreted as the end of the line (last step) for (int i = 0; i < outcomesNodeList.getLength(); i++) { Node outcomeNode = outcomesNodeList.item(i); int index = Integer.parseInt(outcomeNode.getAttributes().getNamedItem("status").getTextContent()); if (index < 0) { throw new WorkflowConfigurationException( "Outcome configuration error for step: " + stepNode.getAttributes().getNamedItem("id") .getTextContent()); } outcomes.put(index, outcomeNode.getTextContent()); } return outcomes; } catch (Exception e) { log.error( "Outcome configuration error for step: " + stepNode.getAttributes().getNamedItem("id").getTextContent(), e); throw new WorkflowConfigurationException( "Outcome configuration error for step: " + stepNode.getAttributes().getNamedItem("id") .getTextContent()); } }
throws TransformerException { Node childNode = XPathAPI.selectSingleNode(parentElement, childName); Node dataNode = childNode.getFirstChild(); String value = dataNode.getNodeValue().trim();