/** * Return the namespace URI that will be applied to all subsequently * added <code>Rule</code> objects. */ public String getRuleNamespaceURI() { return (getRules().getNamespaceURI()); }
/** * Set the namespace URI that will be applied to all subsequently * added <code>Rule</code> objects. * * @param ruleNamespaceURI Namespace URI that must match on all * subsequently added rules, or <code>null</code> for matching * regardless of the current namespace URI */ public void setRuleNamespaceURI(String ruleNamespaceURI) { getRules().setNamespaceURI(ruleNamespaceURI); }
/** * Return the set of rules that apply to the specified match position. * The selected rules are those that match exactly, or those rules * that specify a suffix match and the tail of the rule matches the * current match position. Exact matches have precedence over * suffix matches, then (among suffix matches) the longest match * is preferred. * * @param match The current match position * * @deprecated Call <code>match()</code> on the <code>Rules</code> * implementation returned by <code>getRules()</code> */ @Deprecated List<Rule> getRules(String match) { return (getRules().match(match)); }
/** * <p>Register a new Rule matching the specified pattern. * This method sets the <code>Digester</code> property on the rule.</p> * * @param pattern Element matching pattern * @param rule Rule to be registered */ public void addRule(String pattern, Rule rule) { rule.setDigester(this); getRules().add(pattern, rule); }
/** * This is only invoked after all child elements have been processed, * so we can remove the custom Rules object that does the * child-element-matching. */ @Override public void body(String bodyText) throws Exception { AnyChildRules newRules = (AnyChildRules) digester.getRules(); digester.setRules(newRules.getOldRules()); }
List<Rule> rules = getRules().match(namespaceURI, match); matches.push(rules); if ((rules != null) && (rules.size() > 0)) {
/** * Process notification of the end of the document being reached. * * @exception SAXException if a parsing error is to be reported */ @Override public void endDocument() throws SAXException { if (saxLog.isDebugEnabled()) { if (getCount() > 1) { saxLog.debug("endDocument(): " + getCount() + " elements left"); } else { saxLog.debug("endDocument()"); } } // Fire "finish" events for all defined rules for (Rule rule : getRules().rules()) { try { rule.finish(); } catch (Exception e) { log.error("Finish event threw exception", e); throw createSAXException(e); } catch (Error e) { log.error("Finish event threw error", e); throw e; } } // Perform final cleanup clear(); }
/** * Creates an instance of the indicated class. The class must implement * the DigesterRulesSource interface. Passes the target digester to * that instance. The DigesterRulesSource instance is supposed to add * rules into the digester. The contents of the current pattern stack * will be automatically prepended to all of the pattern strings added * by the DigesterRulesSource instance. */ private void includeProgrammaticRules(String className) throws ClassNotFoundException, ClassCastException, InstantiationException, IllegalAccessException { Class<?> cls = Class.forName(className); DigesterRulesSource rulesSource = (DigesterRulesSource) cls.newInstance(); // wrap the digester's Rules object, to prepend pattern Rules digesterRules = targetDigester.getRules(); Rules prefixWrapper = new RulesPrefixAdapter(patternStack.toString(), digesterRules); targetDigester.setRules(prefixWrapper); try { rulesSource.getRules(targetDigester); } finally { // Put the unwrapped rules back targetDigester.setRules(digesterRules); } } }
/** * Process the body text of this element. * * @param text The body text of this element */ @Override public void body(String namespace, String name, String text) throws Exception { // While this class itself has no work to do in the body method, // we do need to fire the body methods of all dynamically-added // rules matching the same path as this rule. During begin, we had // to manually execute the dynamic rules' begin methods because they // didn't exist in the digester's Rules object when the match begin. // So in order to ensure consistent ordering of rule execution, the // PluginRules class deliberately avoids returning any such rules // in later calls to the match method, instead relying on this // object to execute them at the appropriate time. // // Note that this applies only to rules matching exactly the path // which is also matched by this PluginCreateRule. String path = digester.getMatch(); PluginRules newRules = (PluginRules) digester.getRules(); List<Rule> rules = newRules.getDecoratedRules().match(namespace, path); fireBodyMethods(rules, namespace, name, text); }
newDecl.setProperties(props); PluginRules rc = (PluginRules) digester.getRules(); PluginManager pm = rc.getPluginManager();
/** * Process the beginning of this element. * * @param namespace is the namespace this attribute is in, or null * @param name is the name of the current xml element * @param attributes is the attribute list of this element */ @Override public void begin(String namespace, String name, Attributes attributes) throws Exception { Rules oldRules = digester.getRules(); AnyChildRule anyChildRule = new AnyChildRule(); anyChildRule.setDigester(digester); AnyChildRules newRules = new AnyChildRules(anyChildRule); newRules.init(digester.getMatch()+"/", oldRules); digester.setRules(newRules); }
PluginRules rules = (PluginRules) digester.getRules(); PluginManager pm = rules.getPluginManager();
/** * Invoked by the digester when the closing tag matching this Rule's * pattern is encountered. * </p> * * @param namespace Description of the Parameter * @param name Description of the Parameter * @exception Exception Description of the Exception * * @see #begin */ @Override public void end(String namespace, String name) throws Exception { // see body method for more info String path = digester.getMatch(); PluginRules newRules = (PluginRules) digester.getRules(); List<Rule> rules = newRules.getDecoratedRules().match(namespace, path); fireEndMethods(rules, namespace, name); // pop the stack of PluginRules instances, which // discards all custom rules associated with this plugin digester.setRules(newRules.getParent()); // and get rid of the instance of the plugin class from the // digester object stack. digester.pop(); }
PluginRules oldRules = (PluginRules) digester.getRules(); PluginManager pluginManager = oldRules.getPluginManager(); Declaration currDeclaration = null;
/** * Return the namespace URI that will be applied to all subsequently * added <code>Rule</code> objects. */ public String getRuleNamespaceURI() { return (getRules().getNamespaceURI()); }
/** * Set the namespace URI that will be applied to all subsequently * added <code>Rule</code> objects. * * @param ruleNamespaceURI Namespace URI that must match on all * subsequently added rules, or <code>null</code> for matching * regardless of the current namespace URI */ public void setRuleNamespaceURI(String ruleNamespaceURI) { getRules().setNamespaceURI(ruleNamespaceURI); }
/** * @return Rules loaded from the appropriate XML file */ protected Rules loadRules(String digestorRulesFileName) { // locate Digester rules ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL rulesUrl = classLoader.getResource(digestorRulesFileName); if (rulesUrl == null) { throw new RuntimeException("unable to locate digester rules file " + digestorRulesFileName); } // create and init digester Digester digester = DigesterLoader.createDigester(rulesUrl); return digester.getRules(); } }
/** * This is only invoked after all child elements have been processed, * so we can remove the custom Rules object that does the * child-element-matching. */ public void body(String bodyText) throws Exception { AnyChildRules newRules = (AnyChildRules) digester.getRules(); digester.setRules(newRules.getOldRules()); }
/** * <p>Register a new Rule matching the specified pattern. * This method sets the <code>Digester</code> property on the rule.</p> * * @param pattern Element matching pattern * @param rule Rule to be registered */ public void addRule(String pattern, Rule rule) { rule.setDigester(this); getRules().add(pattern, rule); }
/** * 结束处理, 弹出最近的context * * @throws Exception 如果失败 */ @Override public void end(String namespace, String name) throws Exception { ContextSensitiveRules rules = (ContextSensitiveRules) digester.getRules(); String context = rules.popContext(); if (context != null) { if (digester.getLogger().isDebugEnabled()) { digester.getLogger().debug("[SetContextRule]{" + digester.getMatch() + "} Pop " + context); } } }