FileDocCategorySizeDatePackage
TransformXPath2Filter.javaAPI DocJava SE 6 API7819Tue Jun 10 00:23:04 BST 2008com.sun.org.apache.xml.internal.security.transforms.implementations

TransformXPath2Filter

public class TransformXPath2Filter extends TransformSpi
Implements the XML Signature XPath Filter v2.0
author
$Author: mullan $
see
XPath Filter v2.0 (TR)
see
XPath Filter v2.0 (editors copy)

Fields Summary
public static final String
implementedTransformURI
Field implementedTransformURI
Constructors Summary
Methods Summary
protected java.lang.StringengineGetURI()
Method engineGetURI

inheritDoc

   //J-
   // contains the type of the filter   

   // contains the node set
  
          
      
      return implementedTransformURI;
   
protected com.sun.org.apache.xml.internal.security.signature.XMLSignatureInputenginePerformTransform(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput input)
Method enginePerformTransform

inheritDoc
param
input
throws
TransformationException

	  CachedXPathAPIHolder.setDoc(this._transformObject.getElement().getOwnerDocument());
      try {
    	  List unionNodes=new ArrayList();
    	   List substractNodes=new ArrayList();
    	   List intersectNodes=new ArrayList();

         CachedXPathFuncHereAPI xPathFuncHereAPI =
            new CachedXPathFuncHereAPI(CachedXPathAPIHolder.getCachedXPathAPI());

         
         Element []xpathElements =XMLUtils.selectNodes(
                this._transformObject.getElement().getFirstChild(),
                   XPath2FilterContainer.XPathFilter2NS,
                   XPath2FilterContainer._TAG_XPATH2);
         int noOfSteps = xpathElements.length;


         if (noOfSteps == 0) {
            Object exArgs[] = { Transforms.TRANSFORM_XPATH2FILTER, "XPath" };

            throw new TransformationException("xml.WrongContent", exArgs);
         }

         Document inputDoc = null;
	 if (input.getSubNode() != null) {   
            inputDoc = XMLUtils.getOwnerDocument(input.getSubNode());
	 } else {
            inputDoc = XMLUtils.getOwnerDocument(input.getNodeSet());
	 }

         for (int i = 0; i < noOfSteps; i++) {
            Element xpathElement =XMLUtils.selectNode(
               this._transformObject.getElement().getFirstChild(),
                  XPath2FilterContainer.XPathFilter2NS,
                  XPath2FilterContainer._TAG_XPATH2,i);
            XPath2FilterContainer xpathContainer =
               XPath2FilterContainer.newInstance(xpathElement,
                                                   input.getSourceURI());
           

            NodeList subtreeRoots = xPathFuncHereAPI.selectNodeList(inputDoc,
                                       xpathContainer.getXPathFilterTextNode(),
                                       CachedXPathFuncHereAPI.getStrFromNode(xpathContainer.getXPathFilterTextNode()),
                                       xpathContainer.getElement());
            if (xpathContainer.isIntersect()) {
                intersectNodes.add(subtreeRoots);
             } else if (xpathContainer.isSubtract()) {
            	 substractNodes.add(subtreeRoots);
             } else if (xpathContainer.isUnion()) {
                unionNodes.add(subtreeRoots);
             } 
         }

         input.setNeedsToBeExpanded(true);
         
         input.addNodeFilter(new XPath2NodeFilter(unionNodes,substractNodes,intersectNodes));
         input.setNodeSet(true);
         return input;
      } catch (TransformerException ex) {
         throw new TransformationException("empty", ex);
      } catch (DOMException ex) {
         throw new TransformationException("empty", ex);
      } catch (CanonicalizationException ex) {
         throw new TransformationException("empty", ex);
      } catch (InvalidCanonicalizerException ex) {
         throw new TransformationException("empty", ex);
      } catch (XMLSecurityException ex) {
         throw new TransformationException("empty", ex);
      } catch (SAXException ex) {
         throw new TransformationException("empty", ex);
      } catch (IOException ex) {
         throw new TransformationException("empty", ex);
      } catch (ParserConfigurationException ex) {
         throw new TransformationException("empty", ex);
      }