You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2014/04/24 14:49:35 UTC

svn commit: r1589696 - in /sling/trunk/bundles/scripting/jsp-taglib/src/main: java/org/apache/sling/scripting/jsp/taglib/tei/ resources/META-INF/

Author: justin
Date: Thu Apr 24 12:49:34 2014
New Revision: 1589696

URL: http://svn.apache.org/r1589696
Log:
SLING-3475 - adding TagExtraInfo for JSP tags. Thanks to Julian Sedding for the patch

Added:
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AbstractVarTEI.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AdaptToTEI.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/GetPropertyTEI.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceIteratorVariableTEI.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceVariableTEI.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/StringVariableTEI.java
Modified:
    sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AbstractVarTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AbstractVarTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AbstractVarTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AbstractVarTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
+
+/**
+ * Abstract TEI that that provides the type for a single
+ * variable named in the tag's "var" attribute.
+ * <p>
+ * The name of the attribute can be overwritten via a custom default
+ * constructor or by overwriting {@link #getVariableName(javax.servlet.jsp.tagext.TagData)}.
+ * <p>
+ * All implementations need to overwrite {@link #getClassName(javax.servlet.jsp.tagext.TagData)}
+ * in order to provide the type (class name) of the variable.
+ */
+public abstract class AbstractVarTEI extends TagExtraInfo {
+
+    protected static final String ATTR_VAR = "var";
+
+    private final String variableNameAttribute;
+
+    public AbstractVarTEI() {
+        this(ATTR_VAR);
+    }
+
+    /**
+     * Constructor that takes the name of the attribute that defines the variable name
+     * and the name of the attribute that defines the class name.
+     *
+     * @param variableNameAttribute Name of the attribute that defines the variable name.
+     */
+    protected AbstractVarTEI(final String variableNameAttribute) {
+        this.variableNameAttribute = variableNameAttribute;
+    }
+
+    /**
+     * Provides the name of the variable injected into the {@code pageContext}.
+     *
+     * @param data The TagData.
+     * @return The variable name.
+     */
+    protected String getVariableName(TagData data) {
+        return data.getAttributeString(variableNameAttribute);
+    }
+
+    /**
+     * Provides the fully qualified class name of the variable injected into
+     * the {@code pageContext}.
+     *
+     * @param data The TagData.
+     * @return The class name of the variable's type.
+     */
+    protected abstract String getClassName(TagData data);
+
+    @Override
+    public VariableInfo[] getVariableInfo(TagData data) {
+        final String variableName = getVariableName(data);
+        if (variableName == null) {
+            return new VariableInfo[0];
+        } else {
+            return new VariableInfo[]{
+                    new VariableInfo(variableName, getClassName(data), true, VariableInfo.AT_END)
+            };
+        }
+    }
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AdaptToTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AdaptToTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AdaptToTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/AdaptToTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import javax.servlet.jsp.tagext.TagData;
+
+public class AdaptToTEI extends AbstractVarTEI {
+
+    public static final String ATTR_ADAPT_TO = "adaptTo";
+
+    @Override
+    protected String getClassName(TagData data) {
+        return data.getAttributeString(ATTR_ADAPT_TO);
+    }
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/GetPropertyTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/GetPropertyTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/GetPropertyTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/GetPropertyTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import javax.servlet.jsp.tagext.TagData;
+
+public class GetPropertyTEI extends AbstractVarTEI {
+
+    public static final String ATTR_DEFAULT_VALUE = "defaultValue";
+    public static final String ATTR_RETURN_CLASS = "returnClass";
+
+    @Override
+    protected String getClassName(TagData data) {
+        final Object defaultValue = data.getAttribute(ATTR_DEFAULT_VALUE);
+        final String className = data.getAttributeString(ATTR_RETURN_CLASS);
+        if (defaultValue != null) {
+            return defaultValue.getClass().getName();
+        } else {
+            return className;
+        }
+    }
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceIteratorVariableTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceIteratorVariableTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceIteratorVariableTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceIteratorVariableTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import org.apache.sling.api.resource.Resource;
+
+import javax.servlet.jsp.tagext.TagData;
+import java.util.Iterator;
+
+public class ResourceIteratorVariableTEI extends AbstractVarTEI {
+
+    private static String ITERATOR_CLASS_NAME = Iterator.class.getName();
+    private static String RESOURCE_CLASS_NAME = Resource.class.getName();
+    private static String RESOURCE_ITERATOR_CLASS_NAME = ITERATOR_CLASS_NAME + '<' + RESOURCE_CLASS_NAME + '>';
+
+    @Override
+    protected String getClassName(TagData data) {
+        return RESOURCE_ITERATOR_CLASS_NAME;
+    }
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceVariableTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceVariableTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceVariableTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/ResourceVariableTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import org.apache.sling.api.resource.Resource;
+
+import javax.servlet.jsp.tagext.TagData;
+
+public class ResourceVariableTEI extends AbstractVarTEI {
+
+    private static final String RESOURCE_CLASS_NAME = Resource.class.getName();
+
+    @Override
+    protected String getClassName(TagData data) {
+        return RESOURCE_CLASS_NAME;
+    }
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/StringVariableTEI.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/StringVariableTEI.java?rev=1589696&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/StringVariableTEI.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/tei/StringVariableTEI.java Thu Apr 24 12:49:34 2014
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib.tei;
+
+import javax.servlet.jsp.tagext.TagData;
+
+public class StringVariableTEI extends AbstractVarTEI {
+
+    private static final String STRING_CLASS_NAME = String.class.getName();
+
+    @Override
+    protected String getClassName(TagData data) {
+        return STRING_CLASS_NAME;
+    }
+}

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld?rev=1589696&r1=1589695&r2=1589696&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld Thu Apr 24 12:49:34 2014
@@ -105,6 +105,9 @@
 		<tag-class>
 			org.apache.sling.scripting.jsp.taglib.IncludeTagHandler
 		</tag-class>
+		<tei-class>
+			org.apache.sling.scripting.jsp.taglib.tei.StringVariableTEI
+		</tei-class>
 		<body-content>empty</body-content>
 		<attribute>
 			<description>
@@ -401,6 +404,9 @@
 		<tag-class>
 			org.apache.sling.scripting.jsp.taglib.AdaptToTag
 		</tag-class>
+		<tei-class>
+			org.apache.sling.scripting.jsp.taglib.tei.AdaptToTEI
+		</tei-class>
 		<body-content>empty</body-content>
 		<attribute>
 			<description>
@@ -439,6 +445,9 @@
 		<tag-class>
 			org.apache.sling.scripting.jsp.taglib.FindResourcesTag
 		</tag-class>
+		<tei-class>
+			org.apache.sling.scripting.jsp.taglib.tei.ResourceIteratorVariableTEI
+		</tei-class>
 		<body-content>empty</body-content>
 		<attribute>
 			<description>
@@ -475,6 +484,9 @@
 		<tag-class>
 			org.apache.sling.scripting.jsp.taglib.GetPropertyTag
 		</tag-class>
+		<tei-class>
+			org.apache.sling.scripting.jsp.taglib.tei.GetPropertyTEI
+		</tei-class>
 		<body-content>empty</body-content>
 		<attribute>
 			<description>
@@ -528,6 +540,9 @@
         <tag-class>
             org.apache.sling.scripting.jsp.taglib.GetResourceTag
         </tag-class>
+        <tei-class>
+            org.apache.sling.scripting.jsp.taglib.tei.ResourceVariableTEI
+        </tei-class>
         <body-content>empty</body-content>
         <attribute>
             <description>
@@ -566,6 +581,9 @@
         <tag-class>
             org.apache.sling.scripting.jsp.taglib.ListChildrenTag
         </tag-class>
+        <tei-class>
+            org.apache.sling.scripting.jsp.taglib.tei.ResourceIteratorVariableTEI
+        </tei-class>
         <body-content>empty</body-content>
         <attribute>
             <description>