Search in sources :

Example 51 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project lucene-solr by apache.

the class XPathRecordReader method streamRecords.

/** 
   * Creates an XML stream reader on top of whatever reader has been
   * configured. Then calls parse() with a handler which is
   * invoked forEach record emitted.
   *
   * @param r the stream reader
   * @param handler The callback instance
   */
public void streamRecords(Reader r, Handler handler) {
    try {
        XMLStreamReader parser = factory.createXMLStreamReader(r);
        rootNode.parse(parser, handler, new HashMap<>(), new Stack<>(), false);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 52 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project wildfly by wildfly.

the class KernelDeploymentParsingProcessor method parseDescriptor.

/**
     * Parse -jboss-beans.xml file.
     *
     * @param unit         the deployment unit
     * @param beansXmlFile the beans xml file
     * @throws DeploymentUnitProcessingException
     *          for any error
     */
protected void parseDescriptor(DeploymentUnit unit, VirtualFile beansXmlFile) throws DeploymentUnitProcessingException {
    if (beansXmlFile == null || beansXmlFile.exists() == false)
        return;
    InputStream xmlStream = null;
    try {
        xmlStream = beansXmlFile.openStream();
        final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
        final ParseResult<KernelDeploymentXmlDescriptor> result = new ParseResult<KernelDeploymentXmlDescriptor>();
        xmlMapper.parseDocument(result, reader);
        final KernelDeploymentXmlDescriptor xmlDescriptor = result.getResult();
        if (xmlDescriptor != null)
            unit.addToAttachmentList(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
        else
            throw PojoLogger.ROOT_LOGGER.failedToParse(beansXmlFile);
    } catch (DeploymentUnitProcessingException e) {
        throw e;
    } catch (Exception e) {
        throw PojoLogger.ROOT_LOGGER.parsingException(beansXmlFile, e);
    } finally {
        VFSUtils.safeClose(xmlStream);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) KernelDeploymentXmlDescriptor(org.jboss.as.pojo.descriptor.KernelDeploymentXmlDescriptor) IOException(java.io.IOException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 53 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project wildfly by wildfly.

the class PersistenceUnitXmlParserTestCase method testVersion.

/**
     * See http://issues.jboss.org/browse/STXM-8
     */
@Test
public void testVersion() throws Exception {
    final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + "  <persistence-unit name=\"mypc\">" + "    <description>Persistence Unit." + "    </description>" + "    <jta-data-source>java:/H2DS</jta-data-source>" + "    <class>org.jboss.as.test.integration.jpa.epcpropagation.MyEntity</class>" + "    <properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + "  </persistence-unit>" + "</persistence>";
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(persistence_xml));
    PersistenceUnitMetadataHolder metadataHolder = PersistenceUnitXmlParser.parse(reader, PropertyReplacers.noop());
    PersistenceUnitMetadata metadata = metadataHolder.getPersistenceUnits().get(0);
    String version = metadata.getPersistenceXMLSchemaVersion();
    assertEquals("1.0", version);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) StringReader(java.io.StringReader) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Test(org.junit.Test)

Example 54 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project wildfly by wildfly.

the class PersistenceUnitParseProcessor method parse.

private void parse(final VirtualFile persistence_xml, final List<PersistenceUnitMetadataHolder> listPUHolders, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    ROOT_LOGGER.tracef("parse checking if %s exists, result = %b", persistence_xml.toString(), persistence_xml.exists());
    if (persistence_xml.exists() && persistence_xml.isFile()) {
        InputStream is = null;
        try {
            is = persistence_xml.openStream();
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
            PersistenceUnitMetadataHolder puHolder = PersistenceUnitXmlParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
            postParseSteps(persistence_xml, puHolder, deploymentUnit);
            listPUHolders.add(puHolder);
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(JpaLogger.ROOT_LOGGER.failedToParse(persistence_xml), e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 55 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project wildfly by wildfly.

the class JSFManagedBeanProcessor method processXmlManagedBeans.

/**
     * Parse the faces config files looking for managed bean classes. The parser is quite
     * simplistic as the only information we need is the managed-bean-class element
     */
private void processXmlManagedBeans(final DeploymentUnit deploymentUnit, final Set<String> managedBeanClasses) {
    for (final VirtualFile facesConfig : getConfigurationFiles(deploymentUnit)) {
        InputStream is = null;
        try {
            is = facesConfig.openStream();
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader parser = inputFactory.createXMLStreamReader(is);
            StringBuilder className = null;
            int indent = 0;
            boolean managedBean = false;
            boolean managedBeanClass = false;
            while (true) {
                int event = parser.next();
                if (event == XMLStreamConstants.END_DOCUMENT) {
                    parser.close();
                    break;
                }
                if (event == XMLStreamConstants.START_ELEMENT) {
                    indent++;
                    if (indent == 2) {
                        if (parser.getLocalName().equals(MANAGED_BEAN)) {
                            managedBean = true;
                        }
                    } else if (indent == 3 && managedBean) {
                        if (parser.getLocalName().equals(MANAGED_BEAN_CLASS)) {
                            managedBeanClass = true;
                            className = new StringBuilder();
                        }
                    }
                } else if (event == XMLStreamConstants.END_ELEMENT) {
                    indent--;
                    managedBeanClass = false;
                    if (indent == 1) {
                        managedBean = false;
                    }
                    if (className != null) {
                        managedBeanClasses.add(className.toString().trim());
                        className = null;
                    }
                } else if (managedBeanClass && event == XMLStreamConstants.CHARACTERS) {
                    className.append(parser.getText());
                }
            }
        } catch (Exception e) {
            JSFLogger.ROOT_LOGGER.managedBeansConfigParseFailed(facesConfig);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)243 XMLInputFactory (javax.xml.stream.XMLInputFactory)98 StringReader (java.io.StringReader)85 XMLStreamException (javax.xml.stream.XMLStreamException)78 InputStream (java.io.InputStream)61 IOException (java.io.IOException)43 OMElement (org.apache.axiom.om.OMElement)37 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Test (org.junit.Test)25 JAXBException (javax.xml.bind.JAXBException)16 QName (javax.xml.namespace.QName)16 StAXSource (javax.xml.transform.stax.StAXSource)16 StreamSource (javax.xml.transform.stream.StreamSource)16 FileInputStream (java.io.FileInputStream)14 OMFactory (org.apache.axiom.om.OMFactory)14 Unmarshaller (javax.xml.bind.Unmarshaller)13 InputStreamReader (java.io.InputStreamReader)12 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 Source (javax.xml.transform.Source)11 InputSource (org.xml.sax.InputSource)11