View Javadoc
1 /* 2 * 3 * ==================================================================== 4 * 5 * The Apache Software License, Version 1.1 6 * 7 * Copyright (c) 1999 The Apache Software Foundation. All rights 8 * reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * 22 * 3. The end-user documentation included with the redistribution, if 23 * any, must include the following acknowlegement: 24 * "This product includes software developed by the 25 * Apache Software Foundation (http://www.apache.org/)." 26 * Alternately, this acknowlegement may appear in the software itself, 27 * if and wherever such third-party acknowlegements normally appear. 28 * 29 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 30 * Foundation" must not be used to endorse or promote products derived 31 * from this software without prior written permission. For written 32 * permission, please contact apache@apache.org. 33 * 34 * 5. Products derived from this software may not be called "Apache" 35 * nor may "Apache" appear in their names without prior written 36 * permission of the Apache Group. 37 * 38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 49 * SUCH DAMAGE. 50 * ==================================================================== 51 * 52 * This software consists of voluntary contributions made by many 53 * individuals on behalf of the Apache Software Foundation. For more 54 * information on the Apache Software Foundation, please see 55 * <http://www.apache.org/>;. 56 * 57 */ 58 59 package org.apache.commons.jelly.tags.jsl; 60 61 import org.apache.commons.jelly.JellyContext; 62 import org.apache.commons.jelly.JellyException; 63 import org.apache.commons.jelly.TagSupport; 64 import org.apache.commons.jelly.XMLOutput; 65 66 import org.apache.commons.logging.Log; 67 import org.apache.commons.logging.LogFactory; 68 69 import org.dom4j.Node; 70 import org.dom4j.rule.Action; 71 import org.dom4j.rule.Pattern; 72 import org.dom4j.rule.Rule; 73 74 /*** 75 * This tag represents a declarative matching rule, similar to the template tag in XSLT. 76 * 77 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 78 * @version $Revision: 1.8 $ 79 */ 80 public class TemplateTag extends TagSupport { 81 82 /*** The Log to which logging calls will be made. */ 83 private Log log = LogFactory.getLog(TemplateTag.class); 84 85 86 /*** Holds value of property name. */ 87 private String name; 88 89 /*** Holds value of property mode. */ 90 private String mode; 91 92 /*** Holds value of property priority. */ 93 private double priority; 94 95 /*** The pattern to match */ 96 private Pattern match; 97 98 /*** The source XPath context for any child tags */ 99 private Object xpathSource; 100 101 102 public TemplateTag() { 103 } 104 105 // Tag interface 106 //------------------------------------------------------------------------- 107 public void doTag(XMLOutput output) throws Exception { 108 StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class ); 109 if (tag == null) { 110 throw new JellyException( "This <template> tag must be used inside a <stylesheet> tag" ); 111 } 112 113 if ( log.isDebugEnabled() ) { 114 log.debug( "adding template rule for match: " + match ); 115 } 116 117 Rule rule = createRule(tag, output); 118 if ( rule != null && tag != null) { 119 rule.setMode( mode ); 120 tag.addTemplate( rule ); 121 } 122 } 123 124 // XPathSource interface 125 //------------------------------------------------------------------------- 126 127 /*** 128 * @return the current XPath iteration value 129 * so that any other XPath aware child tags to use 130 */ 131 public Object getXPathSource() { 132 return xpathSource; 133 } 134 135 136 // Properties 137 //------------------------------------------------------------------------- 138 139 public void setMatch(Pattern match) { 140 this.match = match; 141 } 142 143 /*** Getter for property priority. 144 * @return Value of property priority. 145 */ 146 public double getPriority() { 147 return priority; 148 } 149 150 /*** Sets the priority. 151 * @param priority New value of property priority. 152 */ 153 public void setPriority(double priority) { 154 this.priority = priority; 155 } 156 157 /*** Getter for property name. 158 * @return Value of property name. 159 */ 160 public String getName() { 161 return name; 162 } 163 164 /*** Sets the name. 165 * @param name New value of property name. 166 */ 167 public void setName(String name) { 168 this.name = name; 169 } 170 171 172 /*** Sets the mode. 173 * @param mode New value of property mode. 174 */ 175 public void setMode(String mode) { 176 this.mode = mode; 177 } 178 179 180 // Implementation methods 181 //------------------------------------------------------------------------- 182 protected Rule createRule(StylesheetTag tag, XMLOutput output) { 183 return new Rule( match, createAction(tag, output) ); 184 } 185 186 protected Action createAction(final StylesheetTag tag, final XMLOutput output) { 187 return new Action() { 188 public void run(Node node) throws Exception { 189 190 // store the context for use by applyTemplates tag 191 tag.setXPathSource( node ); 192 193 xpathSource = node; 194 195 if (log.isDebugEnabled()) { 196 log.debug( "Firing template body for match: " + match + " and node: " + node ); 197 } 198 invokeBody(output); 199 } 200 }; 201 } 202 }

This page was automatically generated by Maven