use of org.xml.sax.ErrorHandler 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.ErrorHandler 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.ErrorHandler in project intellij-community by JetBrains.
the class RngSchemaValidator method collectInformation.
@Nullable
@Override
public MyValidationMessageConsumer collectInformation(@NotNull final PsiFile file) {
final FileType type = file.getFileType();
if (type != StdFileTypes.XML && type != RncFileType.getInstance()) {
return null;
}
final XmlFile xmlfile = (XmlFile) file;
final XmlDocument document = xmlfile.getDocument();
if (document == null) {
return null;
}
if (type == StdFileTypes.XML) {
final XmlTag rootTag = document.getRootTag();
if (rootTag == null) {
return null;
}
if (!ApplicationLoader.RNG_NAMESPACE.equals(rootTag.getNamespace())) {
return null;
}
} else {
if (!ApplicationManager.getApplication().isUnitTestMode() && MyErrorFinder.hasError(xmlfile)) {
return null;
}
}
final Document doc = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
final MyValidationMessageConsumer consumer = new MyValidationMessageConsumer();
ErrorHandler eh = new DefaultHandler() {
@Override
public void warning(SAXParseException e) {
handleError(e, file, doc, consumer.warning());
}
@Override
public void error(SAXParseException e) {
handleError(e, file, doc, consumer.error());
}
};
RngParser.parsePattern(file, eh, true);
return consumer;
}
use of org.xml.sax.ErrorHandler in project intellij-community by JetBrains.
the class XmlInstanceValidator method doValidation.
public static void doValidation(@NotNull final XmlDocument doc, final Validator.ValidationHost host, final XmlFile descriptorFile) {
try {
final Schema schema = RngParser.getCachedSchema(descriptorFile);
if (schema == null) {
// did not manage to get a compiled schema. no validation...
return;
}
final ErrorHandler eh = MyErrorHandler.create(doc, host);
if (eh == null) {
return;
}
final PropertyMapBuilder builder = new PropertyMapBuilder();
builder.put(ValidateProperty.ERROR_HANDLER, eh);
final ContentHandler handler = schema.createValidator(builder.toPropertyMap()).getContentHandler();
doc.accept(new Psi2SaxAdapter(handler));
} catch (ProcessCanceledException e) {
throw e;
} catch (RuntimeException e) {
LOG.error(e);
} catch (Exception e) {
LOG.info(e);
}
}
use of org.xml.sax.ErrorHandler in project Activiti by Activiti.
the class BpmnDeploymentListener method parse.
protected Document parse(File artifact) throws Exception {
if (dbf == null) {
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
}
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
}
public void error(SAXParseException exception) throws SAXException {
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
return db.parse(artifact);
}
Aggregations