use of javax.xml.parsers.ParserConfigurationException in project head by mifos.
the class TypeParser method parser.
public Files parser(String filename) throws TableTagTypeParserException {
Files file = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
// Specify our own schema - this overrides the schemaLocation in the
// xml file
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "type.xsd");
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
Node fileNode = document.getFirstChild();
file = new Files();
file.setFileName(createFileName(fileNode));
} catch (ParserConfigurationException pce) {
throw new TableTagTypeParserException(pce);
} catch (IOException ioe) {
throw new TableTagTypeParserException(ioe);
} catch (SAXParseException saxpe) {
throw new TableTagTypeParserException(saxpe);
} catch (SAXException saxe) {
throw new TableTagTypeParserException(saxe);
} catch (MifosRuntimeException saxe) {
throw new TableTagTypeParserException(saxe);
}
return file;
}
use of javax.xml.parsers.ParserConfigurationException in project head by mifos.
the class ChartOfAccountsConfig method load.
/**
* Factory method which loads the Chart of Accounts configuration from the
* given filename. Given XML filename will be validated against
* {@link FilePaths#CHART_OF_ACCOUNTS_SCHEMA}.
*
* @param chartOfAccountsXml
* a relative path to the Chart of Accounts configuration file.
*/
public static ChartOfAccountsConfig load(String chartOfAccountsXml) throws ConfigurationException {
ChartOfAccountsConfig instance = null;
Document document = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = dbf.newDocumentBuilder();
if (FilePaths.CHART_OF_ACCOUNTS_DEFAULT.equals(chartOfAccountsXml)) {
// default chart of accounts
document = parser.parse(MifosResourceUtil.getClassPathResourceAsStream(chartOfAccountsXml));
} else {
// custom chart of accounts
document = parser.parse(MifosResourceUtil.getFile(chartOfAccountsXml));
}
// create a SchemaFactory capable of understanding XML schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load an XML schema
ClassPathResource schemaFileResource = new ClassPathResource(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
Source schemaFile = null;
if (schemaFileResource.exists()) {
InputStream in = ChartOfAccountsConfig.class.getClassLoader().getResourceAsStream(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
schemaFile = new StreamSource(in);
} else {
schemaFile = new StreamSource(MifosResourceUtil.getFile(FilePaths.CHART_OF_ACCOUNTS_SCHEMA));
}
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance and validate document
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
} catch (IOException e) {
throw new ConfigurationException(e);
} catch (SAXException e) {
throw new ConfigurationException(e);
} catch (ParserConfigurationException e) {
throw new ConfigurationException(e);
}
instance = new ChartOfAccountsConfig();
instance.coaDocument = document;
return instance;
}
use of javax.xml.parsers.ParserConfigurationException in project head by mifos.
the class StateXMLParser method loadMapFromXml.
public Map<StateEntity, List<StateEntity>> loadMapFromXml(String filename, String configurationName) {
Map<StateEntity, List<StateEntity>> transitionMap = new HashMap<StateEntity, List<StateEntity>>();
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
// Specify our own schema - this overrides the schemaLocation in the
// xml file
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "StateMachine.xsd");
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
Node mapToprocess = null;
/*
* String configurationName = ""; if
* (stateConfiguration=="configuration1") configurationName = "1";
* else configurationName = "2";
*/
NodeList configMaps = document.getElementsByTagName("stateConfiguration");
for (int m = 0; m < configMaps.getLength(); m++) {
Node stateConfiguration = configMaps.item(m);
if (configurationName.equals(stateConfiguration.getAttributes().getNamedItem("configurationName").getNodeValue())) {
mapToprocess = stateConfiguration;
}
}
// NodeList stateList = firstChild.getChildNodes();
NodeList stateList = mapToprocess.getChildNodes();
for (int i = 0; i < stateList.getLength(); i++) {
// each state has state id and possiblestates as childern
Node state = stateList.item(i);
// iterate for each child of state
NodeList stateInfoList = state.getChildNodes();
StateEntity currentState = null;
List<StateEntity> currntPossibleStates = new ArrayList<StateEntity>();
for (int j = 0; j < stateInfoList.getLength(); j++) {
Node info = stateInfoList.item(j);
if ("stateid".equals(info.getLocalName())) {
Element ele = (Element) info;
currentState = new StateEntity(Short.valueOf(((Text) ele.getFirstChild()).getData()));
}
if ("possiblestates".equals(info.getLocalName())) {
// get all the childern
NodeList allStates = info.getChildNodes();
currntPossibleStates = new ArrayList<StateEntity>();
for (int k = 0; k < allStates.getLength(); k++) {
Node infoState = allStates.item(k);
NodeList eachPossiblechild = infoState.getChildNodes();
for (int l = 0; l < eachPossiblechild.getLength(); l++) {
Node eachPossiblechildelement = eachPossiblechild.item(l);
if ("stateid".equals(eachPossiblechildelement.getLocalName())) {
Element element = (Element) eachPossiblechildelement;
Short possibleTrantionId = Short.valueOf(((Text) element.getFirstChild()).getData());
currntPossibleStates.add(new StateEntity(possibleTrantionId));
}
}
}
}
}
if (currentState != null) {
transitionMap.put(currentState, currntPossibleStates);
}
}
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SAXParseException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
}
return transitionMap;
}
use of javax.xml.parsers.ParserConfigurationException in project head by mifos.
the class XMLParser method parser.
public ColumnPropertyMapping parser() throws SystemException {
Document document = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream("org/mifos/framework/util/resources/audit/ColumnMapping.xml"));
getColumnPropertyMapping(document);
} catch (ParserConfigurationException e) {
throw new SystemException(e);
} catch (IOException e) {
throw new SystemException(e);
} catch (SAXParseException e) {
throw new SystemException(e);
} catch (SAXException e) {
throw new SystemException(e);
}
return columnPropertyMapping;
}
use of javax.xml.parsers.ParserConfigurationException in project OpenGrok by OpenGrok.
the class SubversionRepository method setDirectoryName.
@Override
public void setDirectoryName(String directoryName) {
super.setDirectoryName(directoryName);
if (isWorking()) {
// set to true if we manage to find the root directory
Boolean rootFound = Boolean.FALSE;
List<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("info");
cmd.add("--xml");
File directory = new File(getDirectoryName());
Executor executor = new Executor(cmd, directory);
if (executor.exec() == 0) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(executor.getOutputStream());
String url = getValue(document.getElementsByTagName("url").item(0));
if (url == null) {
LOGGER.log(Level.WARNING, "svn info did not contain an URL for [{0}]. Assuming remote repository.", directoryName);
setRemote(true);
} else {
if (!url.startsWith("file")) {
setRemote(true);
}
}
String root = getValue(document.getElementsByTagName("root").item(0));
if (url != null && root != null) {
reposPath = url.substring(root.length());
rootFound = Boolean.TRUE;
}
} catch (SAXException saxe) {
LOGGER.log(Level.WARNING, "Parser error parsing svn output", saxe);
} catch (ParserConfigurationException pce) {
LOGGER.log(Level.WARNING, "Parser configuration error parsing svn output", pce);
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "IOException reading from svn process", ioe);
}
} else {
LOGGER.log(Level.WARNING, "Failed to execute svn info for [{0}]. Repository disabled.", directoryName);
}
setWorking(rootFound);
}
}
Aggregations