From 8c769bae2d6d71677ce71a299d618957029ab4ac Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@d688527b-c9ab-4aba-bd8d-4036d912da1d> Date: Mon, 10 Apr 2006 08:46:26 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'Build_ID-1_3_1'. git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/tags/Build_ID-1_3_1@704 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../slinterface/listeners/ContextListener.java | 185 --------------------- .../listeners/XMLParserErrorHandler.java | 65 -------- 2 files changed, 250 deletions(-) delete mode 100644 spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/ContextListener.java delete mode 100644 spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/XMLParserErrorHandler.java (limited to 'spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners') diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/ContextListener.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/ContextListener.java deleted file mode 100644 index b865b2ee4..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/ContextListener.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Created on 18.11.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.listeners; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.log4j.Logger; -import org.apache.xerces.parsers.DOMParser; -import org.apache.xerces.parsers.XMLGrammarPreparser; -import org.apache.xerces.util.SymbolTable; -import org.apache.xerces.util.XMLGrammarPoolImpl; -import org.apache.xerces.xni.grammars.XMLGrammarDescription; -import org.apache.xerces.xni.grammars.XMLGrammarPool; -import org.apache.xerces.xni.parser.XMLInputSource; -import org.xml.sax.SAXException; - -import at.gv.egovernment.moa.spss.slinterface.Constants; -import at.gv.egovernment.moa.spss.slinterface.URLRewriter; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class ContextListener implements ServletContextListener -{ - private static final String SAX_NAMESPACES_FEATURE = "http://xml.org/sax/features/namespaces"; - private static final String SAX_VALIDATION_FEATURE = "http://xml.org/sax/features/validation"; - - private static final String XERCES_SCHEMA_VALIDATION_FEATURE = - "http://apache.org/xml/features/validation/schema"; - private static final String XERCES_NORMALIZED_VALUE_FEATURE = - "http://apache.org/xml/features/validation/schema/normalized-value"; - private static final String XERCES_INCLUDE_IGNORABLE_WHITESPACE_FEATURE = - "http://apache.org/xml/features/dom/include-ignorable-whitespace"; - private static final String XERCES_CREATE_ENTITY_REF_NODES_FEATURE = - "http://apache.org/xml/features/dom/create-entity-ref-nodes"; - protected static final String XERCES_DEFER_NODE_EXPANSION_ = - "http://apache.org/xml/features/dom/defer-node-expansion"; - - private static final int BIG_PRIME = 2039; - - private static Logger logger_ = Logger.getLogger(Constants.LH_LISTENERS_); - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Initializes the web application. - * - * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) - */ - public void contextInitialized(ServletContextEvent event) - { - logger_.debug("Context is being initialized."); - - ServletContext context = event.getServletContext(); - - String initPropsLoc = System.getProperty(Constants.SP_INIT_PROPS_LOC_); - if (initPropsLoc == null) - { - logger_.error("System property \"" + Constants.SP_INIT_PROPS_LOC_ + "\" not set."); - return; - } - - // Load init properties - try - { - logger_.debug("Init properties location \"" + initPropsLoc + "\" will be used."); - - // Try to interpret init properties location as relative to the web application root - InputStream initPropsIS = context.getResourceAsStream(initPropsLoc); - - if (initPropsIS == null) - { - // If this does not work, try to interpret init properties location as an absolute file system path - initPropsIS = new FileInputStream(initPropsLoc); - } - - Properties initProps = new Properties(); - initProps.load(initPropsIS); - context.setAttribute(Constants.WSCP_INIT_PROPS_, initProps); - } - catch (IOException e) - { - logger_.error("Cannot load initialization properties from location \"" + initPropsLoc + "\".", e); - } - - // Put helper object for rewriting URLs in the result page into the context - URLRewriter urlRewriter = new URLRewriter((Properties)context.getAttribute(Constants.WSCP_INIT_PROPS_)); - context.setAttribute(Constants.WSCP_URL_REWRITER_, urlRewriter); - - // Initialize XML parser - SymbolTable symbolTable = new SymbolTable(BIG_PRIME); - XMLGrammarPool grammarPool = new XMLGrammarPoolImpl(); - - XMLGrammarPreparser preparser = new XMLGrammarPreparser(symbolTable); - preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); - preparser.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX - + org.apache.xerces.impl.Constants.XMLGRAMMAR_POOL_PROPERTY, grammarPool); - preparser.setFeature(SAX_NAMESPACES_FEATURE, true); - preparser.setFeature(SAX_VALIDATION_FEATURE, true); - - // Schema for Security-Layer 1.2 alpha (including LocRefContent) - Properties initProps = (Properties) context.getAttribute(Constants.WSCP_INIT_PROPS_); - String slSchemaLoc = initProps.getProperty(Constants.IP_SL_SCHEMA_); - preparseSchema(context, preparser, slSchemaLoc); - - // Schema for MOA 1.2 - String moaSchemaLoc = initProps.getProperty(Constants.IP_MOA_SCHEMA_); - preparseSchema(context, preparser, moaSchemaLoc); - - // Schema for SLXHTML 1.0 - String slxhtmlSchemaLoc = initProps.getProperty(Constants.IP_SLXHTML_SCHEMA_); - preparseSchema(context, preparser, slxhtmlSchemaLoc); - - // TODO parser is not threadsafe - DOMParser xmlParser = new DOMParser(symbolTable, grammarPool); - try - { - xmlParser.setFeature(SAX_NAMESPACES_FEATURE, true); - xmlParser.setFeature(SAX_VALIDATION_FEATURE, true); - xmlParser.setFeature(XERCES_SCHEMA_VALIDATION_FEATURE, true); - xmlParser.setFeature(XERCES_NORMALIZED_VALUE_FEATURE, false); - xmlParser.setFeature(XERCES_INCLUDE_IGNORABLE_WHITESPACE_FEATURE, true); - xmlParser.setFeature(XERCES_CREATE_ENTITY_REF_NODES_FEATURE, false); - xmlParser.setFeature(XERCES_DEFER_NODE_EXPANSION_, true); - xmlParser.setFeature("http://apache.org/xml/features/validation/schema/augment-psvi", false); // TODO Stringkonstante - xmlParser.setErrorHandler(new XMLParserErrorHandler(false, true, true)); - - } - catch (SAXException e) - { - String message = "Initialization of XML parser failed."; - logger_.error(message, e); - } - context.setAttribute(Constants.WSCP_XMLPARSER_, xmlParser); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * Does some clean up at finalization of the web application. - * - * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) - */ - public void contextDestroyed(ServletContextEvent event) - { - // Remove init properties from web service context - Properties initProps = (Properties) event.getServletContext().getAttribute(Constants.WSCP_INIT_PROPS_); - if (initProps != null) event.getServletContext().removeAttribute(Constants.WSCP_INIT_PROPS_); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private void preparseSchema(ServletContext context, XMLGrammarPreparser preparser, String schemaLoc) - { - InputStream schemaIS = context.getResourceAsStream(schemaLoc); - if (schemaIS == null) - { - String message = "Cannot load schema from location \"" + schemaLoc + "\"."; - logger_.error(message); - } - try - { - String schemaSystemId = context.getResource(schemaLoc).toExternalForm(); - preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, - new XMLInputSource(null, schemaSystemId, null, schemaIS, null)); - } - catch (Exception e) - { - String message = "Parsing schema loaded from location \"" + schemaLoc + "\" failed."; - logger_.error(message, e); - } - } - - -} diff --git a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/XMLParserErrorHandler.java b/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/XMLParserErrorHandler.java deleted file mode 100644 index 496d0aadb..000000000 --- a/spss.slinterface/WEB-INF/src/at/gv/egovernment/moa/spss/slinterface/listeners/XMLParserErrorHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Created on 02.12.2003 - * - * (c) Stabsstelle IKT-Strategie des Bundes - */ -package at.gv.egovernment.moa.spss.slinterface.listeners; - -import org.apache.log4j.Logger; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import at.gv.egovernment.moa.spss.slinterface.Constants; - -/** - * @author Gregor Karlinger (mailto:gregor.karlinger@cio.gv.at) - */ -public class XMLParserErrorHandler implements ErrorHandler -{ - private static Logger logger_ = Logger.getLogger(Constants.LH_LISTENERS_XMLPARSER_); - - private boolean reportWarning_, reportError_, reportFatal_; - - /* ---------------------------------------------------------------------------------------------------- */ - - public XMLParserErrorHandler(boolean reportWarning, boolean reportError, boolean reportFatal) - { - reportWarning_ = reportWarning; - reportError_ = reportError; - reportFatal_ = reportFatal; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) - */ - public void warning(SAXParseException exception) throws SAXException - { - logger_.warn("XML parser reported a warning.", exception); - if (reportWarning_) throw exception; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) - */ - public void error(SAXParseException exception) throws SAXException - { - logger_.error("XML parser reported an error.", exception); - if (reportError_) throw exception; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - /** - * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) - */ - public void fatalError(SAXParseException exception) throws SAXException - { - logger_.error("XML parser reported a fatal error.", exception); - if (reportFatal_) throw exception; - } -} -- cgit v1.2.3