Author: ppoddar
Date: Sun Nov 21 06:07:47 2010
New Revision: 1037388

URL: http://svn.apache.org/viewvc?rev=1037388&view=rev
Log:
OPENJPA-1851: Consolidate representation templates

Modified:
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/DojoFormatter.java
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLElement.java
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/index.html
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
    
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/DojoFormatter.java
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/DojoFormatter.java?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/DojoFormatter.java
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/DojoFormatter.java
 Sun Nov 21 06:07:47 2010
@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.Collections;
 
 import org.apache.openjpa.lib.util.Localizer;
+import static org.apache.openjpa.persistence.jest.HTMLElement.*;
 
 /**
  * Creates HTML document with Dojo JavaScript.
@@ -33,15 +34,34 @@ import org.apache.openjpa.lib.util.Local
  *
  */
 public class DojoFormatter extends XMLFormatter  {
-    private static final Localizer _loc = 
Localizer.forPackage(DojoFormatter.class);
     public static final String MIME_TYPE = "text/html";
+    public static final String DOJO_URL = 
"http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js";;
+    public static final String DOJO_CSS_URL = 
"http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/";; 
+    public static final String DOJO_THEME = "claro";
     static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 
4.01//EN\""
                           + " \"http://www.w3.org/TR/html4/strict.dtd\";>";
-    static String DOJO        = _loc.get("dojo-lib").toString(); 
-    static String DOJO_THEME  = _loc.get("dojo-theme").toString();
-    static String DOJO_CONFIG = _loc.get("dojo-config").toString();
-    static String DOJO_INSTANCE = _loc.get("javascript-instances").toString();
+    /**
+     * dojo Cascaded StyleSheet.
+     */
+    static HTMLElement CSS_DOJO = new HTMLElement("link").set(
+         "rel", "stylesheet", 
+         "type", "text/css", 
+         "href", DOJO_CSS_URL + DOJO_THEME + '/' + DOJO_THEME + ".css");
     
+    /**
+     * dojo JavaScript library.
+     */
+    static HTMLElement JS_DOJO = new HTMLElement("script").set(
+         "src",       DOJO_URL, 
+         "type",     "text/javascript", 
+         "djConfig", "parseOnLoad:true, isDebug:true");
+    
+    private static final HTMLElement TEMPLATE_DOJO = new HTMLElement("html", 
true).add(
+        new HTMLElement("head").add(JS_DOJO, JS_INSTANCE, CSS_DOJO, CSS_JEST),
+        new HTMLElement("body", true).set("class", DOJO_THEME)
+           .add(new HTMLElement("div").set("id", "canvas"), 
+                new HTMLElement("div", true).set("id", "data", "style", 
"display: none;")));
+
     @Override
     public String getMimeType() {
         return MIME_TYPE;
@@ -49,8 +69,6 @@ public class DojoFormatter extends XMLFo
 
     @Override
     public void configure(String key, Object value) {
-        // TODO Auto-generated method stub
-        
     }
 
     @Override
@@ -68,21 +86,8 @@ public class DojoFormatter extends XMLFo
             throw new ProcessingException(e);
         }
         writer.println(DOCTYPE);
-        HTMLElement html = createHTML();
-        writer.println(html);
+        writer.println(TEMPLATE_DOJO);
         super.encode(objs, ctx);
-        writer.println(html.end());
+        writer.println(TEMPLATE_DOJO.end());
     }
-    
-    public HTMLElement createHTML() {
-        HTMLElement html = new HTMLElement("html", true).add(
-            new HTMLElement("head")
-                .add(new HTMLElement("script").set("src", DOJO, "type", 
"text/javascript", "djConfig", DOJO_CONFIG),
-                     new HTMLElement("script").set("src", DOJO_INSTANCE, 
"type", "text/javascript"),
-                     new HTMLElement("link").set("rel", "stylesheet", "type", 
"text/css", "href", DOJO_THEME)),
-            new HTMLElement("body", true).set("class", "claro")
-               .add(new HTMLElement("div").set("id", "canvas"), 
-                 new HTMLElement("div", true).set("id", "data", "style", 
"display: none;")));
-        return html;
-    }    
 }

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLElement.java
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLElement.java?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLElement.java
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/HTMLElement.java
 Sun Nov 21 06:07:47 2010
