use of org.xml.sax.SAXException in project tdi-studio-se by Talend.
the class AutoConvertTypesUtils method load.
public static List<AutoConversionType> load(File file) {
beanList = new ArrayList<>();
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder analyseur = documentBuilderFactory.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.parse(file);
//$NON-NLS-1$
NodeList typeNodes = document.getElementsByTagName("conversionType");
for (int i = 0; i < typeNodes.getLength(); i++) {
Node typeNode = typeNodes.item(i);
NamedNodeMap typeAttributes = typeNode.getAttributes();
AutoConversionType typeObj = new AutoConversionType();
//$NON-NLS-1$
typeObj.setSourceDataType(typeAttributes.getNamedItem("source").getNodeValue());
//$NON-NLS-1$
typeObj.setTargetDataType(typeAttributes.getNamedItem("target").getNodeValue());
//$NON-NLS-1$
typeObj.setConversionFunction(typeAttributes.getNamedItem("function").getNodeValue());
beanList.add(typeObj);
}
} catch (Exception e) {
return beanList;
}
return beanList;
}
use of org.xml.sax.SAXException in project voltdb by VoltDB.
the class CatalogPasswordScrambler method getDeployment.
public static DeploymentType getDeployment(File sourceFH) {
try {
JAXBContext jc = JAXBContext.newInstance("org.voltdb.compiler.deploymentfile");
// This schema shot the sheriff.
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(DependencyPair.class.getResource("compiler/DeploymentFileSchema.xsd"));
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setSchema(schema);
@SuppressWarnings("unchecked") JAXBElement<DeploymentType> result = (JAXBElement<DeploymentType>) unmarshaller.unmarshal(sourceFH);
DeploymentType deployment = result.getValue();
return deployment;
} catch (JAXBException e) {
// Convert some linked exceptions to more friendly errors.
if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
System.err.println(e.getLinkedException().getMessage());
return null;
} else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
System.err.println("Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
return null;
} else {
throw new RuntimeException(e);
}
} catch (SAXException e) {
System.err.println("Error schema validating deployment.xml file. " + e.getMessage());
return null;
}
}
use of org.xml.sax.SAXException 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.SAXException in project tdi-studio-se by Talend.
the class ExpressionBuilderDialog method createButtonsForButtonBar.
/**
* Create contents of the button bar
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).numColumns++;
Composite buttons = new Composite(parent, SWT.NONE);
buttons.setLayout(new GridLayout(2, false));
final Button importButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
final Button exportButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
//$NON-NLS-1$
createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
//$NON-NLS-1$
createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
exportButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
String expresionContent = expressionComposite.getExpression();
List<Variable> variables = new ArrayList<Variable>();
variables = testComposite.getVariableList();
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
if (file != null) {
file.createNewFile();
}
operation.saveExpressionToFile(file, variables, expresionContent);
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
importButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
List list = operation.importExpressionFromFile(file, getShell());
if (list != null && list.size() != 0) {
expressionComposite.setExpression((String) list.get(0), false);
list.remove(0);
if (list.size() > 0) {
testComposite.addVariables(list);
}
}
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
} catch (SAXException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
}
use of org.xml.sax.SAXException 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;
}
Aggregations