001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.jxp;
022:
023: import java.io.*;
024: import javax.xml.parsers.SAXParser;
025: import javax.xml.parsers.SAXParserFactory;
026: import org.onemind.commons.java.xml.digest.SaxDigesterHandler;
027: import org.onemind.jxp.config.JxpConfigDigester;
028: import org.xml.sax.SAXException;
029:
030: /**
031: * The JxpPageSource factory
032: * @author TiongHiang Lee (thlee@onemindsoft.org)
033: *
034: */
035: public final class JxpFactory {
036:
037: /** the parser * */
038: private static SAXParser _parser;
039:
040: /**
041: * Constructor
042: */
043: private JxpFactory() {
044: }
045:
046: /**
047: * set up
048: * @return the parser
049: * @throws Exception if there's problem
050: */
051: private static SAXParser getParser() throws Exception {
052: if (_parser == null) {
053: SAXParserFactory factory = SAXParserFactory.newInstance();
054: _parser = factory.newSAXParser();
055: }
056: return _parser;
057: }
058:
059: /**
060: * Get the page source from the config
061: * @param configFile the config
062: * @return the config
063: * @throws IOException if there's IO problem
064: * @throws SAXException if there's parsing exception
065: * @throws Exception if there's other problem
066: */
067: public static JxpPageSource getPageSource(String configFile)
068: throws SAXException, IOException, Exception {
069: // PageSourceDigesterElement config = new PageSourceDigesterElement();
070: // SaxDigesterHandler handler = new SaxDigesterHandler();
071: // handler.addDigester(config);
072: // getParser().parse(new File(configFile), handler);
073: // return config.getPageSource();
074: return null;
075: }
076:
077: /**
078: * Get the processor from the config
079: * @param configFile the config
080: * @return the processor
081: * @throws IOException if there's IO problem
082: * @throws SAXException if there's parsing problem
083: * @throws Exception if there's other problem
084: */
085: public static JxpProcessor getProcessor(String configFile)
086: throws SAXException, IOException, Exception {
087: return getProcessor(new FileInputStream(configFile));
088: }
089:
090: /**
091: * Get the processor from the config
092: * @param config the config input stream
093: * @return the processor
094: * @throws IOException if there's IO problem
095: * @throws SAXException if there's parsing problem
096: * @throws Exception if there's other problem
097: */
098: public static JxpProcessor getProcessor(InputStream config)
099: throws SAXException, IOException, Exception {
100: SaxDigesterHandler handler = new SaxDigesterHandler();
101: SAXParser parser = SAXParserFactory.newInstance()
102: .newSAXParser();
103: JxpConfigDigester dig = new JxpConfigDigester();
104: handler.addDigester(dig);
105: parser.parse(config, handler);
106: return dig.getProcessor();
107: }
108: }
|