Search in sources :

Example 6 with TransformerImpl

use of org.apache.xalan.transformer.TransformerImpl in project robovm by robovm.

the class TransformerFactoryImpl method newTransformerHandler.

/**
   * Get a TransformerHandler object that can process SAX
   * ContentHandler events into a Result, based on the Templates argument.
   *
   * @param templates The source of the transformation instructions.
   *
   * @return TransformerHandler ready to transform SAX events.
   * @throws TransformerConfigurationException
   */
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
    try {
        TransformerImpl transformer = (TransformerImpl) templates.newTransformer();
        transformer.setURIResolver(m_uriResolver);
        TransformerHandler th = (TransformerHandler) transformer.getInputContentHandler(true);
        return th;
    } catch (TransformerConfigurationException ex) {
        if (m_errorListener != null) {
            try {
                m_errorListener.fatalError(ex);
                return null;
            } catch (TransformerConfigurationException ex1) {
                throw ex1;
            } catch (TransformerException ex1) {
                throw new TransformerConfigurationException(ex1);
            }
        }
        throw ex;
    }
}
Also used : TransformerImpl(org.apache.xalan.transformer.TransformerImpl) TransformerHandler(javax.xml.transform.sax.TransformerHandler) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 7 with TransformerImpl

use of org.apache.xalan.transformer.TransformerImpl in project robovm by robovm.

the class FuncKey method execute.

/**
   * Execute the function.  The function must return
   * a valid object.
   * @param xctxt The current execution context.
   * @return A valid XObject.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    // TransformerImpl transformer = (TransformerImpl)xctxt;
    TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
    XNodeSet nodes = null;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocumentRoot(context);
    if (DTM.NULL == docContext) {
    // path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
    }
    String xkeyname = getArg0().execute(xctxt).str();
    QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
    XObject arg = getArg1().execute(xctxt);
    boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
    KeyManager kmgr = transformer.getKeyManager();
    // Don't bother with nodeset logic if the thing is only one node.
    if (argIsNodeSetDTM) {
        XNodeSet ns = (XNodeSet) arg;
        ns.setShouldCacheNodes(true);
        int len = ns.getLength();
        if (len <= 1)
            argIsNodeSetDTM = false;
    }
    if (argIsNodeSetDTM) {
        Hashtable usedrefs = null;
        DTMIterator ni = arg.iter();
        int pos;
        UnionPathIterator upi = new UnionPathIterator();
        upi.exprSetParent(this);
        while (DTM.NULL != (pos = ni.nextNode())) {
            dtm = xctxt.getDTM(pos);
            XMLString ref = dtm.getStringValue(pos);
            if (null == ref)
                continue;
            if (null == usedrefs)
                usedrefs = new Hashtable();
            if (usedrefs.get(ref) != null) {
                // We already have 'em.
                continue;
            } else {
                // ISTRUE being used as a dummy value.
                usedrefs.put(ref, ISTRUE);
            }
            XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
            nl.setRoot(xctxt.getCurrentNode(), xctxt);
            //        try
            //        {
            upi.addIterator(nl);
        //        }
        //        catch(CloneNotSupportedException cnse)
        //        {
        //          // will never happen.
        //        }
        //mnodeset.addNodesInDocOrder(nl, xctxt); needed??
        }
        int current = xctxt.getCurrentNode();
        upi.setRoot(current, xctxt);
        nodes = new XNodeSet(upi);
    } else {
        XMLString ref = arg.xstr();
        nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
        nodes.setRoot(xctxt.getCurrentNode(), xctxt);
    }
    return nodes;
}
Also used : TransformerImpl(org.apache.xalan.transformer.TransformerImpl) UnionPathIterator(org.apache.xpath.axes.UnionPathIterator) QName(org.apache.xml.utils.QName) Hashtable(java.util.Hashtable) XMLString(org.apache.xml.utils.XMLString) XNodeSet(org.apache.xpath.objects.XNodeSet) DTMIterator(org.apache.xml.dtm.DTMIterator) DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString) KeyManager(org.apache.xalan.transformer.KeyManager) XObject(org.apache.xpath.objects.XObject)

Example 8 with TransformerImpl

use of org.apache.xalan.transformer.TransformerImpl in project robovm by robovm.

the class SerializerUtils method addAttribute.

/**
     * Copy an DOM attribute to the created output element, executing
     * attribute templates as need be, and processing the xsl:use
     * attribute.
     *
     * @param handler SerializationHandler to which the attributes are added.
     * @param attr Attribute node to add to SerializationHandler.
     *
     * @throws TransformerException
     */
