/** * Creates an {@link EntityResolver} that consults {@code /WEB-INF/jax-ws-catalog.xml}. */ private EntityResolver createEntityResolver() { try { return XmlUtil.createEntityResolver(loader.getCatalogFile()); } catch (MalformedURLException e) { throw new WebServiceException(e); } }
public static QName getQName(XMLStreamReader reader, String tag){ String localName = XmlUtil.getLocalPart(tag); String pfix = XmlUtil.getPrefix(tag); String uri = reader.getNamespaceURI(fixNull(pfix)); return new QName(uri, localName); }
private static void displayDOM(Node node, java.io.OutputStream ostream) { try { System.out.println("\n====\n"); XmlUtil.newTransformer().transform( new DOMSource(node), new StreamResult(ostream)); System.out.println("\n====\n"); } catch (Exception e) { e.printStackTrace(); } }
public void registerNamespaces(Element e) { for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) { Attr a = (Attr) iter.next(); if (a.getName().equals(PREFIX_XMLNS)) { // default namespace declaration _nsSupport.declarePrefix("", a.getValue()); } else { String prefix = XmlUtil.getPrefix(a.getName()); if (prefix != null && prefix.equals(PREFIX_XMLNS)) { String nsPrefix = XmlUtil.getLocalPart(a.getName()); String uri = a.getValue(); _nsSupport.declarePrefix(nsPrefix, uri); } } } }
/** * Performs identity transformation. * @param <T> * @param src * @param result * @return * @throws javax.xml.transform.TransformerException * @throws java.io.IOException * @throws org.xml.sax.SAXException * @throws javax.xml.parsers.ParserConfigurationException */ public static <T extends Result> T identityTransform(Source src, T result) throws TransformerException, SAXException, ParserConfigurationException, IOException { if (src instanceof StreamSource) { // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing // is not turned on by default StreamSource ssrc = (StreamSource) src; TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler(); th.setResult(result); XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader(); reader.setContentHandler(th); reader.setProperty(LEXICAL_HANDLER_PROPERTY, th); reader.parse(toInputSource(ssrc)); } else { newTransformer().transform(src, result); } return result; }
msEpr.addr = new MemberSubmissionEndpointReference.Address(); msEpr.addr.uri = XmlUtil.getTextForNode(child); String prefix = XmlUtil.getPrefix(service); String name = XmlUtil.getLocalPart(service); String prefix = XmlUtil.getPrefix(portType); String name = XmlUtil.getLocalPart(portType);
/** * Returns true if body has explicit parts declaration */ private static boolean parseSOAPBodyBinding(XMLStreamReader reader, Map<String, ParameterBinding> parts) { String partsString = reader.getAttributeValue(null, "parts"); if (partsString != null) { List<String> partsList = XmlUtil.parseTokenList(partsString); if (partsList.isEmpty()) { parts.put(" ", ParameterBinding.BODY); } else { for (String part : partsList) { parts.put(part, ParameterBinding.BODY); } } return true; } return false; }
public void writeTo(SOAPMessage saaj) throws SOAPException { try { // TODO what about in-scope namespaces // Not very efficient consider implementing a stream buffer // processor that produces a DOM node from the buffer. Transformer t = XmlUtil.newTransformer(); SOAPHeader header = saaj.getSOAPHeader(); if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); // TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be // uncommented and all lines below, except the catch block, can be removed. // t.transform(epr.asSource(localName), new DOMResult(header)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos); epr.writeTo(localName, w); w.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false); fac.setNamespaceAware(true); Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement(); Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true); header.appendChild(eprNodeToAdd); } catch (Exception e) { throw new SOAPException(e); } }
void addSchema(Source schema) { assert schema.getSystemId() != null; String systemId = schema.getSystemId(); try { XMLStreamBufferResult xsbr = XmlUtil.identityTransform(schema, new XMLStreamBufferResult()); SDDocumentSource sds = SDDocumentSource.create(new URL(systemId), xsbr.getXMLStreamBuffer()); SDDocument sdoc = SDDocumentImpl.create(sds, new QName(""), new QName("")); docs.put(systemId, sdoc); nsMapping.put(((SDDocument.Schema)sdoc).getTargetNamespace(), sdoc); } catch(Exception ex) { LOGGER.log(Level.WARNING, "Exception in adding schemas to resolver", ex); } }
@Override protected XPathFactory initialValue() throws Exception { return XmlUtil.newXPathFactory(true); } };
public static String getRequiredAttribute(Element element, String name) { String result = XmlUtil.getAttributeOrNull(element, name); if (result == null) fail( "parsing.missingRequiredAttribute", element.getTagName(), name); return result; }
public void registerNamespaces(Element e) { for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) { Attr a = (Attr) iter.next(); if (a.getName().equals(PREFIX_XMLNS)) { // default namespace declaration _nsSupport.declarePrefix("", a.getValue()); } else { String prefix = XmlUtil.getPrefix(a.getName()); if (prefix != null && prefix.equals(PREFIX_XMLNS)) { String nsPrefix = XmlUtil.getLocalPart(a.getName()); String uri = a.getValue(); _nsSupport.declarePrefix(nsPrefix, uri); } } } }
msEpr.addr = new MemberSubmissionEndpointReference.Address(); msEpr.addr.uri = XmlUtil.getTextForNode(child); String prefix = XmlUtil.getPrefix(service); String name = XmlUtil.getLocalPart(service); String prefix = XmlUtil.getPrefix(portType); String name = XmlUtil.getLocalPart(portType);
/** * Returns true if body has explicit parts declaration */ private static boolean parseSOAPBodyBinding(XMLStreamReader reader, Map<String, ParameterBinding> parts) { String partsString = reader.getAttributeValue(null, "parts"); if (partsString != null) { List<String> partsList = XmlUtil.parseTokenList(partsString); if (partsList.isEmpty()) { parts.put(" ", ParameterBinding.BODY); } else { for (String part : partsList) { parts.put(part, ParameterBinding.BODY); } } return true; } return false; }
/** * Performs identity transformation. * @param <T> * @param src * @param result * @return * @throws javax.xml.transform.TransformerException * @throws java.io.IOException * @throws org.xml.sax.SAXException * @throws javax.xml.parsers.ParserConfigurationException */ public static <T extends Result> T identityTransform(Source src, T result) throws TransformerException, SAXException, ParserConfigurationException, IOException { if (src instanceof StreamSource) { // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing // is not turned on by default StreamSource ssrc = (StreamSource) src; TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler(); th.setResult(result); XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader(); reader.setContentHandler(th); reader.setProperty(LEXICAL_HANDLER_PROPERTY, th); reader.parse(toInputSource(ssrc)); } else { newTransformer().transform(src, result); } return result; }
public void writeTo(SOAPMessage saaj) throws SOAPException { try { // TODO what about in-scope namespaces // Not very efficient consider implementing a stream buffer // processor that produces a DOM node from the buffer. Transformer t = XmlUtil.newTransformer(); SOAPHeader header = saaj.getSOAPHeader(); if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); // TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be // uncommented and all lines below, except the catch block, can be removed. // t.transform(epr.asSource(localName), new DOMResult(header)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos); epr.writeTo(localName, w); w.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false); fac.setNamespaceAware(true); Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement(); Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true); header.appendChild(eprNodeToAdd); } catch (Exception e) { throw new SOAPException(e); } }
void addSchema(Source schema) { assert schema.getSystemId() != null; String systemId = schema.getSystemId(); try { XMLStreamBufferResult xsbr = XmlUtil.identityTransform(schema, new XMLStreamBufferResult()); SDDocumentSource sds = SDDocumentSource.create(new URL(systemId), xsbr.getXMLStreamBuffer()); SDDocument sdoc = SDDocumentImpl.create(sds, new QName(""), new QName("")); docs.put(systemId, sdoc); nsMapping.put(((SDDocument.Schema)sdoc).getTargetNamespace(), sdoc); } catch(Exception ex) { LOGGER.log(Level.WARNING, "Exception in adding schemas to resolver", ex); } }
@Override protected XPathFactory initialValue() throws Exception { return XmlUtil.newXPathFactory(true); } };
public static String getRequiredAttribute(Element element, String name) { String result = XmlUtil.getAttributeOrNull(element, name); if (result == null) fail( "parsing.missingRequiredAttribute", element.getTagName(), name); return result; }
public static QName getQName(XMLStreamReader reader, String tag){ String localName = XmlUtil.getLocalPart(tag); String pfix = XmlUtil.getPrefix(tag); String uri = reader.getNamespaceURI(fixNull(pfix)); return new QName(uri, localName); }