use of javax.xml.parsers.ParserConfigurationException in project rhino by PLOS.
the class TaxonomyClassificationServiceImplTest method getDocumentBuilder.
private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
if (documentBuilder != null)
return documentBuilder;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
return documentBuilder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}
use of javax.xml.parsers.ParserConfigurationException in project rhino by PLOS.
the class AmbraService method newDocumentBuilder.
/**
* Construct a non-validating document builder. We assume that we don't want to connect to remote servers to validate
* except with a specific reason.
*
* @return a new document builder
*/
public static DocumentBuilder newDocumentBuilder() {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// at a minimum the document builder needs to be namespace aware
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
return factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}
use of javax.xml.parsers.ParserConfigurationException in project OpenAM by OpenRock.
the class DelegationConfig method parseDocument.
private Document parseDocument(String fileName) {
Document document = null;
InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
try {
DocumentBuilder documentBuilder = XMLUtils.getSafeDocumentBuilder(false);
document = documentBuilder.parse(is);
} catch (UnsupportedEncodingException e) {
AMModelBase.debug.error("DelegationConfig.parseDocument", e);
} catch (ParserConfigurationException e) {
AMModelBase.debug.error("DelegationConfig.parseDocument", e);
} catch (SAXException e) {
AMModelBase.debug.error("DelegationConfig.parseDocument", e);
} catch (IOException e) {
AMModelBase.debug.error("DelegationConfig.parseDocument", e);
}
return document;
}
use of javax.xml.parsers.ParserConfigurationException in project ACS by ACS-Community.
the class CDBChecker method checkImplLangMatch.
/******************************************************************
* This method finds files in "Components" and "Containers"
* directories and sub-directories. It then extracts "implLang"
* properties, and compares. Error messages are displayed if
* Components.xml's implLang and Containers.xml's implLang
* don't match.
* Returns 'true' if error is found, false otherwise
* added by panta@naoj 2009/10/05
*****************************************************************/
protected boolean checkImplLangMatch(File compFolder, File contFolder) {
File[] files = compFolder.listFiles();
search: for (int x = 0; x < files.length; x++) {
if (foundErr) {
break search;
}
if (files[x].isDirectory()) {
if (!files[x].getName().equals("CVS")) {
//recursive call
checkImplLangMatch(files[x], contFolder);
}
} else {
//only process .xml files
String ext = "";
int iExt = files[x].getName().lastIndexOf(".");
ext = files[x].getName().substring(iExt + 1, files[x].getName().length());
if (!ext.equals("xml")) {
continue;
}
//System.out.println("\nChecking.. " + files[x]);
DocumentBuilderFactory dbfComp = DocumentBuilderFactory.newInstance();
DocumentBuilder dbComp = null;
try {
dbComp = dbfComp.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document docComp = null;
try {
docComp = dbComp.parse(files[x]);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
docComp.getDocumentElement().normalize();
NodeList compNodeList = docComp.getElementsByTagName("Component");
//modify bhola.panta@naoj 2010-03-15
if (compNodeList.getLength() == 1) {
//only the variant where a single component is configured in its own file
String compName = ((Element) compNodeList.item(0)).getAttribute("Name");
//fileName and "Name" property must match
if (!compName.equals("*") && !files[x].getName().equals("Components.xml")) {
//must support hierarchical component names (separated by "/")
if (!checkHierarchical(files[x], compName)) {
if (!(compName + ".xml").equals(files[x].getName())) {
System.out.print("\nMismatch between component name and XML file name.");
System.out.print("\nComponent File: " + files[x]);
System.out.print("\nComponent name: '" + compName + "'");
System.out.print("\nFile name: '" + files[x].getName() + "'");
foundErr = true;
break search;
}
}
}
}
if (compNodeList.getLength() == 0) {
compNodeList = docComp.getElementsByTagName("_");
if (compNodeList.getLength() == 0) {
continue;
}
}
//this part extracts "implLang" for each component
for (int j = 0; j < compNodeList.getLength(); j++) {
Element elm = (Element) compNodeList.item(j);
String compName = null;
String implLang = null;
String tempContainersFolder = null;
compName = elm.getAttribute("Name");
implLang = elm.getAttribute("ImplLang");
if (compName.equals("*")) {
//--> dynamic component
if (implLang.equals("") || implLang.equals("*")) {
continue;
}
//some dynamic components may not have predefined Containers
if (elm.getAttribute("Container").equals("") || elm.getAttribute("Container").equals("*")) {
continue;
}
} else //component does have a name, but container is dynamic (?), that is, "*"
if (elm.getAttribute("Container").equals("*")) {
continue;
} else {
//actually, ImpLang field in the CDB is mandatory since ACS 8
if (implLang.equals("")) {
System.out.println("\nFile being checked: " + files[x]);
System.out.print("\n'ImplLang' missing for component: " + compName);
foundErr = true;
break search;
}
}
//go get containers at the "Container" location
tempContainersFolder = containersFolder + File.separator + elm.getAttribute("Container");
//open the container file and have a look
DocumentBuilderFactory dbfCont = DocumentBuilderFactory.newInstance();
DocumentBuilder dbCont = null;
try {
dbCont = dbfCont.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document docCont = null;
try {
//System.out.println("\ntempContainersFolder " + tempContainersFolder);
File contFile = new File(tempContainersFolder + File.separator + new File(tempContainersFolder).getName() + ".xml");
//System.out.println("\ncontainerFile " + contFile);
if (contFile.exists()) {
docCont = dbCont.parse(contFile);
docCont.getDocumentElement().normalize();
NodeList contNodeList = docCont.getElementsByTagName("Container");
//Go through Container files and check ImplLang
for (int k = 0; k < contNodeList.getLength(); k++) {
Element elmCont = (Element) contNodeList.item(k);
//check if Component ImplLang and Container ImplLang match
if (implLang.equals(elmCont.getAttribute("ImplLang"))) {
} else {
System.out.println("\nComponent File being checked: " + files[x]);
System.out.println("Container File being checked: " + contFile);
System.out.println("'ImplLang' does not match for component: " + compName + ".");
foundErr = true;
break search;
}
}
//Container for loop
} else {
System.out.print("\nComponent File being checked: " + files[x]);
System.out.print("\nMissing Container " + new File(tempContainersFolder));
System.out.println("");
foundErr = true;
break search;
}
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//Component for loop
}
//is a file (not dir)
}
return foundErr;
}
use of javax.xml.parsers.ParserConfigurationException in project ACS by ACS-Community.
the class ScriptFilter method readStatusFile.
private void readStatusFile(String filename, boolean startup) throws ParserConfigurationException, SAXException, IOException {
try {
if (startup) {
int n = JOptionPane.showConfirmDialog(this, "An old status file has been found\nWould you like to load it?", "Old status file found", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (n == JOptionPane.NO_OPTION) {
return;
}
}
if (validateStatusFile(filename)) {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File(filename));
doc.getDocumentElement().normalize();
NodeList listOfSamplingGroup = doc.getElementsByTagName("SamplingGroup");
for (int s = 0; s < listOfSamplingGroup.getLength(); s++) {
Node firstSamplingGroup = listOfSamplingGroup.item(s);
if (firstSamplingGroup.getNodeType() == Node.ELEMENT_NODE) {
Element firstSamplingGroupElement = (Element) firstSamplingGroup;
// -------
NodeList nameList = firstSamplingGroupElement.getElementsByTagName("SamplingGroupName");
Element nameElement = (Element) nameList.item(0);
NodeList nameText = nameElement.getChildNodes();
String samplingGroupName = ((Node) nameText.item(0)).getNodeValue().trim();
// MAN_NAME
NodeList manNameList = firstSamplingGroupElement.getElementsByTagName("SamplingManagerName");
Element manNameElement = (Element) manNameList.item(0);
NodeList manNameText = manNameElement.getChildNodes();
String manName = ((Node) manNameText.item(0)).getNodeValue().trim();
String[] managers = SampTool.getSamplingManagers();
for (int i = 0; i < managers.length; i++) {
if (managers[i].equals(manName)) {
correctManName = true;
}
}
if (correctManName) {
MAN_NAME = manName;
} else {
System.out.println("ERROR: The Sampling Manager Name on the loaded file doesn't exist.");
return;
}
//-------
NodeList freqList = firstSamplingGroupElement.getElementsByTagName("Frequency");
Element freqElement = (Element) freqList.item(0);
NodeList freqText = freqElement.getChildNodes();
double frequency = Double.parseDouble(((Node) freqText.item(0)).getNodeValue().trim());
//-------
NodeList stList = firstSamplingGroupElement.getElementsByTagName("SamplingTime");
Element stElement = (Element) stList.item(0);
NodeList stText = stElement.getChildNodes();
int samplingtime = Integer.parseInt(((Node) stText.item(0)).getNodeValue().trim());
//-------
NodeList twList = firstSamplingGroupElement.getElementsByTagName("TimeWindow");
Element twElement = (Element) twList.item(0);
NodeList twText = twElement.getChildNodes();
int timewindow = Integer.parseInt(((Node) twText.item(0)).getNodeValue().trim());
//----- Properties
NodeList listProperties = firstSamplingGroupElement.getElementsByTagName("Sample");
for (int o = 0; o < listProperties.getLength(); o++) {
Node firstProperty = listProperties.item(o);
if (firstProperty.getNodeType() == Node.ELEMENT_NODE) {
Element firstPropertyElement = (Element) firstProperty;
//-------
NodeList compList = firstPropertyElement.getElementsByTagName("component");
Element compElement = (Element) compList.item(0);
NodeList compText = compElement.getChildNodes();
String component = ((Node) compText.item(0)).getNodeValue().trim();
//-------
NodeList propList = firstPropertyElement.getElementsByTagName("property");
Element propElement = (Element) propList.item(0);
NodeList propText = propElement.getChildNodes();
String property = ((Node) propText.item(0)).getNodeValue().trim();
boolean checkStatus = checkComponentProperty(component, property);
System.out.println("opening " + component + ", " + property + ", " + samplingGroupName);
if (checkStatus) {
addToSampling(component, property, samplingGroupName);
} else {
JOptionPane.showMessageDialog(this, "The component or the property in:\n\n- " + component + "#" + property + "\n\n are invalid on the Sampling Group: '" + samplingGroupName + "'");
}
}
}
for (BeanGrouper bg : BeanGrouperList) {
if (bg.getGroupName().equals(samplingGroupName)) {
bg.loadConfiguration(frequency, timewindow, samplingtime);
break;
}
}
}
}
} else {
JOptionPane.showMessageDialog(this, "Your XML file have a bad format, please check it");
}
} catch (SAXParseException err) {
System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
System.out.println(" " + err.getMessage());
} catch (SAXException e) {
Exception x = e.getException();
((x == null) ? e : x).printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations