Search in sources :

Example 11 with ErrorHandler

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;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) PersistenceException(org.talend.commons.exception.PersistenceException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException)

Example 12 with ErrorHandler

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);
        }
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) RepositoryContext(org.talend.core.context.RepositoryContext) XMLSerializer(com.sun.org.apache.xml.internal.serialize.XMLSerializer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) OutputFormat(com.sun.org.apache.xml.internal.serialize.OutputFormat) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) Project(org.talend.core.model.general.Project) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException)

Example 13 with ErrorHandler

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;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) RncFileType(org.intellij.plugins.relaxNG.compact.RncFileType) FileType(com.intellij.openapi.fileTypes.FileType) SAXParseException(org.xml.sax.SAXParseException) Document(com.intellij.openapi.editor.Document) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with ErrorHandler

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);
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) Schema(com.thaiopensource.validate.Schema) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder) ContentHandler(org.xml.sax.ContentHandler) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 15 with ErrorHandler

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);
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Aggregations

ErrorHandler (org.xml.sax.ErrorHandler)38 SAXException (org.xml.sax.SAXException)36 SAXParseException (org.xml.sax.SAXParseException)33 IOException (java.io.IOException)16 DocumentBuilder (javax.xml.parsers.DocumentBuilder)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)14 Document (org.w3c.dom.Document)13 InputSource (org.xml.sax.InputSource)9 InputStream (java.io.InputStream)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)7 Element (org.w3c.dom.Element)7 FileInputStream (java.io.FileInputStream)6 EntityResolver (org.xml.sax.EntityResolver)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 StringReader (java.io.StringReader)4 OutputFormat (com.sun.org.apache.xml.internal.serialize.OutputFormat)3 XMLSerializer (com.sun.org.apache.xml.internal.serialize.XMLSerializer)3 Attr (org.w3c.dom.Attr)3 NodeList (org.w3c.dom.NodeList)3