Example usage for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES

List of usage examples for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES.

Prototype

String IS_REPLACING_ENTITY_REFERENCES

To view the source code for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES.

Click Source Link

Document

Requires the parser to replace internal entity references with their replacement text and report them as characters

Usage

From source file:com.dulion.astatium.mesh.shredder.XmlShredder.java

public XmlShredder(MetaGraph metaGraph) {
    this.manager = (ContextManager) metaGraph;
    this.factory = ThreadLocal.withInitial(() -> {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        return factory;
    });//from   w ww .jav a  2  s .c om
}

From source file:com.predic8.membrane.core.multipart.XOPReconstitutor.java

public XOPReconstitutor() {
    xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
}

From source file:com.github.lindenb.jvarkit.tools.blast.BlastFilterJS.java

@Override
protected Collection<Throwable> call(String inputName) throws Exception {

    final CompiledScript compiledScript;
    Unmarshaller unmarshaller;//ww w . j  a  v  a 2 s.  c o m
    Marshaller marshaller;
    try {
        compiledScript = super.compileJavascript();

        JAXBContext jc = JAXBContext.newInstance("gov.nih.nlm.ncbi.blast");

        unmarshaller = jc.createUnmarshaller();
        marshaller = jc.createMarshaller();

        XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        PrintWriter pw = openFileOrStdoutAsPrintWriter();
        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
        XMLEventWriter w = xof.createXMLEventWriter(pw);

        StreamSource src = null;
        if (inputName == null) {
            LOG.info("Reading stdin");
            src = new StreamSource(stdin());
        } else {
            LOG.info("Reading file " + inputName);
            src = new StreamSource(new File(inputName));
        }

        XMLEventReader r = xmlInputFactory.createXMLEventReader(src);

        XMLEventFactory eventFactory = XMLEventFactory.newFactory();

        SimpleBindings bindings = new SimpleBindings();
        while (r.hasNext()) {
            XMLEvent evt = r.peek();
            switch (evt.getEventType()) {
            case XMLEvent.START_ELEMENT: {
                StartElement sE = evt.asStartElement();
                Hit hit = null;
                JAXBElement<Hit> jaxbElement = null;
                if (sE.getName().getLocalPart().equals("Hit")) {
                    jaxbElement = unmarshaller.unmarshal(r, Hit.class);
                    hit = jaxbElement.getValue();
                } else {
                    w.add(r.nextEvent());
                    break;
                }

                if (hit != null) {

                    bindings.put("hit", hit);

                    boolean accept = super.evalJavaScriptBoolean(compiledScript, bindings);

                    if (accept) {
                        marshaller.marshal(jaxbElement, w);
                        w.add(eventFactory.createCharacters("\n"));
                    }
                }

                break;
            }
            case XMLEvent.SPACE:
                break;
            default: {
                w.add(r.nextEvent());
                break;
            }
            }
            r.close();
        }
        w.flush();
        w.close();
        pw.flush();
        pw.close();
        return RETURN_OK;
    } catch (Exception err) {
        return wrapException(err);
    } finally {

    }
}

From source file:ValidateStax.java

private static XMLEventReader getXMLEventReader(String filename) {
    XMLInputFactory xmlif = null;
    XMLEventReader xmlr = null;/* ww w  .ja va 2s  .  c  o m*/
    try {
        xmlif = XMLInputFactory.newInstance();
        xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);

        FileInputStream fis = new FileInputStream(filename);
        xmlr = xmlif.createXMLEventReader(filename, fis);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return xmlr;
}

From source file:StreamSrcStAXRst.java

private static XMLEventReader getXMLEventReader(String filename) {

    XMLInputFactory xmlif = null;
    XMLEventReader xmlr = null;/*  www.j  a  v  a  2 s  .c o m*/
    try {
        xmlif = XMLInputFactory.newInstance();
        xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);

        FileInputStream fis = new FileInputStream(filename);
        xmlr = xmlif.createXMLEventReader(filename, fis);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return xmlr;
}

From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java

private void setupFactories() {
    inFac = XMLInputFactory2.newInstance();
    inFac.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    inFac.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    inFac.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);

    outFac = XMLOutputFactory2.newInstance();

    eventFac = Stax2EventFactoryImpl.newInstance();
}

From source file:com.predic8.membrane.core.interceptor.schemavalidation.SchematronValidator.java

