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);
}
}
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);
}
}
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);
}
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
}
}
}
}
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
}
}
}
}
Aggregations