Java Code Examples for org.apache.cxf.helpers.DOMUtils#findAllElementsByTagNameNS()
The following examples show how to use
org.apache.cxf.helpers.DOMUtils#findAllElementsByTagNameNS() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolSpec.java From cxf with Apache License 2.0 | 6 votes |
public boolean isValidInputStream(String id) { Element streams = getStreams(); if (streams == null) { return false; } List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(streams, Tool.TOOL_SPEC_PUBLIC_ID, "instream"); for (Element elem : elemList) { if (elem.getAttribute("id").equals(id)) { return true; } } return false; }
Example 2
Source File: Option.java From cxf with Apache License 2.0 | 6 votes |
public Option(Element el) { this.element = el; List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "associatedArgument"); if (elemList != null && !elemList.isEmpty()) { argument = elemList.get(0); } elemList = DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "annotation"); if (elemList != null && !elemList.isEmpty()) { annotation = elemList.get(0); } if (annotation == null && argument != null) { elemList = DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID, "annotation"); if (elemList != null && !elemList.isEmpty()) { annotation = elemList.get(0); } } }
Example 3
Source File: Option.java From cxf with Apache License 2.0 | 6 votes |
private boolean hasInvalidCharacter(String argValue) { List<Element> list = DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID, "valuetype"); //NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valuetype"); if (list != null && !list.isEmpty()) { String valuetypeStr = list.get(0).getFirstChild().getNodeValue(); if ("IdentifyString".equals(valuetypeStr)) { return !isIdentifyString(argValue, false); } else if ("NamingSpacePackageString".equals(valuetypeStr)) { return !isNamingSpacePackageString(argValue); } else if ("Digital".equals(valuetypeStr)) { for (int i = 0; i < argValue.length(); i++) { if (!Character.isDigit(argValue.charAt(i))) { return true; } } } } return false; }
Example 4
Source File: Option.java From cxf with Apache License 2.0 | 6 votes |
private boolean isInEnumArgumentValue(String argValue) { boolean result = true; List<Element> list = DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID, "valueenum"); //NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valueenum"); if (list != null && list.size() == 1) { result = false; String enumValue = list.get(0).getTextContent(); StringTokenizer stk = new StringTokenizer(enumValue, VALUE_ENUM_SEPARATOR); if (stk.countTokens() <= 0) { return result; } while (stk.hasMoreTokens()) { if (argValue.equals(stk.nextToken())) { result = true; } } } return result; }
Example 5
Source File: NettyHttpServerEngineFactoryBeanDefinitionParser.java From cxf with Apache License 2.0 | 5 votes |
private List<Object> getRequiredElementsList(Element parent, ParserContext ctx, QName name, BeanDefinitionBuilder bean) { List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(parent, name.getNamespaceURI(), name.getLocalPart()); ManagedList<Object> list = new ManagedList<>(elemList.size()); list.setSource(ctx.extractSource(parent)); for (Element elem : elemList) { list.add(ctx.getDelegate().parsePropertySubElement(elem, bean.getBeanDefinition())); } return list; }
Example 6
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGenericImplementation() throws Exception { setUpGenericImplementationTest(); WadlGenerator wg = new WadlGenerator(); wg.setApplicationTitle("My Application"); wg.setNamespacePrefix("ns"); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(ActualResource.class, ActualResource.class, true, true); Message m = mockMessage("http://example.com", "/", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); checkDocs(doc.getDocumentElement(), "My Application", "", ""); List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(2, schemasEls.size()); List<Element> importEls = DOMUtils.getChildrenWithName(schemasEls.get(0), Constants.URI_2001_SCHEMA_XSD, "import"); int schemaElementsIndex = !importEls.isEmpty() ? 0 : 1; int schemaTypesIndex = schemaElementsIndex == 0 ? 1 : 0; checkGenericImplSchemaWithTypes(schemasEls.get(schemaTypesIndex)); checkGenericImplSchemaWithElements(schemasEls.get(schemaElementsIndex)); List<Element> reps = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), WadlGenerator.WADL_NS, "representation"); assertEquals(2, reps.size()); assertEquals("ns1:actual", reps.get(0).getAttribute("element")); assertEquals("ns1:actual", reps.get(1).getAttribute("element")); }
Example 7
Source File: ToolSpec.java From cxf with Apache License 2.0 | 5 votes |
public Element getPipeline() { List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), Tool.TOOL_SPEC_PUBLIC_ID, "pipeline"); if (!elemList.isEmpty()) { return elemList.get(0); } return null; }
Example 8
Source File: ResourceUtils.java From cxf with Apache License 2.0 | 5 votes |
private static UserOperation getOperationFromElement(Element e) { UserOperation op = new UserOperation(); op.setName(e.getAttribute("name")); op.setVerb(e.getAttribute("verb")); op.setPath(e.getAttribute("path")); op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway"))); op.setConsumes(e.getAttribute("consumes")); op.setProduces(e.getAttribute("produces")); List<Element> paramEls = DOMUtils.findAllElementsByTagNameNS(e, "http://cxf.apache.org/jaxrs", "param"); List<Parameter> params = new ArrayList<>(paramEls.size()); for (int i = 0; i < paramEls.size(); i++) { Element paramEl = paramEls.get(i); Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name")); p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded"))); p.setDefaultValue(paramEl.getAttribute("defaultValue")); String pClass = paramEl.getAttribute("class"); if (!StringUtils.isEmpty(pClass)) { try { p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class)); } catch (Exception ex) { throw new RuntimeException(ex); } } params.add(p); } op.setParameters(params); return op; }
Example 9
Source File: ToolSpec.java From cxf with Apache License 2.0 | 5 votes |
public List<String> getInstreamIds() { List<String> res = new ArrayList<>(); Element streams = getStreams(); if (streams != null) { List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(streams, Tool.TOOL_SPEC_PUBLIC_ID, "instream"); for (Element elem : elemList) { res.add(elem.getAttribute("id")); } } return Collections.unmodifiableList(res); }
Example 10
Source File: ToolSpec.java From cxf with Apache License 2.0 | 5 votes |
public Element getStreams() { List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), Tool.TOOL_SPEC_PUBLIC_ID, "streams"); if (!elemList.isEmpty()) { return elemList.get(0); } return null; }
Example 11
Source File: CommandLineParser.java From cxf with Apache License 2.0 | 5 votes |
public String getDetailedUsage(String id) { String result = null; Element element = toolspec.getElementById(id); List<Element> annotations = DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "annotation"); if ((annotations != null) && (!annotations.isEmpty())) { result = annotations.get(0).getFirstChild().getNodeValue(); } return result; }
Example 12
Source File: SamlResponseCreator.java From cxf-fediz with Apache License 2.0 | 5 votes |
public String createSAMLResponse(RequestContext context, Idp idp, Element rpToken, String consumerURL, String requestId, String requestIssuer) throws ProcessingException { List<Element> samlTokens = DOMUtils.findAllElementsByTagNameNS(rpToken, WSConstants.SAML2_NS, "Assertion"); if (samlTokens.isEmpty() || samlTokens.size() != 1) { throw new ProcessingException(TYPE.BAD_REQUEST); } try { SamlAssertionWrapper wrapper = new SamlAssertionWrapper(samlTokens.get(0)); if (wrapper.getSaml2() == null) { throw new ProcessingException(TYPE.BAD_REQUEST); } String remoteAddr = WebUtils.getHttpServletRequest(context).getRemoteAddr(); Assertion saml2Assertion = createSAML2Assertion(context, idp, wrapper, requestId, requestIssuer, remoteAddr, consumerURL); Element response = createResponse(idp, requestId, saml2Assertion); return encodeResponse(response); } catch (Exception ex) { LOG.warn("Error marshalling SAML Token: {}", ex.getMessage()); throw new ProcessingException(TYPE.BAD_REQUEST); } }
Example 13
Source File: JettyHTTPServerEngineFactoryBeanDefinitionParser.java From cxf with Apache License 2.0 | 5 votes |
private List<Object> getRequiredElementsList(Element parent, ParserContext ctx, QName name, BeanDefinitionBuilder bean) { List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(parent, name.getNamespaceURI(), name.getLocalPart()); ManagedList<Object> list = new ManagedList<>(elemList.size()); list.setSource(ctx.extractSource(parent)); for (Element elem : elemList) { list.add(ctx.getDelegate().parsePropertySubElement(elem, bean.getBeanDefinition())); } return list; }
Example 14
Source File: OptionGroup.java From cxf with Apache License 2.0 | 5 votes |
public OptionGroup(Element el) { this.element = el; List<Element> optionEls = DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "option"); for (Element elem : optionEls) { options.add(new Option(elem)); } }
Example 15
Source File: WSDLGetUtils.java From cxf with Apache License 2.0 | 5 votes |
protected void rewriteAddressProtocolHostPort(String base, Element el, String httpBasePathProp, String soapNS) { List<Element> sadEls = DOMUtils.findAllElementsByTagNameNS(el, soapNS, "address"); for (Element soapAddress : sadEls) { String location = soapAddress.getAttribute("location").trim(); try { URI locUri = new URI(location); if (locUri.isAbsolute()) { URL baseUrl = new URL(base); StringBuilder sb = new StringBuilder(baseUrl.getProtocol()); sb.append("://").append(baseUrl.getHost()); int port = baseUrl.getPort(); if (port > 0) { sb.append(':').append(port); } sb.append(locUri.getPath()); soapAddress.setAttribute("location", sb.toString()); } else if (httpBasePathProp != null) { soapAddress.setAttribute("location", httpBasePathProp + location); } } catch (Exception e) { //ignore } } }
Example 16
Source File: JAXBUtils.java From cxf with Apache License 2.0 | 5 votes |
private static Node innerJaxbBinding(Element schema) { String schemaNamespace = schema.getNamespaceURI(); List<Element> annoList = DOMUtils.findAllElementsByTagNameNS(schema, schemaNamespace, "annotation"); Element annotation = null; if (!annoList.isEmpty()) { annotation = annoList.get(0); } else { annotation = schema.getOwnerDocument().createElementNS(schemaNamespace, "annotation"); } List<Element> appList = DOMUtils.findAllElementsByTagNameNS(annotation, schemaNamespace, "appinfo"); Element appInfo = null; if (!appList.isEmpty()) { appInfo = appList.get(0); } else { appInfo = schema.getOwnerDocument().createElementNS(schemaNamespace, "appinfo"); annotation.appendChild(appInfo); } Element jaxbBindings = null; List<Element> jaxbList = DOMUtils.findAllElementsByTagNameNS(schema, ToolConstants.NS_JAXB_BINDINGS, "schemaBindings"); if (!jaxbList.isEmpty()) { jaxbBindings = jaxbList.get(0); } else { jaxbBindings = schema.getOwnerDocument().createElementNS(ToolConstants.NS_JAXB_BINDINGS, "schemaBindings"); appInfo.appendChild(jaxbBindings); } return jaxbBindings; }
Example 17
Source File: WSDLGetUtils.java From cxf with Apache License 2.0 | 5 votes |
protected void rewriteAddress(String base, Element el, String soapNS) { List<Element> sadEls = DOMUtils.findAllElementsByTagNameNS(el, soapNS, "address"); for (Element soapAddress : sadEls) { soapAddress.setAttribute("location", base); } }
Example 18
Source File: ResourceUtils.java From cxf with Apache License 2.0 | 5 votes |
public static List<UserResource> getResourcesFromElement(Element modelEl) { List<UserResource> resources = new ArrayList<>(); List<Element> resourceEls = DOMUtils.findAllElementsByTagNameNS(modelEl, "http://cxf.apache.org/jaxrs", "resource"); for (Element e : resourceEls) { resources.add(getResourceFromElement(e)); } return resources; }
Example 19
Source File: ValidatorUtil.java From cxf with Apache License 2.0 | 4 votes |
/** * Get a map of wsdls imported by the given wsdl. Keys in the * map are the imported namespaces. Values are the imported * wsdl Documents. * * @param document The wsdl Document * @param basePath The path of the wsdl * @return map of imported wsdls * @throws IOException * @throws SAXException */ public static Map<String, Document> getImportedWsdlMap(Document document, String basePath) throws IOException, SAXException { Map<String, Document> docMap = new HashMap<>(); if (document == null) { return docMap; } DocumentBuilder docBuilder = null; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); docFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); docBuilder = docFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new ToolException(e); } // // Remove the scheme part of a URI - need to escape spaces in // case we are on Windows and have spaces in directory names. // String myBasePath = basePath; try { myBasePath = new URI(basePath.replaceAll(" ", "%20")).getPath(); } catch (URISyntaxException e1) { // This will be problematic... } List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(document.getDocumentElement(), WSDLConstants.NS_WSDL11, "import"); for (Element elem : elemList) { NamedNodeMap attributes = elem.getAttributes(); String systemId; String namespace = attributes.getNamedItem("namespace").getNodeValue(); // Is this ok? if (docMap.containsKey(namespace)) { continue; } try { systemId = getImportedUrl( attributes.getNamedItem("location").getNodeValue(), myBasePath); } catch (IOException ioe) { throw new ToolException(ioe); } if (namespace != null && systemId != null) { Document docImport = docBuilder.parse(systemId); Node node = DOMUtils.getChild(docImport, null); if (node != null && !"definitions".equals(node.getLocalName())) { Message msg = new Message("NOT_A_WSDLFILE", LOG, systemId); throw new ToolException(msg); } docMap.putAll(getImportedWsdlMap(docImport, myBasePath)); docMap.put(namespace, docImport); } } return docMap; }
Example 20
Source File: ValidatorUtil.java From cxf with Apache License 2.0 | 4 votes |
/** * Get a list of schemas found in a wsdl Document. * The list will include any schemas from imported wsdls. * * @param document The wsdl Document. * @param baseURI The URI of the wsdl. Allows schemas with relative * paths to be resolved. * @return XmlSchemaCollection list * @throws IOException * @throws SAXException */ public static List<SchemaCollection> getSchemaList(Document document, String baseURI) throws IOException, SAXException { List<SchemaCollection> schemaList = new ArrayList<>(); if (document == null) { return schemaList; } synchronized (document) { // URL might need encoding for special characters. baseURI = URLEncoder.encode(baseURI, "utf-8"); SchemaCollection schemaCol = new SchemaCollection(); schemaCol.setBaseUri(baseURI); List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(document.getDocumentElement(), WSDLConstants.NS_SCHEMA_XSD, "schema"); for (Element schemaEl : elemList) { String tns = schemaEl.getAttribute("targetNamespace"); try { schemaCol.read(schemaEl, tns); } catch (RuntimeException ex) { LOG.log(Level.WARNING, "SCHEMA_READ_FAIL", tns); // Couldn't find schema... check if it's relative to wsdl. // Using setBaseUri() on the XmlSchemaCollection, // only seems to work for the first imported xsd... so pass // in the baseURI here. try { schemaCol.read(schemaEl, baseURI); } catch (RuntimeException ex2) { LOG.log(Level.WARNING, "SCHEMA_READ_FAIL", baseURI); continue; } } } schemaList.add(schemaCol); // Now add schemas from imported wsdl files. Map<String, Document> wsdlImports = getImportedWsdlMap( document, baseURI); for (Document wsdlImport : wsdlImports.values()) { schemaList.addAll(getSchemaList(wsdlImport, baseURI)); } } return schemaList; }