Examples of TransformerHandler


Examples of javax.xml.transform.sax.TransformerHandler

             
              if (!useXSLTC)
                stf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL,
                   Boolean.TRUE);
                
              TransformerHandler th = stf.newTransformerHandler(stylesheet);
             
              reader.setContentHandler(th);
              reader.setDTDHandler(th);
             
              if(th instanceof org.xml.sax.ErrorHandler)
                reader.setErrorHandler((org.xml.sax.ErrorHandler)th);
             
              try
              {
                reader.setProperty(
                  "http://xml.org/sax/properties/lexical-handler", th);
              }
              catch (org.xml.sax.SAXNotRecognizedException e){}
              catch (org.xml.sax.SAXNotSupportedException e){}
              try
              {
                reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
                                  true);
              } catch (org.xml.sax.SAXException se) {}
       
              try
              {
                reader.setFeature("http://apache.org/xml/features/validation/dynamic",
                                  true);
              } catch (org.xml.sax.SAXException se) {}
             
              th.setResult(strResult);
             
              reader.parse(new InputSource(inFileName));
              }                           
            }
            else
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

            if (document == null) {
                DOMResult domResult = new DOMResult();
                try {
                    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
                    SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
                    TransformerHandler transformerHandler = saxTransformerFactory.newTransformerHandler();
                    transformerHandler.setResult(domResult);
                    xmlReader.setContentHandler(new XIncludeHandler(transformerHandler, uriDocMap));
                    xmlReader.parse(url.toExternalForm());
                } catch (TransformerConfigurationException e) {
                    throw new SAXException(e);
                } catch (IOException e) {
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

        }

        StreamResult streamResult = new StreamResult(os);
        final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

        TransformerHandler handler = transformerFactory.newTransformerHandler();
        Transformer serializer = handler.getTransformer();
        serializer.setOutputProperty(OutputKeys.ENCODING, SyncopeConstants.DEFAULT_ENCODING);
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        handler.setResult(streamResult);
        handler.startDocument();
        handler.startElement("", "", ROOT_ELEMENT, new AttributesImpl());

        Connection conn = null;
        ResultSet rs = null;
        try {
            conn = DataSourceUtils.getConnection(dataSource);
            final DatabaseMetaData meta = conn.getMetaData();

            final String schema = dbSchema;

            rs = meta.getTables(null, schema, null, new String[] {"TABLE"});

            final Set<String> tableNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);

            while (rs.next()) {
                String tableName = rs.getString("TABLE_NAME");
                LOG.debug("Found table {}", tableName);
                if (isTableAllowed(tableName)) {
                    tableNames.add(tableName);
                }
            }

            LOG.debug("Tables to be exported {}", tableNames);

            // then sort tables based on foreign keys and dump
            for (String tableName : sortByForeignKeys(conn, tableNames)) {
                try {
                    doExportTable(handler, conn, tableName, TABLES_TO_BE_FILTERED.get(tableName.toUpperCase()));
                } catch (Exception e) {
                    LOG.error("Failure exporting table {}", tableName, e);
                }
            }
        } catch (SQLException e) {
            LOG.error("While exporting database content", e);
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    LOG.error("While closing tables result set", e);
                }
            }

            DataSourceUtils.releaseConnection(conn, dataSource);
            if (conn != null) {
                try {
                    if (!conn.isClosed()) {
                        conn.close();
                    }
                } catch (SQLException e) {
                    LOG.error("While releasing connection", e);
                }
            }
        }

        handler.endElement("", "", ROOT_ELEMENT);
        handler.endDocument();
    }
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

             
              if (!useXSLTC)
                stf.setAttribute(org.apache.xalan.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL,
                   Boolean.TRUE);
                
              TransformerHandler th = stf.newTransformerHandler(stylesheet);
             
              reader.setContentHandler(th);
              reader.setDTDHandler(th);
             
              if(th instanceof org.xml.sax.ErrorHandler)
                reader.setErrorHandler((org.xml.sax.ErrorHandler)th);
             
              try
              {
                reader.setProperty(
                  "http://xml.org/sax/properties/lexical-handler", th);
              }
              catch (org.xml.sax.SAXNotRecognizedException e){}
              catch (org.xml.sax.SAXNotSupportedException e){}
              try
              {
                reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
                                  true);
              } catch (org.xml.sax.SAXException se) {}
       
              th.setResult(strResult);
             
              reader.parse(new InputSource(inFileName));
              }                           
            }
            else
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

            SAXTransformerFactory f = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

            ByteArrayOutputStream result = new ByteArrayOutputStream();
            StreamResult sr = new StreamResult(result);

            TransformerHandler handler = f.newTransformerHandler();
            Transformer t = handler.getTransformer();
            t.setOutputProperty(OutputKeys.INDENT, "yes");
            handler.setResult(sr);
            handler.startDocument();
            startElement(handler, TAG_RESOURCE);
            for (Map.Entry<String, Object> property : content.entrySet()) {
                Object value = property.getValue();
                if (value instanceof String) {
                    String tagName = property.getKey();
                    String tagValue = (String) value;
                    AttributesImpl attributes = new AttributesImpl();
                    attributes.addAttribute("", ATT_PROPERTY_NAME, ATT_PROPERTY_NAME, null, tagName);
                    handler.startElement("", TAG_PROPERTY, TAG_PROPERTY, attributes);
                    handler.characters(tagValue.toCharArray(), 0, tagValue.length());
                    handler.endElement("", TAG_PROPERTY, TAG_PROPERTY);
                } else {
                    // TODO multi-valued properties, other primitives
                    System.err.println("Can't yet handle property " + property.getKey() + " of type "
                            + value.getClass());
                }
            }

            endElement(handler, TAG_RESOURCE);
            handler.endDocument();

            // TODO - also add the serialization type
            return new SerializationData(resource.getPath(), CONTENT_XML, result.toByteArray(), null);
        } catch (TransformerConfigurationException e) {
            // TODO proper exception handling
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

    /**
     * Construct a new instance of this DOMBuilder.
     */
    public DOMBuilder() throws IOException {
        try {
            final TransformerHandler handler = FACTORY.newTransformerHandler();
            this.contentHandler = handler;
            this.lexicalHandler = handler;
            this.result = new DOMResult();
            handler.setResult(this.result);
        } catch (javax.xml.transform.TransformerException local) {
            throw (IOException) new IOException("Fatal-Error: Unable to get transformer handler").initCause(local);
        }
    }
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

    /**
     * @see org.apache.sling.rewriter.SerializerFactory#createSerializer()
     */
    public Serializer createSerializer() {
        TransformerHandler tHandler = null;
        try {
            tHandler = this.tfactory.newTransformerHandler();
        } catch (TransformerConfigurationException e) {
            logger.error("Unable to create new transformer handler.", e);
        }
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

        final String uri = "namespaceuri";
        final String prefix = "nsp";
        final String check = "xmlns:" + prefix + "='" + uri + "'";

        final TransformerHandler handler = this.tfactory.newTransformerHandler();
        handler.setResult(new StreamResult(writer));

        // Output a single element
        handler.startDocument();
        handler.startPrefixMapping(prefix, uri);
        handler.startElement(uri, "element", "element", new AttributesImpl());
        handler.endElement(uri, "element", "element");
        handler.endPrefixMapping(prefix);
        handler.endDocument();

        final String text = writer.toString();

        // Check if the namespace is there (replace " by ' to be sure of what we search in)
        return (text.replace('"', '\'').indexOf(check) == -1);
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

        this.parameters = new HashMap<String, Object>(configuration);
    }

    @Override
    protected void setXMLConsumer(XMLConsumer consumer) {
        TransformerHandler transformerHandler;
        try {
            transformerHandler = this.createTransformerHandler();
        } catch (Exception ex) {
            throw new RuntimeException("Could not initialize transformer handler.", ex);
        }

        final Map<String, Object> map = this.getLogicSheetParameters();
        if (map != null) {
            final Transformer transformer = transformerHandler.getTransformer();

            for (Entry<String, Object> entry : map.entrySet()) {
                transformer.setParameter(entry.getKey(), entry.getValue());
            }
        }

        final SAXResult result = new SAXResult();
        result.setHandler(consumer);
        // According to TrAX specs, all TransformerHandlers are LexicalHandlers
        result.setLexicalHandler(consumer);
        transformerHandler.setResult(result);

        super.setXMLConsumer(new XMLConsumerAdapter(transformerHandler, transformerHandler));
    }
View Full Code Here

Examples of javax.xml.transform.sax.TransformerHandler

        xmlReader.setContentHandler(templatesHandler);
        InputSource inputSource = new InputSource(getXsltSource());
        xmlReader.parse(inputSource);

        // Create transformer handler
        final TransformerHandler handler = transformerFactory.newTransformerHandler(templatesHandler.getTemplates());

        return handler;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.