public static void addAttribute(SerializationHandler handler, int attr) throws TransformerException {
    TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
    DTM dtm = transformer.getXPathContext().getDTM(attr);
    if (SerializerUtils.isDefinedNSDecl(handler, attr, dtm))
        return;
    String ns = dtm.getNamespaceURI(attr);
    if (ns == null)
        ns = "";
    // %OPT% ...can I just store the node handle?
    try {
        handler.addAttribute(ns, dtm.getLocalName(attr), dtm.getNodeName(attr), "CDATA", dtm.getNodeValue(attr), false);
    } catch (SAXException e) {
    // do something?
    }
}
Also used : TransformerImpl(org.apache.xalan.transformer.TransformerImpl) DTM(org.apache.xml.dtm.DTM) SAXException(org.xml.sax.SAXException)

Example 9 with TransformerImpl

use of org.apache.xalan.transformer.TransformerImpl in project robovm by robovm.

the class SerializerUtils method addAttributes.

// end copyAttributeToTarget method
/**
     * Copy DOM attributes to the result element.
     *
     * @param src Source node with the attributes
     *
     * @throws TransformerException
     */
public static void addAttributes(SerializationHandler handler, int src) throws TransformerException {
    TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
    DTM dtm = transformer.getXPathContext().getDTM(src);
    for (int node = dtm.getFirstAttribute(src); DTM.NULL != node; node = dtm.getNextAttribute(node)) {
        addAttribute(handler, node);
    }
}
Also used : TransformerImpl(org.apache.xalan.transformer.TransformerImpl) DTM(org.apache.xml.dtm.DTM)

Example 10 with TransformerImpl

use of org.apache.xalan.transformer.TransformerImpl in project robovm by robovm.

the class FuncExtElementAvailable method execute.

/**
   * Execute the function.  The function must return
   * a valid object.
   * @param xctxt The current execution context.
   * @return A valid XObject.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    String prefix;
    String namespace;
    String methName;
    String fullName = m_arg0.execute(xctxt).str();
    int indexOfNSSep = fullName.indexOf(':');
    if (indexOfNSSep < 0) {
        prefix = "";
        namespace = Constants.S_XSLNAMESPACEURL;
        methName = fullName;
    } else {
        prefix = fullName.substring(0, indexOfNSSep);
        namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
        if (null == namespace)
            return XBoolean.S_FALSE;
        methName = fullName.substring(indexOfNSSep + 1);
    }
    if (namespace.equals(Constants.S_XSLNAMESPACEURL) || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {
        try {
            TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
            return transformer.getStylesheet().getAvailableElements().containsKey(new QName(namespace, methName)) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
        } catch (Exception e) {
            return XBoolean.S_FALSE;
        }
    } else {
        //dml
        ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
        return extProvider.elementAvailable(namespace, methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
    }
}
Also used : ExtensionsProvider(org.apache.xpath.ExtensionsProvider) TransformerImpl(org.apache.xalan.transformer.TransformerImpl) QName(org.apache.xml.utils.QName)

Aggregations

TransformerImpl (org.apache.xalan.transformer.TransformerImpl)12 DTM (org.apache.xml.dtm.DTM)6 QName (org.apache.xml.utils.QName)4 TransformerException (javax.xml.transform.TransformerException)3 Hashtable (java.util.Hashtable)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerHandler (javax.xml.transform.sax.TransformerHandler)2 KeyManager (org.apache.xalan.transformer.KeyManager)2 DTMIterator (org.apache.xml.dtm.DTMIterator)2 XMLString (org.apache.xml.utils.XMLString)2 ExtensionsProvider (org.apache.xpath.ExtensionsProvider)2 UnionPathIterator (org.apache.xpath.axes.UnionPathIterator)2 XNodeSet (org.apache.xpath.objects.XNodeSet)2 XObject (org.apache.xpath.objects.XObject)2 SAXException (org.xml.sax.SAXException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 TooManyListenersException (java.util.TooManyListenersException)1 StreamResult (javax.xml.transform.stream.StreamResult)1 SerializationHandler (org.apache.xml.serializer.SerializationHandler)1 DefaultErrorHandler (org.apache.xml.utils.DefaultErrorHandler)1