Author: xlawrence
Date: Tue Nov 13 15:33:45 2007
New Revision: 19137

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19137&repname=
=3Djahia
Log:
added a Tag in order to generate <meta> elements. The implementation allows=
 the user to retrieve a value from a Jahia metadata or to specify his/her o=
wn value

Added:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/metad=
ata/
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/metad=
ata/HTMLMetaTag.java

Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/me=
tadata/HTMLMetaTag.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/metadata/HTMLMetaTag.ja=
va&rev=3D19137&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/metad=
ata/HTMLMetaTag.java (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/metad=
ata/HTMLMetaTag.java Tue Nov 13 15:33:45 2007
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2002-2006 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
+ *
+ *  http://www.jahia.org/license/
+ *
+ * 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.jahia.taglibs.metadata;
+
+import org.jahia.exceptions.JahiaException;
+import org.jahia.params.ProcessingContext;
+import org.jahia.taglibs.AbstractJahiaTag;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import java.io.IOException;
+
+/**
+ * Generates html meta tags of the form:</br>
+ * <meta name=3D"description" lang=3D"en" content=3D"my page"/>
+ *
+ * @author Xavier Lawrence
+ */
+public class HTMLMetaTag extends AbstractJahiaTag {
+    private static final org.apache.log4j.Logger logger =3D
+            org.apache.log4j.Logger.getLogger(HTMLMetaTag.class);
+
+    /**
+     * Value to use as it is for the meta content attribute
+     */
+    private String value;
+    /**
+     * name attribute of the meta element generated
+     */
+    private String name;
+    /**
+     * Name of a Jahia metadata to use in order to fetch the coresponding =
metadata value and it for the content attribute
+     */
+    private String metadata;
+
+    public int doStartTag() throws JspException {
+        try {
+            if (name =3D=3D null || name.length() < 0) {
+                throw new IllegalArgumentException("Attribute 'name' must =
not be null or empty");
+            }
+            final boolean valueAttributeSpecified =3D value !=3D null && v=
alue.length() > 0;
+            final boolean metaDataAttributeSpecified =3D metadata !=3D nul=
l && metadata.length() > 0;
+            if (!valueAttributeSpecified && !metaDataAttributeSpecified) {
+                throw new IllegalArgumentException("You must provide a val=
ue for attribute 'value' or attribute 'metaData'");
+            }
+            if (logger.isDebugEnabled()) {
+                logger.debug("HTMLMetaTag: name=3D" + name + ", value=3D" =
+ value + ", metaData=3D" + metadata);
+            }
+            final JspWriter out =3D pageContext.getOut();
+            final StringBuffer buff =3D new StringBuffer();
+            buff.append("<meta ");
+            buff.append("name=3D\"");
+            buff.append(name);
+            buff.append("\" ");
+
+            if (languageCode !=3D null && languageCode.length() > 0) {
+                buff.append("lang=3D\"");
+                buff.append(languageCode);
+                buff.append("\" ");
+            }
+
+            buff.append("content=3D\"");
+
+            if (valueAttributeSpecified) {
+                buff.append(value);
+            } else {
+                final HttpServletRequest request =3D (HttpServletRequest) =
pageContext.getRequest();
+                final ProcessingContext jParams =3D (ProcessingContext) re=
quest.getAttribute("org.jahia.params.ParamBean");
+                final String metadataValue =3D jParams.getContentPage().ge=
tMetadataValue(metadata, jParams, "").trim();
+                if (metadataValue.length() =3D=3D 0) {
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("Empty value for metadata " + metadat=
a);
+                    }
+                    return SKIP_BODY;
+                }
+                buff.append(metadataValue);
+            }
+
+            buff.append("\" ");
+            if (xhtmlCompliantHtml) {
+                buff.append("/");
+            }
+            buff.append(">");
+            out.println(buff.toString());
+
+        } catch (final IOException e) {
+            logger.error("IOException in doStartTag", e);
+
+        } catch (final JahiaException je) {
+            logger.error("JahiaException in doStartTag", je);
+        }
+        return SKIP_BODY;
+    }
+
+    public int doEndTag() throws JspException {
+        value =3D null;
+        name =3D null;
+        metadata =3D null;
+        return EVAL_PAGE;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value =3D value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name =3D name;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+
+    public void setMetadata(String metadata) {
+        this.metadata =3D metadata;
+    }
+}

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to