use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.
the class ComplexSAXLooper method parse.
/**
* Parse the XML file. Buffer the result in LoopEntry.
*
* @param is InputStream
*/
public void parse(java.io.InputStream is, String charset) {
this.charset = charset;
Reader reader = null;
try {
DefaultHandler hd = null;
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
if (rootPath == null || rootPath.equals("")) {
hd = newHandler();
} else {
hd = newHandler2();
}
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
// routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
reader = new UnicodeReader(is, this.charset);
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
saxParser.parse(inSource, hd);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.
the class MetadataExportXmlCommandExt method execute.
/*
* (non-Java)
*
* @see org.talend.commons.ui.command.CommonCommand#execute()
*/
@Override
public void execute() {
try {
if (file != null) {
file.createNewFile();
if (extendedTableModel != null) {
IMetadataTable currentTable = extendedTableModel.getMetadataTable();
// get all the columns from the table
if (currentTable != null) {
MetadataSchemaExt ext = new MetadataSchemaExt(extendedTableModel.getRowGenUI().getFunctionManager());
ext.saveColumnsToFile(file, currentTable);
}
}
}
} catch (IOException e) {
ExceptionHandler.process(e);
} catch (ParserConfigurationException e) {
ExceptionHandler.process(e);
}
}
use of javax.xml.parsers.ParserConfigurationException in project mustangproject by ZUGFeRD.
the class ZUGFeRDImporter method parse.
public void parse() {
DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
Document document = null;
if (!extracted) {
throw new RuntimeException("extract() or extractLowLevel() must be used before parsing.");
}
factory = DocumentBuilderFactory.newInstance();
//otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
factory.setNamespaceAware(true);
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException ex3) {
// TODO Auto-generated catch block
ex3.printStackTrace();
}
try {
InputStream bais = new ByteArrayInputStream(rawXML);
document = builder.parse(bais);
} catch (SAXException ex1) {
ex1.printStackTrace();
} catch (IOException ex2) {
ex2.printStackTrace();
}
NodeList ndList;
// rootNode = document.getDocumentElement();
// ApplicableSupplyChainTradeSettlement
ndList = document.getDocumentElement().getElementsByTagNameNS("*", //$NON-NLS-1$
"PaymentReference");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value
setForeignReference(booking.getTextContent());
}
/*
ndList = document
.getElementsByTagName("GermanBankleitzahlID"); //$NON-NLS-1$
for (int bookingIndex = 0; bookingIndex < ndList
.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value
setBIC(booking.getTextContent());
}
ndList = document.getElementsByTagName("ProprietaryID"); //$NON-NLS-1$
for (int bookingIndex = 0; bookingIndex < ndList
.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value
setIBAN(booking.getTextContent());
}
<ram:PayeePartyCreditorFinancialAccount>
<ram:IBANID>DE1234</ram:IBANID>
</ram:PayeePartyCreditorFinancialAccount>
<ram:PayeeSpecifiedCreditorFinancialInstitution>
<ram:BICID>DE5656565</ram:BICID>
<ram:Name>Commerzbank</ram:Name>
</ram:PayeeSpecifiedCreditorFinancialInstitution>
*/
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "PayeePartyCreditorFinancialAccount");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// there are many "name" elements, so get the one below
// SellerTradeParty
NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
Node detail = bookingDetails.item(detailIndex);
if ((detail.getLocalName() != null) && (detail.getLocalName().equals("IBANID"))) {
//$NON-NLS-1$
setIBAN(detail.getTextContent());
}
}
}
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "PayeeSpecifiedCreditorFinancialInstitution");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// there are many "name" elements, so get the one below
// SellerTradeParty
NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
Node detail = bookingDetails.item(detailIndex);
if ((detail.getLocalName() != null) && (detail.getLocalName().equals("BICID"))) {
//$NON-NLS-1$
setBIC(detail.getTextContent());
}
if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) {
//$NON-NLS-1$
setBankName(detail.getTextContent());
}
}
}
//
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "SellerTradeParty");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// there are many "name" elements, so get the one below
// SellerTradeParty
NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
Node detail = bookingDetails.item(detailIndex);
if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) {
//$NON-NLS-1$
setHolder(detail.getTextContent());
}
}
}
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "DuePayableAmount");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value
amountFound = true;
setAmount(booking.getTextContent());
}
if (!amountFound) {
/* there is apparently no requirement to mention DuePayableAmount,,
* if it's not there, check for GrandTotalAmount
*/
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "GrandTotalAmount");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value
amountFound = true;
setAmount(booking.getTextContent());
}
}
//$NON-NLS-1$
ndList = document.getElementsByTagNameNS("*", "SpecifiedTradePaymentTerms");
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// there are many "name" elements, so get the one below
// SellerTradeParty
NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) {
Node detail = bookingDetails.item(detailIndex);
if ((detail.getLocalName() != null) && (detail.getLocalName().equals("DueDateDateTime"))) {
//$NON-NLS-1$
setDueDate(detail.getTextContent().trim());
}
}
}
parsed = true;
}
use of javax.xml.parsers.ParserConfigurationException in project zm-mailbox by Zimbra.
the class W3cDomUtil method getDom4jSAXParserWhichUsesSecureProcessing.
public static SAXParser getDom4jSAXParserWhichUsesSecureProcessing() throws XmlParseException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setXIncludeAware(false);
factory.setValidating(false);
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
} catch (SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException ex) {
ZimbraLog.misc.error("Problem setting up SAXParser which supports secure XML processing", ex);
throw XmlParseException.PARSE_ERROR();
}
try {
return factory.newSAXParser();
} catch (ParserConfigurationException | SAXException e) {
ZimbraLog.misc.error("Problem setting up SAXParser", e);
throw XmlParseException.PARSE_ERROR();
}
}
use of javax.xml.parsers.ParserConfigurationException in project robo4j by Robo4J.
the class XmlConfigurationFactory method fromXml.
public static Configuration fromXml(String xml) throws ConfigurationFactoryException {
DefaultConfiguration config = new DefaultConfiguration();
SAXParser saxParser;
try {
saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(new ByteArrayInputStream(xml.getBytes(Constants.DEFAULT_ENCODING)), new ConfigurationHandler(config));
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new ConfigurationFactoryException("Could not parse the configuration", e);
}
return config;
}
Aggregations