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/12/07 13:25:49 UTC
svn commit: r1043002 - in /incubator/wookie/trunk/src/org/apache/wookie:
beans/IWidget.java util/WidgetFormattingUtils.java
Author: scottbw
Date: Tue Dec 7 12:25:49 2010
New Revision: 1043002
URL: http://svn.apache.org/viewvc?rev=1043002&view=rev
Log:
Use BIDI-formatting rules for displaying human-readable widget metadata as used in the Wookie UI - title, short title, description, license etc. This is to enable us to pass W3C's i18n tests in the P&C test suite. This change affects the Widget Gallery view and the Admin views, but does not affect the REST API, which does not use the convenience methods in IWidget.
Added:
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetFormattingUtils.java
Modified:
incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java
Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java?rev=1043002&r1=1043001&r2=1043002&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java Tue Dec 7 12:25:49 2010
@@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.apache.wookie.util.WidgetFormattingUtils;
import org.apache.wookie.w3c.IW3CXMLConfiguration;
import org.apache.wookie.w3c.util.LocalizationUtils;
@@ -326,6 +327,10 @@ public interface IWidget extends IBean
/**
* Get widget title for locale.
*
+ * Note that the title is automatically formatted
+ * to use CSS BIDI properties. To get the "raw" name
+ * you should call getNames().
+ *
* @param widget widget
* @param locale locale
* @return widget title
@@ -334,11 +339,15 @@ public interface IWidget extends IBean
{
IName[] names = widget.getNames().toArray(new IName[widget.getNames().size()]);
IName name = (IName)LocalizationUtils.getLocalizedElement(names, new String[]{locale});
- return ((name != null) ? name.getName() : IW3CXMLConfiguration.UNKNOWN);
+ return ((name != null) ? WidgetFormattingUtils.getFormattedWidgetName(name) : IW3CXMLConfiguration.UNKNOWN);
}
/**
* Get widget description for locale.
+ *
+ * Note that the description is automatically formatted
+ * to use CSS BIDI properties. To get the "raw" description
+ * you should call getDescriptions().
*
* @param widget widget
* @param locale locale
@@ -348,11 +357,15 @@ public interface IWidget extends IBean
{
IDescription[] descriptions = widget.getDescriptions().toArray(new IDescription[widget.getDescriptions().size()]);
IDescription description = (IDescription)LocalizationUtils.getLocalizedElement(descriptions, new String[]{locale});
- return ((description != null) ? description.getContent() : null);
+ return ((description != null) ? WidgetFormattingUtils.getFormattedWidgetDescription(description) : null);
}
/**
* Get widget short name for locale.
+ *
+ * Note that the short name is automatically formatted
+ * to use CSS BIDI properties. To get the "raw" name
+ * you should call getNames().
*
* @param widget widget
* @param locale locale
@@ -362,7 +375,7 @@ public interface IWidget extends IBean
{
IName[] names = widget.getNames().toArray(new IName[widget.getNames().size()]);
IName name = (IName)LocalizationUtils.getLocalizedElement(names, new String[]{locale});
- return ((name != null) ? name.getShortName() : IW3CXMLConfiguration.UNKNOWN);
+ return ((name != null) ? WidgetFormattingUtils.getFormattedWidgetShortName(name) : IW3CXMLConfiguration.UNKNOWN);
}
/**
Added: incubator/wookie/trunk/src/org/apache/wookie/util/WidgetFormattingUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/WidgetFormattingUtils.java?rev=1043002&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/WidgetFormattingUtils.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/WidgetFormattingUtils.java Tue Dec 7 12:25:49 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+package org.apache.wookie.util;
+
+import org.apache.wookie.beans.IDescription;
+import org.apache.wookie.beans.ILicense;
+import org.apache.wookie.beans.IName;
+import org.apache.wookie.beans.IWidget;
+import org.apache.wookie.w3c.util.FormattingUtils;
+
+/**
+ * i18n formatting utilities
+ *
+ * The methods in this class can be used to generate i18n strings using
+ * CSS bidi properties for use in display. This involves inserting HTML
+ * <span> tags containing CSS styling properties for text direction
+ *
+ */
+public class WidgetFormattingUtils extends FormattingUtils{
+
+ /**
+ * Returns the CSS formatted i18n string for the widget name
+ * @param name the Widget's Name
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetName(IName name){
+ return getFormatted(name.getDir(), name.getName());
+ }
+ /**
+ * Returns the CSS formatted i18n string for the widget short name
+ * @param name the Widget's Name
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetShortName(IName name){
+ return getFormatted(name.getDir(), name.getShortName());
+ }
+ /**
+ * Returns the CSS formatted i18n string for the widget version
+ * @param widget the Widget
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetVersion(IWidget widget){
+ return getFormatted(widget.getVersion());
+ }
+ /**
+ * Returns the CSS formatted i18n string for the widget description
+ * @param description the Widget's description
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetDescription(IDescription description){
+ return getFormatted(description.getDir(), description.getContent());
+ }
+ /**
+ * Returns the CSS formatted i18n string for the widget author's name
+ * @param widget the Widget
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetAuthor(IWidget widget){
+ return getFormatted(widget.getWidgetAuthor());
+ }
+ /**
+ * Returns the CSS formatted i18n string for the widget license
+ * @param license the Widget's License
+ * @return a CSS-formatted i18n string
+ */
+ public static String getFormattedWidgetLicense(ILicense license){
+ return getFormatted(license.getDir(), license.getText());
+ }
+
+
+}