You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/01/02 18:19:59 UTC
svn commit: r895242 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/functional/
src/org/apache/wookie/controller/ src/org/apache/wookie/helpers/
widgets/localetest/ widgets/localetest/Images/ widgets/localetest/locales/
widgets/localete...
Author: scottbw
Date: Sat Jan 2 17:19:56 2010
New Revision: 895242
URL: http://svn.apache.org/viewvc?rev=895242&view=rev
Log:
Fix for WOOKIE-92 (part of WOOKIE-67) which adds an optional locale parameter to the API method for obtaining a widget instance. If the locale value is a valid language tag, it is stored with the widget instance, and is used to determine the start file URL returned. Functional tests are provided along with a localized widget to support the tests. If no locale is set, the default server locale is used instead.
Added:
incubator/wookie/trunk/widgets/localetest/
incubator/wookie/trunk/widgets/localetest/Images/
incubator/wookie/trunk/widgets/localetest/Images/test.png (with props)
incubator/wookie/trunk/widgets/localetest/build.xml
incubator/wookie/trunk/widgets/localetest/config.xml (with props)
incubator/wookie/trunk/widgets/localetest/locales/
incubator/wookie/trunk/widgets/localetest/locales/en/
incubator/wookie/trunk/widgets/localetest/locales/en/index.htm
incubator/wookie/trunk/widgets/localetest/locales/fr/
incubator/wookie/trunk/widgets/localetest/locales/fr/Images/
incubator/wookie/trunk/widgets/localetest/locales/fr/Images/test.png (with props)
incubator/wookie/trunk/widgets/localetest/locales/fr/index.htm
incubator/wookie/trunk/widgets/localetest/locales/index.htm
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java
incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java
incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java?rev=895242&r1=895241&r2=895242&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetInstancesControllerTest.java Sat Jan 2 17:19:56 2010
@@ -31,6 +31,63 @@
*/
public class WidgetInstancesControllerTest extends AbstractControllerTest {
+ private static final String LOCALIZED_WIDGET = "http://www.getwookie.org/widgets/localetest";
+
+ @Test
+ public void getLocalizedInstance(){
+ try {
+ HttpClient client = new HttpClient();
+ PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+ post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+LOCALIZED_WIDGET+"&userid=localetest&shareddatakey=localetest&locale=fr");
+ client.executeMethod(post);
+ int code = post.getStatusCode();
+ assertEquals(201,code);
+ assertTrue(post.getResponseBodyAsString().contains("locales/fr/index.htm"));
+ post.releaseConnection();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail("post failed");
+ }
+ }
+
+ @Test
+ public void getNonLocalizedInstance(){
+ try {
+ HttpClient client = new HttpClient();
+ PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+ post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+LOCALIZED_WIDGET+"&userid=localetest2&shareddatakey=localetest2&locale=bu");
+ client.executeMethod(post);
+ int code = post.getStatusCode();
+ assertEquals(201,code);
+ assertFalse(post.getResponseBodyAsString().contains("locales/fr/index.htm"));
+ assertFalse(post.getResponseBodyAsString().contains("locales/en/index.htm"));
+ post.releaseConnection();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail("post failed");
+ }
+ }
+
+ @Test
+ public void getDefaultLocalizedInstance(){
+ try {
+ HttpClient client = new HttpClient();
+ PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+ post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+LOCALIZED_WIDGET+"&userid=localetest3&shareddatakey=localetest3");
+ client.executeMethod(post);
+ int code = post.getStatusCode();
+ assertEquals(201,code);
+ assertTrue(post.getResponseBodyAsString().contains("locales/en/index.htm"));
+ post.releaseConnection();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail("post failed");
+ }
+ }
+
@Test
public void getInstanceById(){
try {
Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=895242&r1=895241&r2=895242&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java Sat Jan 2 17:19:56 2010
@@ -28,6 +28,7 @@
import org.apache.log4j.Logger;
import org.apache.wookie.Messages;
import org.apache.wookie.beans.SharedData;
+import org.apache.wookie.beans.StartFile;
import org.apache.wookie.beans.WidgetInstance;
import org.apache.wookie.exceptions.InvalidWidgetCallException;
import org.apache.wookie.helpers.Notifier;
@@ -35,6 +36,7 @@
import org.apache.wookie.helpers.WidgetInstanceHelper;
import org.apache.wookie.helpers.WidgetKeyManager;
import org.apache.wookie.server.LocaleHandler;
+import org.apache.wookie.util.LocalizationUtils;
/**
* REST implementation for widgetInstance
@@ -198,7 +200,8 @@
// Widget exists
if(instance==null){
String apiKey = request.getParameter("api_key"); //$NON-NLS-1$
- instance = WidgetFactory.getWidgetFactory(session, localizedMessages).newInstance(apiKey, userId, sharedDataKey, serviceType, widgetId);
+ String locale = request.getParameter("locale");//$NON-NLS-1$
+ instance = WidgetFactory.getWidgetFactory(session, localizedMessages).newInstance(apiKey, userId, sharedDataKey, serviceType, widgetId, locale);
response.setStatus(HttpServletResponse.SC_CREATED);
} else {
response.setStatus(HttpServletResponse.SC_OK);
@@ -272,9 +275,10 @@
*/
protected static String getUrl(HttpServletRequest request, WidgetInstance instance) throws IOException{
String url = "";
+ StartFile sf = (StartFile) LocalizationUtils.getLocalizedElement(StartFile.findByValue("widget", instance.getWidget()), new String[]{instance.getLang()});
URL urlWidget = new URL(request.getScheme() ,
request.getServerName() ,
- request.getServerPort() , instance.getWidget().getUrl());
+ request.getServerPort() , sf.getUrl());
if (urlWidget.getQuery() != null){
url+= urlWidget + "&idkey=" + instance.getIdKey() //$NON-NLS-1$
Modified: incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java?rev=895242&r1=895241&r2=895242&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java Sat Jan 2 17:19:56 2010
@@ -24,6 +24,7 @@
import org.apache.wookie.beans.Widget;
import org.apache.wookie.beans.WidgetInstance;
import org.apache.wookie.util.HashGenerator;
+import org.apache.wookie.util.LocalizationUtils;
import org.apache.wookie.util.RandomGUID;
import org.apache.wookie.util.opensocial.OpenSocialUtils;
@@ -83,7 +84,7 @@
* @param localizedMessages
* @return
*/
- public WidgetInstance newInstance(String apiKey, String userId, String sharedDataKey, String serviceType, String widgetId){
+ public WidgetInstance newInstance(String apiKey, String userId, String sharedDataKey, String serviceType, String widgetId, String lang){
try {
Widget widget;
WidgetInstance widgetInstance;
@@ -114,7 +115,7 @@
Configuration properties = (Configuration) session.getServletContext().getAttribute("opensocial"); //$NON-NLS-1$
- widgetInstance = addNewWidgetInstance(apiKey, userId, sharedDataKey, widget, nonce, hashKey, properties);
+ widgetInstance = addNewWidgetInstance(apiKey, userId, sharedDataKey, widget, nonce, hashKey, properties, lang);
return widgetInstance;
} catch (Exception ex) {
return null;
@@ -132,13 +133,14 @@
* @param properties
* @return
*/
- private WidgetInstance addNewWidgetInstance(String api_key, String userId, String sharedDataKey, Widget widget, String nonce, String idKey, Configuration properties) {
+ private WidgetInstance addNewWidgetInstance(String api_key, String userId, String sharedDataKey, Widget widget, String nonce, String idKey, Configuration properties, String lang) {
WidgetInstance widgetInstance = new WidgetInstance();
widgetInstance.setUserId(userId);
widgetInstance.setSharedDataKey(sharedDataKey);
widgetInstance.setIdKey(idKey);
widgetInstance.setNonce(nonce);
widgetInstance.setApiKey(api_key);
+ if (LocalizationUtils.isValidLanguageTag(lang)) widgetInstance.setLang(lang);
// set the defaults widget for this type
widgetInstance.setWidget(widget);
widgetInstance.setHidden(false);
Modified: incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java?rev=895242&r1=895241&r2=895242&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetHelper.java Sat Jan 2 17:19:56 2010
@@ -109,8 +109,12 @@
out += "</description>\n";
// Do icons
- WidgetIcon[] icons = WidgetIcon.findForWidget(widget);
- icons = (WidgetIcon[]) LocalizationUtils.processElementsByLocales(icons, locales);
+ WidgetIcon[] icons;
+ if (locales != null && locales.length != 0){
+ icons = (WidgetIcon[]) LocalizationUtils.processElementsByLocales(WidgetIcon.findForWidget(widget), locales);
+ } else {
+ icons = WidgetIcon.findForWidget(widget);
+ }
if (icons!=null){
for (WidgetIcon icon: icons){
try {
Added: incubator/wookie/trunk/widgets/localetest/Images/test.png
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/Images/test.png?rev=895242&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/wookie/trunk/widgets/localetest/Images/test.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/wookie/trunk/widgets/localetest/build.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/build.xml?rev=895242&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/build.xml (added)
+++ incubator/wookie/trunk/widgets/localetest/build.xml Sat Jan 2 17:19:56 2010
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<project default="build-widget" basedir="." name="widget build file">
+ <property name="wookie.widgets.dir" location="../"/>
+ <property name="widget.shortname" value="localetest"/>
+
+ <import file="../build.xml"/>
+</project>
\ No newline at end of file
Added: incubator/wookie/trunk/widgets/localetest/config.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/config.xml?rev=895242&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/config.xml (added)
+++ incubator/wookie/trunk/widgets/localetest/config.xml Sat Jan 2 17:19:56 2010
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets" id="http://www.getwookie.org/widgets/localetest" height="383" width="255">
+ <name>localetest</name>
+ <description>widget for testing localization</description>
+ <icon src="icon.png"/>
+ <author>Scott Wilson</author>
+ <license>Licensed under the Apache 2.0 License (see http://www.apache.org/licenses/LICENSE-2.0)</license>
+</widget>
\ No newline at end of file
Propchange: incubator/wookie/trunk/widgets/localetest/config.xml
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/wookie/trunk/widgets/localetest/locales/en/index.htm
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/en/index.htm?rev=895242&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/locales/en/index.htm (added)
+++ incubator/wookie/trunk/widgets/localetest/locales/en/index.htm Sat Jan 2 17:19:56 2010
@@ -0,0 +1,3 @@
+<p>Hello World!</p>
+
+<p><img src="Images/test.png"/></p>
\ No newline at end of file
Added: incubator/wookie/trunk/widgets/localetest/locales/fr/Images/test.png
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/fr/Images/test.png?rev=895242&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/wookie/trunk/widgets/localetest/locales/fr/Images/test.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/wookie/trunk/widgets/localetest/locales/fr/index.htm
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/fr/index.htm?rev=895242&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/locales/fr/index.htm (added)
+++ incubator/wookie/trunk/widgets/localetest/locales/fr/index.htm Sat Jan 2 17:19:56 2010
@@ -0,0 +1,3 @@
+<p>Bonjour tout le Monde!</p>
+
+<p><img src="Images/test.png"/></p>
\ No newline at end of file
Added: incubator/wookie/trunk/widgets/localetest/locales/index.htm
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/localetest/locales/index.htm?rev=895242&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/localetest/locales/index.htm (added)
+++ incubator/wookie/trunk/widgets/localetest/locales/index.htm Sat Jan 2 17:19:56 2010
@@ -0,0 +1,3 @@
+<p>Hello World! (non-localized)</p>
+
+<p><img src="Images/test.png"/></p>
\ No newline at end of file