use of org.jaffa.util.DefaultEntityResolver in project jaffa-framework by jaffa-projects.
the class DomParser method parse.
/**
* Parses the XML. It returns a Map.
* @param uri The location of the content to be parsed.
* @param validate if the XML is to be validated while parsing.
* @throws ParserConfigurationException if a DocumentBuilder cannot be created which satisfies the configuration requested.
* @throws SAXException If any parse errors occur.
* @throws IOException If any IO errors occur.
* @return The Map.
*/
public static Map parse(String uri, boolean validate) throws ParserConfigurationException, SAXException, IOException {
// Create a factory object for creating DOM parsers
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Specifies that the parser produced by this factory will validate documents as they are parsed.
factory.setValidating(validate);
// Now use the factory to create a DOM parser
DocumentBuilder parser = factory.newDocumentBuilder();
// Specifies the EntityResolver to resolve DTD used in XML documents
parser.setEntityResolver(new DefaultEntityResolver());
// Specifies the ErrorHandler to handle warning/error/fatalError conditions
parser.setErrorHandler(new DefaultErrorHandler());
Document document = parser.parse(uri);
return parseXML(document);
}
use of org.jaffa.util.DefaultEntityResolver in project jaffa-framework by jaffa-projects.
the class PatternGenerator method generateSourceFiles.
/**
* Create source files based on the contents of an XML file
* @param tempFileName the temporary file to be parsed, whose contents will
* determine which files get created.
* @param context contains information needed for processing, including
* information from WebMacro.properties and PatternGenerator
* properties.
* @throws PatternGeneratorException
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
* @throws WebMacroException
* @throws SourceDecomposerException
*/
private void generateSourceFiles(String tempFileName, Context context) throws PatternGeneratorException, ParserConfigurationException, SAXException, IOException, WebMacroException, SourceDecomposerException {
// parse the tempFileName.. Force XML validation
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder parser = factory.newDocumentBuilder();
parser.setEntityResolver(new DefaultEntityResolver());
parser.setErrorHandler(new DefaultErrorHandler());
Document document = parser.parse(tempFileName);
// check for Prerequisites
// @todo : this currently only supports java files..
// Need to enhance this logic to support other files too !!
String preReqErrLog = null;
Node preReq = document.getElementsByTagName(XML_PREREQUESITES).item(0);
NodeList classes = preReq.getChildNodes();
if (classes != null) {
for (int i = 0; i < classes.getLength(); i++) {
Node clazz = classes.item(i);
if (clazz.getNodeType() == Node.ELEMENT_NODE) {
String requiredClassName = XmlHelper.getTextTrim(clazz);
try {
Class.forName(requiredClassName);
} catch (ClassNotFoundException e) {
if (preReqErrLog == null) {
preReqErrLog = "";
}
preReqErrLog += "Error: PreRequesite Class " + requiredClassName + " not found\n";
}
}
}
}
if (preReqErrLog != null) {
writeMessage(m_auditFile, preReqErrLog, true);
throw new PatternGeneratorException(preReqErrLog);
}
processComponents(context, document);
}
Aggregations