You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by sg...@apache.org on 2002/06/13 11:23:22 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/layouts JetspeedLayout.java
sgala 2002/06/13 02:23:22
Modified: webapp/WEB-INF/conf media.xreg registry.xml
src/java/org/apache/jetspeed/util MimeType.java
src/java/org/apache/jetspeed/services/template
JetspeedTemplateLocatorService.java
TemplateLocatorService.java
src/java/org/apache/jetspeed/services/profiler
JetspeedProfilerService.java
src/java/org/apache/jetspeed/om/registry/base
BaseMediaTypeEntry.java
src/java/org/apache/jetspeed/om/registry MediaTypeEntry.java
src/java/org/apache/jetspeed/modules/pages
JetspeedVelocityPage.java
src/java/org/apache/jetspeed/modules/layouts
JetspeedLayout.java
Added: src/java/org/apache/jetspeed/util TestMimeType.java
Log:
Changes to move Character Set specification to the media registry. Now you can specify a Character Set for each media type. Default is UTF-8 for all (assumed in the test). A rudimentary test has been inserted. Remaining work: test for different media types, clean some of the classes touched. Tested. Passes test suit.
Revision Changes Path
1.3 +3 -0 jakarta-jetspeed/webapp/WEB-INF/conf/media.xreg
Index: media.xreg
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/media.xreg,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- media.xreg 9 Apr 2002 22:20:01 -0000 1.2
+++ media.xreg 13 Jun 2002 09:23:21 -0000 1.3
@@ -4,6 +4,7 @@
<media-type-entry name="html">
<mime-type>text/html</mime-type>
+ <character-set>UTF-8</character-set>
<meta-info>
<title>HTML</title>
<description>Rich HTML for HTML 4.0 compliants browsers</description>
@@ -12,6 +13,7 @@
<media-type-entry name="wml">
<mime-type>text/vnd.wap.wml</mime-type>
+ <character-set>UTF-8</character-set>
<meta-info>
<title>WML</title>
<description>Format for mobile phones and PDAs compatible with WML 1.1</description>
@@ -20,6 +22,7 @@
<media-type-entry name="vxml">
<mime-type>text/vxml</mime-type>
+ <character-set>UTF-8</character-set>
<meta-info>
<title>VoiceXML</title>
<description>Format suitable for use with an audio VoiceXML server</description>
1.9 +4 -0 jakarta-jetspeed/webapp/WEB-INF/conf/registry.xml
Index: registry.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/registry.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- registry.xml 29 Mar 2002 01:08:58 -0000 1.8
+++ registry.xml 13 Jun 2002 09:23:21 -0000 1.9
@@ -197,6 +197,10 @@
<field name="mimeType" type="java.lang.String">
<bind-xml name="mime-type" node="element"/>
</field>
+
+ <field name="characterSet" type="java.lang.String">
+ <bind-xml name="character-set" node="element"/>
+ </field>
</class>
1.7 +54 -9 jakarta-jetspeed/src/java/org/apache/jetspeed/util/MimeType.java
Index: MimeType.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/MimeType.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MimeType.java 27 Apr 2001 11:51:51 -0000 1.6
+++ MimeType.java 13 Jun 2002 09:23:21 -0000 1.7
@@ -56,21 +56,32 @@
/**
-Utility class for declaring MIME types to use for various requests and provide
-utility manipulation methods.
+
+<p>Utility class for declaring MIME types to use for various requests and provide
+utility manipulation methods.</p>
+<p>Added Content-Encoding capability, with defaults
@author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
+@author <a href="mailto:sgala@apache.org">Santiago Gala</a>
@version $Id$
*/
public class MimeType {
- public static final MimeType HTML = new MimeType( "text/html" );
+ public static final MimeType HTML = new MimeType( "text/html", "UTF-8" ); //FIXME: test
public static final MimeType XHTML = new MimeType( "text/xhtml" );
public static final MimeType WML = new MimeType( "text/vnd.wap.wml" );
public static final MimeType XML = new MimeType( "text/xml" );
public static final MimeType VXML = new MimeType( "text/vxml" );
+ /**
+ * Standard ContentType String, with no encoding appended.
+ */
private String mimeType = "";
+ /**
+ * null value means default encoding.
+ * Otherwise, charset to be used.
+ */
+ private String charSet = null;
public MimeType( String mimeType ) {
if(mimeType == null) {
@@ -79,14 +90,25 @@
this.mimeType = mimeType;
}
- /** Extracts from a MimeType a user-friendly identifying code
+ /**
+ *
+ */
+ public MimeType( String mimeType, String charSet ) {
+ if(mimeType == null) {
+ throw new NullPointerException();
+ }
+ this.mimeType = mimeType;
+ this.charSet = charSet;
+ }
+
+ /** Extracts from this MimeType a user-friendly identifying code
* ie "html" for "text/html" or "wml" for "text/vnd.wap.wml"
*
* @param mime the type to simplify
* @return the simplified type
*/
- public static String getCode( MimeType mime ) {
- String type = mime.toString();
+ public String getCode() {
+ String type = this.mimeType;
// get everything after "/"
type = type.substring(type.indexOf("/")+1);
// remove any dot in the name
@@ -104,10 +126,33 @@
}
/**
- Convert this MimeType to its internal String representation
+ Return the media type associated
*/
- public String toString() {
+ public String getContentType()
+ {
return this.mimeType;
+ }
+
+ /**
+ Return the character encoding associated, if any
+ */
+ public String getCharSet()
+ {
+ return this.charSet;
+ }
+
+ /**
+ Convert this MimeType to its external String representation
+ */
+ public String toString()
+ {
+ if( null == this.charSet )
+ {
+ return this.mimeType;
+ }
+ return this.mimeType +
+ "; charset=" +
+ this.charSet;
}
/**
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestMimeType.java
Index: TestMimeType.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.util;
// Java imports
// ECS imports
import org.apache.ecs.ConcreteElement;
// Junit imports
import junit.awtui.TestRunner;
import junit.framework.Test;
import junit.framework.TestSuite;
// Cactus imports
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
// Jetspeed imports
import org.apache.jetspeed.capability.CapabilityMap;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.ProfileLocator;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.services.Profiler;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.test.TurbineTestUtilities;
// Turbine imports
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.pull.TurbinePull;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.RunDataFactory;
// Velocity
import org.apache.velocity.context.Context;
/**
*
* @author <a href="paulsp@apache.org">Paul Spencer</a>
* @version $Id: TestMimeType.java,v 1.1 2002/06/13 09:23:21 sgala Exp $
*/
public class TestMimeType extends ServletTestCase
{
private static String TEST_ANON_USER_NAME = "";
private static String TEST_CONTEXT = null;
private static String TEST_DEFAULT_PAGE = "default";
private static String TEST_HOST = "localhost";
private static String TEST_SERVLET = "/portal";
private static String TEST_GROUP = "apache";
private static String TEST_PAGE = "news";
private static String TEST_USER = "turbine";
private static String TEST_USER_PASSWORD ="turbine";
private RunData rundata = null;
/**
* Defines the testcase name for JUnit.
*
* @param name the testcase's name.
*/
public TestMimeType(String name)
{
super( name );
}
/**
* Start the tests.
*
* @param args the arguments. Not used
*/
public static void main(String args[])
{
TestRunner.main( new String[] { TestMimeType.class.getName() } );
}
/**
* Creates the test suite.
*
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
public static Test suite()
{
// All methods starting with "test" will be executed in the test suite.
return new TestSuite( TestMimeType.class );
}
/**
* Sets up the test case.
*
*/
protected void setUp () throws Exception
{
}
/**
* Test: DefaultURL
* With the default URL "/"
* 1) A page is generated
* 2) The user is anonymous
* 3) Group and Role are not set
*/
public void beginDefaultURL(WebRequest theRequest)
{
System.out.println("URL = " + theRequest.getURL());
theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET, "", null);
System.out.println("post set URL = " + theRequest.getURL());
}
/**
* Execute the test
*
* @throws Exception
*/
public void testDefaultURL() throws Exception
{
// Create the RunData object to be used during testing.
rundata = RunDataFactory.getRunData ( request, response, config );
assertNotNull( "Got rundata", rundata);
TurbineTestUtilities.setupRunData(rundata);
// Verify we have a CapabilityMap
CapabilityMap cm = ((JetspeedRunData)rundata).getCapability();
assertNotNull( "Got Capability", cm);
// Verify we have a profile
Profile profile = Profiler.getProfile(rundata);
assertNotNull( "Got profile from Profiler", profile);
System.out.println("DocumentName = " + profile.getDocument().getName());
// Get and populate the context
Context context = TurbineVelocity.getContext(rundata);
assertNotNull( "Got context", context);
TurbinePull.populateContext( context, rundata);
// Verify tool are in the context
assertNotNull( "Got jlink from context", context.get("jlink"));
// Generatate and output thre page
TurbineTestUtilities.generatePage(rundata);
assertTrue( "Character Set is UTF-8", "UTF-8".equals( rundata.getCharSet() ) );
TurbineTestUtilities.outputPage(rundata);
// Return the used RunData to the factory for recycling.
RunDataFactory.putRunData(rundata);
}
public void endDefaultURL(org.apache.cactus.WebResponse theResponse)
{
System.out.println("text length = " + theResponse.getText().length());
// System.out.println("text length = " + theResponse.getText());
}
}
1.9 +3 -3 jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateLocatorService.java
Index: JetspeedTemplateLocatorService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateLocatorService.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JetspeedTemplateLocatorService.java 28 May 2002 23:04:56 -0000 1.8
+++ JetspeedTemplateLocatorService.java 13 Jun 2002 09:23:21 -0000 1.9
@@ -578,8 +578,8 @@
// set the content type (including charset)
CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( data );
- String type = MimeType.getCode( cm.getPreferredType() );
- data.setContentType( cm.getPreferredType().toString() );
+ String type = cm.getPreferredType().getCode();
+ //data.setContentType( cm.getPreferredType().toString() );
if ((type != null) && (type.length() > 0))
templatePath.append(PATH_SEPARATOR).append(type);
1.4 +2 -2 jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/TemplateLocatorService.java
Index: TemplateLocatorService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/TemplateLocatorService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TemplateLocatorService.java 24 Nov 2001 00:44:36 -0000 1.3
+++ TemplateLocatorService.java 13 Jun 2002 09:23:21 -0000 1.4
@@ -57,7 +57,7 @@
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.services.Profiler;
import org.apache.jetspeed.capability.CapabilityMap;
-import org.apache.jetspeed.util.MimeType;
+//import org.apache.jetspeed.util.MimeType;
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.Service;
1.32 +3 -3 jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java
Index: JetspeedProfilerService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- JetspeedProfilerService.java 26 May 2002 01:36:00 -0000 1.31
+++ JetspeedProfilerService.java 13 Jun 2002 09:23:21 -0000 1.32
@@ -668,7 +668,7 @@
MimeType mimeType = cm.getPreferredType();
if (null != mimeType)
{
- String key = mimeType.toString();
+ String key = mimeType.getContentType();
String agent = cm.getAgent();
if (agent.indexOf("wml") > -1) // FIXME:
key = "text/vnd.wap.wml";
@@ -872,7 +872,7 @@
public Profile createProfile( RunData data, Profile profile, MimeType mt )
throws ProfileException
{
- CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(mt.toString());
+ CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(mt.getContentType());
profile.setMediaType( getMediaType(data, cm) );
return createProfile(data, profile);
}
1.3 +15 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseMediaTypeEntry.java
Index: BaseMediaTypeEntry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseMediaTypeEntry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseMediaTypeEntry.java 1 Apr 2002 23:16:53 -0000 1.2
+++ BaseMediaTypeEntry.java 13 Jun 2002 09:23:21 -0000 1.3
@@ -68,6 +68,7 @@
{
protected String mimeType;
+ protected String characterSet;
public BaseMediaTypeEntry()
{}
@@ -101,4 +102,17 @@
{
this.mimeType = mimeType;
}
+
+ /** @return the character set associated with this MediaType */
+ public String getCharacterSet()
+ {
+ return this.characterSet;
+ }
+
+ /** Sets the character set associated with this MediaType */
+ public void setCharacterSet( String charSet)
+ {
+ this.characterSet = charSet;
+ }
+
}
1.2 +7 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/MediaTypeEntry.java
Index: MediaTypeEntry.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/MediaTypeEntry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MediaTypeEntry.java 29 Jul 2001 13:41:53 -0000 1.1
+++ MediaTypeEntry.java 13 Jun 2002 09:23:22 -0000 1.2
@@ -75,4 +75,10 @@
*/
public void setMimeType( String mimeType );
+ /** @return the character set associated with this MediaType */
+ public String getCharacterSet();
+
+ /** Sets the character set associated with this MediaType */
+ public void setCharacterSet( String charSet);
+
}
1.5 +25 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/pages/JetspeedVelocityPage.java
Index: JetspeedVelocityPage.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/pages/JetspeedVelocityPage.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JetspeedVelocityPage.java 25 Nov 2001 20:53:37 -0000 1.4
+++ JetspeedVelocityPage.java 13 Jun 2002 09:23:22 -0000 1.5
@@ -55,11 +55,15 @@
package org.apache.jetspeed.modules.pages;
import org.apache.turbine.util.RunData;
+import org.apache.turbine.util.Log;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.services.velocity.VelocityService;
import org.apache.velocity.context.Context;
import org.apache.jetspeed.util.template.*;
import org.apache.jetspeed.services.resources.JetspeedResources;
+import org.apache.jetspeed.capability.CapabilityMap;
+import org.apache.jetspeed.capability.CapabilityMapFactory;
+import org.apache.jetspeed.util.MimeType;
/**
* Extends JetspeedTemplatePage to set the Velocity template Context.
@@ -103,7 +107,27 @@
context.put("jnavigation", new JetspeedTemplateNavigation(data));
data.getTemplateInfo().setTemplateContext(VelocityService.CONTEXT, context);
+
+ //Set the ContentType of the page
+ CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( data );
+ MimeType mt = cm.getPreferredType();
+ data.setContentType( mt.getContentType() );
+ data.setCharSet( mt.getCharSet() );
+
+ Log.debug( "JetspeedVelocityPage: Setting type to: " + mt );
+
}
+
+ /**
+ * Allows the VelocityService to peform post-request actions.
+ * (releases the (non-global) tools in the context for reuse later)
+ */
+ protected void doPostBuild(RunData data) throws Exception
+ {
+ Context context = TurbineVelocity.getContext(data);
+ TurbineVelocity.requestFinished(context);
+ }
+
}
1.7 +8 -4 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/layouts/JetspeedLayout.java
Index: JetspeedLayout.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/layouts/JetspeedLayout.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JetspeedLayout.java 7 Mar 2001 06:43:54 -0000 1.6
+++ JetspeedLayout.java 13 Jun 2002 09:23:22 -0000 1.7
@@ -102,10 +102,14 @@
{
CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( data );
-
- data.setContentType( cm.getPreferredType().toString() );
- if ( cm.getPreferredType().equals( MimeType.WML ) ) {
+ MimeType mt = cm.getPreferredType();
+ data.setContentType( mt.getContentType() );
+ data.setCharSet( mt.getCharSet() );
+
+ Log.debug( "Layout: Setting type to: " + mt );
+
+ if ( mt.equals( MimeType.WML ) ) {
// we should output WML code, use raw output
// don"t use navigations for WML
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>