Search in sources :

Example 66 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project ACS by ACS-Community.

the class ScriptFilter method getFileMenuLoadStatusButton.

/**
	 * This method initializes FileMenuLoadStatusButton
	 * @return javax.swing.JMenuItem
	 */
private JMenuItem getFileMenuLoadStatusButton() {
    if (FileMenuLoadStatusButton == null) {
        FileMenuLoadStatusButton = new JMenuItem();
        FileMenuLoadStatusButton.setText("Load GUI Status");
        FileMenuLoadStatusButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                Filter filter = new Filter();
                chooser.setFileFilter(filter);
                int returnVal = chooser.showOpenDialog(cl.utfsm.samplingSystemUI.SamplingSystemGUI.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    try {
                        readStatusFile(chooser.getSelectedFile().getAbsolutePath(), false);
                    } catch (ParserConfigurationException e1) {
                        e1.printStackTrace();
                    } catch (SAXException e1) {
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
    }
    return FileMenuLoadStatusButton;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) ActionEvent(java.awt.event.ActionEvent) SAXException(org.xml.sax.SAXException)

Example 67 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project zaproxy by zaproxy.

the class ReportGenerator method stringToHtml.

public static String stringToHtml(String inxml, String infilexsl) {
    Document doc = null;
    // factory.setNamespaceAware(true);
    // factory.setValidating(true);
    File stylesheet = null;
    StringReader inReader = new StringReader(inxml);
    StringWriter writer = new StringWriter();
    try {
        stylesheet = new File(infilexsl);
        DocumentBuilder builder = XmlUtils.newXxeDisabledDocumentBuilderFactory().newDocumentBuilder();
        doc = builder.parse(new InputSource(inReader));
        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        StreamSource stylesource = new StreamSource(stylesheet);
        Transformer transformer = tFactory.newTransformer(stylesource);
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
    } catch (TransformerException | SAXException | ParserConfigurationException | IOException e) {
        showDialogForGUI();
        logger.error(e.getMessage(), e);
    } finally {
    }
    // we should really adopt something other than XSLT ;)
    return writer.toString().replace("&lt;p&gt;", "<p>").replace("&lt;/p&gt;", "</p>");
}
Also used : InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 68 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project claw-compiler by C2SM-RCM.

the class FortranDecompiler method decompile.

/**
   * Decompile the XcodeML file into Fortran code.
   *
   * @param outputFilepath Fortran output file path.
   * @param inputFilepath  XcodeML input file path.
   * @param maxColumns     Maximum number of column for the output file.
   * @param lineDirectives If true, preprocessor line directives are added.
   * @return True if the decompilation succeeded. False otherwise.
   */
public boolean decompile(String outputFilepath, String inputFilepath, int maxColumns, boolean lineDirectives) {
    if (!lineDirectives) {
        XmOption.setIsSuppressLineDirective(true);
    }
    XmOption.setCoarrayNoUseStatement(true);
    XmOption.setDebugOutput(false);
    if (!openXcodeMLFile(inputFilepath)) {
        return false;
    }
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFilepath)));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        XmDecompiler decompiler = _toolFactory.createDecompiler();
        XmDecompilerContext context = _toolFactory.createDecompilerContext();
        if (maxColumns > 0) {
            context.setProperty(XmDecompilerContext.KEY_MAX_COLUMNS, "" + maxColumns);
        }
        try {
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = docFactory.newDocumentBuilder();
            Document xcodeDoc;
            xcodeDoc = builder.parse(inputFilepath);
            decompiler.decompile(context, xcodeDoc, writer);
        } catch (ParserConfigurationException | SAXException | IOException e) {
            return false;
        }
        if (writer != null) {
            writer.flush();
        } else {
            return false;
        }
        return true;
    } catch (Exception ex) {
        if (_reader != null) {
            try {
                _reader.close();
            } catch (IOException ignored) {
            }
        }
        if (writer != null) {
            writer.close();
        }
    }
    return false;
}
Also used : XmDecompiler(xcodeml.util.XmDecompiler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmDecompilerContext(xcodeml.util.XmDecompilerContext) Document(org.w3c.dom.Document) XmException(xcodeml.XmException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 69 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project cubrid-manager by CUBRID.

the class ImportERDataDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite p) {
    Composite parent = (Composite) super.createDialogArea(p);
    Composite comp = new Composite(parent, SWT.NONE);
    {
        final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
        layoutData.widthHint = 400;
        comp.setLayoutData(layoutData);
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        layout.makeColumnsEqualWidth = false;
        comp.setLayout(layout);
    }
    Label fileLbl = new Label(comp, SWT.NONE);
    fileLbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    fileLbl.setText(Messages.lblFilePath);
    final Text filePathText = new Text(comp, SWT.BORDER);
    {
        GridData gdFilePathData = new GridData();
        gdFilePathData.widthHint = 200;
        filePathText.setLayoutData(gdFilePathData);
    }
    final Button fileButton = new Button(comp, SWT.PUSH);
    fileButton.setText(Messages.btnBrowse);
    fileButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.erd", "*.xml" });
            dialog.setFilterNames(new String[] { "ERD file", "ERwin XML file" });
            String filePath = dialog.open();
            if (filePath == null || filePath.equals("")) {
                ImportERDataDialog.this.close();
                return;
            }
            filename = filePath;
            filePathText.setText(filename);
            selectedMode = dialog.getFilterIndex();
            if (isGsonFile()) {
                handleGsonFile(filename);
            } else if (isERWinFile()) {
                handleDocument(filename);
            }
        }

        private void handleDocument(String filePath) {
            DocumentBuilder docBuilder = null;
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                factory.setIgnoringComments(true);
                docBuilder = factory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                LOGGER.error(e.getMessage(), e);
                return;
            }
            try {
                FileInputStream fis = new FileInputStream(filePath);
                doc = docBuilder.parse(fis);
                fis.close();
            } catch (FileNotFoundException e) {
                LOGGER.error(e.getMessage(), e);
                CommonUITool.openErrorBox(Messages.errFileNotExist);
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
                String errMsg = Messages.bind(Messages.errFileCannotRead, filePath);
                CommonUITool.openErrorBox(errMsg);
            } catch (SAXException e) {
                LOGGER.error(e.getMessage(), e);
                CommonUITool.openErrorBox(Messages.errInvalidFile);
            }
        }

        private void handleGsonFile(String filePath) {
            try {
                gsonData = FileUtil.readData(filePath, FileUtil.CHARSET_UTF8);
            } catch (IOException e) {
                CommonUITool.openErrorBox(e.getMessage());
                return;
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    setTitle(com.cubrid.common.ui.er.Messages.titleImportSchemaData);
    setMessage(com.cubrid.common.ui.er.Messages.msgImportSchemaData);
    getShell().setText(com.cubrid.common.ui.er.Messages.titleImportSchemaData);
    comp.pack();
    return comp;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) DocumentBuilder(javax.xml.parsers.DocumentBuilder) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 70 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project perun by CESNET.

the class MuPasswordManagerModule method parseResponse.

/**
	 * Parse XML response from IS MU to XML document.
	 *
	 * @param inputStream Stream to be parsed to Document
	 * @param requestID ID of request made to IS MU.
	 * @return XML document for further processing
	 * @throws InternalErrorException
	 */
private Document parseResponse(InputStream inputStream, int requestID) throws InternalErrorException {
    //Create new document factory builder
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
        throw new InternalErrorException("Error when creating newDocumentBuilder. Request ID: " + requestID, ex);
    }
    String response = null;
    try {
        response = convertStreamToString(inputStream, "UTF-8");
    } catch (IOException ex) {
        log.error("Unable to convert InputStream to String: {}", ex);
    }
    log.trace("Request ID: " + requestID + " Response: " + response);
    Document doc;
    try {
        doc = builder.parse(new InputSource(new StringReader(response)));
    } catch (SAXParseException ex) {
        throw new InternalErrorException("Error when parsing uri by document builder. Request ID: " + requestID, ex);
    } catch (SAXException ex) {
        throw new InternalErrorException("Problem with parsing is more complex, not only invalid characters. Request ID: " + requestID, ex);
    } catch (IOException ex) {
        throw new InternalErrorException("Error when parsing uri by document builder. Problem with input or output. Request ID: " + requestID, ex);
    }
    //Prepare xpath expression
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();
    XPathExpression isErrorExpr;
    XPathExpression getErrorTextExpr;
    XPathExpression getDbErrorTextExpr;
    try {
        isErrorExpr = xpath.compile("//resp/stav/text()");
        getErrorTextExpr = xpath.compile("//resp/error/text()");
        getDbErrorTextExpr = xpath.compile("//resp/dberror/text()");
    } catch (XPathExpressionException ex) {
        throw new InternalErrorException("Error when compiling xpath query. Request ID: " + requestID, ex);
    }
    // OK or ERROR
    String responseStatus;
    try {
        responseStatus = (String) isErrorExpr.evaluate(doc, XPathConstants.STRING);
    } catch (XPathExpressionException ex) {
        throw new InternalErrorException("Error when evaluate xpath query on document to resolve response status. Request ID: " + requestID, ex);
    }
    log.trace("Request ID: " + requestID + " Response status: " + responseStatus);
    if ("OK".equals(responseStatus)) {
        return doc;
    } else {
        try {
            String error = (String) getErrorTextExpr.evaluate(doc, XPathConstants.STRING);
            if (error == null || error.isEmpty()) {
                error = (String) getDbErrorTextExpr.evaluate(doc, XPathConstants.STRING);
            }
            throw new InternalErrorException("IS MU (password manager backend) responded with error to a Request ID: " + requestID + " Error: " + error);
        } catch (XPathExpressionException ex) {
            throw new InternalErrorException("Error when evaluate xpath query on document to resolve error status. Request ID: " + requestID, ex);
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

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