com.sun.org.apache.xpath.internal.jaxp.JAXPExtensionsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.jaxp-ri
Show all versions of org.apache.servicemix.bundles.jaxp-ri
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
The newest version!
/*
* 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: JAXPExtensionsProvider.java,v 1.7 2010-11-01 04:35:16 joehw Exp $
package com.sun.org.apache.xpath.internal.jaxp;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;
import com.sun.org.apache.xpath.internal.ExtensionsProvider;
import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.objects.XObject;
import com.sun.org.apache.xpath.internal.objects.XNodeSet;
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
import com.sun.org.apache.xpath.internal.functions.FuncExtFunction;
import java.util.Vector;
import java.util.ArrayList;
import javax.xml.namespace.QName;
/**
*
* @author Ramesh Mandava ( [email protected] )
*/
public class JAXPExtensionsProvider implements ExtensionsProvider {
private final XPathFunctionResolver resolver;
private boolean extensionInvocationDisabled = false;
public JAXPExtensionsProvider(XPathFunctionResolver resolver) {
this.resolver = resolver;
this.extensionInvocationDisabled = false;
}
public JAXPExtensionsProvider(XPathFunctionResolver resolver,
boolean featureSecureProcessing ) {
this.resolver = resolver;
this.extensionInvocationDisabled = featureSecureProcessing;
}
/**
* Is the extension function available?
*/
public boolean functionAvailable(String ns, String funcName)
throws javax.xml.transform.TransformerException {
try {
if ( funcName == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"Function Name"} );
throw new NullPointerException ( fmsg );
}
//Find the XPathFunction corresponding to namespace and funcName
javax.xml.namespace.QName myQName = new QName( ns, funcName );
javax.xml.xpath.XPathFunction xpathFunction =
resolver.resolveFunction ( myQName, 0 );
if ( xpathFunction == null ) {
return false;
}
return true;
} catch ( Exception e ) {
return false;
}
}
/**
* Is the extension element available?
*/
public boolean elementAvailable(String ns, String elemName)
throws javax.xml.transform.TransformerException {
return false;
}
/**
* Execute the extension function.
*/
public Object extFunction(String ns, String funcName, Vector argVec,
Object methodKey) throws javax.xml.transform.TransformerException {
try {
if ( funcName == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"Function Name"} );
throw new NullPointerException ( fmsg );
}
//Find the XPathFunction corresponding to namespace and funcName
javax.xml.namespace.QName myQName = new QName( ns, funcName );
// JAXP 1.3 spec says When XMLConstants.FEATURE_SECURE_PROCESSING
// feature is set then invocation of extension functions need to
// throw XPathFunctionException
if ( extensionInvocationDisabled ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
new Object[] { myQName.toString() } );
throw new XPathFunctionException ( fmsg );
}
// Assuming user is passing all the needed parameters ( including
// default values )
int arity = argVec.size();
javax.xml.xpath.XPathFunction xpathFunction =
resolver.resolveFunction ( myQName, arity );
// not using methodKey
ArrayList argList = new ArrayList( arity);
for ( int i=0; i