use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class RolesEditorForm method doValidate.
/**
* This method should be invoked to copy the fields from the FormBean to the component after successful validation.
* @return true of the values are copied successfully
*/
public boolean doValidate() throws FrameworkException, ApplicationExceptions {
String value = null;
ApplicationExceptions appExps = new ApplicationExceptions();
value = getFileContentsWM().getValue();
if (value == null || (value != null && value.trim().length() == 0)) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(MessageHelper.findMessage("label.Jaffa.Admin.RoleEditor.NoContent", null))));
throw appExps;
}
try {
// 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(true);
// Now use the factory to create a DOM parser
DocumentBuilder parser = factory.newDocumentBuilder();
// Specifies the EntityResolver onceto 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(new InputSource(new StringReader(value)));
} catch (ParserConfigurationException e) {
// Cannot pass e.toString() and pass as parameter as the the meesage contains quotes
// which dows not work properly with displaying the messages
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (SAXException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
setFileContents(value);
return true;
}
use of org.jaffa.util.DefaultErrorHandler 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.DefaultErrorHandler 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