Java XPath Expression createNewXPath(@Nullable final NamespaceContext aNamespaceContext)

Here you can find the source of createNewXPath(@Nullable final NamespaceContext aNamespaceContext)

Description

Create a new XPath with the passed namespace context using the default XPathFactory .

License

Apache License

Parameter

Parameter Description
aNamespaceContext Namespace context to be used. May be <code>null</code>.

Return

The created non-null object

Declaration

@Nonnull
public static XPath createNewXPath(@Nullable final NamespaceContext aNamespaceContext) 

Method Source Code

//package com.java2s;
/**// w ww. j  a va 2s  .c  o  m
 * Copyright (C) 2006-2013 phloc systems
 * http://www.phloc.com
 * office[at]phloc[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;

import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathVariableResolver;

public class Main {
    private static final XPathFactory s_aXPathFactory = XPathFactory.newInstance();

    /**
     * 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);
    }

    /**
     * Create a new {@link XPath} without any special settings.
     * 
     * @param aXPathFactory
     *        The XPath factory object to use. May not be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nonnull final XPathFactory aXPathFactory) {
        return createNewXPath(aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null,
                (NamespaceContext) null);
    }

    /**
     * Create a new {@link XPath} with the passed variable resolver using the
     * default {@link XPathFactory}.
     * 
     * @param aVariableResolver
     *        Variable resolver to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nullable final XPathVariableResolver aVariableResolver) {
        return createNewXPath(s_aXPathFactory, aVariableResolver, (XPathFunctionResolver) null,
                (NamespaceContext) null);
    }

    /**
     * Create a new {@link XPath} with the passed variable resolver.
     * 
     * @param aXPathFactory
     *        The XPath factory object to use. May not be <code>null</code>.
     * @param aVariableResolver
     *        Variable resolver to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nonnull final XPathFactory aXPathFactory,
            @Nullable final XPathVariableResolver aVariableResolver) {
        return createNewXPath(aXPathFactory, aVariableResolver, (XPathFunctionResolver) null,
                (NamespaceContext) null);
    }

    /**
     * Create a new {@link XPath} with the passed function resolver using the
     * default {@link XPathFactory}.
     * 
     * @param aFunctionResolver
     *        Function resolver to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nullable final XPathFunctionResolver aFunctionResolver) {
        return createNewXPath(s_aXPathFactory, (XPathVariableResolver) null, aFunctionResolver,
                (NamespaceContext) null);
    }

    /**
     * Create a new {@link XPath} with the passed function resolver.
     * 
     * @param aXPathFactory
     *        The XPath factory object to use. May not be <code>null</code>.
     * @param aFunctionResolver
     *        Function resolver to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nonnull final XPathFactory aXPathFactory,
            @Nullable final XPathFunctionResolver aFunctionResolver) {
        return createNewXPath(aXPathFactory, (XPathVariableResolver) null, aFunctionResolver,
                (NamespaceContext) null);
    }

    /**
     * Create a new {@link XPath} with the passed namespace context using the
     * default {@link XPathFactory}.
     * 
     * @param aNamespaceContext
     *        Namespace context to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nullable final NamespaceContext aNamespaceContext) {
        return createNewXPath(s_aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null,
                aNamespaceContext);
    }

    /**
     * Create a new {@link XPath} with the passed namespace context.
     * 
     * @param aXPathFactory
     *        The XPath factory object to use. May not be <code>null</code>.
     * @param aNamespaceContext
     *        Namespace context to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nonnull final XPathFactory aXPathFactory,
            @Nullable final NamespaceContext aNamespaceContext) {
        return createNewXPath(aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null,
                aNamespaceContext);
    }

    /**
     * Create a new {@link XPath} with the passed variable resolver and namespace
     * context using the default {@link XPathFactory}.
     * 
     * @param aVariableResolver
     *        Variable resolver to be used. May be <code>null</code>.
     * @param aNamespaceContext
     *        Namespace context to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nullable final XPathVariableResolver aVariableResolver,
            @Nullable final NamespaceContext aNamespaceContext) {
        return createNewXPath(s_aXPathFactory, aVariableResolver, (XPathFunctionResolver) null, aNamespaceContext);
    }

    /**
     * Create a new {@link XPath} with the passed variable resolver, function
     * resolver and namespace context using the default {@link XPathFactory}.
     * 
     * @param aVariableResolver
     *        Variable resolver to be used. May be <code>null</code>.
     * @param aFunctionResolver
     *        Function resolver to be used. May be <code>null</code>.
     * @param aNamespaceContext
     *        Namespace context to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nullable final XPathVariableResolver aVariableResolver,
            @Nullable final XPathFunctionResolver aFunctionResolver,
            @Nullable final NamespaceContext aNamespaceContext) {
        return createNewXPath(s_aXPathFactory, aVariableResolver, aFunctionResolver, aNamespaceContext);
    }

    /**
     * Create a new {@link XPath} with the passed variable resolver, function
     * resolver and namespace context.
     * 
     * @param aXPathFactory
     *        The XPath factory object to use. May not be <code>null</code>.
     * @param aVariableResolver
     *        Variable resolver to be used. May be <code>null</code>.
     * @param aFunctionResolver
     *        Function resolver to be used. May be <code>null</code>.
     * @param aNamespaceContext
     *        Namespace context to be used. May be <code>null</code>.
     * @return The created non-<code>null</code> {@link XPath} object
     */
    @Nonnull
    public static XPath createNewXPath(@Nonnull final XPathFactory aXPathFactory,
            @Nullable final XPathVariableResolver aVariableResolver,
            @Nullable final XPathFunctionResolver aFunctionResolver,
            @Nullable final NamespaceContext aNamespaceContext) {
        if (aXPathFactory == null)
            throw new NullPointerException("XPathFactory");

        final XPath aXPath = aXPathFactory.newXPath();
        if (aVariableResolver != null)
            aXPath.setXPathVariableResolver(aVariableResolver);
        if (aFunctionResolver != null)
            aXPath.setXPathFunctionResolver(aFunctionResolver);
        if (aNamespaceContext != null)
            aXPath.setNamespaceContext(aNamespaceContext);
        return aXPath;
    }
}

Related

  1. compile(String expression)
  2. compile(String path)
  3. compileXPathExpression(String xPathExpression)
  4. constructXPathForElement(Element inElem, String xPathRest)
  5. createFactory()
  6. createQueryResourcePropertiesCallBody(String aXqueryExpression)
  7. createReverseCMDIComponentItemMap(String urlToComponent)
  8. createXPath()
  9. createXPath(NamespaceContext namespaceContext, XPathFunctionResolver functionResolver)