incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1043469 - in /sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling: explorer/js/ servlet/default/explorer/
Date Wed, 08 Dec 2010 16:01:55 GMT
Author: clemens
Date: Wed Dec  8 16:01:55 2010
New Revision: 1043469

URL: http://svn.apache.org/viewvc?rev=1043469&view=rev
Log:
fixing SLING-1890 "JCR Explorer - improvements"

Modified:
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/explorer/js/explorer.js
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/edit.esp
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/explorer.esp
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/item.esp
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/node.esp
    sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/search.esp

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/explorer/js/explorer.js
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/explorer/js/explorer.js?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/explorer/js/explorer.js
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/explorer/js/explorer.js
Wed Dec  8 16:01:55 2010
@@ -19,6 +19,9 @@
  
 /** replace the default get and post jQuery utility functions */
 (function($) {
+	$.ajaxSetup({
+	   timeout: 5 * 60 * 1000 // in ms, 5 minutes
+	});
     $.getRaw = $.get;
     $.getJSONRaw = $.getJSON;
     $.postRaw = $.post;
@@ -50,21 +53,28 @@ init_load = function(path) {
 		type: 'GET',
 		// data: params,
 		success: function( data, textStatus, xmlHttpRequest ) {
+			try
+			{
 				// load others
-            var paths = path.split("/");
-            paths.splice(0, 1); // remove first slash
-            var rPath = "";
-            for (p in paths) {
-                rPath += paths[p];
-                load_branch(rPath);
-                rPath += "/";
-            }
+				var paths = path.split("/");
+				paths.splice(0, 1); // remove first slash
+				var rPath = "";
+				for (p in paths) {
+					rPath += paths[p];
+					load_branch(rPath);
+					rPath += "/";
+				}
 
-            // load properties
-            load_props( path );
+				// load properties
+				load_props( path );
+			}
+			catch(e)
+			{
+				show_error( e );
+			}
 		},
 		error: function( xmlHttpRequest, textStatus, errorThrown ) {
-			show_error( xmlHttpRequest.responseText );
+			show_error( "(" + textStatus + ")" + xmlHttpRequest.responseText );
 		}
 	});
 }