public SchematronValidator(ResolverMap resourceResolver, String schematron,
        ValidatorInterceptor.FailureHandler failureHandler, Router router, BeanFactory beanFactory)
        throws Exception {
    this.failureHandler = failureHandler;

    //works as standalone "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"
    TransformerFactory fac;/*w  w  w . ja  v a  2s . c  om*/
    try {
        fac = beanFactory.getBean("transformerFactory", TransformerFactory.class);
    } catch (NoSuchBeanDefinitionException e) {
        throw new RuntimeException(
                "Please define a bean called 'transformerFactory' in monitor-beans.xml, e.g. with "
                        + "<spring:bean id=\"transformerFactory\" class=\"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl\" />",
                e);
    }
    fac.setURIResolver(new URIResolver() {
        @Override
        public Source resolve(String href, String base) throws TransformerException {
            return new StreamSource(SchematronValidator.class.getResourceAsStream(href));
        }
    });
    Transformer t = fac.newTransformer(
            new StreamSource(SchematronValidator.class.getResourceAsStream("conformance1-5.xsl")));

    // transform schematron-XML into XSLT
    DOMResult r = new DOMResult();
    t.transform(new StreamSource(router.getResolverMap().resolve(schematron)), r);

    // build XSLT transformers
    fac.setURIResolver(null);
    int concurrency = Runtime.getRuntime().availableProcessors() * 2;
    transformers = new ArrayBlockingQueue<Transformer>(concurrency);
    for (int i = 0; i < concurrency; i++) {
        Transformer transformer = fac.newTransformer(new DOMSource(r.getNode()));
        transformer.setErrorListener(new NullErrorListener()); // silence console logging
        transformers.put(transformer);
    }

    xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java

/**
 * This constructor gets a new {@link XMLInputFactory} instance that is reused every time
 * {@link #process(com.autonomy.aci.client.transport.AciResponseInputStream)} is called, this
 * should be faster than creating a new instance every time this method is called.
 * <p>/*from ww w .  j  a  v  a  2s  .  c o  m*/
 * The properties are set to the following defaults if they are not specified as system properties:
 * <table summary="">
 * <tr><th>Property</th><th>Default</th></tr>
 * <tr><td>XMLInputFactory.IS_NAMESPACE_AWARE</td><td><tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_VALIDATING<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_COALESCING<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES<tt>true</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.SUPPORT_DTD<tt>true</tt></td></tr>
 * </table>
 */
protected AbstractStAXProcessor() {
    // See if the various XMLInputFactory properties are set as system properties...
    namespaceAware = BooleanUtils.toBoolean(
            StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE), "false"));
    validating = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_VALIDATING), "false"));
    coalescing = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_COALESCING), "false"));
    replacingEntityReferences = BooleanUtils.toBoolean(StringUtils
            .defaultString(System.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES), "true"));
    supportingExternalEntities = BooleanUtils.toBoolean(StringUtils
            .defaultString(System.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES), "false"));
    supportDtd = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.SUPPORT_DTD), "true"));

    // Create the XMLStreamReader factory...
    xmlInputFactory = XMLInputFactory.newInstance();
}

From source file:ddf.catalog.source.opensearch.OpenSearchSource.java

private void configureXmlInputFactory() {
    xmlInputFactory = XMLInputFactory2.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);

}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java

/**
 * This method firstly checks that the content type of the response is text based and can be parsed. If so, it
 * converts the <tt>AciResponseInputStream</tt> into a StAX <tt>XMLStreamReader</tt> and calls the the {@link
 * #process(javax.xml.stream.XMLStreamReader)} method that should be implemented in a subclass to do all the work.
 * @param aciResponseInputStream The ACI response to process
 * @return An object of type <tt>T</tt>
 * @throws AciErrorException  If the ACI response was an error response
 * @throws ProcessorException If an error occurred during the processing of the IDOL response
 *///from  ww  w .  j a  v a 2 s.c om
public T process(final AciResponseInputStream aciResponseInputStream) {
    LOGGER.trace("process() called...");

    if (!"text/xml".equalsIgnoreCase(aciResponseInputStream.getContentType())) {
        throw new ProcessorException(
                "This processor is unable to process non-text ACI responses. The content type for this response is "
                        + aciResponseInputStream.getContentType());
    }

    // Define this here so we can make sure it's closed when the processor is finished...
    XMLStreamReader xmlStreamReader = null;

    try {
        // Update the factory with the various properties as they might have changed since the last run...
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware);
        xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, validating);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, coalescing);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
                supportingExternalEntities);
        xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, supportDtd);

        // Convert the input stream..
        xmlStreamReader = xmlInputFactory.createXMLStreamReader(aciResponseInputStream);
        return process(xmlStreamReader);
    } catch (final XMLStreamException xmlse) {
        throw new ProcessorException("Unable to convert the InputStream to a XMLStreamReader", xmlse);
    } finally {
        if (xmlStreamReader != null) {
            try {
                // This does NOT close the underlying AciResponseInputStream
                xmlStreamReader.close();
            } catch (final XMLStreamException xmlse) {
                LOGGER.error("Unable to close the XMLStreamReader.", xmlse);
            }
        }
    }
}