List of usage examples for org.apache.commons.digester Digester register
public void register(String publicId, String entityURL)
Convenience method that registers the string version of an entity URL instead of a URL version.
From source file:cn.zhouyafeng.tomcat.util.modeler.modules.MbeansDescriptorsDigesterSource.java
private static Digester createDigester() { Digester digester = new Digester(); digester.setNamespaceAware(false);/*ww w . j a v a2 s .c o m*/ digester.setValidating(false); URL url = Registry.getRegistry(null, null).getClass() .getResource("/org/apache/tomcat/util/modeler/mbeans-descriptors.dtd"); digester.register("-//Apache Software Foundation//DTD Model MBeans Configuration File", url.toString()); // Configure the parsing rules digester.addObjectCreate("mbeans-descriptors/mbean", "org.apache.tomcat.util.modeler.ManagedBean"); digester.addSetProperties("mbeans-descriptors/mbean"); digester.addSetNext("mbeans-descriptors/mbean", "add", "java.lang.Object"); digester.addObjectCreate("mbeans-descriptors/mbean/attribute", "org.apache.tomcat.util.modeler.AttributeInfo"); digester.addSetProperties("mbeans-descriptors/mbean/attribute"); digester.addSetNext("mbeans-descriptors/mbean/attribute", "addAttribute", "org.apache.tomcat.util.modeler.AttributeInfo"); digester.addObjectCreate("mbeans-descriptors/mbean/notification", "org.apache.tomcat.util.modeler.NotificationInfo"); digester.addSetProperties("mbeans-descriptors/mbean/notification"); digester.addSetNext("mbeans-descriptors/mbean/notification", "addNotification", "org.apache.tomcat.util.modeler.NotificationInfo"); digester.addObjectCreate("mbeans-descriptors/mbean/notification/descriptor/field", "org.apache.tomcat.util.modeler.FieldInfo"); digester.addSetProperties("mbeans-descriptors/mbean/notification/descriptor/field"); digester.addSetNext("mbeans-descriptors/mbean/notification/descriptor/field", "addField", "org.apache.tomcat.util.modeler.FieldInfo"); digester.addCallMethod("mbeans-descriptors/mbean/notification/notification-type", "addNotifType", 0); digester.addObjectCreate("mbeans-descriptors/mbean/operation", "org.apache.tomcat.util.modeler.OperationInfo"); digester.addSetProperties("mbeans-descriptors/mbean/operation"); digester.addSetNext("mbeans-descriptors/mbean/operation", "addOperation", "org.apache.tomcat.util.modeler.OperationInfo"); digester.addObjectCreate("mbeans-descriptors/mbean/operation/descriptor/field", "org.apache.tomcat.util.modeler.FieldInfo"); digester.addSetProperties("mbeans-descriptors/mbean/operation/descriptor/field"); digester.addSetNext("mbeans-descriptors/mbean/operation/descriptor/field", "addField", "org.apache.tomcat.util.modeler.FieldInfo"); digester.addObjectCreate("mbeans-descriptors/mbean/operation/parameter", "org.apache.tomcat.util.modeler.ParameterInfo"); digester.addSetProperties("mbeans-descriptors/mbean/operation/parameter"); digester.addSetNext("mbeans-descriptors/mbean/operation/parameter", "addParameter", "org.apache.tomcat.util.modeler.ParameterInfo"); return digester; }
From source file:com.sun.faces.generate.AbstractGenerator.java
/** * <p>Configure and return a <code>Digester</code> instance suitable for * use in the environment specified by our parameter flags.</p> * * @param dtd[] array of absolute pathnames of the DTDs to be registered (if any) * and their corresponding public identifiers * @param design Include rules suitable for design time use in a tool * @param generate Include rules suitable for generating component, * renderer, and tag classes/* ww w .j a va 2s .c o m*/ * @param runtime Include rules suitable for runtime execution * * @exception MalformedURLException if a URL cannot be formed correctly */ protected static Digester digester(String dtd[], boolean design, boolean generate, boolean runtime) throws MalformedURLException { Digester digester = new Digester(); // Configure basic properties digester.setNamespaceAware(false); digester.setUseContextClassLoader(true); digester.setValidating(true); // Configure parsing rules digester.addRuleSet(new FacesConfigRuleSet(design, generate, runtime)); // Configure preregistered entities int i = 0; while (dtd.length > 0) { if (dtd[i] != null && dtd[i + 1] != null) { digester.register(dtd[i], (new File(dtd[i + 1])).toURL().toString()); } i += 2; if (i >= dtd.length) { break; } } return (digester); }
From source file:catalina.startup.ContextConfig.java
/** * Create (if necessary) and return a Digester configured to process a tag * library descriptor, looking for additional listener classes to be * registered.// w w w . j a v a 2s . c o m */ private static Digester createTldDigester() { URL url = null; Digester tldDigester = new Digester(); tldDigester.setValidating(true); url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_11); tldDigester.register(Constants.TldDtdPublicId_11, url.toString()); url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_12); tldDigester.register(Constants.TldDtdPublicId_12, url.toString()); tldDigester.addRuleSet(new TldRuleSet()); return (tldDigester); }
From source file:catalina.startup.ContextConfig.java
/** * Create (if necessary) and return a Digester configured to process the * web application deployment descriptor (web.xml). *//*from www . j a v a 2s .com*/ private static Digester createWebDigester() { URL url = null; Digester webDigester = new Digester(); webDigester.setValidating(true); url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_22); webDigester.register(Constants.WebDtdPublicId_22, url.toString()); url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_23); webDigester.register(Constants.WebDtdPublicId_23, url.toString()); webDigester.addRuleSet(new WebRuleSet()); return (webDigester); }
From source file:net.jakubholy.jeeutils.jsfelcheck.beanfinder.jsf11.Jsf11FacesConfigXmlBeanFinder.java
protected Digester digester(boolean validateXml) { Digester digester = new Digester(); digester.setNamespaceAware(false);//from ww w. ja v a 2s .c o m digester.setUseContextClassLoader(true); digester.setValidating(validateXml); digester.addRuleSet(new FacesConfigRuleSet(false, false, true)); for (int i = 0; i < DTD_INFO.length; i++) { URL url = getClass().getResource(DTD_INFO[i][0]); if (url != null) { digester.register(DTD_INFO[i][1], url.toString()); } else { throw new RuntimeException("NO_DTD_FOUND_ERROR: " + DTD_INFO[i][1] + "," + DTD_INFO[i][0]); } } digester.push(new FacesConfigBean()); return digester; }
From source file:net.jcreate.xkins.XkinsLoader.java
/** * Carga el Skin desde la definicin si la tiene aparte. *//* ww w . j a v a2 s . c om*/ public Skin loadDefinition(Skin skin) throws XkinsException { if (skin.getDefinition() == null) { return null; } log.info(":" + skin.getSkinDefinition()); try { log.info("Loading Definition from file " + skin.getSkinDefinition() + "..."); addDefinitionFilesTimeStamp(getSkinFile(skin.getSkinDefinition())); InputStream in = getSkinStream(skin.getSkinDefinition()); Digester digester = new Digester(); URL url = this.getClass().getResource(this.dtd); if (url != null) { digester.register(this.registration, url.toString()); //digester.setValidating(true); } digester.push(skin); this.skinDigester(digester, ""); try { // Parse the input stream to initialize our database digester.parse(in); in.close(); } catch (SAXException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { log.error("Error Loading skin Definition.", e); } } } XkinsLoadEvent xle = new XkinsLoadEvent(this); xle.setXkins(skin.getXkins()); skin.getXkins().sendEvent(xle); return skin; } catch (Throwable thr) { log.error("Error Loading Definition.", thr); throw new XkinsException(thr.getMessage()); } }
From source file:net.jcreate.xkins.XkinsLoader.java
/** * Carga los skins. Mtodo privado que utilizan los dems. Usa el Digester. * @param in//from ww w. j a v a2s. c o m * @param xk * @return * @throws XkinsException */ private Xkins loadSkins(InputStream in, Xkins xk) throws XkinsException { try { Digester digester = new Digester(); Xkins xkLoading = new Xkins(); URL url = this.getClass().getResource(this.dtd); if (url != null) { digester.register(this.registration, url.toString()); //digester.setValidating(true); } digester.push(xkLoading); digester.addSetProperties("xkins"); //Crea los Skins digester.addFactoryCreate("xkins/skin", new SkinFactory(xkLoading)); digester.addSetProperties("xkins/skin"); digester.addSetProperty("xkins/skin/set-property", "property", "value"); digester.addSetTop("xkins/skin", "setXkins", XKINS_CLASS_NAME); digester.addObjectCreate("xkins/global-processor", PROCESSOR_CLASS_NAME); digester.addSetProperties("xkins/global-processor"); digester.addSetNext("xkins/global-processor", "addProcessor", PROCESSOR_CLASS_NAME); this.skinDigester(digester, "xkins/"); //Agrega el skin digester.addSetNext("xkins/skin", "addSkin", SKIN_CLASS_NAME); try { // Parse the input stream to initialize our database digester.parse(in); in.close(); } catch (SAXException e) { System.out.println(":" + e.getMessage()); System.out.println(":" + e); e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { } } } this.loadSkinsDefinition(xkLoading); //copio los xkins cargados al xk Iterator it = xkLoading.getSkins().keySet().iterator(); while (it.hasNext()) { String skinName = (String) it.next(); Skin sk = (Skin) xkLoading.getSkins().get(skinName); sk.setXkins(xk); xk.addSkin(sk); } XkinsLoadEvent xle = new XkinsLoadEvent(this); xle.setXkins(xk); xk.sendEvent(xle); xk.addProcessors(xkLoading.getProcessors()); return xk; } catch (Throwable thr) { thr.printStackTrace(); throw new XkinsException(thr); } }
From source file:net.jetrix.config.ServerConfig.java
/** * Load the configuration./*ww w. j ava 2 s.com*/ */ public void load(URL serverConfigURL) { this.serverConfigURL = serverConfigURL; try { // parse the server configuration Digester digester = new Digester(); digester.register("-//LFJR//Jetrix TetriNET Server//EN", findResource("tetrinet-server.dtd").toString()); digester.setValidating(true); digester.addRuleSet(new ServerRuleSet()); digester.push(this); Reader reader = new InputStreamReader(serverConfigURL.openStream(), ENCODING); digester.parse(new InputSource(reader)); reader.close(); // parse the channel configuration digester = new Digester(); digester.register("-//LFJR//Jetrix Channels//EN", findResource("tetrinet-channels.dtd").toString()); digester.setValidating(true); digester.addRuleSet(new ChannelsRuleSet()); digester.push(this); channelsConfigURL = new URL(serverConfigURL, channelsFile); reader = new InputStreamReader(channelsConfigURL.openStream(), ENCODING); digester.parse(new InputSource(reader)); reader.close(); } catch (Exception e) { log.log(Level.SEVERE, "Unable to load the configuration", e); } }
From source file:com.sun.faces.config.ConfigureListener.java
/** * <p>Configure and return a <code>Digester</code> instance suitable for * parsing the runtime configuration information we need.</p> * * @param validateXml if true, validation is turned on during parsing. *///from w ww. j a v a2s.co m protected Digester digester(boolean validateXml) { Digester digester = new Digester(); // Configure basic properties digester.setNamespaceAware(false); digester.setUseContextClassLoader(true); digester.setValidating(validateXml); // Configure parsing rules // PENDING - Read from file? digester.addRuleSet(new FacesConfigRuleSet(false, false, true)); // Register known entities for (int i = 0; i < DTD_INFO.length; i++) { URL url = this.getClass().getResource(DTD_INFO[i][0]); if (url != null) { digester.register(DTD_INFO[i][1], url.toString()); } else { throw new FacesException(Util.getExceptionMessageString(Util.NO_DTD_FOUND_ERROR_ID, new Object[] { DTD_INFO[i][1], DTD_INFO[i][0] })); } } // Push an initial FacesConfigBean onto the stack digester.push(new FacesConfigBean()); return (digester); }
From source file:be.ff.gui.web.struts.action.ActionPlugInPlugIn.java
/** * Loads and verifies (using a DTD) the action plug-in configuration file. Afterwards this * method initializes the <code>ActionPlugInChain</code>. * * @param config ApplicationConfig for the sub-application with which this plug in is associated * @exception ServletException if this <code>PlugIn</code> cannot be successfully initialized *//* w ww.j a va2 s .c o m*/ public void init(ActionServlet config, ModuleConfig module) throws ServletException { if (ActionPlugInChain.foiInicializado()) { if (log.isDebugEnabled()) { log.debug("O ActionPlugInPlugIn j foi inicializado anteriormente. Ignorando."); } return; } if (log.isDebugEnabled()) { log.debug("Entrada no mtodo"); } // this value object will hold the values specified in the action plug-in config file ActionPlugInChainDefinition chainDefintion = new ActionPlugInChainDefinition(); // create a digester to scan through the action plug-in config file Digester digester = new Digester(); digester.push(chainDefintion); // try to find a local DTD to validate the configuration file ServletContext context = config.getServletContext(); if (getConfigDTD() == null) { String msg = "[ActionPlugInPlugIn::init] Please specify a valid context relative location of " + "the DTD for the action plug-in configuration file. Do this in the Struts configuration " + "file at the plug-in tag that initializes the Action Plug-in Extension."; log.warn(msg); digester.setValidating(false); // Although set to false the SAX based parser STILL wants to load the publicly // available DTD that is specified in the XML file!! This causes an error on // times when the DTD at the specified location is not available. // Why doesn't this statement turn this of???? } else { URL dtdURL = null; try { dtdURL = context.getResource(getConfigDTD()); if (dtdURL == null) { String msg = "[ActionPlugInPlugIn::init] The action plug-in configuration DTD was not found at the " + "context relative location '" + getConfigDTD() + "'. Please make sure that this DTD is available at " + "a context relative location, because the system identifier that is specified in the " + "configuration file might not be accessible."; log.warn(msg); digester.setValidating(false); // Although set to false the SAX based parser STILL wants to load the publicly // available DTD that is specified in the XML file!! This causes an error on // times when the DTD at the specified location is not available. // Why doesn't this statement turn this of???? } else { digester.register(DOCTYPE_PUBLIC_ID, dtdURL.toString()); digester.setValidating(true); } } catch (MalformedURLException e) { String msg = "[ActionPlugInPlugIn::init] The location of the DTD for the action plug-in configuration file was " + "invalid:'" + getConfigDTD() + "'. Please specify a valid context relative location for the DTD."; log.warn(msg); digester.setValidating(false); // Although set to false the SAX based parser STILL wants to load the publicly // available DTD that is specified in the XML file!! This causes an error on // times when the DTD at the specified location is not available. // Why doesn't this statement turn this of???? } } // add rules digester.addObjectCreate("action-plug-in-config/action-plug-in", ActionPlugInDefinition.class); digester.addSetNext("action-plug-in-config/action-plug-in", "addActionPlugInDefintion", ActionPlugInDefinition.class.getName()); digester.addCallMethod("action-plug-in-config/action-plug-in/class", "setClassName", 0); digester.addCallMethod("action-plug-in-config/action-plug-in/init-params/param", "addInitParam", 2); digester.addCallParam("action-plug-in-config/action-plug-in/init-params/param/name", 0); digester.addCallParam("action-plug-in-config/action-plug-in/init-params/param/value", 1); digester.addCallMethod("action-plug-in-config/action-plug-in/disabled-for/action-path", "addDisabledActionPath", 0); digester.addCallMethod("action-plug-in-config/action-plug-in/enabled-for/action-path", "addEnabledActionPath", 0); // point to the XML file InputStream input = context.getResourceAsStream(getConfigFile()); if (input == null) { String msg = "[ActionPlugInPlugIn::init] The action plug-in configuration file was not found " + "at location '" + getConfigFile() + "'. Please make sure that you have specified " + "the correct value for the 'configFile' property of the action plug-in Struts " + "plug-in that is defined in struts-config.xml. Please note that this path is Web " + "application context relative."; throw new ServletException(msg); } // run the digester try { digester.parse(new BufferedInputStream(input)); } catch (Exception e) { String msg = "[ActionPlugInPlugIn::init] An exception was thrown during the parsing of the " + "action plug-in configuration file (" + getConfigFile() + "). Make sure that " + "the configuration file refers to a DTD and that its content is valid according to " + "that DTD."; throw new ServletException(msg, e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { log.error( "[ActionPlugInPlugIn::init] An IOException was thrown while trying to close the input stream of the action plug-in configuration file.", e); } } } // ask the action plug-in chain to initialize itself ActionPlugInChain.init(chainDefintion, context); }