Package org.xml.sax

Examples of org.xml.sax.ContentHandler


        try {
            tHandler = this.tfactory.newTransformerHandler();
        } catch (TransformerConfigurationException e) {
            logger.error("Unable to create new transformer handler.", e);
        }
        final ContentHandler ch;
        if ( this.needsNamespacesAsAttributes ) {
            final NamespaceAsAttributes nsPipeline = new NamespaceAsAttributes(tHandler, this.logger);
            ch = nsPipeline;
        } else {
            ch = tHandler;
View Full Code Here


        final ProcessingComponentConfiguration serializerConfig = config.getSerializerConfiguration();
        this.serializer = this.getPipelineComponent(Serializer.class, serializerConfig.getType(), false);
        LOGGER.debug("Using serializer type {}: {}.", serializerConfig.getType(), serializer);
        serializer.init(processingContext, serializerConfig);

        ContentHandler pipelineComponent = serializer;
        // now chain pipeline
        for(int i=index; i>0; i--) {
            transformers[i-1].setContentHandler(pipelineComponent);
            pipelineComponent = transformers[i-1];
        }
View Full Code Here

        InputSource sheetSource = new InputSource(sheetInputStream);
        SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        SAXParser saxParser = saxFactory.newSAXParser();
        XMLReader sheetParser = saxParser.getXMLReader();
        ContentHandler handler = new MyXSSFSheetHandler(styles, strings, this.minColumns, this.output);
        sheetParser.setContentHandler(handler);
        sheetParser.parse(sheetSource);
    }
View Full Code Here

            public void parse(InputSource input) throws IOException, SAXException {
                parse();
            }
           
            private void parse() throws SAXException {
                ContentHandler handler = getContentHandler();
                // <root xmlns='http://springframework.org'><string>Foo</string></root>
                handler.startDocument();
                handler.startPrefixMapping("", "http://springframework.org");
                handler.startElement("http://springframework.org", "root", "root", new AttributesImpl());
                handler.startElement("http://springframework.org", "string", "string", new AttributesImpl());
                handler.characters("Foo".toCharArray(), 0, 3);
                handler.endElement("http://springframework.org", "string", "string");
                handler.endElement("http://springframework.org", "root", "root");
                handler.endPrefixMapping("");
                handler.endDocument();
            }
        };
        final SAXSource source = new SAXSource(xmlReader, new InputSource());
       
        // Create a mock WebServiceMessage that returns the SAXSource as payload source.
View Full Code Here

     * @see #createContentHandler()
     * @see #getResponse(org.xml.sax.ContentHandler)
     */
    @Override
    public final Source invoke(Source request) throws Exception {
        ContentHandler contentHandler = null;
        if (request != null) {
            contentHandler = createContentHandler();
            SAXResult result = new SAXResult(contentHandler);
            transform(request, result);
        }
View Full Code Here

            final String localization)
    throws SCRDescriptorException {
        final String namespace = detectMetatypeVersion(metaData);

        try {
            final ContentHandler contentHandler = IOUtils.getSerializer(file);

            contentHandler.startDocument();
            contentHandler.startPrefixMapping(PREFIX, namespace);

            final AttributesImpl ai = new AttributesImpl();
            IOUtils.addAttribute(ai, "localization", localization);

            contentHandler.startElement(namespace, METADATA_ELEMENT, METADATA_ELEMENT_QNAME, ai);
            IOUtils.newline(contentHandler);

            for(final ComponentContainer comp : components) {
                if ( comp.getMetatypeContainer() != null ) {
                    generateOCDXML(comp.getMetatypeContainer(), contentHandler);
                    generateDesignateXML(comp.getMetatypeContainer(), contentHandler);
                }
            }

            // end wrapper element
            contentHandler.endElement(namespace, METADATA_ELEMENT, METADATA_ELEMENT_QNAME);
            IOUtils.newline(contentHandler);
            contentHandler.endPrefixMapping(PREFIX);
            contentHandler.endDocument();
        } catch (final IOException e) {
            throw new SCRDescriptorException("Unable to generate xml", file.toString(), e);
        } catch (final TransformerException e) {
            throw new SCRDescriptorException("Unable to generate xml", file.toString(), e);
        } catch (final SAXException e) {
View Full Code Here

            final List<ComponentContainer> components,
            final File descriptorFile,
            final Log logger) throws SAXException, IOException, TransformerException {
        logger.info("Writing " + components.size() + " Service Component Descriptors to "
                + descriptorFile);
        final ContentHandler contentHandler = IOUtils.getSerializer(descriptorFile);
        // detect namespace to use
        final String namespace = module.getOptions().getSpecVersion().getNamespaceUrl();

        contentHandler.startDocument();
        contentHandler.startPrefixMapping(PREFIX, namespace);

        // wrapper element to generate well formed xml
        contentHandler.startElement("", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS, new AttributesImpl());
        IOUtils.newline(contentHandler);

        for (final ComponentContainer component : components) {
            generateXML(namespace, module, component, contentHandler);
        }

        // end wrapper element
        contentHandler.endElement("", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS);
        IOUtils.newline(contentHandler);
        contentHandler.endPrefixMapping(PREFIX);
        contentHandler.endDocument();
    }
View Full Code Here

     * 'org.springmodules.jcr.JcrTemplate.getImportContentHandler(String, int)'
     */
    public void testGetImportContentHandler() throws RepositoryException {
        String path = "path";
        MockControl resultMock = MockControl.createControl(ContentHandler.class);
        ContentHandler result = (ContentHandler) resultMock.getMock();
       
        sessionControl.expectAndReturn(session.getImportContentHandler(path, 0), result);
        sessionControl.replay();
        sfControl.replay();

View Full Code Here

    private String extractTextWithTika(byte[] textBytes, Metadata metadata) throws TikaException, SAXException, IOException {
        AutoDetectParser parser = new AutoDetectParser(new MimeTypes());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(baos, "UTF-8");
        ContentHandler handler = new BodyContentHandler(writer);
        ParseContext context = new ParseContext();
        context.set(PDFParserConfig.class, new LumifyParserConfig());
        parser.parse(new ByteArrayInputStream(textBytes), handler, metadata, context);
        return IOUtils.toString(baos.toByteArray(), "UTF-8");
    }
View Full Code Here

  @Test
  public void testTika() throws Exception {
    //<start id="tika"/>
    InputStream input = new FileInputStream(
            new File("src/test/resources/pdfBox-sample.pdf"));//<co id="tika.is"/>
    ContentHandler textHandler = new BodyContentHandler();//<co id="tika.handler"/>
    Metadata metadata = new Metadata();//<co id="tika.metadata"/>
    Parser parser = new AutoDetectParser();//<co id="tika.parser"/>
    ParseContext context = new ParseContext();
    parser.parse(input, textHandler, metadata, context);//<co id="tika.parse"/>
    System.out.println("Title: " + metadata.get(Metadata.TITLE));//<co id="tika.title"/>
    System.out.println("Body: " + textHandler.toString());//<co id="tika.body"/>
    /*
<calloutlist>
    <callout arearefs="tika.is"><para>Create the <classname>InputStream</classname> to read in the content</para></callout>
    <callout arearefs="tika.handler"><para>The <classname>BodyContentHandler</classname> is a Tika-provided <classname>ContentHandler</classname> that extracts just the "body" of the InputStream</para></callout>
  <callout arearefs="tika.metadata"><para>The <classname>Metadata</classname> object will hold metadata like author, title, etc. about the content in a map.</para></callout>
View Full Code Here

TOP

Related Classes of org.xml.sax.ContentHandler

Copyright © 2018 www.massapicom. 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.