@@ -82,10 +92,9 @@ explorer_toggle = function( path ) {
     }
     else
     {
-        // toggle
-          
+        // toggle          
         if (is_open) {
-            // remove children
+            // close, i.e. remove children
             $('p#'+id).parent().find('ul').each(function(){
                 $(this).empty();
                 this.parentNode.removeChild( this )
@@ -94,14 +103,24 @@ explorer_toggle = function( path ) {
             $('p#'+id).parent().removeClass('branch'); // remove css class    
             load_props( path );
         } else {
+			// just reload properties
             load_branch(path, function(){ load_props( path ); });
         }
     }
 }
 
+var loadingbranch = false;
+var lastloaded = null;
+
 /** load branch/subtree **/
 load_branch = function( path, callback, reload ) {
-	if (path != '') {
+	if ( loadingbranch ) {
+		alert("busy...");
+		return;
+	}
+	if ( path != '' ) 
+	{
+		loadingbranch = true;
 		var id = path_2_id( path );
 		$('p#' + id + ">a").removeAttr('href'); // remove onclick
 
@@ -115,27 +134,47 @@ load_branch = function( path, callback, 
             url: uri,
             type: 'GET',
             success: function( data, textStatus, xmlHttpRequest ) {
-                if ( data.length > 0 ) {
-                    $('p#' + id).parent().addClass('branch'); // add css class
-                    if ( reload )
-                    {
-                        $('ul', $('p#' + id).parent()).remove();
-                    }
-                    $('p#' + id).after(data); // add data
-                    $('p#' + id + ">a").attr('href', "#"); // reactivate onclick
-                    $('p#' + id + ">a").addClass('open'); // open
-                    $('p#' + id).addClass('loaded');
-                    if ( callback ) { callback() };
-                }
+				try
+				{
+					if ( data.length > 0 ) {
+						$('p#' + id).parent().addClass('branch'); // add css class
+						if ( reload )
+						{
+							$('ul', $('p#' + id).parent()).remove();
+						}
+						$('p#' + id).after( data ); // add data
+						$('p#' + id + ">a").attr('href', "#"); // reactivate onclick
+						$('p#' + id + ">a").addClass('open'); // open
+						$('p#' + id).addClass('loaded');
+						lastloaded	= path;
+						if ( callback ) {
+							loadingbranch = false;
+							callback() 
+						};
+					}
+				}
+				catch(e)
+				{
+					show_error( e + data );
+				}
+
             },
             error: function( xmlHttpRequest, textStatus, errorThrown ) {
-                show_error( xmlHttpRequest.responseText );
-            }
+                show_error( "(" + textStatus + ")" + xmlHttpRequest.responseText );
+            },
+			complete: function( xmlHttpRequest, textStatus) {
+				loadingbranch = false;
+				if ( textStatus.equals("timeout") )
+				{
+					show_error("Timeout!");
+				}
+			}
         });
 	}
 }
 
 var currentPath = null;
+
 load_props = function( path ) {
     var id = path_2_id( path );
     $('#expl_content').data("currently_selected_node", id);
@@ -176,26 +215,54 @@ add_prop = function( node ) {
 		type: 'POST',
 		data: params,
 		success: function( data, textStatus, xmlHttpRequest ) {
-			reload_properties();
+			try
+			{
+				reload_properties();
+			}
+			catch(e)
+			{
+				show_error( e );
+			}
+
 		},
 		error: function( xmlHttpRequest, textStatus, errorThrown ) {
-			show_error( xmlHttpRequest.responseText );
+			show_error( "(" + textStatus + ")" + xmlHttpRequest.responseText );
 		}
 	});
 }
 
 search = function( language, expression, page ) {
+	if ( page != null )
+	{
+		// $('#sql_search_result').html( "" );
+		// adjust_height();
+	}
+	$('#searchButton').attr("value", "Please Wait...");
+	$('#searchButton').attr('disabled', true);
 	// search and load search results
 	$.ajax({
 		url: "/.explorer.search.html",
 		type: 'GET',
 		data: { "language" : language, "expression" : expression, "page" : page },
 		success: function( data, textStatus, xmlHttpRequest ) {
-			$('#sql_search_result').html( data );
-			adjust_height();
+			try
+			{
+				$('#sql_search_result').html( data );
+				adjust_height();
+			}
+			catch(e)
+			{
+				show_error( e );
+			}
+
 		},
 		error: function( xmlHttpRequest, textStatus, errorThrown ) {
-			show_error( xmlHttpRequest.responseText );
+			
+			show_error( "(" + textStatus + ")" + xmlHttpRequest.responseText );
+		},
+		complete: function( xmlHttpRequest, textStatus) {
+			$('#searchButton').attr("value", "Execute!");
+			$('#searchButton').removeAttr('disabled');
 		}
 	});
 }
@@ -216,8 +283,15 @@ expand_tree = function( path, callback )
 			var id = path_2_id( partialPath ); // replacing / with _
 			if (($('p#' + id).length === 0) || !$('p#' + id).hasClass('loaded'))
 			{
-				// asynchronous recursion: expand_tree is re-called after ajax call has finished
-				load_branch( partialPath, function() { expand_tree( path, callback ); } );
+				if ( partialPath == lastloaded )
+				{
+					show_error("failed to expand path " + partialPath);
+				}
+				else
+				{
+					// asynchronous recursion: expand_tree is re-called after ajax call has finished
+					load_branch( partialPath, function() { expand_tree( path, callback ); } );
+				}
 				return;
 			}
 		}
@@ -233,10 +307,15 @@ path_2_id = function( path ) {
         id = id.replace(/^_/, ""); // remove trailing _
     }
 	id = id.replace(/\./g, '_');// due to the css selectors
+	id = id.replace(/\,/g, '_');// due to the css selectors
 	id = id.replace(/:/g, '_');// due to the css selectors
 	id = id.replace(/\[/g, '_');// due to the css selectors
 	id = id.replace(/\]/g, '_');// due to the css selectors
     id = id.replace(/\+/g, '_');// due to the css selectors
+	id = id.replace(/\-/g, '_');// due to the css selectors
+	id = id.replace(/\(/g, '_');// due to the css selectors
+	id = id.replace(/\)/g, '_');// due to the css selectors
+	id = id.replace(/\s/g, '_');// due to the css selectors
 	return id;
 }
 

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/edit.esp
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/edit.esp?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/edit.esp
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/edit.esp
Wed Dec  8 16:01:55 2010
@@ -84,7 +84,7 @@
 				<fieldset>
 					<label for="<%= mixinTypesId %>"><%= mixinTypesId %></label>
 					<%	
