Search in sources :

Example 6 with DefaultErrorHandler

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();
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DefaultEntityResolver(org.jaffa.util.DefaultEntityResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) DefaultErrorHandler(org.jaffa.util.DefaultErrorHandler) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SourceDecomposerException(org.jaffa.tools.common.SourceDecomposerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 7 with DefaultErrorHandler

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DefaultEntityResolver(org.jaffa.util.DefaultEntityResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DefaultErrorHandler(org.jaffa.util.DefaultErrorHandler)

Example 8 with DefaultErrorHandler

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DefaultEntityResolver(org.jaffa.util.DefaultEntityResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DefaultErrorHandler(org.jaffa.util.DefaultErrorHandler)

Example 9 with DefaultErrorHandler

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);
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) DefaultEntityResolver(org.jaffa.util.DefaultEntityResolver) DefaultErrorHandler(org.jaffa.util.DefaultErrorHandler)

Example 10 with DefaultErrorHandler

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;
}
Also used : InputSource(org.xml.sax.InputSource) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Log4jEntityResolver(org.apache.log4j.xml.Log4jEntityResolver) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DefaultErrorHandler(org.jaffa.util.DefaultErrorHandler) Log4jConfigException(org.jaffa.applications.jaffa.modules.admin.components.log4jconfig.ui.exceptions.Log4jConfigException)

Aggregations

DefaultErrorHandler (org.jaffa.util.DefaultErrorHandler)13 DefaultEntityResolver (org.jaffa.util.DefaultEntityResolver)12 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)9 IOException (java.io.IOException)7 InputSource (org.xml.sax.InputSource)7 SAXException (org.xml.sax.SAXException)7 Document (org.w3c.dom.Document)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 StringReader (java.io.StringReader)4 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 XMLReader (org.xml.sax.XMLReader)3 FileNotFoundException (java.io.FileNotFoundException)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StringTokenizer (java.util.StringTokenizer)1