com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl Maven / Gradle / Ivy
Show all versions of jaxp-ri Show documentation
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
// $Id: XPathFactoryImpl.java,v 1.11 2010-11-01 04:35:16 joehw Exp $
package com.sun.org.apache.xpath.internal.jaxp;
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
import javax.xml.XMLConstants;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathVariableResolver;
/**
* The XPathFactory builds XPaths.
*
* @version $Revision: 1.11 $
* @author Ramesh Mandava
*/
public class XPathFactoryImpl extends XPathFactory {
/**
* Name of class as a constant to use for debugging.
*/
private static final String CLASS_NAME = "XPathFactoryImpl";
/**
*XPathFunctionResolver for this XPathFactory and created XPaths.
*/
private XPathFunctionResolver xPathFunctionResolver = null;
/**
* XPathVariableResolver for this XPathFactory and created XPaths
*/
private XPathVariableResolver xPathVariableResolver = null;
/**
* State of secure processing feature.
*/
private boolean _isNotSecureProcessing = true;
/**
* State of secure mode.
*/
private boolean _isSecureMode = false;
/**
* javax.xml.xpath.XPathFactory implementation.
*/
public XPathFactoryImpl() {
if (System.getSecurityManager() != null) {
_isSecureMode = true;
_isNotSecureProcessing = false;
}
}
/**
* Is specified object model supported by this
* XPathFactory
?
*
* @param objectModel Specifies the object model which the returned
* XPathFactory
will understand.
*
* @return true
if XPathFactory
supports
* objectModel
, else false
.
*
* @throws NullPointerException If objectModel
is null
.
* @throws IllegalArgumentException If objectModel.length() == 0
.
*/
public boolean isObjectModelSupported(String objectModel) {
if (objectModel == null) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_OBJECT_MODEL_NULL,
new Object[] { this.getClass().getName() } );
throw new NullPointerException( fmsg );
}
if (objectModel.length() == 0) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_OBJECT_MODEL_EMPTY,
new Object[] { this.getClass().getName() } );
throw new IllegalArgumentException( fmsg );
}
// know how to support default object model, W3C DOM
if (objectModel.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
return true;
}
// don't know how to support anything else
return false;
}
/**
* Returns a new XPath
object using the underlying
* object model determined when the factory was instantiated.
*
* @return New XPath
*/
public javax.xml.xpath.XPath newXPath() {
return new com.sun.org.apache.xpath.internal.jaxp.XPathImpl(
xPathVariableResolver, xPathFunctionResolver,
!_isNotSecureProcessing );
}
/**
* Set a feature for this XPathFactory
and
* XPath
s created by this factory.
*
*
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link XPathFactoryConfigurationException} is thrown if this
* XPathFactory
or the XPath
s
* it creates cannot support the feature.
* It is possible for an XPathFactory
to expose a feature
* value but be unable to change its state.
*
*
* See {@link javax.xml.xpath.XPathFactory} for full documentation
* of specific features.
*
* @param name Feature name.
* @param value Is feature state true
or false
.
*
* @throws XPathFactoryConfigurationException if this
* XPathFactory
or the XPath
s
* it creates cannot support this feature.
* @throws NullPointerException if name
is
* null
.
*/
public void setFeature(String name, boolean value)
throws XPathFactoryConfigurationException {
// feature name cannot be null
if (name == null) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_FEATURE_NAME_NULL,
new Object[] { CLASS_NAME, new Boolean( value) } );
throw new NullPointerException( fmsg );
}
// secure processing?
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
if ((_isSecureMode) && (!value)) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_SECUREPROCESSING_FEATURE,
new Object[] { name, CLASS_NAME, new Boolean(value) } );
throw new XPathFactoryConfigurationException( fmsg );
}
_isNotSecureProcessing = !value;
// all done processing feature
return;
}
// unknown feature
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_FEATURE_UNKNOWN,
new Object[] { name, CLASS_NAME, new Boolean(value) } );
throw new XPathFactoryConfigurationException( fmsg );
}
/**
* Get the state of the named feature.
*
*
* Feature names are fully qualified {@link java.net.URI}s.
* Implementations may define their own features.
* An {@link XPathFactoryConfigurationException} is thrown if this
* XPathFactory
or the XPath
s
* it creates cannot support the feature.
* It is possible for an XPathFactory
to expose a feature
* value but be unable to change its state.
*
*
* @param name Feature name.
*
* @return State of the named feature.
*
* @throws XPathFactoryConfigurationException if this
* XPathFactory
or the XPath
s
* it creates cannot support this feature.
* @throws NullPointerException if name
is
* null
.
*/
public boolean getFeature(String name)
throws XPathFactoryConfigurationException {
// feature name cannot be null
if (name == null) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_GETTING_NULL_FEATURE,
new Object[] { CLASS_NAME } );
throw new NullPointerException( fmsg );
}
// secure processing?
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return !_isNotSecureProcessing;
}
// unknown feature
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_GETTING_UNKNOWN_FEATURE,
new Object[] { name, CLASS_NAME } );
throw new XPathFactoryConfigurationException( fmsg );
}
/**
* Establish a default function resolver.
*
* Any XPath
objects constructed from this factory will use
* the specified resolver by default.
*
* A NullPointerException
is thrown if
* resolver
is null
.
*
* @param resolver XPath function resolver.
*
* @throws NullPointerException If resolver
is
* null
.
*/
public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
// resolver cannot be null
if (resolver == null) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_NULL_XPATH_FUNCTION_RESOLVER,
new Object[] { CLASS_NAME } );
throw new NullPointerException( fmsg );
}
xPathFunctionResolver = resolver;
}
/**
* Establish a default variable resolver.
*
* Any XPath
objects constructed from this factory will use
* the specified resolver by default.
*
* A NullPointerException
is thrown if resolver
is null
.
*
* @param resolver Variable resolver.
*
* @throws NullPointerException If resolver
is
* null
.
*/
public void setXPathVariableResolver(XPathVariableResolver resolver) {
// resolver cannot be null
if (resolver == null) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_NULL_XPATH_VARIABLE_RESOLVER,
new Object[] { CLASS_NAME } );
throw new NullPointerException( fmsg );
}
xPathVariableResolver = resolver;
}
}