-					create_multivalueinput_for_type( mixinTypesId, "Name", mixinTypes, false );
+					create_multivalueinput_for_type( mixinTypesId, Packages.javax.jcr.PropertyType.NAME,
mixinTypes, false );
 					%>
 					<% if (canModifyProperties) { %>
 						<select id="<%= mixinTypesId %>_new_entry" >
@@ -102,12 +102,17 @@
 			</form>
 		</div>
 	<%  
-	}	
-    var propKeys = properties.keySet().toArray();
-	if ( (propKeys.length > 0) || canModifyProperties ) { %>
+	}
+	// sort properties
+	var propKeys = Packages.java.util.Arrays.asList( properties.keySet().toArray() );
+	Packages.java.util.Collections.sort( propKeys );
+	propKeys = propKeys.toArray();
+	if ( (propKeys.length > 0) || canModifyProperties ) 
+	{ 
+%>
 		<h3>properties</h3>
-	<%
-		for (var idx in propKeys) {
+<%
+		for ( var idx in propKeys ) {
 			var id = propKeys[idx];
 			var isProperty = false;
 			var isMultivalueProperty = false;
@@ -128,21 +133,30 @@
 			<div id="property_element_<%= id %>" class="<% if ( isMultivalueProperty )
{%> multivalued <% } %> property_element">
 			<form id="properties_form_<%= id %>" action="<%=path%>" method="post">
 				<fieldset>
-					<label for="<%= id %>"><%= id %> [ <%= type %> <% if ( isMultivalueProperty
) {%>MULTIVALUE<% } %>] </label>
-					<% if ( isMultivalueProperty ) 
-					{  
-						create_multivalueinput_for_type( id, type, val, true );
-					} else { 
-						if ( isProperty )
-						{
-							create_input_for_type( id, val.getType(), val, ( canModifyProperties && !val.getDefinition().isProtected()
), false  );
-						}
-						else {
-						%>
-							<input class="prop_value text" id="<%= id %>" name="<%= id %>" value="<%=
val %>" /> [not a property!]
-						<%
+					<label for="<%= id %>"><%= id %> 
+					<% if (isProperty) { %>
+					[ <%= type %> <% if ( isMultivalueProperty ) {%>MULTIVALUE<% } %>]
+					<% } else { %>
+					[not a property!]
+					<% } %>
+					</label>
+					<% 
+					if ( isProperty )
+					{
+						if ( isMultivalueProperty ) 
+						{					
+							create_multivalueinput_for_type( id, val.type, val, true );
+						} else { 
+							if ( isProperty )
+							{
+								create_input_for_type( id, val.getType(), val, ( canModifyProperties && !val.getDefinition().isProtected()
), false  );
+							}
 						}
-					} 
+					}	
+					else {					
+						// used to output: <input class="prop_value text" id="<%= id %>" name="<%=
id %>" value="<%= val %>" />					
+					}
+					 
 			%>
 				<input name=":redirect" type="hidden" value="<%=request.getContextPath()%><%=path%>.explorer.html">
 				</fieldset>
@@ -404,7 +418,7 @@
 		break; 
 		case Packages.javax.jcr.PropertyType.BOOLEAN : %>
 			<input type="hidden" name="<%= id %>" id="<%= id %>_cb" value="<%= val
%>" >
-			<input type="checkbox" class="checkbox" id="<%= id %>" <% if(!editable) {
%> class="protected" <%}%> <% if ( val.getBoolean() ) { %>checked<% } %>
onchange="$('[id=<%= id %>_cb]').val( this.checked ? 'true' : 'false' );">
+			<input type="checkbox" class="checkbox" id="<%= id %>" <% if ( val.getBoolean()
) { %>checked<% } %> onchange="$('[id=<%= id %>_cb]').val( this.checked ? 'true'
: 'false' );" <% if(!editable) { %> class="protected" disabled<%}%>>
 		<% 
 			break;
 		case Packages.javax.jcr.PropertyType.REFERENCE :
@@ -430,19 +444,42 @@
 	} // switch 
 } %>
     
-<% function create_multivalueinput_for_type( id, type, multivalue_property, include_add_field
) {
+<%
+function create_multivalueinput_for_type( id, type, multivalue_property, include_add_field
) {
+	var typeStr = Packages.javax.jcr.PropertyType.nameFromValue( type );
 %>
-	<input type="hidden" name="<%= id %>@TypeHint" value="<%= type %>[]" />

+	<input type="hidden" name="<%= id %>@TypeHint" value="<%= typeStr %>[]" />

 	<ul id="<%= id %>_entries">
 	<% 
 	if ( multivalue_property ) {
+		var editable = canModifyProperties && !multivalue_property.getDefinition().isProtected()
 		for ( var idx in multivalue_property.getValues() )
 		{ 
 			var entry = multivalue_property.getValues()[idx];	%>
 			<li>
 				<input type="hidden" name="<%= id %>" value="<%= entry.getString() %>"
/>
+				<%
+				switch (type)
+				{
+					case Packages.javax.jcr.PropertyType.REFERENCE :
+					case Packages.javax.jcr.PropertyType.WEAKREFERENCE :
+					case Packages.javax.jcr.PropertyType.PATH :
+						try {
+							var refNode = session.getNodeByIdentifier(entry.getQValue().getString());
+							%>
+				-&gt; <a href="#" onclick="skip_to('<%= refNode.getPath() %>');"><%=
refNode.getPath() %> (<%= refNode.getIdentifier() %>)</a> 
+ 
+							<% 
+						} catch ( ex ) {
+						}
+						break;
+					default:
+				%>
 				<%= entry.getString() %> 
-				<% if ( canModifyProperties && !multivalue_property.getDefinition().isProtected()
) { %>
+				<% 
+				} // switch
+				%>
+				<% if ( editable ) { %>
 					<a href="#" class="button" onclick="$(this).parent().remove();update_property('<%=
id %>');">delete</a>
 				<% } %>
 			</li>
@@ -453,7 +490,7 @@
 	</ul>
 	<div class="addMultivalueproperty">
 		<% if ( include_add_field && canModifyProperties && !multivalue_property.getDefinition().isProtected()
) { 
-			create_input_for_type( id+"_new_entry", type, '', true, true );
+			create_input_for_type( id+"_new_entry", typeStr, '', true, true );
 			%>
 			<a href="#" onclick="add_property_entry('<%= id %>')" class="button">add</a>
 			<div class="clear"></div>

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/explorer.esp
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/explorer.esp?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/explorer.esp
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/explorer.esp
Wed Dec  8 16:01:55 2010
@@ -23,7 +23,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 
-<title>Sling || JCR Explorer</title>
+<title>Sling || JCR Explorer 1.0.0</title>
 
 	<link rel="stylesheet" href="<%= request.getContextPath() %>/libs/sling/explorer/css/explorer.css"
type="text/css"/>
 	<link rel="stylesheet" href="<%= request.getContextPath() %>/libs/sling/explorer/css/jquery-ui.css"
type="text/css" media="all" />
@@ -109,8 +109,8 @@
 						<input type="text" class="text" name="search_expression" id="search_expression"
></input>
 						<br class="clear" />
 					</p>
-					<p>
-						<input class="button" type="submit" value="Execute!" onclick="search($('#query_language').val(),
$('#search_expression').val(), 1 ); return false;" /> 
+					<p>						
+						<input class="button" type="submit" id="searchButton" value="Execute!" onclick="search($('#query_language').val(),
$('#search_expression').val(), 1 ); return false;" /> 
 						<br class="clear" />
 					</p>					
 				</form>

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/item.esp
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/item.esp?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/item.esp
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/item.esp
Wed Dec  8 16:01:55 2010
@@ -19,51 +19,59 @@
  */
 --%>
 <%
-var nodes = request.resourceResolver.listChildren( resource );
-if (nodes.hasNext()) {
-    %>
-    <ul>
-    <%
-    while (nodes.hasNext()) {
-      var child = nodes.next();
-	var name = Packages.org.apache.sling.api.resource.ResourceUtil.getName(child);
-	
-	var path = child.path;
-	
-	var wsSepPos = path.indexOf(":/", 0);
-    if (wsSepPos != -1) {
-        path = path.substring(wsSepPos + 1);
-    }
-	
-	path = path.substr(1);
-	// WARNING: have a look at explorer.js - duplicate code!
-	var id = path.replace(/\//g, "_");
-	if ( path.length > 1 )
-    {
-        id = id.replace(/^_/, ""); // remove trailing _
-    }
-	id = id.replace(/\./g, '_');// due to the css selectors
-	id = id.replace(/:/g, '_');// due to the css selectors
-	id = id.replace(/\[/g, '_');// due to the css selectors
-	id = id.replace(/\]/g, '_');// due to the css selectors
-    id = id.replace(/\+/g, '_');// due to the css selectors
-	%>
-	<li>
-        <p id="<%= id %>">
-			<%
-				var resourceType = '';
-				var node = child.adaptTo(Packages.javax.jcr.Node);
-				if ( node && node.hasProperty( 'sling:resourceType' ) ) {
-					resourceType = node.getProperty('sling:resourceType');
-				}
+if ( resource )
+{
+	var nodes = request.resourceResolver.listChildren( resource );
+	if ( nodes && nodes.hasNext() ) 
+	{
+		%>
+		<ul>
+		<%
+		while (nodes.hasNext()) {
+			var child = nodes.next();
+			var name = Packages.org.apache.sling.api.resource.ResourceUtil.getName(child);		
+			var path = child.path;
+
+			var wsSepPos = path.indexOf(":/", 0);
+			if (wsSepPos != -1) {
+				path = path.substring(wsSepPos + 1);
+			}
+
+			path = path.substr(1);
+			// WARNING: have a look at explorer.js - duplicate code!
+			var id = path.replace(/\//g, "_");
+			if ( path.length > 1 )
+			{
+				id = id.replace(/^_/, ""); // remove trailing _
+			}
+			id = id.replace(/\./g, '_');// due to the css selectors
+			id = id.replace(/\,/g, '_');// due to the css selectors
+			id = id.replace(/:/g, '_');// due to the css selectors
+			id = id.replace(/\[/g, '_');// due to the css selectors
+			id = id.replace(/\]/g, '_');// due to the css selectors
+			id = id.replace(/\+/g, '_');// due to the css selectors
+			id = id.replace(/\-/g, '_');// due to the css selectors
+			id = id.replace(/\(/g, '_');// due to the css selectors
+			id = id.replace(/\)/g, '_');// due to the css selectors
+			id = id.replace(/\s/g, '_');// due to the css selectors
 			%>
-            <a href="#" onclick="explorer_toggle('<%= path %>', '<%= resourceType
%>')" ><%= name %></a>
-        </p>
-      </li>
+			<li>
+				<p id="<%= id %>">
+					<%
+						var resourceType = '';
+						var node = child.adaptTo(Packages.javax.jcr.Node);
+						if ( node && node.hasProperty( 'sling:resourceType' ) ) {
+							resourceType = node.getProperty('sling:resourceType');
+						}
+					%>
+					<a href="#" onclick="explorer_toggle('<%= path %>', '<%= resourceType %>')"
><%= name %></a>
+				</p>
+			  </li>
+			<%
+		} // while
+	%>
+	</ul>
 	<%
-	} // while
-%>
-</ul>
-<%
-} // if (nodes.hasNext())
+	} // if (nodes.hasNext())
+} // if (resource)
 %>
\ No newline at end of file

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/node.esp
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/node.esp?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/node.esp
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/node.esp
Wed Dec  8 16:01:55 2010
@@ -185,7 +185,7 @@
         function add_new_child_node()
         {
                 $.ajax({
-                        url: '<%=path%>/*',
+                        url: '<%=(path == '/') ? '' : path%>/*',
                         type: 'POST',
                         data: $("form[id='new_child_node_form']" ).serialize(),
                         success: function( data, textStatus, xmlHttpRequest ) 
@@ -269,44 +269,74 @@
     }
 </script>
 <% 
-    function create_input_for_type( id, type, val, editable, omitName ) { 
-            switch ( type ) { 
-                    case Packages.javax.jcr.PropertyType.DATE :                     
-                            %>
+function create_input_for_type( id, type, val, editable, omitName ) { 
+	switch ( type ) { 
+		case Packages.javax.jcr.PropertyType.DATE :                     
+%>
     <form>
       <input class="prop_value text datepicker&lt;% if(!editable) { %&gt; protected&lt;%}%&gt;"
<% if (!omitName) { %> name="<%= id %>" <% } %> id="<%= id %>" value="<%=
dateFormatter.format( val.getDate().getTime() ) %>"> <%
                       break; 
-                      case Packages.javax.jcr.PropertyType.BOOLEAN : %> <input type="hidden"
name="<%= id %>" id="<%= id %>_cb" value="<%= val %>"> <input type="checkbox"
id="<%= id %>" <% if(!editable) { %> class="protected" <%}%> <% if (
val.getBoolean() ) { %> checked <% } %> onchange="$('[id=&lt;%= id %&gt;_cb]').val(
this.checked ? 'true' : 'false' );"> <% 
-                              break;
-                      case Packages.javax.jcr.PropertyType.REFERENCE :
-                      case Packages.javax.jcr.PropertyType.WEAKREFERENCE :
-                      case Packages.javax.jcr.PropertyType.PATH :
-                              try {
-                                      var refNode = val.getNode();
-                      %> -&gt; <a href="#" onclick="skip_to('&lt;%= refNode.getPath()
%&gt;')"><%= refNode.getPath() %> (<%= refNode.getIdentifier() %>)</a>
<input class="prop_value text &lt;% if(!editable) { %&gt; protected &lt;%}%&gt;"
id="<%= id %>" <% if (!omitName) { %> name="<%= id %>" <% } %> value="<%=
val %>"> <% 
-                              } catch ( ex ) {}
-                              break;
-                      case Packages.javax.jcr.PropertyType.BINARY :
-                      %> <a class="saveAs" href="%3C%=%20path%20%%3E" target="_blank">Download
content (use "Save as...")</a> <%
-                              break;
-                      default: %> <input class="prop_value text &lt;% if(!editable)
{ %&gt; protected &lt;%}%&gt;" id="<%= id %>" <% if (!omitName) { %>
name="<%= id %>" <% } %> value="<%= val %>"> <% 
-                              break; 
-              } // switch 
-      } %> <% function create_multivalueinput_for_type( id, type, multivalue_property,
include_add_field ) {
-      %> <input type="hidden" name="<%= id %>@TypeHint" value="<%= type %>[]">
-    </form>
+		case Packages.javax.jcr.PropertyType.BOOLEAN : 
+%> <input type="hidden" name="<%= id %>" id="<%= id %>_cb" value="<%=
val %>"> <input type="checkbox" id="<%= id %>" <% if(!editable) { %>
class="protected" <%}%> <% if ( val.getBoolean() ) { %> checked <% } %>
onchange="$('[id=&lt;%= id %&gt;_cb]').val( this.checked ? 'true' : 'false' );">

+<% 
+			break;
+		case Packages.javax.jcr.PropertyType.REFERENCE :
+		case Packages.javax.jcr.PropertyType.WEAKREFERENCE :
+		case Packages.javax.jcr.PropertyType.PATH :
+			try {
+				var refNode = val.getNode();
+%> -&gt; <a href="#" onclick="skip_to('&lt;%= refNode.getPath() %&gt;')"><%=
refNode.getPath() %> (<%= refNode.getIdentifier() %>)</a> <input class="prop_value
text &lt;% if(!editable) { %&gt; protected &lt;%}%&gt;" id="<%= id %>"
<% if (!omitName) { %> name="<%= id %>" <% } %> value="<%= val %>">
<% 
+			} catch ( ex ) {}
+			break;
+		case Packages.javax.jcr.PropertyType.BINARY :
+%> <a class="saveAs" href="%3C%=%20path%20%%3E" target="_blank">Download content
(use "Save as...")</a> <%
+			break;
+		default: %> <input class="prop_value text &lt;% if(!editable) { %&gt; protected
&lt;%}%&gt;" id="<%= id %>" <% if (!omitName) { %> name="<%= id %>"
<% } %> value="<%= val %>"> <% 
+				  break; 
+	} // switch 
+}
+	  
+function create_multivalueinput_for_type( id, type, multivalue_property, include_add_field
) {
+%> 
+	<input type="hidden" name="<%= id %>@TypeHint" value="<%= type %>[]">
+	</form>
     <ul id="<%= id %>_entries">
-      <% 
-              if ( multivalue_property ) {
-                      for ( var idx in multivalue_property.getValues() )
-                      { 
-                              var entry = multivalue_property.getValues()[idx];       %>
-      <li>
-        <input type="hidden" name="<%= id %>" value="<%= entry.getString() %>">
<%= entry.getString() %> <% if ( canModifyProperties && !multivalue_property.getDefinition().isProtected()
) { %> <a href="#" class="button" onclick="$(this).parent().remove();update_property('&lt;%=
id %&gt;');">delete</a> <% } %>
-      </li><% 
-                      } // for
-              } // if
-              %>
+<% 
+	if ( multivalue_property )
+	{
+		var editable = canModifyProperties && !multivalue_property.getDefinition().isProtected()
+		for ( var idx in multivalue_property.getValues() )
+		{ 
+			var entry = multivalue_property.getValues()[idx];
+%>
+<li><input type="hidden" name="<%= id %>" value="<%= entry.getString()
%>">
+<%			
+			switch (type)
+			{
+				case Packages.javax.jcr.PropertyType.REFERENCE :
+				case Packages.javax.jcr.PropertyType.WEAKREFERENCE :
+				case Packages.javax.jcr.PropertyType.PATH :
+					try {
+						var refNode = entry.getNode();
+%> -&gt; <a href="#" onclick="skip_to('&lt;%= refNode.getPath() %&gt;')"><%=
refNode.getPath() %> (<%= refNode.getIdentifier() %>)</a> <input class="prop_value
text &lt;% if(!editable) { %&gt; protected &lt;%}%&gt;" id="<%= id %>"
<% if (!include_add_field) { %> name="<%= id %>" <% } %> value="<%= entry
%>"> <% 
+					} catch ( ex ) {}
+					break;
+				default:
+%>
+					<%= entry.getString() %> 
+<% 
+			} // switch
+			if ( editable ) 
+			{ 
+%>
+<a href="#" class="button" onclick="$(this).parent().remove();update_property('&lt;%=
id %&gt;');">delete</a> 
+<% 			
+			} // if 
+%></li>
+<% 
+		} // for
+	} // if ( multivalue_property ) 
+%>
     </ul>
     <div class="addMultivalueproperty">
       <% if ( include_add_field && canModifyProperties && !multivalue_property.getDefinition().isProtected()
) { 
@@ -318,4 +348,4 @@
     <% 
         }
     }
-    %>
+    %>
\ No newline at end of file

Modified: sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/search.esp
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/search.esp?rev=1043469&r1=1043468&r2=1043469&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/search.esp
(original)
+++ sling/trunk/bundles/extensions/explorer/src/main/resources/libs/sling/servlet/default/explorer/search.esp
Wed Dec  8 16:01:55 2010
@@ -23,10 +23,11 @@
 --%>
 <%
 var entriesPerPage = 10;
+var maxEntries = 100;
 var session = request.resourceResolver.adaptTo(Packages.javax.jcr.Session);
 if ( session )
 {
-	var expression = request.getParameter("expression");
+	var expression = unescape(request.getParameter("expression"));
 	var language = request.getParameter("language");
 	var page = parseInt(request.getParameter("page") || 1);
 	var queryManager = session.getWorkspace().getQueryManager();
@@ -38,17 +39,6 @@ if ( session )
 	var knownNumberOfHits = false;
 	if ( !countExpression.toLowerCase().match(/order\s*by/) )
 	{	
-		/* this switch does not seem to work...
-		switch ( language ) {
-			case 'JCR-SQL2' :			
-				countExpression += ' order by [jcr:score] desc';
-				break;
-			case 'xpath' :
-				countExpression += ' order by @jcr:score descending';
-				break;
-			default:
-		}; // switch
-		*/
 		if ( language == 'JCR-SQL2' ) { 
 			countExpression += ' order by [jcr:score] desc'; 
 		}
@@ -56,93 +46,125 @@ if ( session )
 			countExpression += ' order by @jcr:score descending';
 		}
 	}
-	var overallEntryCount = 'unknown';
-	var durationInMs = 'unknown';
+	var overallEntryCount = 'unknown ';
+	var durationInMs = 'unknown ';
+	var results = null;
+	var start = new Date();
 	if ( countExpression.toLowerCase().match(/order\s*by/) )
 	{
 		var countQuery = queryManager.createQuery( countExpression , language );
-		var start = new Date();
-		var results = countQuery.execute();
-		var end = new Date();
-		var durationInMs = end.getTime() - start.getTime();
+		results = countQuery.execute();
 		overallEntryCount = results.getRows().getSize();
-		knownNumberOfHits = true;
+		knownNumberOfHits = (overallEntryCount != -1);
+		overallEntryCount = knownNumberOfHits ? overallEntryCount.toString() : 'unknown';
 	}
-	%>
-	<h4>Hits: <%= overallEntryCount %> (took <%= durationInMs %>ms)</h4>
-	<%
+	else
+	{
+		var query = queryManager.createQuery( expression , language );
+		results = query.execute();
+	}
+
+	/* WE DON'T REPERFORM THE QUERY ANYMORE!
+	var query = queryManager.createQuery( expression, language );
+	if ( overallEntryCount != 'unknown')
+	{
+		query.setOffset( (page - 1) * entriesPerPage );
+		query.setLimit( entriesPerPage );
+	}
+	else
+	{
+		query.setLimit( maxEntries );
+	}
+	results = query.execute();
+	*/
 	
-	var query = queryManager.createQuery( expression, language ); 
-	query.setOffset( (page - 1) * entriesPerPage );
-	query.setLimit(entriesPerPage);
-	var results = query.execute();
-	var ri = results.getRows(); // RowIterator
 	var count = 0;
-	while ( ri.hasNext() ) {
-	    var row = ri.nextRow(); // row
-	    var score = row.getScore(); // double
-	    /*
-	    var values = row.getValues();
-	    var excerpt = '';
-	    for (idx in values)
-	    {
-	    	excerpt += (values[idx]).getString();
-	    } 
-	    */
-		var resourceType = '';
-		var node = row.getNode();
-		if ( node && node.hasProperty( 'sling:resourceType' ) ) {
-			resourceType = node.getProperty('sling:resourceType');
-		}
+	var ri = results.getRows(); // RowIterator
+	try
+	{
+		ri.skip((page - 1) * entriesPerPage);
+		var end = new Date();
+		durationInMs = end.getTime() - start.getTime();
+	%>
+	<h4>Hits: <%= overallEntryCount %> (took <%= durationInMs %>ms)</h4>

+	<%		
+		while ( ri.hasNext() && count < entriesPerPage ) {
+			var row = ri.nextRow(); // row
+			var score = row.getScore(); // double
+			var resourceType = '';
+			var node = row.getNode();
+			if ( node && node.hasProperty( 'sling:resourceType' ) ) {
+				resourceType = node.getProperty('sling:resourceType');
+			}
 %>
 <li>
 <a href="#" onclick="skip_to('<%= row.getPath() %>', '<%= resourceType %>')"><%=
row.getPath() %></a> (score: <%= score %>)
 </li>
 <%	    
-		count++;
-	} // while
+			count++;
+		} // while		
+	}
+	catch( noSuchElementException )
+	{
+	}
+
 	var moreToCome = (count == entriesPerPage);
+	var lastPage = 0;
 	if ( knownNumberOfHits )
 	{
-		var lastPage = Math.round(overallEntryCount / entriesPerPage) + (((overallEntryCount %
10) < 5 && (overallEntryCount % 10) > 0)  ? 1 : 0);
+		lastPage = Math.round(overallEntryCount / entriesPerPage) + (((overallEntryCount % 10)
< 5 && (overallEntryCount % 10) > 0)  ? 1 : 0);
 		moreToCome = ((lastPage > 0) && lastPage != page);
 	}
 
 %>
 </ul>
 <div id="page_navigation">
-<% if (page > 1) { %>
+<% 
+	if (page > 1) { 
+%>
 	<a href="#" class="button" id="first_page" title="first page">|&lt;</a>

 	<a href="#" class="button" id="previous_page" title="previous page">
 	<%= ((page - 2) * entriesPerPage) + 1 %>..<%= ((page - 1) * entriesPerPage) %>
 	</a> 
 <script>
 $('#previous_page').click( function(e) {
-	search('<%= language %>', '<%= expression %>', <%= page - 1 %> );
+	search('<%= language %>', '<%= escape(expression) %>', <%= page - 1 %>
);
 });
 $('#first_page').click( function(e) {
-	search('<%= language %>', '<%= expression %>', 1 );
+	search('<%= language %>', '<%= escape(expression) %>', 1 );
 });
 </script>	
-<% } %>
+<% 
+	} // if (page > 1)
+%>
+
 <%= ((page - 1) * entriesPerPage) + 1 %>..<%= ((page - 1) * entriesPerPage) + count
%>
-<% if ( moreToCome ) { %>
+<% 
+	if ( moreToCome ) 
+	{		
+%>
 <a href="#" class="button" id="next_page" title="next page">
 <%= (page * entriesPerPage) + 1 %>..<%= ((page + 1) * entriesPerPage) %>
 </a>
-<% if (lastPage) { %>
+<% 
+		if (lastPage > 0) { 
+%>
 <a href="#" class="button" id="last_page">&gt;|</a>
-<% } %>
+<% 
+		} 
+%>
 </div>
 <script>
-$('#next_page').click( function(e) {
-	search('<%= language %>', '<%= expression %>', <%= page + 1 %> );
-});
-$('#last_page').click( function(e) {
-	search('<%= language %>', '<%= expression %>', <%= lastPage %> );
-});
-</script>
+	$('#next_page').click( function(e) {
+		search('<%= language %>', '<%= escape(expression) %>', <%= page + 1 %>
);
+	});
+<% if (lastPage > 0) { %>	
+	$('#last_page').click( function(e) {
+		search('<%= language %>', '<%= escape(expression) %>', <%= lastPage %>
);
+	});
 <% } %>
-<%
+</script>
+<% 
+	} // if (moreToCome)
 } // if	
 %>



Mime
View raw message