You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2010/04/01 17:52:40 UTC
svn commit: r930022 - in /portals/applications/gems/trunk: pom.xml
src/main/java/org/apache/portals/gems/tags/
src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java
src/main/resources/META-INF/ src/main/resources/META-INF/fmt-portlet.tld
Author: woonsan
Date: Thu Apr 1 15:52:40 2010
New Revision: 930022
URL: http://svn.apache.org/viewvc?rev=930022&view=rev
Log:
APA-34: Adding portlet set bundle tag
Added:
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/
portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java (with props)
portals/applications/gems/trunk/src/main/resources/META-INF/
portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld (with props)
Modified:
portals/applications/gems/trunk/pom.xml
Modified: portals/applications/gems/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/pom.xml?rev=930022&r1=930021&r2=930022&view=diff
==============================================================================
--- portals/applications/gems/trunk/pom.xml (original)
+++ portals/applications/gems/trunk/pom.xml Thu Apr 1 15:52:40 2010
@@ -35,6 +35,8 @@
<properties>
<javax.servlet.version>2.4</javax.servlet.version>
+ <jsp-api.version>2.0</jsp-api.version>
+ <jstl.version>1.1.2</jstl.version>
<portals.portlet2-api-spec.version>1.0</portals.portlet2-api-spec.version>
<velocity.version>1.6.3</velocity.version>
<org.apache.portals.bridges.common.version>1.0.4</org.apache.portals.bridges.common.version>
@@ -63,6 +65,18 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>${jsp-api.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <version>${jstl.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity.version}</version>
@@ -165,8 +179,9 @@
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
+ <include>**/*.tld</include>
<include>**/*.properties</include>
- <include>**/*.vm</include>
+ <include>**/*.vm</include>
</includes>
</resource>
</resources>
Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java?rev=930022&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java Thu Apr 1 15:52:40 2010
@@ -0,0 +1,139 @@
+/*
+ * 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.portals.gems.tags;
+
+import java.util.Locale;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.jstl.core.Config;
+import javax.servlet.jsp.jstl.fmt.LocalizationContext;
+import javax.servlet.jsp.tagext.TagSupport;
+
+/**
+ * SetPortletBundleTag
+ *
+ * @version $Id$
+ */
+public class SetPortletBundleTag extends TagSupport
+{
+ private static final long serialVersionUID = 1L;
+
+ // *********************************************************************
+ // Protected state
+ protected String basename; // 'basename' attribute
+
+ // *********************************************************************
+ // Private state
+ private int scope; // 'scope' attribute
+
+ private String var; // 'var' attribute
+
+ // *********************************************************************
+ // Constructor and initialization
+ public SetPortletBundleTag()
+ {
+ super();
+ init();
+ }
+
+ private void init()
+ {
+ basename = null;
+ scope = PageContext.PAGE_SCOPE;
+ }
+
+ // *********************************************************************
+ // Tag attributes known at translation time
+ public void setVar(String var)
+ {
+ this.var = var;
+ }
+
+ public void setScope(String scope)
+ {
+ this.scope = getScope(scope);
+ }
+
+ // *********************************************************************
+ // Accessor methods
+ // for tag attribute
+ public void setBasename(String basename) throws JspTagException
+ {
+ this.basename = basename;
+ }
+
+ // *********************************************************************
+ // Tag logic
+ public int doEndTag() throws JspException
+ {
+ LocalizationContext locCtxt = getLocalizationContext(pageContext, basename);
+
+ if (var != null)
+ {
+ pageContext.setAttribute(var, locCtxt, scope);
+ }
+ else
+ {
+ Config.set(pageContext, Config.FMT_LOCALIZATION_CONTEXT, locCtxt, scope);
+ }
+
+ return EVAL_PAGE;
+ }
+
+ // Releases any resources we may have (or inherit)
+ public void release()
+ {
+ init();
+ }
+
+ public static LocalizationContext getLocalizationContext(PageContext pc, String basename)
+ {
+ PortletConfig portletConfig = (PortletConfig) pc.getRequest().getAttribute("javax.portlet.config");
+
+ if (portletConfig == null)
+ {
+ return new LocalizationContext();
+ }
+ else
+ {
+ PortletRequest portletRequest = (PortletRequest) pc.getRequest().getAttribute("javax.portlet.request");
+ return new LocalizationContext(portletConfig.getResourceBundle(portletRequest != null ? portletRequest.getLocale() : Locale.getDefault()));
+ }
+ }
+
+ private static int getScope(String scope)
+ {
+ if ("request".equalsIgnoreCase(scope))
+ {
+ return PageContext.REQUEST_SCOPE;
+ }
+ else if ("session".equalsIgnoreCase(scope))
+ {
+ return PageContext.SESSION_SCOPE;
+ }
+ else if ("application".equalsIgnoreCase(scope))
+ {
+ return PageContext.APPLICATION_SCOPE;
+ }
+
+ return PageContext.PAGE_SCOPE;
+ }
+}
Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/tags/SetPortletBundleTag.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld?rev=930022&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld (added)
+++ portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld Thu Apr 1 15:52:40 2010
@@ -0,0 +1,67 @@
+<?xml version="1.0" ?>
+<!--
+ Copyright 2008 Hippo
+
+ Licensed 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.
+-->
+<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
+ version="2.0">
+
+ <description>APA-GEMS Portlet i18n-capable formatting library</description>
+ <display-name>APA-GEMS Portlet fmt</display-name>
+ <tlib-version>1.1</tlib-version>
+ <short-name>fmt-portlet</short-name>
+ <uri>http://portals.apache.org/applications/gems/fmt-portlet</uri>
+
+ <tag>
+ <description>
+ Loads a resource bundle from the portlet config and
+ stores it in the named scoped variable or
+ the bundle configuration variable
+ </description>
+ <name>setBundle</name>
+ <tag-class>org.apache.portals.gems.tags.SetPortletBundleTag</tag-class>
+ <body-content>empty</body-content>
+ <attribute>
+ <description>
+ This attribute is always ignored because resource bundle is retrieved
+ from the portlet config directly.
+ </description>
+ <name>basename</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <description>
+ Name of the exported scoped variable which stores
+ the i18n localization context of type
+ javax.servlet.jsp.jstl.fmt.LocalizationContext.
+ </description>
+ <name>var</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ <attribute>
+ <description>
+ Scope of var or the localization context
+ configuration variable.
+ </description>
+ <name>scope</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ </tag>
+
+</taglib>
Propchange: portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/applications/gems/trunk/src/main/resources/META-INF/fmt-portlet.tld
------------------------------------------------------------------------------
svn:mime-type = text/plain