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;
}
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("<p>", "<p>").replace("</p>", "</p>");
}
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;
}
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;
}
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);
}
}
}
Aggregations