Java Code Examples for javax.xml.namespace.NamespaceContext

The following examples show how to use javax.xml.namespace.NamespaceContext. These examples are extracted from open source projects. 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 Project: XACML   Source File: XPathExpressionWrapper.java    License: MIT License 6 votes vote down vote up
public synchronized XPathExpression getXpathExpressionWrapped() {
	if (this.xpathExpressionWrapped == null && (this.getStatus() == null || this.getStatus().isOk())) {
		String thisPath	= this.getPath();
		if (thisPath != null) {
			XPath xPath	= XPathFactory.newInstance().newXPath();
			NamespaceContext namespaceContextThis	= this.getNamespaceContext();
			if (namespaceContextThis != null) {
				xPath.setNamespaceContext(namespaceContextThis);
			}
			try {
				this.xpathExpressionWrapped	= xPath.compile(thisPath);
			} catch (XPathExpressionException ex) {
				this.status	= new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, "Error compiling XPath " + thisPath + ": " + ex.getMessage());
			}
		}
	}
	return this.xpathExpressionWrapped;
}
 
Example 2
public void run() {
    NamespaceContext ns = nsc;
    if(xsw!=null)   ns = xsw.getNamespaceContext();
    if(xew!=null)   ns = xew.getNamespaceContext();

    // StAX javadoc isn't very clear on the behavior,
    // so work defensively in anticipation of broken implementations.
    if(ns==null)
        return;

    // we can't enumerate all the in-scope namespace bindings in StAX,
    // so we only look for the known static namespace URIs.
    // this is less than ideal, but better than nothing.
    for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
        String p = ns.getPrefix(nsUri);
        if(p!=null)
            serializer.addInscopeBinding(nsUri,p);
    }
}
 
Example 3
@Override
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
    if(locator!=null)
        this.locator = locator;
    this.environmentNamespaceContext = nsContext;
    // reset the object
    result = null;
    current = root;

    patchersLen=0;
    aborted = false;
    isUnmarshalInProgress = true;
    nsLen=0;

    if(expectedType!=null)
        root.loader = EXPECTED_TYPE_ROOT_LOADER;
    else
        root.loader = DEFAULT_ROOT_LOADER;

    idResolver.startDocument(this);
}
 
Example 4
@Override
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
    if(locator!=null)
        this.locator = locator;
    this.environmentNamespaceContext = nsContext;
    // reset the object
    result = null;
    current = root;

    patchersLen=0;
    aborted = false;
    isUnmarshalInProgress = true;
    nsLen=0;

    if(expectedType!=null)
        root.loader = EXPECTED_TYPE_ROOT_LOADER;
    else
        root.loader = DEFAULT_ROOT_LOADER;

    idResolver.startDocument(this);
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: Internalizer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private NodeList getWSDLDefintionNode(Node bindings, Node target) {
    return evaluateXPathMultiNode(bindings, target, "wsdl:definitions",
            new NamespaceContext() {
                @Override
                public String getNamespaceURI(String prefix) {
                    return "http://schemas.xmlsoap.org/wsdl/";
                }

                @Override
                public String getPrefix(String nsURI) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Iterator getPrefixes(String namespaceURI) {
                    throw new UnsupportedOperationException();
                }
            });
}
 
Example 6
public void marshal(Marshaller m, Object object, OutputStream output, NamespaceContext nsContext) throws JAXBException {
    m.setProperty(Marshaller.JAXB_FRAGMENT,true);
    try {
        ((MarshallerImpl)m).marshal(object,output,nsContext);
    } finally {
        m.setProperty(Marshaller.JAXB_FRAGMENT,false);
    }
}
 
Example 7
Source Project: hottub   Source File: SchemaImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
    try {
        return SCD.create(scd,nsContext).select(this);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 8
Source Project: hsac-fitnesse-fixtures   Source File: XPathHelper.java    License: Apache License 2.0 5 votes vote down vote up
protected XPathExpression createXPathExpression(NamespaceContext context, String xPathExpr) {
    XPath xpath = createXPath(context);
    try {
        return xpath.compile(xPathExpr);
    } catch (XPathExpressionException e) {
        String msg = getMessage(e);
        throw new FitFailureException("Unable to compile xpath: " + xPathExpr + "\n" + msg);
    }
}
 
Example 9
Source Project: ph-commons   Source File: XPathHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link XPath} without any special settings using the default
 * {@link XPathFactory}.
 *
 * @return The created non-<code>null</code> {@link XPath} object
 */
@Nonnull
public static XPath createNewXPath ()
{
  return createNewXPath (s_aXPathFactory,
                         (XPathVariableResolver) null,
                         (XPathFunctionResolver) null,
                         (NamespaceContext) null);
}
 
Example 10
Source Project: woodstox   Source File: BaseNsStreamWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *<p>
 * Note: Root namespace context works best if automatic prefix
 * creation ("namespace/prefix repairing" in StAX lingo) is enabled.
 */
@Override
public void setNamespaceContext(NamespaceContext ctxt)
    throws XMLStreamException
{
    // This is only allowed before root element output:
    if (mState != STATE_PROLOG) {
        throwOutputError("Called setNamespaceContext() after having already output root element.");
    }

    mRootNsContext = ctxt;
    mCurrElem.setRootNsContext(ctxt);
}
 
Example 11
Source Project: ph-commons   Source File: XPathExpressionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static Boolean evalXPathToBoolean (@Nullable final XPathVariableResolver aVariableResolver,
                                          @Nullable final XPathFunctionResolver aFunctionResolver,
                                          @Nullable final NamespaceContext aNamespaceContext,
                                          @Nonnull final String sXPath,
                                          @Nonnull final Document aDoc)
{
  return evalXPathToBoolean (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext),
                             sXPath,
                             aDoc);
}
 
