Author: scottbw
Date: Thu May 30 06:28:48 2013
New Revision: 1487763
URL: http://svn.apache.org/r1487763
Log:
Made default height/width attributes configurable. See WOOKIE-401
Modified:
wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
wookie/trunk/src/org/apache/wookie/helpers/WidgetInstanceHelper.java
wookie/trunk/src/widgetserver.properties
Modified:
wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
URL:
http://svn.apache.org/viewvc/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=1487763&r1=1487762&r2=1487763&view=diff
==============================================================================
---
wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
(original)
+++
wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
Thu May 30 06:28:48 2013
@@ -136,12 +136,25 @@ public class WidgetInstancesController e
response.setStatus(HttpServletResponse.SC_OK);
//
+ // Use default sizes where none provided?
+ //
+ boolean useDefaultSizes = true;
+ Configuration properties = (Configuration)
request.getSession().getServletContext().getAttribute("properties");
//$NON-NLS-1$
+ if (properties.containsKey("widget.use_default_sizes")){
+ try {
+ useDefaultSizes =
properties.getBoolean("widget.use_default_sizes");
+ } catch (Exception e) {
+ useDefaultSizes = true;
+ }
+ }
+
+ //
// Return XML or JSON
//
switch(format(request)){
- case XML:
returnXml(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale), response); break;
- case JSON: returnJson(WidgetInstanceHelper.toJson(instance, url,
locale), response); break;
- default:
returnXml(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale), response); break;
+ case XML:
returnXml(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale, useDefaultSizes), response); break;
+ case JSON: returnJson(WidgetInstanceHelper.toJson(instance, url,
locale, useDefaultSizes), response); break;
+ default:
returnXml(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale, useDefaultSizes), response); break;
}
}
@@ -271,10 +284,23 @@ public class WidgetInstancesController e
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
+ //
+ // Use default sizes where none provided?
+ //
+ boolean useDefaultSizes = true;
+ Configuration properties = (Configuration)
request.getSession().getServletContext().getAttribute("properties");
//$NON-NLS-1$
+ if (properties.containsKey("widget.use_default_sizes")){
+ try {
+ useDefaultSizes =
properties.getBoolean("widget.use_default_sizes");
+ } catch (Exception e) {
+ useDefaultSizes = true;
+ }
+ }
+
String url = getUrl(request, instance);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
-
out.println(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale));
+
out.println(WidgetInstanceHelper.createXMLWidgetInstanceDocument(instance, url,
locale, useDefaultSizes));
}
/**
Modified: wookie/trunk/src/org/apache/wookie/helpers/WidgetInstanceHelper.java
URL:
http://svn.apache.org/viewvc/wookie/trunk/src/org/apache/wookie/helpers/WidgetInstanceHelper.java?rev=1487763&r1=1487762&r2=1487763&view=diff
==============================================================================
--- wookie/trunk/src/org/apache/wookie/helpers/WidgetInstanceHelper.java
(original)
+++ wookie/trunk/src/org/apache/wookie/helpers/WidgetInstanceHelper.java Thu
May 30 06:28:48 2013
@@ -37,14 +37,21 @@ public class WidgetInstanceHelper {
* @param locale the locale of the widget instance
* @return an XML representation of the Widget Instance as a String
*/
- public static String createXMLWidgetInstanceDocument(IWidgetInstance
instance, String url, String locale){
+ public static String createXMLWidgetInstanceDocument(IWidgetInstance
instance, String url, String locale, boolean useDefaultSizes){
String xml = XMLDECLARATION;
IWidget widget = instance.getWidget();
+
+
+ String width = null;
+ String height = null;
+
// Return a default width and height where the original value
is either not provided
// or of an invalid range (<0)
- String width =
String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
- String height =
String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+ if (useDefaultSizes){
+ width =
String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
+ height =
String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+ }
if (widget.getWidth()!=null && widget.getWidth()>0) width =
widget.getWidth().toString();
if (widget.getHeight()!=null && widget.getHeight()>0) height =
widget.getHeight().toString();
@@ -52,17 +59,23 @@ public class WidgetInstanceHelper {
xml += "\t<url>"+url+"</url>"; //$NON-NLS-1$ //$NON-NLS-2$
xml += "\t<identifier>"+instance.getIdKey()+"</identifier>\n";
//$NON-NLS-1$ //$NON-NLS-2$
xml +=
"\t<title>"+StringEscapeUtils.escapeXml(widget.getLocalName(locale))+"</title>\n";
//$NON-NLS-1$ //$NON-NLS-2$
- xml += "\t<height>"+height+"</height>\n"; //$NON-NLS-1$
//$NON-NLS-2$
- xml += "\t<width>"+width+"</width>\n"; //$NON-NLS-1$
//$NON-NLS-2$
+ if (height != null) xml += "\t<height>"+height+"</height>\n";
//$NON-NLS-1$ //$NON-NLS-2$
+ if (width != null) xml += "\t<width>"+width+"</width>\n";
//$NON-NLS-1$ //$NON-NLS-2$
xml += "</widgetdata>"; //$NON-NLS-1$
return xml;
}
- public static String toJson(IWidgetInstance instance, String url, String
locale) {
+ public static String toJson(IWidgetInstance instance, String url, String
locale, boolean useDefaultSizes) {
IWidget widget = instance.getWidget();
- String width = String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
- String height = String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+
+ String width = null;
+ String height = null;
+
+ if (useDefaultSizes){
+ width = String.valueOf(IW3CXMLConfiguration.DEFAULT_WIDTH_LARGE);
+ height = String.valueOf(IW3CXMLConfiguration.DEFAULT_HEIGHT_LARGE);
+ }
if (widget.getWidth() != null && widget.getWidth() > 0)
width = widget.getWidth().toString();
if (widget.getHeight() != null && widget.getHeight() > 0)
@@ -72,8 +85,8 @@ public class WidgetInstanceHelper {
json.put("url", url);
json.put("identifier", instance.getIdKey());
json.put("title", widget.getLocalName(locale));
- json.put("height", height);
- json.put("width", width);
+ if (height != null) json.put("height", height);
+ if (width != null) json.put("width", width);
} catch (JSONException e) {
logger.error("Problem rendering instance using JSON",e);
}
Modified: wookie/trunk/src/widgetserver.properties
URL:
http://svn.apache.org/viewvc/wookie/trunk/src/widgetserver.properties?rev=1487763&r1=1487762&r2=1487763&view=diff
==============================================================================
--- wookie/trunk/src/widgetserver.properties (original)
+++ wookie/trunk/src/widgetserver.properties Thu May 30 06:28:48 2013
@@ -6,6 +6,13 @@ widget.web.page=http://wookie.apache.org
widget.debug=true
#######################################################################
+# When set to true, Wookie will supply default values for height and
+# width for widgets where these aren't supplied in the widget metadata.
+# Set to false it will simply omit height and or width attributes when
+# returning widget instance metadata from the REST API
+widget.use_default_sizes=true
+
+#######################################################################
# By default Wookie will use the same scheme/host/port it is being
# served from when generating URLs for widgets. By changing these
# settings you can override this, for example when deploying Wookie