use of org.xml.sax.SAXParseException in project tdi-studio-se by Talend.
the class GenerateSpagoBIXML method createSpagoBIXML.
private void createSpagoBIXML() {
if (file != null) {
try {
Project project = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject();
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
fabrique.setValidating(true);
final DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = analyseur.newDocument();
//$NON-NLS-1$
Element spagobi = document.createElement("etl");
document.appendChild(spagobi);
// ///////////////////add job element.
//$NON-NLS-1$
Element projectElement = document.createElement("job");
spagobi.appendChild(projectElement);
//$NON-NLS-1$
Attr attr = document.createAttribute("project");
attr.setNodeValue(project.getEmfProject().getLabel());
projectElement.setAttributeNode(attr);
//$NON-NLS-1$
attr = document.createAttribute("jobName");
attr.setNodeValue(item.getProperty().getLabel());
projectElement.setAttributeNode(attr);
//$NON-NLS-1$
attr = document.createAttribute("context");
attr.setNodeValue(contextName);
projectElement.setAttributeNode(attr);
//$NON-NLS-1$
attr = document.createAttribute("language");
attr.setNodeValue(project.getLanguage().getName());
projectElement.setAttributeNode(attr);
XMLSerializer serializer = new XMLSerializer();
OutputFormat outputFormat = new OutputFormat();
outputFormat.setIndenting(true);
serializer.setOutputFormat(outputFormat);
serializer.setOutputCharStream(new java.io.FileWriter(file));
serializer.serialize(document);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
}
use of org.xml.sax.SAXParseException in project tdi-studio-se by Talend.
the class ExpressionFileOperation method saveExpressionToFile.
/**
* yzhang Comment method "savingExpression".
*
* @return
* @throws IOException
* @throws ParserConfigurationException
*/
public boolean saveExpressionToFile(File file, List<Variable> variables, String expressionContent) throws IOException, ParserConfigurationException {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final Bundle b = Platform.getBundle(PLUGIN_ID);
final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
final File schema = new File(url.getPath());
//$NON-NLS-1$
fabrique.setAttribute(SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");
fabrique.setAttribute(SCHEMA_VALIDATOR, schema);
fabrique.setValidating(true);
final DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = analyseur.newDocument();
//$NON-NLS-1$
Element expressionElement = document.createElement("expression");
document.appendChild(expressionElement);
//$NON-NLS-1$
Attr content = document.createAttribute(Messages.getString("ExpressionFileOperation.content"));
content.setNodeValue(expressionContent);
expressionElement.setAttributeNode(content);
for (Variable variable : variables) {
//$NON-NLS-1$
Element variableElement = document.createElement("variable");
expressionElement.appendChild(variableElement);
//$NON-NLS-1$
Attr name = document.createAttribute(Messages.getString("ExpressionFileOperation.name"));
name.setNodeValue(variable.getName());
variableElement.setAttributeNode(name);
//$NON-NLS-1$
Attr value = document.createAttribute(Messages.getString("ExpressionFileOperation.value"));
value.setNodeValue(variable.getValue());
variableElement.setAttributeNode(value);
//$NON-NLS-1$
Attr talendType = document.createAttribute(Messages.getString("ExpressionFileOperation.talendType"));
//$NON-NLS-1$
talendType.setNodeValue(variable.getTalendType());
variableElement.setAttributeNode(talendType);
//$NON-NLS-1$
Attr nullable = document.createAttribute(Messages.getString("ExpressionFileOperation.nullable"));
//$NON-NLS-1$
nullable.setNodeValue(String.valueOf(variable.isNullable()));
variableElement.setAttributeNode(nullable);
}
// use specific Xerces class to write DOM-data to a file:
XMLSerializer serializer = new XMLSerializer();
OutputFormat outputFormat = new OutputFormat();
outputFormat.setIndenting(true);
serializer.setOutputFormat(outputFormat);
FileWriter writer = new FileWriter(file);
serializer.setOutputCharStream(writer);
serializer.serialize(document);
writer.close();
return true;
}
use of org.xml.sax.SAXParseException 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.SAXParseException in project ACS by ACS-Community.
the class ScriptFilter method readStatusFile.
private void readStatusFile(String filename, boolean startup) throws ParserConfigurationException, SAXException, IOException {
try {
if (startup) {
int n = JOptionPane.showConfirmDialog(this, "An old status file has been found\nWould you like to load it?", "Old status file found", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (n == JOptionPane.NO_OPTION) {
return;
}
}
if (validateStatusFile(filename)) {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File(filename));
doc.getDocumentElement().normalize();
NodeList listOfSamplingGroup = doc.getElementsByTagName("SamplingGroup");
for (int s = 0; s < listOfSamplingGroup.getLength(); s++) {
Node firstSamplingGroup = listOfSamplingGroup.item(s);
if (firstSamplingGroup.getNodeType() == Node.ELEMENT_NODE) {
Element firstSamplingGroupElement = (Element) firstSamplingGroup;
// -------
NodeList nameList = firstSamplingGroupElement.getElementsByTagName("SamplingGroupName");
Element nameElement = (Element) nameList.item(0);
NodeList nameText = nameElement.getChildNodes();
String samplingGroupName = ((Node) nameText.item(0)).getNodeValue().trim();
// MAN_NAME
NodeList manNameList = firstSamplingGroupElement.getElementsByTagName("SamplingManagerName");
Element manNameElement = (Element) manNameList.item(0);
NodeList manNameText = manNameElement.getChildNodes();
String manName = ((Node) manNameText.item(0)).getNodeValue().trim();
String[] managers = SampTool.getSamplingManagers();
for (int i = 0; i < managers.length; i++) {
if (managers[i].equals(manName)) {
correctManName = true;
}
}
if (correctManName) {
MAN_NAME = manName;
} else {
System.out.println("ERROR: The Sampling Manager Name on the loaded file doesn't exist.");
return;
}
//-------
NodeList freqList = firstSamplingGroupElement.getElementsByTagName("Frequency");
Element freqElement = (Element) freqList.item(0);
NodeList freqText = freqElement.getChildNodes();
double frequency = Double.parseDouble(((Node) freqText.item(0)).getNodeValue().trim());
//-------
NodeList stList = firstSamplingGroupElement.getElementsByTagName("SamplingTime");
Element stElement = (Element) stList.item(0);
NodeList stText = stElement.getChildNodes();
int samplingtime = Integer.parseInt(((Node) stText.item(0)).getNodeValue().trim());
//-------
NodeList twList = firstSamplingGroupElement.getElementsByTagName("TimeWindow");
Element twElement = (Element) twList.item(0);
NodeList twText = twElement.getChildNodes();
int timewindow = Integer.parseInt(((Node) twText.item(0)).getNodeValue().trim());
//----- Properties
NodeList listProperties = firstSamplingGroupElement.getElementsByTagName("Sample");
for (int o = 0; o < listProperties.getLength(); o++) {
Node firstProperty = listProperties.item(o);
if (firstProperty.getNodeType() == Node.ELEMENT_NODE) {
Element firstPropertyElement = (Element) firstProperty;
//-------
NodeList compList = firstPropertyElement.getElementsByTagName("component");
Element compElement = (Element) compList.item(0);
NodeList compText = compElement.getChildNodes();
String component = ((Node) compText.item(0)).getNodeValue().trim();
//-------
NodeList propList = firstPropertyElement.getElementsByTagName("property");
Element propElement = (Element) propList.item(0);
NodeList propText = propElement.getChildNodes();
String property = ((Node) propText.item(0)).getNodeValue().trim();
boolean checkStatus = checkComponentProperty(component, property);
System.out.println("opening " + component + ", " + property + ", " + samplingGroupName);
if (checkStatus) {
addToSampling(component, property, samplingGroupName);
} else {
JOptionPane.showMessageDialog(this, "The component or the property in:\n\n- " + component + "#" + property + "\n\n are invalid on the Sampling Group: '" + samplingGroupName + "'");
}
}
}
for (BeanGrouper bg : BeanGrouperList) {
if (bg.getGroupName().equals(samplingGroupName)) {
bg.loadConfiguration(frequency, timewindow, samplingtime);
break;
}
}
}
}
} else {
JOptionPane.showMessageDialog(this, "Your XML file have a bad format, please check it");
}
} catch (SAXParseException err) {
System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
System.out.println(" " + err.getMessage());
} catch (SAXException e) {
Exception x = e.getException();
((x == null) ? e : x).printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.xml.sax.SAXParseException in project perun by CESNET.
the class MuPasswordManagerModule method parseResponse.
/**
* Parse XML response from IS MU to XML document.
*
* @param inputStream Stream to be parsed to Document
* @param requestID ID of request made to IS MU.
* @return XML document for further processing
* @throws InternalErrorException
*/
private Document parseResponse(InputStream inputStream, int requestID) throws InternalErrorException {
//Create new document factory builder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
throw new InternalErrorException("Error when creating newDocumentBuilder. Request ID: " + requestID, ex);
}
String response = null;
try {
response = convertStreamToString(inputStream, "UTF-8");
} catch (IOException ex) {
log.error("Unable to convert InputStream to String: {}", ex);
}
log.trace("Request ID: " + requestID + " Response: " + response);
Document doc;
try {
doc = builder.parse(new InputSource(new StringReader(response)));
} catch (SAXParseException ex) {
throw new InternalErrorException("Error when parsing uri by document builder. Request ID: " + requestID, ex);
} catch (SAXException ex) {
throw new InternalErrorException("Problem with parsing is more complex, not only invalid characters. Request ID: " + requestID, ex);
} catch (IOException ex) {
throw new InternalErrorException("Error when parsing uri by document builder. Problem with input or output. Request ID: " + requestID, ex);
}
//Prepare xpath expression
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression isErrorExpr;
XPathExpression getErrorTextExpr;
XPathExpression getDbErrorTextExpr;
try {
isErrorExpr = xpath.compile("//resp/stav/text()");
getErrorTextExpr = xpath.compile("//resp/error/text()");
getDbErrorTextExpr = xpath.compile("//resp/dberror/text()");
} catch (XPathExpressionException ex) {
throw new InternalErrorException("Error when compiling xpath query. Request ID: " + requestID, ex);
}
// OK or ERROR
String responseStatus;
try {
responseStatus = (String) isErrorExpr.evaluate(doc, XPathConstants.STRING);
} catch (XPathExpressionException ex) {
throw new InternalErrorException("Error when evaluate xpath query on document to resolve response status. Request ID: " + requestID, ex);
}
log.trace("Request ID: " + requestID + " Response status: " + responseStatus);
if ("OK".equals(responseStatus)) {
return doc;
} else {
try {
String error = (String) getErrorTextExpr.evaluate(doc, XPathConstants.STRING);
if (error == null || error.isEmpty()) {
error = (String) getDbErrorTextExpr.evaluate(doc, XPathConstants.STRING);
}
throw new InternalErrorException("IS MU (password manager backend) responded with error to a Request ID: " + requestID + " Error: " + error);
} catch (XPathExpressionException ex) {
throw new InternalErrorException("Error when evaluate xpath query on document to resolve error status. Request ID: " + requestID, ex);
}
}
}
Aggregations