/** * Set the Digester instance with which this Rules instance is associated. * * @param digester The newly associated Digester instance */ public void setDigester(Digester digester) { this.digester = digester; for (Rule rule : rules) { rule.setDigester(digester); } }
/** * This method is called when the beginning of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #begin(Attributes) begin} without the * <code>namespace</code> and <code>name</code> parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list of this element * @since Digester 1.4 */ public void begin(String namespace, String name, Attributes attributes) throws Exception { begin(attributes); }
/** * Registers a new Rule instance matching the specified pattern. * This implementation sets the <code>Digester</code> and the * <code>namespaceURI</code> on the <code>Rule</code> before calling {@link #registerRule}. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { // set up rule if (this.digester != null) { rule.setDigester(this.digester); } if (this.namespaceURI != null) { rule.setNamespaceURI(this.namespaceURI); } registerRule(pattern, rule); }
/** * This method is called when the end of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #end end} without the * <code>namespace</code> and <code>name</code> parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @since Digester 1.4 */ public void end(String namespace, String name) throws Exception { end(); }
/** * This method is called when the body of a matching XML element is * encountered. If the element has no body, this method is * called with an empty string as the body text. * <p> * The default implementation delegates to the deprecated method * {@link #body(String) body} without the <code>namespace</code> and * <code>name</code> parameters, to retain backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param text The text of the body of this element * @since Digester 1.4 */ public void body(String namespace, String name, String text) throws Exception { body(text); }
/** * Return a List of Rule instances for the specified pattern that also * match the specified namespace URI (if any). If there are no such * rules, return <code>null</code>. * * @param namespaceURI Namespace URI to match, or <code>null</code> to * select matching rules regardless of namespace URI * @param pattern Pattern to be matched */ protected List<Rule> lookup(String namespaceURI, String pattern) { // Optimize when no namespace URI is specified List<Rule> list = this.cache.get(pattern); if (list == null) { return (null); } if ((namespaceURI == null) || (namespaceURI.length() == 0)) { return (list); } // Select only Rules that match on the specified namespace URI ArrayList<Rule> results = new ArrayList<Rule>(); for (Rule item : list) { if ((namespaceURI.equals(item.getNamespaceURI())) || (item.getNamespaceURI() == null)) { results.add(item); } } return (results); }
/** * 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(); }
/** * {@inheritDoc} */ public void addRuleInstances(Digester digester) { String pattern; Rule rule; for (Entry<String, List<AnnotationRuleProvider<Annotation, AnnotatedElement, Rule>>> entry : this.rules.entrySet()) { pattern = entry.getKey(); for (AnnotationRuleProvider<Annotation, AnnotatedElement, Rule> provider : entry.getValue()) { rule = provider.get(); if (this.namespaceURI != null) { rule.setNamespaceURI(this.namespaceURI); } digester.addRule(pattern, rule); } } }
/** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { // to help users who accidently add '/' to the end of their patterns int patternLength = pattern.length(); if (patternLength>1 && pattern.endsWith("/")) { pattern = pattern.substring(0, patternLength-1); } List<Rule> list = cache.get(pattern); if (list == null) { list = new ArrayList<Rule>(); cache.put(pattern, list); } list.add(rule); rules.add(rule); if (this.digester != null) { rule.setDigester(this.digester); } if (this.namespaceURI != null) { rule.setNamespaceURI(this.namespaceURI); } }
log.debug(" Fire end() for " + rule); rule.end(namespaceURI, name); } catch (Exception e) { throw digester.createSAXException(e);
/** * Duplicate the processing that the Digester does when firing the * body methods of rules. It would be really nice if the Digester * class provided a way for this functionality to just be invoked * directly. */ private void fireBodyMethods(List<Rule> rules, String namespaceURI, String name, String text) throws Exception { if ((rules != null) && (rules.size() > 0)) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < rules.size(); i++) { try { Rule rule = rules.get(i); if (debug) { log.debug(" Fire body() for " + rule); } rule.body(namespaceURI, name, text); } catch (Exception e) { throw digester.createSAXException(e); } catch (Error e) { throw e; } } } }
while (it.hasNext()) { Rule rule = it.next(); String ns_uri = rule.getNamespaceURI(); if (ns_uri != null && !ns_uri.equals(namespace)) { it.remove();
/** * 清除环境. * * @throws Exception 如果失败 */ @Override public void finish() throws Exception { rule.finish(); }
/** * 设置名字空间. * * @param namespaceURI 名字空间 */ @Override public void setNamespaceURI(String namespaceURI) { rule.setNamespaceURI(namespaceURI); }
/** * Constructor sets the associated Digester. * * @param digester The digester with which this rule is associated * @deprecated The digester instance is now set in the {@link Digester#addRule} method. Use {@link #Rule()} instead. */ @Deprecated public Rule(Digester digester) { super(); setDigester(digester); }
/** Adds a rule to be fired when wrapped implementation returns no matches */ public void addDefault(Rule rule) { // set up rule if (wrappedRules.getDigester() != null) { rule.setDigester(wrappedRules.getDigester()); } if (wrappedRules.getNamespaceURI() != null) { rule.setNamespaceURI(wrappedRules.getNamespaceURI()); } defaultRules.add(rule); allRules.add(rule); }
/** * Duplicate the processing that the Digester does when firing the * begin methods of rules. It would be really nice if the Digester * class provided a way for this functionality to just be invoked * directly. */ public void fireBeginMethods(List<Rule> rules, String namespace, String name, org.xml.sax.Attributes list) throws java.lang.Exception { if ((rules != null) && (rules.size() > 0)) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < rules.size(); i++) { try { Rule rule = rules.get(i); if (debug) { log.debug(" Fire begin() for " + rule); } rule.begin(namespace, name, list); } catch (Exception e) { throw digester.createSAXException(e); } catch (Error e) { throw e; } } } }
/** * 匹配结束. * * @param namespace 名字空间 * @param name XML元素local名 * @throws Exception 如果失败 */ @Override public void end(String namespace, String name) throws Exception { rule.end(namespace, name); }