@@ -28,6 +28,14 @@ import java.util.Map;
 
 /**
  * An utility to write HTML elements.
+ * A HTMLElement consists of a tag, zero or more attributes, zero or more 
children HTMLElement and an optional body.
+ * <br> 
+ * <code>toString()</code> on HTMLElement returns a well-formed HTML text. 
+ * A HTMLElement can be <em>open</em>, and in that case, the tags are not 
closed. This is useful when a parent
+ * tag can be filled in with some other data and then it can be {...@linkplain 
#end() closed} the open tags.
+ * <p>
+ * 
+ * Also maintains a set of constant elements used throughout the dynamically 
generated pages.
  * 
  * @author Pinaki Poddar
  *
@@ -46,18 +54,43 @@ public class HTMLElement {
     private static char QUOTE = '"';
     private static String NEWLINE = "\r\n";
     
-    public static HTMLElement JEST_CSS = new HTMLElement("link").set("rel", 
"stylesheet", "type", "text/css", 
-        "href", "jest.css");
+    /**
+     * JEST Cascaded StyleSheet.
+     */
+    public static HTMLElement CSS_JEST = new HTMLElement("link").set("rel", 
"stylesheet", "type", "text/css", 
+         "href", "jest.css");
+    
+    /**
+     * JavaScript to render object graph using dojo widgets.
+     */
+    static HTMLElement JS_INSTANCE = new HTMLElement("script").set("src", 
"instances.js", "type", "text/javascript");
 
+    /**
+     * Create an element with the given tag which will close itself.
+     * 
+     * @param tag name of the element such as <code>div</code> or 
<code>tr</code>
+     */
     public HTMLElement(String tag) {
         this(tag, false);
     }
     
+    /**
+     * Create an element with the given tag.
+     * 
+     * @param tag name of the element such as <code>div</code> or 
<code>tr</code>
+     * @param open flags if the tag will be open.
+     */
     public HTMLElement(String tag, boolean open) {
         this.tag = tag;
         this.open = open;
     }
     
+    /**
+     * Sets attributes of this element.
+     * 
+     * @param pairs must be even number of key-value pair.
+     * @return this element for chaining
+     */
     public HTMLElement set(String... pairs) {
         if (pairs == null)
             return this;
@@ -70,12 +103,24 @@ public class HTMLElement {
         return this;
     }
     
+    /**
+     * Sets the text content of this element.
+     * @return this element for chaining
+     */
     public HTMLElement setBody(String b) {
         body = b;
         return this;
     }
     
+    /**
+     * Adds the given children.
+     * 
+     * @param children one or more HTMLElelement as children.
+     * @return this element for chaining
+     */
     public HTMLElement add(HTMLElement... children) {
+        if (children == null || children.length == 0)
+            return this;
         if (_children == null) {
             _children = new ArrayList<HTMLElement>();
         }
@@ -84,6 +129,11 @@ public class HTMLElement {
         return this;
     }
     
+    /**
+     * Produces a string as end tags of the open tags in correct order.
+     * 
+     * @return
+     */
     public String end() {
         StringBuilder buf = new StringBuilder();
         if (_children != null) {
@@ -96,6 +146,9 @@ public class HTMLElement {
         return buf.toString();
     }
     
+    /**
+     * A string representation of the given element and all its children 
recursively.
+     */
     public String toString() {
         StringBuilder buf = new StringBuilder();
         buf.append(START).append(tag);
@@ -124,5 +177,4 @@ public class HTMLElement {
         }
         return buf.toString();
     }
-    
 }

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
 Sun Nov 21 06:07:47 2010
@@ -66,15 +66,15 @@ public class ProcessingException extends
         response.setContentType("text/html");
         response.setStatus(_errorCode);
         PrintWriter writer = response.getWriter();
-        createPage(writer);
+        writeHTML(writer);
     }
     
-    public void createPage(PrintWriter writer) {
+    public void writeHTML(PrintWriter writer) {
         HTMLElement html = new HTMLElement("html")
            .add(new HTMLElement("head")
-               .add(HTMLElement.JEST_CSS), 
+               .add(HTMLElement.CSS_JEST), 
                 new HTMLElement("body")
-               .add(new HTMLElement("p").set("class", 
"error-message").setBody("HTTP Error " + _errorCode), 
+               .add(new HTMLElement("p").set("class", 
"error-header").setBody("HTTP Error " + _errorCode), 
                     new HTMLElement("p").set("class", 
"error-message").setBody(getLocalizedMessage()), 
                     new HTMLElement("br").setBody("Error Stack Trace:"), 
                     new HTMLElement("pre", true)));

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/PropertiesFormatter.java
 Sun Nov 21 06:07:47 2010
@@ -30,7 +30,7 @@ import java.util.Map;
  */
 public class PropertiesFormatter {
     public HTMLElement writeHTML(String caption, String tkey, String tvalue, 
Map<String,Object> properties) {
-        return writeHTML(caption, tkey, tvalue, properties, 
HTMLElement.JEST_CSS, new String[]{"even", "odd"});
+        return writeHTML(caption, tkey, tvalue, properties, 
HTMLElement.CSS_JEST, new String[]{"even", "odd"});
     }
     
     public HTMLElement writeHTML(String caption, String tkey, String tvalue, 
Map<String,Object> properties,

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/index.html
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/index.html?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/index.html
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/index.html
 Sun Nov 21 06:07:47 2010
@@ -49,7 +49,7 @@ The documentation on JEST is available i
        <td><img alt="View"   src="images/properties.jpg"  width="100" 
height="100"></td>
 </tr>
 <tr>
-       <td><a href="javascript:switchid('deploy');">Deploy</a> </td>
+       <td><a href="javascript:switchid('deploy');">deploy</a> </td>
        <td><a href="javascript:switchid('find');">find instances</a></td>
        <td><a href="javascript:switchid('query');">query objects</a> </td>
        <td><a href="javascript:switchid('browse');">browse domain</a></td>
@@ -57,7 +57,7 @@ The documentation on JEST is available i
 </tr>
 </table>
 <p>
-<div id="deploy" style="display:none;">
+<div id="deploy" class="highlight" style="display:none;">
        You can deploy JEST as a servlet in a web application.
        <hr>
        Following <code>WEB-INF/web.xml</code> descriptor will enable JEST to
@@ -66,18 +66,18 @@ The documentation on JEST is available i
        using <code>jestdemo</code> as its persistence unit.  
        <br>
 <pre>
-&lt;servlet&gt;
-  &lt;servlet-name&gt;<span style="color:blue">jest</span>&lt;/servlet-name&gt;
-  &lt;servlet-class&gt;<span 
style="color:blue;font-weight:bold">org.apache.openjpa.persistence.jest.JESTServlet</span>&lt;/servlet-class&gt;
-       &lt;init-param&gt;
-         &lt;param-name&gt;<span 
style="color:red;font-weight:bold">persistence.unit</span>&lt;/param-name&gt;
-         &lt;param-value&gt;<span 
style="color:blue">jestdemo</span>&lt;/param-value&gt;
-       &lt;/init-param&gt;
-&lt;/servlet&gt;
-&lt;servlet-mapping&gt;
-  &lt;servlet-name&gt;<span style="color:blue">jest</span>&lt;/servlet-name&gt;
-  &lt;url-pattern&gt;<span style="color:red">/jest/*</span>&lt;/url-pattern&gt;
-&lt;/servlet-mapping&gt;
+<code class="tag">&lt;servlet&gt;</code>
+  <code class="tag">&lt;servlet-name&gt;</code>jest<code 
class="tag">&lt;/servlet-name&gt;</code>
+  <code class="tag">&lt;servlet-class&gt;</code><span 
style="color:blue">org.apache.openjpa.persistence.jest.JESTServlet</span><code 
class="tag">&lt;/servlet-class&gt;</code>
+       <code class="tag">&lt;init-param&gt;</code>
+         <code class="tag">&lt;param-name&gt;</code><span 
style="color:red;">persistence.unit</span><code 
class="tag">&lt;/param-name&gt;</code>
+         <code class="tag">&lt;param-value&gt;</code><span 
style="color:red">jestdemo</span><code class="tag">&lt;/param-value&gt;</code>
+       <code class="tag">&lt;/init-param&gt;</code>
+<code class="tag">&lt;/servlet&gt;</code>
+<code class="tag">&lt;servlet-mapping&gt;</code>
+  <code class="tag">&lt;servlet-name&gt;</code>jest<code 
class="tag">&lt;/servlet-name&gt;</code>
+  <code class="tag">&lt;url-pattern&gt;</code><span 
style="color:red">/jest/*</span><code class="tag">&lt;/url-pattern&gt;</code>
+<code class="tag">&lt;/servlet-mapping&gt;</code>
 
 </pre>
        If you deploy an application named <code>demo</code> containing the 
above JEST servlet 
@@ -89,7 +89,7 @@ The documentation on JEST is available i
                <a href="http://openjpa.apache.org/jest-usage.html"; 
target="_blank">more...</a>
 </div>
                 
-<div id="find" style="display:none;">
+<div id="find"  class="highlight" style="display:none;">
        You can find persistent objects by simple or compound primary key.
        <hr>
        
@@ -100,7 +100,7 @@ The documentation on JEST is available i
        <a href="http://openjpa.apache.org/jest-syntax.html"; 
target="_blank">more...</a>
 </div>
                 
-<div id="query" style="display:none;">
+<div id="query"  class="highlight" style="display:none;">
                 You can execute JPQL or named query with parameters.
                 <hr>
                 <code class="url">http://www.jpa.com/demo/jest/query?q=select 
p from Person p where p.name=:x&x=John</code>
@@ -115,7 +115,7 @@ The documentation on JEST is available i
                 <a href="http://openjpa.apache.org/jest-syntax.html"; 
target="_blank">more...</a>
 </div>
                 
-<div id="browse" style="display:none;">
+<div id="browse"  class="highlight" style="display:none;">
                 You can display the persistent domain model.
                 <hr>
                 <code class="url">http://www.jpa.com/demo/jest/domain</code>
@@ -125,7 +125,7 @@ The documentation on JEST is available i
                 <a href="http://openjpa.apache.org/jest-syntax.html"; 
target="_blank">more...</a>
 </div>
                 
-<div id="properties" style="display:none;">
+<div id="properties"  class="highlight" style="display:none;">
                 You can view the configuration properties of the persistence 
unit.
                 <hr>
                 <code 
class="url">http://www.jpa.com/demo/jest/properties</code>

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.css
 Sun Nov 21 06:07:47 2010
@@ -17,28 +17,35 @@
  * under the License.    
  */
 
+/** -----------------------------------------------------------------------
+ * Visible/Invisible divisions
+ * --------------------------------------------------------------------- */
 .open {
        display:block;
 }
 .close {
        display:none;
 }
-
-p {
-       font-size:1.2em;
-}
-LI {
-       font-size:1.2em;
-}
-
-
-div {
-       background-color:#F0F0F0;
+/** -----------------------------------------------------------------------
+ * Highlighted blocks
+ * --------------------------------------------------------------------- */
+.highlight {
+       background-color:#F9F9F9;
        width:60em;
        border:1px solid black;
        padding:2em 4em 2em 2em;
 }
-/* Table Styles */
+/** -----------------------------------------------------------------------
+ * XML Tag 
+ * --------------------------------------------------------------------- */
+.tag {
+       color:green;
+       font:"Courier New";
+       font-weight:bold;
+}
+/** -----------------------------------------------------------------------
+ * Table
+ * --------------------------------------------------------------------- */
 table {
        width : 70%;
        border-collapse:collapse;
@@ -51,13 +58,9 @@ th {
    background-color:black;
    color:white;
 }
-
-.error-message {
-       color:red;
-       font-weight:bold;
-       font-size:1.5em;
-}
-
+/** -----------------------------------------------------------------------
+ * Alternate Table Row
+ * --------------------------------------------------------------------- */
 tr.even td {
    background-color: #FFFFFF; color: black;
    padding:2x 20px;
@@ -69,6 +72,10 @@ tr.odd td {
        border:2px solid black;
 }
 
+/** -----------------------------------------------------------------------
+ * Hyperlinks
+ * --------------------------------------------------------------------- */
+
 a {
        target:_blank;
 }
@@ -76,10 +83,20 @@ a {
 
 .url {
        color:blue;
-       font-size:1.2em;
+       font-size:1.1em;
        font-family:"Courier New", Arial;
 }
-body
-{
-background-color:#FFFFFF;
+/** -----------------------------------------------------------------------
+ * Error Page 
+ * --------------------------------------------------------------------- */
+.error-header {
+       color:red;
+       font-size:2em;
+       font-weight:bold;
+}
+.error-message {
+       color:red;
+       font-size:1.2em;
 }
+
+

Modified: 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties?rev=1037388&r1=1037387&r2=1037388&view=diff
==============================================================================
--- 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
 (original)
+++ 
openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/localizer.properties
 Sun Nov 21 06:07:47 2010
@@ -45,11 +45,3 @@ parse-less-argument: {0} command must ha
 format-xml-null-parent: A null XML parent element encountered during 
serialization 
 format-xml-null-doc: Given parent element is not part of XML document
 format-xml-null-closure: Set of visited instances can not be null for 
serialization
-
-
-DOCTYPE: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd";>
-dojo-lib: http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js
-dojo-theme:http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css
-dojo-config:parseOnLoad:true, isDebug:true
-javascript-instances:instances.js
-jest-css:jest.css


Reply via email to