Search in sources :

Example 51 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.

the class Snapshot method getTimeStamp.

/*
     * @see ISnapshot#getTimeStamp()
     */
@Override
public String getTimeStamp() {
    if (timeStamp != null) {
        return timeStamp;
    }
    if (snapshotType == SnapshotType.Hprof) {
        long lastModified = fileStore.fetchInfo().getLastModified();
        if (lastModified == EFS.NONE) {
            return null;
        }
        Date currentDate = new Date(lastModified);
        //$NON-NLS-1$
        String date = new SimpleDateFormat("yyyy/MM/dd").format(currentDate);
        //$NON-NLS-1$
        String time = new SimpleDateFormat("HH:mm:ss").format(currentDate);
        //$NON-NLS-1$
        timeStamp = date + " " + time;
        return timeStamp;
    }
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(new File(fileStore.toURI().getPath()));
        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
        Element root = document.getDocumentElement();
        //$NON-NLS-1$
        timeStamp = root.getAttribute("date");
        return timeStamp;
    } catch (SAXException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.readFileFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.readFileFailedMsg, fileStore.toURI().getPath()), e);
    } catch (ParserConfigurationException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.readFileFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return null;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 52 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.

the class HeapDumpEditor method parseDumpFile.

/**
     * Parses the dump file.
     * 
     * @param filePath The file path
     */
private void parseDumpFile(final String filePath) {
    Job job = new Job(Messages.parseHeapDumpFileJobLabel) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            HeapDumpParser parser = new HeapDumpParser(new File(filePath), heapListElements, monitor);
            try {
                parser.parse();
            } catch (ParserConfigurationException e) {
                //$NON-NLS-1$
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load heap dump file.", e);
            } catch (SAXException e) {
                //$NON-NLS-1$
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load heap dump file.", e);
            } catch (IOException e) {
                //$NON-NLS-1$
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load heap dump file.", e);
            }
            setProfileInfo(parser.getProfileInfo());
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (heapHistogramPage != null) {
                        heapHistogramPage.refresh();
                    }
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job) HeapDumpParser(org.talend.designer.runtime.visualization.core.dump.HeapDumpParser) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 53 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException 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 54 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException 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);
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 55 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.

the class WsdlTokenManager method getValueFromXML.

private String getValueFromXML(String inputXML, String xPathQuery) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException {
    DocumentBuilder builder;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new ByteArrayInputStream(inputXML.getBytes()));
        XPath xpath = XPathFactory.newInstance().newXPath();
        String expression = xPathQuery;
        Node cipherValue = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
        return cipherValue == null ? null : cipherValue.getTextContent();
    } catch (XPathExpressionException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (SAXException e) {
        logger.error(e.getMessage());
        throw e;
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1353 SAXException (org.xml.sax.SAXException)975 IOException (java.io.IOException)891 Document (org.w3c.dom.Document)710 DocumentBuilder (javax.xml.parsers.DocumentBuilder)631 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)569 Element (org.w3c.dom.Element)372 InputSource (org.xml.sax.InputSource)246 NodeList (org.w3c.dom.NodeList)226 Node (org.w3c.dom.Node)210 SAXParser (javax.xml.parsers.SAXParser)175 TransformerException (javax.xml.transform.TransformerException)163 File (java.io.File)162 InputStream (java.io.InputStream)158 SAXParserFactory (javax.xml.parsers.SAXParserFactory)137 ByteArrayInputStream (java.io.ByteArrayInputStream)129 StringReader (java.io.StringReader)117 ArrayList (java.util.ArrayList)115 DOMSource (javax.xml.transform.dom.DOMSource)109 StreamResult (javax.xml.transform.stream.StreamResult)93