openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1042259 - in /openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest: jest.css jest.html jest.js
Date Sat, 04 Dec 2010 23:05:32 GMT
Author: ppoddar
Date: Sat Dec  4 23:05:32 2010
New Revision: 1042259

URL: http://svn.apache.org/viewvc?rev=1042259&view=rev
Log:
OPENJPA-1851: Pretty print XML

Modified:
    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/jest.html
    openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js

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=1042259&r1=1042258&r2=1042259&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
Sat Dec  4 23:05:32 2010
@@ -201,3 +201,32 @@ p.small {
 .ref {
 	color : blue;
 }
+.delimiter {
+  color:lightgray;
+  font-weight:bold;
+}
+.attr-name {
+	color:gray;
+}
+.attr-value {
+	color:green;
+}
+.node-value {
+	font-weight:bold;
+}
+.entity {
+	font-weight:bold;
+}
+.metamodel {
+	font-weight:bold;
+}
+
+.instances {
+	font-weight:bold;
+}
+.instance {
+	font-weight:bold;
+}
+
+
+	
\ No newline at end of file

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html?rev=1042259&r1=1042258&r2=1042259&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.html
Sat Dec  4 23:05:32 2010
@@ -269,8 +269,8 @@ The response always contains the <em>clo
 <!--    Command window for browsing persistent domain model                          
    -->
 <!-- ====================================================================================
-->
 <div id="domain"  class="highlight" style="display:none;" dojoType="dijit.TitlePane" 
-  title='<b><a href="http://openjpa.apache.org/jest-syntax.html" target="_blank">Browse</a>

-  persistent domain model.</b>'>
+  title='<a href="http://openjpa.apache.org/jest-syntax.html" target="_blank">Browse</a>

+  <b>persistent domain model.</b>'>
   
 	This command accepts no qualifier or arguments.	 <br>
 	
@@ -282,8 +282,8 @@ The response always contains the <em>clo
 <!--    Command window for viewing configuration of the persistence unit.            
    -->
 <!-- ====================================================================================
-->
 <div id="properties"  class="highlight" style="display:none;" dojoType="dijit.TitlePane"

- title='<b><a href="http://openjpa.apache.org/jest-syntax.html" target="_blank">View</a>

- configuration properties of the persistence unit.</b>'>
+ title='<a href="http://openjpa.apache.org/jest-syntax.html" target="_blank">View</a>

+ <b>configuration properties of the persistence unit.</b>'>
  
 	This command accepts no qualifier or arguments	 <br>
 		 

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js?rev=1042259&r1=1042258&r2=1042259&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
Sat Dec  4 23:05:32 2010
@@ -607,24 +607,22 @@ function getSupportedDisplayModes(/*enum
 function render(/* string */ uri, /* id */ targetId, /* enum */contentType, /* enum */iformat)
{
     var targetNode = dojo.byId(targetId);
     clearElement(targetId);
-    var handleAsJSON = (iformat == 'json' && contentType == 'instances');
-    console.log("render(): content [" + contentType + "] response format [" + iformat + "]
json? " + handleAsJSON);
+
     //The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
     var xhrArgs = {
         url: uri,
         handleAs: (iformat == 'json' && contentType == 'instances') ? 'json' : 'xml',
-        preventCache: true,
+        preventCache: contentType == 'instances',
         timeout : 1000,
         load: function(data, ioargs) {
-    		var displayModes = getSupportedDisplayModes(iformat, contentType);
     		var newDivs = null;
         	if (iformat == 'json') {
         		newDivs = renderJSONResponse(data, contentType);
         	} else {
         		newDivs = renderXMLResponse(data, contentType);
         	} 
-        	var displayMode = createDisplayModeControl(displayModes);
-        	targetNode.appendChild(displayMode);
+    		var displayModes = getSupportedDisplayModes(iformat, contentType);
+        	targetNode.appendChild(createDisplayModeControl(displayModes));
         	for (var i = 0; i < newDivs.length; i++) {
         		targetNode.appendChild(newDivs[i]);
         	}
@@ -710,7 +708,6 @@ function createModeSwitchFunction(/* str
 function renderXMLResponse(/*XML DOM*/dom, /*enum*/contentType) {
 	var displayModes = getSupportedDisplayModes('xml', contentType);
 	var newDivs = new Array(displayModes.length);
-	console.log("Display formats [" + displayModes + " Content Type [" + contentType + "]");
 	for (var i = 0; i < displayModes.length; i++) {
 		var displayMode = displayModes[i];
 		if (displayMode == 'xml') {
@@ -986,15 +983,129 @@ function createEntityTypeDojoWidget(node
  */
 function renderXMLasXML(/*XML DOM*/dom) {
 	var newDiv = document.createElement('div');
-	var pre    = document.createElement('pre');
-	newDiv.appendChild(pre);
-	// replace all < character to &lt; so that they display properly
-	var replaced = dojox.xml.parser.innerXML(dom).replace(/</g, '&lt;');
-	pre.innerHTML = replaced;
+//	var pre    = document.createElement('pre');
+//	newDiv.appendChild(pre);
+//	// replace all < character to &lt; so that they display properly
+//	var replaced = dojox.xml.parser.innerXML(dom).replace(/</g, '&lt;');
+//	pre.innerHTML = replaced;
+	
+	print(dom.documentElement, newDiv, 0);
 	return newDiv;
 }
 
 /**
+ * Renders a XML DOM node as a new child of the given HTML node.
+ * 
+ * CSS styles used: 
+ * node-value : The value of a text node
+ * attr-name  : The name of an attribute
+ * attr-value : The value of an attribute
+ * delimiter  : symbols such = " < \ > used in visual XML
+ * the XML element name : e.g. A <metamodel> tag will be decorated with .metamodel
CSS style    
+ *  
+ */
+function print(/* XML node */xnode, /* HTML node*/ hnode, /*int*/counter) {
+	if (xnode.nodeName == '#text') {
+		addTextNode(hnode, xnode.nodeValue, "node-value");
+		return;
+	}
+	var root = document.createElement('div');
+	root.style.position = 'relative';
+	root.style.left = '2em';
+	addRoot(xnode, hnode, root, ++counter);
+	
+	var attrs = xnode.attributes;
+	if (attrs) {
+	 	for (var i = 0; i < attrs.length; i++) {
+			var attr = attrs[i];
+			addTextNode(root, ' ' + attr.nodeName, "attr-name");
+			addDelimiter(root, '=');
+			addTextNode(root, '"' + attr.nodeValue + '"', "attr-value");
+		}
+	 	addDelimiter(root, '>');
+	}
+	var children = xnode.childNodes;
+	if (children) {
+		for (var i = 0; i < children.length; i++) {
+			print(children[i], root, ++counter);
+		}
+	}
+	addDelimiter(root, '</');
+	addTextNode(root, xnode.nodeName, xnode.nodeName);
+	addDelimiter(root, '>');
+    return;	
+}
+
+/**
+ * Adds the given delimiter text with CSS style 'delimiter' to the given parent node
+ * @param parentNode
+ * @param text
+ */
+function addDelimiter(/* HTML node*/ parentNode, /* Delimiter String*/ delim) {
+	addTextNode(parentNode, delim, 'delimiter');
+}
+/**
+ * Adds a <span> node of given className to the given parentNode with the given text.
+ * 
+ * @param parentNode the parent node to which new text is added as a <span> element.
+ * @param text text to be added to the new <span> element
+ * @param className class of the new <span> element
+ * @returns the new <span> node
+ */
+function addTextNode(/* HTML node*/parentNode, /* String */text, /* String*/className) {
+	if (isEmpty(text)) return null;
+	newNode = document.createElement('span');
+	if (className) {  
+		newNode.className  = className;
+	}
+	if (text) { 
+		newNode.appendChild(document.createTextNode(text)); 
+	}
+	if (parentNode) { 
+		parentNode.appendChild(newNode); 
+	}
+	return newNode;		
+}
+function isTextNode(/* XML node */ xnode) {
+	return xnode == null || xnode.nodeName == '#text';
+}
+
+function isTogglable(/* XML node */ xnode) {
+	if (xnode == null) return false;
+	if (isTextNode(xnode)) return false;
+	var children = xnode.childNodes;
+	if (children == null || children.length == 0) return false;
+	if (children.length == 1 && isTextNode(children[0])) return false;
+	return true;
+}
+
+function addRoot(xnode, hnode, root, counter) {
+   if (isTogglable(xnode)) {
+	   hnode.appendChild(document.createElement('br'));
+		var ctrl = addTextNode(hnode, '-');
+		root.setAttribute("id", counter);
+		var moniker = '&lt;' + xnode.nodeName + '&gt;...';
+		ctrl.setAttribute("onclick", 'javascript:toggle(this, "' + moniker + '", "' + counter +
'");');
+   } 
+   addDelimiter(root, '<');
+   addTextNode(root, xnode.nodeName, xnode.nodeName);
+   hnode.appendChild(root);
+   
+}
+
+function toggle(/* HTML node */ctrl, /* id */ moniker, /* id */ targetId) {
+	var visible = ctrl.innerHTML == '-';
+	ctrl.innerHTML = visible ? '+' + moniker : '-';
+	var target = document.getElementById(targetId);
+	if (visible) {
+		target.style.display = "none";
+	} else {
+		target.style.display = "block";
+	}
+}
+
+
+/**
  * Renders server response of JSON objects.
  * Server sends always an array of JSON objects.
  * @param json an array of hopefully non-empty array of JSON objects



Mime
View raw message