| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jelly.tags.define.TaglibTag |
|
|
| 1 | /* |
|
| 2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | package org.apache.commons.jelly.tags.define; |
|
| 17 | ||
| 18 | import org.apache.commons.jelly.JellyTagException; |
|
| 19 | import org.apache.commons.jelly.TagSupport; |
|
| 20 | import org.apache.commons.jelly.XMLOutput; |
|
| 21 | import org.apache.commons.jelly.impl.DynamicTagLibrary; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * The <taglib> tag is used to define a new tag library |
|
| 25 | * using a Jelly script. The tag library is identified by its |
|
| 26 | * {@link #getURI() URI}. |
|
| 27 | * |
|
| 28 | * The tags for a taglib are declared using the {@link TagTag}. |
|
| 29 | * |
|
| 30 | * You can 'inherit' tags from a previously defined taglib, as well, |
|
| 31 | * allowing runtime extension of tag libraries |
|
| 32 | * |
|
| 33 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
| 34 | * @version $Revision: 155420 $ |
|
| 35 | */ |
|
| 36 | public class TaglibTag extends TagSupport { |
|
| 37 | ||
| 38 | /** The namespace URI */ |
|
| 39 | private String uri; |
|
| 40 | /** The new tags being added */ |
|
| 41 | private DynamicTagLibrary tagLibrary; |
|
| 42 | /** Whether or not inheritence is enabled */ |
|
| 43 | 36 | private boolean inherit = true; |
| 44 | ||
| 45 | 36 | public TaglibTag() { |
| 46 | 36 | } |
| 47 | ||
| 48 | 0 | public TaglibTag(String uri) { |
| 49 | 0 | this.uri = uri; |
| 50 | 0 | } |
| 51 | ||
| 52 | // Tag interface |
|
| 53 | //------------------------------------------------------------------------- |
|
| 54 | public void doTag(XMLOutput output) throws JellyTagException { |
|
| 55 | 36 | String uri = getUri(); |
| 56 | 36 | tagLibrary = new DynamicTagLibrary( uri ); |
| 57 | ||
| 58 | // inherit tags from an existing tag library |
|
| 59 | 36 | if ( isInherit() ) { |
| 60 | 27 | tagLibrary.setParent( context.getTagLibrary( uri ) ); |
| 61 | } |
|
| 62 | 36 | context.registerTagLibrary( uri, tagLibrary ); |
| 63 | ||
| 64 | 36 | invokeBody(output); |
| 65 | ||
| 66 | 36 | tagLibrary = null; |
| 67 | 36 | } |
| 68 | ||
| 69 | // Properties |
|
| 70 | //------------------------------------------------------------------------- |
|
| 71 | public String getUri() { |
|
| 72 | 36 | return uri; |
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Sets the namespace URI to register this new dynamic tag library with |
|
| 77 | */ |
|
| 78 | public void setUri(String uri) { |
|
| 79 | 36 | this.uri = uri; |
| 80 | 36 | } |
| 81 | ||
| 82 | public DynamicTagLibrary getTagLibrary() { |
|
| 83 | 36 | return tagLibrary; |
| 84 | } |
|
| 85 | ||
| 86 | /** |
|
| 87 | * Returns the inherit. |
|
| 88 | * @return boolean |
|
| 89 | */ |
|
| 90 | public boolean isInherit() { |
|
| 91 | 36 | return inherit; |
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Sets whether this dynamic tag should inherit from the current existing tag library |
|
| 96 | * of the same URI. This feature is enabled by default so that tags can easily be |
|
| 97 | * some tags can be overridden in an existing library, such as when making Mock Tags. |
|
| 98 | * |
|
| 99 | * You can disable this option if you want to disable any tags in the base library, |
|
| 100 | * turning them into just normal static XML. |
|
| 101 | * |
|
| 102 | * @param inherit The inherit to set |
|
| 103 | */ |
|
| 104 | public void setInherit(boolean inherit) { |
|
| 105 | 21 | this.inherit = inherit; |
| 106 | 21 | } |
| 107 | ||
| 108 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |