use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class PatternGenerator method processPattern.
/**
* This will invoke the Pattern Generation routine.
*
* @throws PatternGeneratorException if any error occurs.
*/
public void processPattern() throws PatternGeneratorException {
try {
// Step 1 - Get the patternTemplate from m_patternMetaData
// Note: The XML should not be validated.. since it may contain WebMacro script variables
String patternTemplate = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
DocumentBuilder parser = factory.newDocumentBuilder();
parser.setEntityResolver(new DefaultEntityResolver());
parser.setErrorHandler(new DefaultErrorHandler());
String metaDataFileName = m_patternMetaData.getFile();
Document document = parser.parse(metaDataFileName);
NodeList nodes = document.getElementsByTagName(XML_PATTERN_TEMPLATE);
if (nodes != null && nodes.getLength() > 0) {
Node node = nodes.item(0);
patternTemplate = XmlHelper.getTextTrim(node);
}
if (patternTemplate == null || patternTemplate.equals("")) {
throw new PatternGeneratorException("The " + XML_PATTERN_TEMPLATE + " element is not supplied in the input Meta Data File");
}
// Step2 - Generate the TemporaryMetaDataFile from patternTemplate + m_patternMetaData
Context context = getContextWithData();
String tempFileName = generateTempFile(patternTemplate, (new File(metaDataFileName)).getName(), context);
// Step3 - Generate the source code files
generateSourceFiles(tempFileName, context);
} catch (PatternGeneratorException e) {
throw e;
} catch (Exception e) {
throw new PatternGeneratorException(e);
} finally {
destroy();
}
}
use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class AbstractLoader method createParser.
// ---------------------------------------------------------------------------------
//
// CONVENIENCE METHODS
//
// ----------------------------------------------------------------------------------
/**
* Returns an XML Parser.
* @return an XML Parser.
* @throws ParserConfigurationException if any error occurs
*/
protected DocumentBuilder createParser() throws ParserConfigurationException {
// 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(false);
// 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());
return parser;
}
use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class AopConstants method createParser.
/**
* Creates a DocumentBuilder that is configured to read Xml Documents in a common way.
*
* @return A configured parser
*/
public static DocumentBuilder createParser() throws ParserConfigurationException {
// 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(false);
// 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());
return parser;
}
use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class MainMenu method process.
private void process(HttpServletRequest request, PageContext pageContext) throws JDOMException, FileNotFoundException, IOException {
String prop = (String) Config.getProperty(Config.PROP_MENULIST_URL, DEFAULT_MENULIST_LOCATION);
URL roleUrl = null;
try {
// Create a URL for the resource file...
roleUrl = URLHelper.newExtendedURL(prop);
} catch (MalformedURLException e) {
log.fatal("Can't Find Menu List File, Bad URL - " + prop, e);
throw new SecurityException();
}
// parse the tempFileName.. Force XML validation
SAXBuilder builder = new SAXBuilder(true);
// Specifies the EntityResolver to resolve DTD used in XML documents
builder.setEntityResolver(new DefaultEntityResolver());
// Specifies the ErrorHandler to handle warning/error/fatalError conditions
builder.setErrorHandler(new DefaultErrorHandler());
Document document = builder.build(roleUrl);
Element root = document.getRootElement();
hm = new LinkedHashMap();
List components = root.getChildren();
List groups = new ArrayList();
for (Iterator itr = components.iterator(); itr.hasNext(); ) {
if (m_group == null)
m_group = new Group();
else {
if (!(coll.isEmpty())) {
hm.put(m_group, coll);
coll = new ArrayList();
m_group = new Group();
}
}
Element group = (Element) itr.next();
String groupName = group.getChildTextTrim(XML_GROUPNAME);
String description = group.getChildTextTrim(XML_DESC);
String groupIcon = group.getChildTextTrim(XML_GROUPICON);
String title = group.getChildTextTrim(XML_TITLE);
String gTitle = null;
if (MessageHelper.hasTokens(title)) {
gTitle = MessageHelper.replaceTokens(pageContext, title);
title = gTitle;
}
m_group.setGroupName(groupName);
m_group.setDescription(description);
m_group.setGroupIcon(groupIcon);
m_group.setGroupTitle(title);
List groupElements = group.getChildren(XML_OPTION);
int i = 0;
for (Iterator itr1 = groupElements.iterator(); itr1.hasNext(); ) {
Element build = (Element) itr1.next();
String optionName = build.getChildTextTrim(XML_OPTIONNAME);
String optionIcon = build.getChildTextTrim(XML_OPTIONICON);
String component = build.getChildTextTrim(XML_COMPONENT);
String comp_URL;
boolean compExist = false;
if (build.getChildTextTrim(XML_COMPONENT) == null || build.getChildTextTrim(XML_COMPONENT).length() == 0)
comp_URL = build.getChildTextTrim(XML_URL);
else {
comp_URL = build.getChildTextTrim(XML_COMPONENT);
compExist = true;
}
if (log.isDebugEnabled())
log.debug(XML_COMPONENT + ":" + comp_URL);
m_option = new Option();
String name = null;
if (MessageHelper.hasTokens(optionName)) {
name = MessageHelper.replaceTokens(pageContext, optionName);
optionName = name;
}
if (log.isDebugEnabled())
log.debug("The Option Name is : " + optionName);
m_option.setName(optionName);
m_option.setIcon(optionIcon);
m_option.setCompURL(comp_URL);
if (compExist) {
m_option.setURLTrue(false);
// check if user has access to the component
if (SecurityTag.hasComponentAccess(request, comp_URL))
coll.add(m_option);
} else {
m_option.setURLTrue(true);
coll.add(m_option);
}
}
}
if (!(coll.isEmpty()))
hm.put(m_group, coll);
}
use of org.jaffa.util.DefaultErrorHandler in project jaffa-framework by jaffa-projects.
the class Log4jConfigForm 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 Log4jConfigException(Log4jConfigException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(MessageHelper.findMessage("label.Jaffa.Admin.Log4JConfig.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 Log4jEntityResolver());
// 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 Log4jConfigException(Log4jConfigException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (SAXException e) {
appExps.add(new Log4jConfigException(Log4jConfigException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
appExps.add(new Log4jConfigException(Log4jConfigException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
setFileContents(value);
return true;
}
Aggregations