use of org.apache.commons.digester.Digester in project sonarqube by SonarSource.
the class ActionServlet method initServlet.
/**
* <p>Initialize the servlet mapping under which our controller servlet is
* being accessed. This will be used in the <code>&html:form></code>
* tag to generate correct destination URLs for form submissions.</p>
*
* @throws ServletException if error happens while scanning web.xml
*/
protected void initServlet() throws ServletException {
// Remember our servlet name
this.servletName = getServletConfig().getServletName();
// Prepare a Digester to scan the web application deployment descriptor
Digester digester = new Digester();
digester.push(this);
digester.setNamespaceAware(true);
digester.setValidating(false);
// Register our local copy of the DTDs that we can find
for (int i = 0; i < registrations.length; i += 2) {
URL url = this.getClass().getResource(registrations[i + 1]);
if (url != null) {
digester.register(registrations[i], url.toString());
}
}
// Configure the processing rules that we need
digester.addCallMethod("web-app/servlet-mapping", "addServletMapping", 2);
digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);
// Process the web application deployment descriptor
if (log.isDebugEnabled()) {
log.debug("Scanning web.xml for controller servlet mapping");
}
InputStream input = getServletContext().getResourceAsStream("/WEB-INF/web.xml");
if (input == null) {
log.error(internal.getMessage("configWebXml"));
throw new ServletException(internal.getMessage("configWebXml"));
}
try {
digester.parse(input);
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} catch (SAXException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} finally {
try {
input.close();
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
}
}
// Record a servlet context attribute (if appropriate)
if (log.isDebugEnabled()) {
log.debug("Mapping for servlet '" + servletName + "' = '" + servletMapping + "'");
}
if (servletMapping != null) {
getServletContext().setAttribute(Globals.SERVLET_KEY, servletMapping);
}
}
use of org.apache.commons.digester.Digester in project sonarqube by SonarSource.
the class ActionServlet method initModuleConfig.
/**
* <p>Initialize the module configuration information for the specified
* module.</p>
*
* @param prefix Module prefix for this module
* @param paths Comma-separated list of context-relative resource path(s)
* for this modules's configuration resource(s)
* @return The new module configuration instance.
* @throws ServletException if initialization cannot be performed
* @since Struts 1.1
*/
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
}
// Parse the configuration for this module
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
ModuleConfig config = factoryObject.createModuleConfig(prefix);
// Configure the Digester instance we will use
Digester digester = initConfigDigester();
List urls = splitAndResolvePaths(paths);
URL url;
for (Iterator i = urls.iterator(); i.hasNext(); ) {
url = (URL) i.next();
digester.push(config);
this.parseModuleConfigFile(digester, url);
}
getServletContext().setAttribute(Globals.MODULE_KEY + config.getPrefix(), config);
return config;
}
use of org.apache.commons.digester.Digester in project sonarqube by SonarSource.
the class TestModuleConfig method parseConfig.
// ------------------------------------------------ Individual Test Methods
private void parseConfig(String publicId, String entityURL, String strutsConfig) {
// Prepare a Digester for parsing a struts-config.xml file
Digester digester = new Digester();
digester.push(config);
digester.setNamespaceAware(true);
digester.setValidating(true);
digester.addRuleSet(new ConfigRuleSet());
digester.register(publicId, this.getClass().getResource(entityURL).toString());
// Parse the test struts-config.xml file
try {
InputStream input = this.getClass().getResourceAsStream(strutsConfig);
assertNotNull("Got an input stream for " + strutsConfig, input);
digester.parse(input);
input.close();
} catch (Throwable t) {
t.printStackTrace(System.out);
fail("Parsing threw exception: " + t);
}
}
use of org.apache.commons.digester.Digester in project gocd by gocd.
the class GoPluginDescriptorParser method initDigester.
private static Digester initDigester() throws SAXNotRecognizedException, SAXNotSupportedException {
Digester digester = new Digester();
digester.setValidating(true);
digester.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
}
@Override
public void error(SAXParseException exception) throws SAXException {
throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
}
});
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", GoPluginDescriptorParser.class.getResourceAsStream("/plugin-descriptor.xsd"));
return digester;
}
use of org.apache.commons.digester.Digester in project gocd by gocd.
the class GoPluginDescriptorParser method parseXML.
public static GoPluginDescriptor parseXML(InputStream pluginXML, String pluginJarFileLocation, File pluginBundleLocation, boolean isBundledPlugin) throws IOException, SAXException {
Digester digester = initDigester();
GoPluginDescriptorParser parserForThisXML = new GoPluginDescriptorParser(pluginJarFileLocation, pluginBundleLocation, isBundledPlugin);
digester.push(parserForThisXML);
digester.addCallMethod("go-plugin", "createPlugin", 2);
digester.addCallParam("go-plugin", 0, "id");
digester.addCallParam("go-plugin", 1, "version");
digester.addCallMethod("go-plugin/about", "createAbout", 4);
digester.addCallParam("go-plugin/about/name", 0);
digester.addCallParam("go-plugin/about/version", 1);
digester.addCallParam("go-plugin/about/target-go-version", 2);
digester.addCallParam("go-plugin/about/description", 3);
digester.addCallMethod("go-plugin/about/vendor", "createVendor", 2);
digester.addCallParam("go-plugin/about/vendor/name", 0);
digester.addCallParam("go-plugin/about/vendor/url", 1);
digester.addCallMethod("go-plugin/about/target-os/value", "addTargetOS", 1);
digester.addCallParam("go-plugin/about/target-os/value", 0);
digester.parse(pluginXML);
return parserForThisXML.descriptor;
}
Aggregations