List of usage examples for org.apache.commons.digester Digester addCallMethod
public void addCallMethod(String pattern, String methodName, int paramCount)
From source file:org.apache.tiles.xmlDefinition.XmlParser.java
/** * Init digester for components syntax./*from www .j a v a 2 s. co m*/ * This is an old set of rules, left for backward compatibility. * @param digester Digester instance to use. */ private void initDigesterForComponentsDefinitionsSyntax(Digester digester) { // Common constants String PACKAGE_NAME = "org.apache.tiles.xmlDefinition"; String DEFINITION_TAG = "component-definitions/definition"; String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition"; String PUT_TAG = DEFINITION_TAG + "/put"; String putAttributeHandlerClass = PACKAGE_NAME + ".XmlAttribute"; String LIST_TAG = DEFINITION_TAG + "/putList"; String listHandlerClass = PACKAGE_NAME + ".XmlListAttribute"; String ADD_LIST_ELE_TAG = LIST_TAG + "/add"; // syntax rules digester.addObjectCreate(DEFINITION_TAG, definitionHandlerClass); digester.addSetProperties(DEFINITION_TAG); digester.addSetNext(DEFINITION_TAG, "putDefinition", definitionHandlerClass); // put / putAttribute rules digester.addObjectCreate(PUT_TAG, putAttributeHandlerClass); digester.addSetNext(PUT_TAG, "addAttribute", putAttributeHandlerClass); digester.addSetProperties(PUT_TAG); digester.addCallMethod(PUT_TAG, "setBody", 0); // list rules digester.addObjectCreate(LIST_TAG, listHandlerClass); digester.addSetProperties(LIST_TAG); digester.addSetNext(LIST_TAG, "addAttribute", putAttributeHandlerClass); // list elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. digester.addObjectCreate(ADD_LIST_ELE_TAG, putAttributeHandlerClass); digester.addSetNext(ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); digester.addSetProperties(ADD_LIST_ELE_TAG); digester.addCallMethod(ADD_LIST_ELE_TAG, "setBody", 0); }
From source file:org.apache.tiles.xmlDefinition.XmlParser.java
/** * Init digester for Tiles syntax.//from ww w . jav a2 s . co m * Same as components, but with first element = tiles-definitions * @param digester Digester instance to use. */ private void initDigesterForTilesDefinitionsSyntax(Digester digester) { // Common constants String PACKAGE_NAME = "org.apache.tiles.xmlDefinition"; String DEFINITION_TAG = "tiles-definitions/definition"; String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition"; String PUT_TAG = DEFINITION_TAG + "/put"; String putAttributeHandlerClass = PACKAGE_NAME + ".XmlAttribute"; //String LIST_TAG = DEFINITION_TAG + "/putList"; // List tag value String LIST_TAG = "putList"; String DEF_LIST_TAG = DEFINITION_TAG + "/" + LIST_TAG; String listHandlerClass = PACKAGE_NAME + ".XmlListAttribute"; // Tag value for adding an element in a list String ADD_LIST_ELE_TAG = "*/" + LIST_TAG + "/add"; // syntax rules digester.addObjectCreate(DEFINITION_TAG, definitionHandlerClass); digester.addSetProperties(DEFINITION_TAG); digester.addSetNext(DEFINITION_TAG, "putDefinition", definitionHandlerClass); // put / putAttribute rules // Rules for a same pattern are called in order, but rule.end() are called // in reverse order. // SetNext and CallMethod use rule.end() method. So, placing SetNext in // first position ensure it will be called last (sic). digester.addObjectCreate(PUT_TAG, putAttributeHandlerClass); digester.addSetNext(PUT_TAG, "addAttribute", putAttributeHandlerClass); digester.addSetProperties(PUT_TAG); digester.addCallMethod(PUT_TAG, "setBody", 0); // Definition level list rules // This is rules for lists nested in a definition digester.addObjectCreate(DEF_LIST_TAG, listHandlerClass); digester.addSetProperties(DEF_LIST_TAG); digester.addSetNext(DEF_LIST_TAG, "addAttribute", putAttributeHandlerClass); // list elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. digester.addObjectCreate(ADD_LIST_ELE_TAG, putAttributeHandlerClass); digester.addSetNext(ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); digester.addSetProperties(ADD_LIST_ELE_TAG); digester.addCallMethod(ADD_LIST_ELE_TAG, "setBody", 0); // nested list elements rules // Create a list handler, and add it to parent list String NESTED_LIST = "*/" + LIST_TAG + "/" + LIST_TAG; digester.addObjectCreate(NESTED_LIST, listHandlerClass); digester.addSetProperties(NESTED_LIST); digester.addSetNext(NESTED_LIST, "add", putAttributeHandlerClass); // item elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. //String ADD_WILDCARD = LIST_TAG + "/addItem"; // non String ADD_WILDCARD = LIST_TAG + "/addx*"; String ADD_WILDCARD = "*/item"; String menuItemDefaultClass = "org.apache.tiles.beans.SimpleMenuItem"; digester.addObjectCreate(ADD_WILDCARD, menuItemDefaultClass, "classtype"); digester.addSetNext(ADD_WILDCARD, "add", "java.lang.Object"); digester.addSetProperties(ADD_WILDCARD); // bean elements rules String BEAN_TAG = "*/bean"; String beanDefaultClass = "org.apache.tiles.beans.SimpleMenuItem"; digester.addObjectCreate(BEAN_TAG, beanDefaultClass, "classtype"); digester.addSetNext(BEAN_TAG, "add", "java.lang.Object"); digester.addSetProperties(BEAN_TAG); // Set properties to surrounding element digester.addSetProperty(BEAN_TAG + "/set-property", "property", "value"); }
From source file:org.architecturerules.configuration.xml.DigesterConfigurationFactory.java
void processProperties(final String xml) throws IOException, SAXException, ParserConfigurationException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.properties, Properties.class); digester.addCallMethod(XmlConfiguration.property, "put", 2); digester.addCallParam(XmlConfiguration.property, 0, "key"); digester.addCallParam(XmlConfiguration.property, 1, "value"); final StringReader reader = new StringReader(xml.trim()); final Object o; try {//from w w w . ja va2 s . c o m o = digester.parse(reader); } catch (SAXException e) { if (e.getException().toString().equals("java.lang.NullPointerException")) { throw new InvalidConfigurationException( "Invalid XML configuration for <properties>. <property> must only contain both a key and a value attribute.", e); } // at this time, I don't even know how to get to this path, but I'm sure some user will figure it out : P throw new InvalidConfigurationException( "Unable to parse XML configuration for <properties>: " + e.getMessage(), e); } if (o == null) { return; } final Properties properties = (Properties) o; addProperties(properties); }
From source file:org.architecturerules.configuration.xml.DigesterConfigurationFactory.java
private Set<String> getListenerClassNames(final String xml, final String path) throws IOException, SAXException, ParserConfigurationException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.listeners, ArrayList.class); digester.addObjectCreate(path, StringBuffer.class); // TODO rather than StringBuffer can digester.addCallMethod(path, "append", 0); // TODO this be a String? digester.addSetRoot(path, "add"); final Set<String> classNames = new HashSet<String>(); final StringReader includeReader = new StringReader(xml); Object o = digester.parse(includeReader); if (o == null) { // return empty Set return classNames; }// w w w . j a v a 2 s .co m Collection<StringBuffer> classNamesAsStringBuffers = (Collection<StringBuffer>) o; /** * When the configuration contains no listener settings, return the empty Set */ if (classNamesAsStringBuffers == null) { return classNames; } for (StringBuffer classNamesAsStringBuffer : classNamesAsStringBuffers) { classNames.add(classNamesAsStringBuffer.toString()); } return classNames; }
From source file:org.architecturerules.configuration.xml.DigesterConfigurationFactory.java
/** * <p>Read xml configuration for source directories into SourceDirectory instances.</p> * <p/>//from w ww .j a va2 s . c o m * <p>package scope so that it could be individually tested</p> * * @param xml String xml to parse * @throws IOException when an input/output error occurs * @throws SAXException when given xml can not be parsed * @throws ParserConfigurationException */ void processSources(final String xml) throws IOException, SAXException, ParserConfigurationException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.sources, ArrayList.class); digester.addObjectCreate(XmlConfiguration.source, SourceDirectory.class); digester.addCallMethod(XmlConfiguration.source, "setPath", 0); digester.addSetProperties(XmlConfiguration.source, "not-found", "notFound"); digester.addSetNext(XmlConfiguration.source, "add"); final StringReader reader = new StringReader(xml); Object o = digester.parse(reader); if ((o != null) && o instanceof List) { final List<SourceDirectory> parsedSources = (ArrayList<SourceDirectory>) o; for (final SourceDirectory sourceDirectory : parsedSources) { getSources().add(sourceDirectory); } } }
From source file:org.architecturerules.configuration.xml.DigesterConfigurationFactory.java
/** * <p>Process XML configuration to read rules elements into <code>Rules</code></p> * <p/>//from w w w.ja v a 2 s . c o m * <p>package scope so that it could be individually tested</p> * * @param xml String xml to parse * @throws IOException when an input/output error occurs * @throws SAXException when given xml can not be parsed * @throws ParserConfigurationException */ void processRules(final String xml) throws IOException, SAXException, ParserConfigurationException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.rules, ArrayList.class); digester.addObjectCreate(XmlConfiguration.rule, Rule.class); digester.addSetProperties(XmlConfiguration.rule, "id", "idString"); digester.addCallMethod(XmlConfiguration.ruleComment, "setComment", 0); digester.addCallMethod(XmlConfiguration.rulePackage, "addPackage", 0); digester.addCallMethod(XmlConfiguration.ruleViolation, "addViolation", 0); digester.addSetNext(XmlConfiguration.rule, "add"); final StringReader reader = new StringReader(xml); Object o = digester.parse(reader); if (o != null) { final List<Rule> parsedRules = (ArrayList<Rule>) o; getRules().addAll(parsedRules); } }
From source file:org.aspectj.testing.xml.AjcSpecXmlReader.java
/** set up the mapping between the xml and Java. */ private void setupDigester(Digester digester) { // XXX supply sax parser to ignore white space? digester.setValidating(true);// w ww .j a va 2 s. c o m // try { // // this is the correct approach, but the commons parser // // fails to accept a second, overriding registration - see // // http://lists.xml.org/archives/xml-dev/200111/msg00959.html // digester.getXMLReader().setEntityResolver(new SuiteResolver(suiteFile)); // } catch (SAXException e) { // System.err.println("unable to set entity resolver"); // e.printStackTrace(System.err); // } // element names come from the element components final String suiteX = AjcTest.Suite.Spec.XMLNAME; final String ajctestX = suiteX + "/" + AjcTest.Spec.XMLNAME; final String compileX = ajctestX + "/" + CompilerRun.Spec.XMLNAME; final String inccompileX = ajctestX + "/" + IncCompilerRun.Spec.XMLNAME; final String runX = ajctestX + "/" + JavaRun.Spec.XMLNAME; final String dirchangesX = "*/" + DirChanges.Spec.XMLNAME; final String messageX = "*/" + SoftMessage.XMLNAME; final String messageSrcLocX = messageX + "/" + SoftSourceLocation.XMLNAME; // ---- each sub-element needs to be created // handle messages the same at any level digester.addObjectCreate(suiteX, AjcTest.Suite.Spec.class.getName()); digester.addObjectCreate(ajctestX, AjcTest.Spec.class.getName()); digester.addObjectCreate(compileX, CompilerRun.Spec.class.getName()); //digester.addObjectCreate(compileX + "/file", AbstractRunSpec.WrapFile.class.getName()); digester.addObjectCreate(inccompileX, IncCompilerRun.Spec.class.getName()); digester.addObjectCreate(runX, JavaRun.Spec.class.getName()); digester.addObjectCreate(messageX, SoftMessage.class.getName()); digester.addObjectCreate(messageSrcLocX, SoftSourceLocation.class.getName()); digester.addObjectCreate(dirchangesX, DirChanges.Spec.class.getName()); // ---- set bean properties for sub-elements created automatically // -- some remapped - warnings // - if property exists, map will not be used digester.addSetProperties(suiteX); // ok to have suite messages and global suite options, etc. digester.addSetProperties(ajctestX, new String[] { "title", "dir", "pr" }, new String[] { "description", "testDirOffset", "bugId" }); digester.addSetProperties(compileX, new String[] { "files", "argfiles" }, new String[] { "paths", "argfiles" }); digester.addSetProperties(compileX + "/file"); digester.addSetProperties(inccompileX, "classes", "paths"); digester.addSetProperties(runX, new String[] { "class", "vm", "skipTester", "fork", "vmargs", "aspectpath" }, new String[] { "className", "javaVersion", "skipTester", "fork", "vmArgs", "aspectpath" }); digester.addSetProperties(dirchangesX); digester.addSetProperties(messageX); digester.addSetProperties(messageSrcLocX, "line", "lineAsString"); digester.addSetProperties(messageX, "kind", "kindAsString"); digester.addSetProperties(messageX, "line", "lineAsString"); //digester.addSetProperties(messageX, "details", "details"); // only file subelement of compile uses text as path... XXX vestigial digester.addCallMethod(compileX + "/file", "setFile", 0); // ---- when subelements are created, add to parent // add ajctest to suite, runs to ajctest, files to compile, messages to any parent... // the method name (e.g., "addSuite") is in the parent (SuiteHolder) // the class (e.g., AjcTest.Suite.Spec) refers to the type of the object created digester.addSetNext(suiteX, "addSuite", AjcTest.Suite.Spec.class.getName()); digester.addSetNext(ajctestX, "addChild", AjcTest.Spec.class.getName()); digester.addSetNext(compileX, "addChild", CompilerRun.Spec.class.getName()); digester.addSetNext(inccompileX, "addChild", IncCompilerRun.Spec.class.getName()); digester.addSetNext(runX, "addChild", JavaRun.Spec.class.getName()); //digester.addSetNext(compileX + "/file", "addWrapFile", AbstractRunSpec.WrapFile.class.getName()); digester.addSetNext(messageX, "addMessage", IMessage.class.getName()); // setSourceLocation is for the inline variant // addSourceLocation is for the extra digester.addSetNext(messageSrcLocX, "addSourceLocation", ISourceLocation.class.getName()); digester.addSetNext(dirchangesX, "addDirChanges", DirChanges.Spec.class.getName()); // can set parent, but prefer to have "knows-about" flow down only... }
From source file:org.codehaus.enunciate.config.DeploymentModuleOne.java
@Override public RuleSet getConfigurationRules() { return new RuleSetBase() { public void addRuleInstances(Digester digester) { digester.addCallMethod("enunciate/modules/module1/element", "putElement", 2); digester.addCallParam("enunciate/modules/module1/element", 0, "name"); digester.addCallParam("enunciate/modules/module1/element", 1); }// w w w . j a va 2s. c om }; }
From source file:org.codehaus.enunciate.config.DeploymentModuleTwo.java
@Override public RuleSet getConfigurationRules() { return new RuleSetBase() { public void addRuleInstances(Digester digester) { digester.addCallMethod("enunciate/modules/module2/element", "putElement", 2); digester.addCallParam("enunciate/modules/module2/element", 0, "name"); digester.addCallParam("enunciate/modules/module2/element", 1); }/*from ww w . j a v a2 s.c om*/ }; }
From source file:org.codehaus.enunciate.config.EnunciateConfiguration.java
/** * Loads the configuration specified by the given stream. * * @param in The stream./*from w w w . j a v a2 s .c o m*/ */ public void load(Reader in) throws IOException, SAXException { Digester digester = createDigester(); digester.setErrorHandler(this); digester.setValidating(false); digester.push(this); //set any root-level attributes digester.addSetProperties("enunciate"); //allow a validator to be configured. digester.addObjectCreate("enunciate/validator", "class", DefaultValidator.class); digester.addSetNext("enunciate/validator", "setValidator"); //set up the include/excludes digester.addSetProperties("enunciate/api-classes"); digester.addCallMethod("enunciate/api-classes/include", "addApiIncludePattern", 1); digester.addCallParam("enunciate/api-classes/include", 0, "pattern"); digester.addCallMethod("enunciate/api-classes/exclude", "addApiExcludePattern", 1); digester.addCallParam("enunciate/api-classes/exclude", 0, "pattern"); //set up the ability to disable certain rules digester.addCallMethod("enunciate/disable-rule", "addDisabledRule", 1); digester.addCallParam("enunciate/disable-rule", 0, "id"); //set up the ability to include/exclude facets digester.addCallMethod("enunciate/facets/include", "addFacetInclude", 1); digester.addCallParam("enunciate/facets/include", 0, "name"); digester.addCallMethod("enunciate/facets/exclude", "addFacetExclude", 1); digester.addCallParam("enunciate/facets/exclude", 0, "name"); //allow for classes and packages to be imported for JAXB. digester.addObjectCreate("enunciate/api-import", APIImport.class); digester.addSetProperties("enunciate/api-import", new String[] { "classname", "class", "pattern", "seekSource" }, new String[] { "pattern", "pattern", "pattern", "seekSource" }); digester.addSetNext("enunciate/api-import", "addAPIImport"); //allow for the deployment configuration to be specified. digester.addSetProperties("enunciate/deployment", new String[] { "protocol", "host", "context" }, new String[] { "deploymentProtocol", "deploymentHost", "deploymentContext" }); //allow for namespace prefixes to be specified in the config file. digester.addCallMethod("enunciate/namespaces/namespace", "putNamespace", 2); digester.addCallParam("enunciate/namespaces/namespace", 0, "uri"); digester.addCallParam("enunciate/namespaces/namespace", 1, "id"); //allow for the default soap subcontext to be set. digester.addSetProperties("enunciate/services/rest"); //allow for namespace prefixes to be specified in the config file. digester.addCallMethod("enunciate/services/rest/content-types/content-type", "putContentType", 2); digester.addCallParam("enunciate/services/rest/content-types/content-type", 0, "type"); digester.addCallParam("enunciate/services/rest/content-types/content-type", 1, "id"); //allow for custom resource parameter annotations. digester.addCallMethod("enunciate/services/rest/custom-resource-parameter-annotation", "addCustomResourceParameterAnnotation", 1); digester.addCallParam("enunciate/services/rest/custom-resource-parameter-annotation", 0, "qualifiedName"); //allow for the default soap subcontext to be set. digester.addSetProperties("enunciate/services/soap", "defaultSubcontext", "defaultSoapSubcontext"); //allow for custom location of soap endpoints digester.addCallMethod("enunciate/services/soap/service", "addSoapEndpointLocation", 2); digester.addCallParam("enunciate/services/soap/service", 0, "name"); digester.addCallParam("enunciate/services/soap/service", 1, "relativePath"); digester.addObjectCreate("enunciate/webapp", WebAppConfig.class); digester.addSetProperties("enunciate/webapp"); digester.addSetNext("enunciate/webapp", "setWebAppConfig"); digester.addObjectCreate("enunciate/webapp/resource-env-ref", WebAppResource.class); digester.addSetProperties("enunciate/webapp/resource-env-ref"); digester.addSetNext("enunciate/webapp/resource-env-ref", "addResourceEnvRef"); digester.addObjectCreate("enunciate/webapp/resource-ref", WebAppResource.class); digester.addSetProperties("enunciate/webapp/resource-ref"); digester.addSetNext("enunciate/webapp/resource-ref", "addResourceRef"); digester.addObjectCreate("enunciate/webapp/env", WebAppResource.class); digester.addSetProperties("enunciate/webapp/env"); digester.addSetNext("enunciate/webapp/env", "addEnvEntry"); //allow jboss options to be added. digester.addCallMethod("enunciate/webapp/attribute", "addWebXmlAttribute", 2); digester.addCallParam("enunciate/webapp/attribute", 0, "name"); digester.addCallParam("enunciate/webapp/attribute", 1, "value"); digester.addObjectCreate("enunciate/webapp/excludeJar", IncludeExcludeLibs.class); digester.addSetProperties("enunciate/webapp/excludeJar"); digester.addSetNext("enunciate/webapp/excludeJar", "addExcludeLibs"); digester.addObjectCreate("enunciate/webapp/excludeLibs", IncludeExcludeLibs.class); digester.addSetProperties("enunciate/webapp/excludeLibs"); digester.addSetNext("enunciate/webapp/excludeLibs", "addExcludeLibs"); digester.addObjectCreate("enunciate/webapp/includeLibs", IncludeExcludeLibs.class); digester.addSetProperties("enunciate/webapp/includeLibs"); digester.addSetNext("enunciate/webapp/includeLibs", "addIncludeLibs"); digester.addCallMethod("enunciate/webapp/manifest/attribute", "addManifestAttribute", 3); digester.addCallParam("enunciate/webapp/manifest/attribute", 0, "section"); digester.addCallParam("enunciate/webapp/manifest/attribute", 1, "name"); digester.addCallParam("enunciate/webapp/manifest/attribute", 2, "value"); digester.addObjectCreate("enunciate/webapp/resources", CopyResources.class); digester.addSetProperties("enunciate/webapp/resources"); digester.addSetNext("enunciate/webapp/resources", "addCopyResources"); digester.addObjectCreate("enunciate/webapp/globalServletFilter", FilterComponent.class); digester.addSetProperties("enunciate/webapp/globalServletFilter"); digester.addSetNext("enunciate/webapp/globalServletFilter", "addGlobalServletFilter"); digester.addCallMethod("enunciate/webapp/globalServletFilter/init-param", "addInitParam", 2); digester.addCallParam("enunciate/webapp/globalServletFilter/init-param", 0, "name"); digester.addCallParam("enunciate/webapp/globalServletFilter/init-param", 1, "value"); //set up the module configuration. for (DeploymentModule module : getAllModules()) { String pattern = String.format("enunciate/modules/%s", module.getName()); digester.addRule(pattern, new PushModuleRule(module)); digester.addSetProperties(pattern); if (module.getAliases() != null) { for (String alias : module.getAliases()) { pattern = String.format("enunciate/modules/%s", alias); digester.addRule(pattern, new PushModuleRule(module)); digester.addSetProperties(pattern); } } RuleSet configRules = module.getConfigurationRules(); if (configRules != null) { digester.addRuleSet(configRules); } } digester.parse(in); }