Example 12
public static String _printQName(QName val, NamespaceContext nsc) {
    // Double-check
    String qname;
    String prefix = nsc.getPrefix(val.getNamespaceURI());
    String localPart = val.getLocalPart();

    if (prefix == null || prefix.length() == 0) { // be defensive
        qname = localPart;
    } else {
        qname = prefix + ':' + localPart;
    }

    return qname;
}
 
Example 13
Source Project: openjdk-8   Source File: SchemaSetImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
    try {
        return SCD.create(scd,nsContext).select(this);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 14
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
    try {
        return SCD.create(scd,nsContext).select(this);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 15
Source Project: openjdk-8-source   Source File: Bridge.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.0.2
 */
public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
    Marshaller m = context.marshallerPool.take();
    m.setAttachmentMarshaller(am);
    marshal(m,object,output,nsContext);
    m.setAttachmentMarshaller(null);
    context.marshallerPool.recycle(m);
}
 
Example 16
Source Project: google-cloud-eclipse   Source File: WebXmlValidator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds all defined servlet names to a set, then adds a
 * {@link ServletMappingElement} to the problems list for all
 * <servlet-mapping> elements whose <servlet-name> is undefined.
 */
private void validateServletMapping() {
  try {
    XPath xPath = FACTORY.newXPath();
    NamespaceContext nsContext = new JavaContext();
    xPath.setNamespaceContext(nsContext);
    String selectServletNames = "//prefix:servlet/prefix:servlet-name";
    NodeList servletNameNodes = (NodeList) xPath
        .compile(selectServletNames)
        .evaluate(document, XPathConstants.NODESET);
    Set<String> servletNames = new HashSet<>();
    for (int i = 0; i < servletNameNodes.getLength(); i++) {
      String servletName = servletNameNodes.item(i).getTextContent();
      servletNames.add(servletName);
    }
    String selectServletMappings = "//prefix:servlet-mapping/prefix:servlet-name";
    NodeList servletMappings = (NodeList) xPath
        .compile(selectServletMappings)
        .evaluate(document, XPathConstants.NODESET);
    for (int i = 0; i < servletMappings.getLength(); i++) {
      Node servletMapping = servletMappings.item(i);
      String textContent = servletMapping.getTextContent();
      if (!servletNames.contains(textContent)) {
        DocumentLocation location = (DocumentLocation) servletMapping.getUserData("location");
        ElementProblem element =
            new ServletMappingElement(textContent, location, textContent.length());
        problems.add(element);
      }
    }
  } catch (XPathExpressionException ex) {
    throw new RuntimeException("Invalid XPath expression");
  }
}
 
Example 17
Source Project: TencentKona-8   Source File: Bridge.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.0.2
 */
public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
    Marshaller m = context.marshallerPool.take();
    m.setAttachmentMarshaller(am);
    marshal(m,object,output,nsContext);
    m.setAttachmentMarshaller(null);
    context.marshallerPool.recycle(m);
}
 
Example 18
Source Project: TencentKona-8   Source File: SchemaImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public XSComponent selectSingle(String scd, NamespaceContext nsContext) {
    try {
        return SCD.create(scd,nsContext).selectSingle(this);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 19
Source Project: spring-analysis-note   Source File: XMLEventStreamWriter.java    License: MIT License 4 votes vote down vote up
@Override
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
	this.eventWriter.setNamespaceContext(context);
}
 
Example 20
Source Project: jaxb2-basics   Source File: CMInfoFactory.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected abstract NamespaceContext getDefaultValueNamespaceContext(
API propertyInfo);
 
Example 21
public String printQName(QName val, NamespaceContext nsc) {
    return _printQName(val, nsc);
}
 
Example 22
Source Project: yangtools   Source File: AbstractXmlCodec.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final T parseValue(final NamespaceContext namespaceContext, final String str) {
    return codec.deserialize(str);
}
 
Example 23
@Override
public NamespaceContext getNamespaceContext ()
{
    return writer.getNamespaceContext();
}
 
Example 24
Source Project: jdk8u60   Source File: StAXParserWrapper.java    License: GNU General Public License v2.0 4 votes vote down vote up
public NamespaceContext getNamespaceContext() {
    return _reader.getNamespaceContext();
}
 
Example 25
Source Project: JDKSourceCode1.8   Source File: StreamReaderDelegate.java    License: MIT License 4 votes vote down vote up
public NamespaceContext getNamespaceContext() {
  return reader.getNamespaceContext();
}
 
Example 26
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
    this.nsContext = nsContext;
    validator.setDocumentLocator(locator);
    validator.startDocument();
    next.startDocument(locator,nsContext);
}
 
Example 27
Source Project: openjdk-jdk8u   Source File: MtomCodec.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public NamespaceContextEx getNamespaceContext() {
    NamespaceContext nsContext = writer.getNamespaceContext();
    return new MtomNamespaceContextEx(nsContext);
}
 
Example 28
Source Project: jlibs   Source File: DOMXPathNameConvertor.java    License: Apache License 2.0 4 votes vote down vote up
public DOMXPathNameConvertor(NamespaceContext nsContext){
    this.nsContext = nsContext;
}
 
Example 29
Source Project: fabric8-forge   Source File: JaxbNoNamespaceWriter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
    delegate.setNamespaceContext(context);
}
 
Example 30
Source Project: cs-actions   Source File: XmlUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static XPathExpression createXPathExpression(NamespaceContext context, String xPathQuery) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(context);
    return xpath.compile(xPathQuery);
}