Search in sources :

Example 86 with SAXException

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;
}
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 87 with SAXException

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;
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) SAXException(org.xml.sax.SAXException) Unmarshaller(javax.xml.bind.Unmarshaller) DependencyPair(org.voltdb.DependencyPair)

Example 88 with SAXException

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);
        }
    }
}
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 89 with SAXException

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);
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ExpressionFileOperation(org.talend.expressionbuilder.ExpressionFileOperation) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 90 with SAXException

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;
}
Also used : Path(org.eclipse.core.runtime.Path) ErrorHandler(org.xml.sax.ErrorHandler) XMLSerializer(com.sun.org.apache.xml.internal.serialize.XMLSerializer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) Bundle(org.osgi.framework.Bundle) Element(org.w3c.dom.Element) FileWriter(java.io.FileWriter) OutputFormat(com.sun.org.apache.xml.internal.serialize.OutputFormat) Document(org.w3c.dom.Document) URL(java.net.URL) Attr(org.w3c.dom.Attr) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) File(java.io.File)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151