Author: mrdon Date: Wed Apr 27 21:55:17 2005 New Revision: 165098 URL: http://svn.apache.org/viewcvs?rev=165098&view=rev Log: Adding attribute 'ref' to html base tag to allow different base values: "page" - Base value of the jsp path (default) "site" - Base value of the context path
PR: 33426 Modified: struts/taglib/trunk/doc/userGuide/struts-html.xml struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseTag.java struts/taglib/trunk/src/test-cactus/org/apache/struts/taglib/html/TestBaseTag.java struts/taglib/trunk/src/webapp/org/apache/struts/taglib/html/TestBaseTag.jsp Modified: struts/taglib/trunk/doc/userGuide/struts-html.xml URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/doc/userGuide/struts-html.xml?rev=165098&r1=165097&r2=165098&view=diff ============================================================================== --- struts/taglib/trunk/doc/userGuide/struts-html.xml (original) +++ struts/taglib/trunk/doc/userGuide/struts-html.xml Wed Apr 27 21:55:17 2005 @@ -66,6 +66,19 @@ <p>The server name to use instead of request.getServerName().</p> </info> </attribute> + <attribute> + <name>ref</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>The reference from which the base uri will created. Possible values are: + </p> + <ul> + <li><code>page</code> - The base uri will be the jsp page location. (default)</li> + <li><code>site</code> - The base uri will be the application context path.</li> + </ul> + </info> + </attribute> </tag> Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseTag.java URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseTag.java?rev=165098&r1=165097&r2=165098&view=diff ============================================================================== --- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseTag.java (original) +++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseTag.java Wed Apr 27 21:55:17 2005 @@ -45,6 +45,9 @@ public class BaseTag extends TagSupport { + protected final String REF_SITE = "site"; + protected final String REF_PAGE = "page"; + /** * The message resources for this package. */ @@ -61,6 +64,37 @@ */ protected String target = null; + /** + * The reference to which the base will created. + */ + protected String ref = REF_PAGE; + + /** + * Gets the reference to which the base will be created + */ + public String getRef() { + return (this.ref); + } + + /** + * Sets the reference to which the base will be created. + * + * @param ref Either "page" to render the base as the jsp path + * located, or "site" as the application's context + */ + public void setRef(String ref) { + if (ref == null) { + throw new IllegalArgumentException("Ref attribute cannot be null"); + } + ref = ref.toLowerCase(); + if (ref.equals(REF_PAGE) || ref.equals(REF_SITE)) { + this.ref = ref; + } else { + throw new IllegalArgumentException("Ref attribute must either be "+ + "'" + REF_PAGE + "' or '" + REF_SITE + "'"); + } + } + public String getTarget() { return (this.target); } @@ -128,8 +162,14 @@ String uri) { StringBuffer tag = new StringBuffer("<base href=\""); - tag.append(RequestUtils.createServerUriStringBuffer(scheme,serverName,port,uri).toString()); - + if(ref.equals(REF_SITE)) { + StringBuffer contextBase = new StringBuffer(((HttpServletRequest)pageContext.getRequest()).getContextPath()); + contextBase.append("/"); + tag.append(RequestUtils.createServerUriStringBuffer(scheme,serverName,port,contextBase.toString()).toString()); + } + else { + tag.append(RequestUtils.createServerUriStringBuffer(scheme,serverName,port,uri).toString()); + } tag.append("\""); if (this.target != null) { Modified: struts/taglib/trunk/src/test-cactus/org/apache/struts/taglib/html/TestBaseTag.java URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/test-cactus/org/apache/struts/taglib/html/TestBaseTag.java?rev=165098&r1=165097&r2=165098&view=diff ============================================================================== --- struts/taglib/trunk/src/test-cactus/org/apache/struts/taglib/html/TestBaseTag.java (original) +++ struts/taglib/trunk/src/test-cactus/org/apache/struts/taglib/html/TestBaseTag.java Wed Apr 27 21:55:17 2005 @@ -68,18 +68,22 @@ */ public void testBase() throws Exception { runMyTest("testBase"); - } + } public void testBaseTarget() throws Exception { runMyTest("testBaseTarget"); - } + } + + public void testBaseRef() throws Exception { + runMyTest("testBaseRef"); + } public void testBaseServer() throws Exception { runMyTest("testBaseServer"); - } + } public void testBaseServerTarget() throws Exception { runMyTest("testBaseServerTarget"); - } + } } Modified: struts/taglib/trunk/src/webapp/org/apache/struts/taglib/html/TestBaseTag.jsp URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/webapp/org/apache/struts/taglib/html/TestBaseTag.jsp?rev=165098&r1=165097&r2=165098&view=diff ============================================================================== --- struts/taglib/trunk/src/webapp/org/apache/struts/taglib/html/TestBaseTag.jsp (original) +++ struts/taglib/trunk/src/webapp/org/apache/struts/taglib/html/TestBaseTag.jsp Wed Apr 27 21:55:17 2005 @@ -35,6 +35,15 @@ </bean:define> </logic:equal> +<logic:equal name="runTest" value="testBaseRef"> + <bean:define id="TEST_RESULTS" toScope="page"> + <html:base ref="site"/> + </bean:define> + <bean:define id="EXPECTED_RESULTS" toScope="page"> + <base href="http://<%=server%><%=portString%><%= request.getContextPath() %>/"> + </bean:define> +</logic:equal> + <logic:equal name="runTest" value="testBaseServer"> <bean:define id="TEST_RESULTS" toScope="page"> <html:base server="www.my-server-name.com"/> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]