use of org.xml.sax.SAXException in project tdi-studio-se by Talend.
the class ExportProjectSettings method saveProjectSettings.
public void saveProjectSettings() {
if (path == null) {
return;
}
File xmlFile = new File(path);
org.talend.core.model.properties.Project project = pro.getEmfProject();
try {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
@Override
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = analyseur.newDocument();
//$NON-NLS-1$
Element root = document.createElement("exportParameters");
createVersionAttr(document, root);
document.appendChild(root);
// status
List technicals = project.getTechnicalStatus();
//$NON-NLS-1$
createStatus(technicals, document, root, "technicalStatus");
List documentation = project.getDocumentationStatus();
//$NON-NLS-1$
createStatus(documentation, document, root, "documentationStatus");
// security
//$NON-NLS-1$
Element security = document.createElement("exportParameter");
root.appendChild(security);
//$NON-NLS-1$
Attr typeAttr = document.createAttribute("type");
//$NON-NLS-1$
typeAttr.setNodeValue("security");
security.setAttributeNode(typeAttr);
//$NON-NLS-1$
Attr name = document.createAttribute("name");
//$NON-NLS-1$
name.setNodeValue("hidePassword");
security.setAttributeNode(name);
security.setTextContent(String.valueOf(project.isHidePassword()));
// stats and logs
if (project.getStatAndLogsSettings() != null) {
List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
//$NON-NLS-1$
saveParameters(document, root, statAndLogs, "statAndLogs");
}
// implicit context
if (project.getImplicitContextSettings() != null) {
List implicit = project.getImplicitContextSettings().getParameters().getElementParameter();
//$NON-NLS-1$
saveParameters(document, root, implicit, "implicitContext");
}
// palette
List componentSettings = project.getComponentsSettings();
savePalette(document, root, componentSettings);
saveDocumentByEncoding(document, xmlFile);
} catch (ParserConfigurationException e) {
ExceptionHandler.process(e);
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
use of org.xml.sax.SAXException in project tdi-studio-se by Talend.
the class WsdlTokenManager method getValueFromXML.
private String getValueFromXML(String inputXML, String xPathQuery) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException {
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream(inputXML.getBytes()));
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = xPathQuery;
Node cipherValue = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
return cipherValue == null ? null : cipherValue.getTextContent();
} catch (XPathExpressionException e) {
logger.error(e.getMessage());
throw e;
} catch (ParserConfigurationException e) {
logger.error(e.getMessage());
throw e;
} catch (SAXException e) {
logger.error(e.getMessage());
throw e;
} catch (IOException e) {
logger.error(e.getMessage());
throw e;
}
}
use of org.xml.sax.SAXException 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 org.xml.sax.SAXException in project tdi-studio-se by Talend.
the class Rfh2AreaParser method parse.
public RFH2Area parse(String stringToParse) {
SAXParser parser;
try {
parser = SAXParserFactory.newInstance().newSAXParser();
} catch (Exception e) {
throw new RuntimeException("Failed to create XML parser, can not parse RFH2 areas", e);
}
SaxHandler handler = new SaxHandler();
try {
parser.parse(new InputSource(new StringReader(stringToParse)), handler);
} catch (SAXException e) {
throw new RuntimeException("Invalid RFH2 header", e);
} catch (IOException e) {
throw new RuntimeException("Invalid RFH2 header", e);
}
return handler.getArea();
}
use of org.xml.sax.SAXException 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;
}
Aggregations