FELIX-2287 Improved Handling of queries on the OBR page:
- accept empty query to select all resources
- print error message if filter string is invalid
- fix WebConsoleUtil.urlDecode to return an empty string if
the value is an empty string (to be inline with the
URLDecode.decode methods).
- add resource symbolic name in parens after presentation
name to differentiate resources with the same presentation
name but different symbolic names
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@984322 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
index 5c609e4..4190d71 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -354,7 +354,7 @@
// shortcut for empty or missing values
if ( value == null || value.length() == 0 )
{
- return null;
+ return value;
}
try
@@ -375,7 +375,7 @@
* is array and will property display it.
*
* If the value is byte[] the elements are shown as Hex
- *
+ *
* @param value the value to convert
* @return the string representation of the value
*/
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
index b1ff55f..9b6ec2a 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
@@ -106,7 +106,7 @@
final ConfigurationAdmin ca = this.getConfigurationAdmin();
// ignore this request if the pid and/or configuration admin is missing
- if ( pid == null || ca == null )
+ if ( pid == null || pid.length() == 0 || ca == null )
{
// should log this here !!
return;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
index a46288b..4628b29 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
@@ -82,7 +82,7 @@
pw.print( command == null ? "" : WebConsoleUtil.escapeHtml( command ) );
pw.println( "</span><br />" );
- if ( command != null && !"".equals( command ) )
+ if ( command != null && command.length() > 0 )
{
ShellService shellService = getShellService();
if ( shellService != null )
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
index dec0c08..99a0b26 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
@@ -221,7 +221,7 @@
}
}
sb.append( ")" );
- filter = sb.toString();
+ filter = (sb.length() > 3) ? sb.toString() : null;
}
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/FelixBundleRepositoryRenderHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/FelixBundleRepositoryRenderHelper.java
index a9df5ba..16d101d 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/FelixBundleRepositoryRenderHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/FelixBundleRepositoryRenderHelper.java
@@ -56,9 +56,9 @@
RepositoryAdmin admin = ( RepositoryAdmin ) getRepositoryAdmin();
if ( admin != null )
{
+ JSONObject json = new JSONObject();
try
{
- JSONObject json = new JSONObject();
json.put( "status", admin != null );
json.put( "details", details );
@@ -76,16 +76,29 @@
json.append( "resources", toJSON( resources[i], bundles, details ) );
}
- return json.toString();
- }
- catch ( InvalidSyntaxException e )
- {
- logger.log( "Failed to parse filter.", e );
}
catch ( JSONException e )
{
logger.log( "Failed to serialize repository to JSON object.", e );
}
+ catch ( Exception e )
+ {
+ logger.log( "Failed to parse filter '" + filter + "'", e );
+ try
+ {
+ String reason = "filter=" + filter;
+ if ( e.getMessage() != null )
+ {
+ reason = e.getMessage() + "(" + reason + ")";
+ }
+ json.put( "error", reason );
+ }
+ catch ( JSONException je )
+ {
+ // ignore
+ }
+ }
+ return json.toString();
}
// fall back to no data
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/OsgiBundleRepositoryRenderHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/OsgiBundleRepositoryRenderHelper.java
index 61477b1..0efe724 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/OsgiBundleRepositoryRenderHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/OsgiBundleRepositoryRenderHelper.java
@@ -53,9 +53,9 @@
RepositoryAdmin admin = ( RepositoryAdmin ) getRepositoryAdmin();
if ( admin != null )
{
+ JSONObject json = new JSONObject();
try
{
- JSONObject json = new JSONObject();
json.put( "status", admin != null );
json.put( "details", details );
@@ -72,13 +72,30 @@
{
json.append( "resources", toJSON( resources[i], bundles, details ) );
}
-
- return json.toString();
}
catch ( JSONException e )
{
logger.log( "Failed to serialize repository to JSON object.", e );
}
+ catch ( Exception e )
+ {
+ logger.log( "Failed to parse filter '" + filter + "'", e );
+ try
+ {
+ String reason = "filter=" + filter;
+ if ( e.getMessage() != null )
+ {
+ reason = e.getMessage() + "(" + reason + ")";
+ }
+ json.put( "error", reason );
+ }
+ catch ( JSONException je )
+ {
+ // ignore
+ }
+ }
+
+ return json.toString();
}
// fall back to no data
diff --git a/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties b/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
index 5ef7777..1ea0ad9 100644
--- a/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
+++ b/webconsole/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
@@ -222,6 +222,9 @@
obr.repo.title=Bundle Repositories
obr.action.add=Hinzufügen
obr.action.search=Suchen
+obr.action.search.description=Geben Sie einen Teil des Präsentations- oder \
+ symoblischen Namens der gesuchten Bundles oder einen gültigen OSGi \
+ Filter Ausdruck
obr.action.deploy=Ausgewählte Installieren
obr.action.deploystart=Ausgewählte Installieren und Starten
obr.repo.name=Name
@@ -231,6 +234,7 @@
obr.res.title=Verfügbare Resourcen
obr.res.name=Resource Name
obr.res.installedVer=Installierte Version
+obr.error=Fehler bei der Auswahl der Resourcen
# Configuration Status plugin
configStatus.pluginTitle=Configuration Status
diff --git a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
index b194815..7df8e19 100644
--- a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -225,6 +225,8 @@
obr.repo.title=Bundle Repositories
obr.action.add=Add
obr.action.search=Search
+obr.action.search.description=Enter word contained in bundle presentation \
+ and/or symbolic name or a valid OSGi Filter Expression
obr.action.deploy=Deploy Selected
obr.action.deploystart=Deploy and Start Selected
obr.repo.name=Name
@@ -234,6 +236,7 @@
obr.res.title=Available Resources
obr.res.name=Resource Name
obr.res.installedVer=Installed Version
+obr.error=Error Filtering Resources
# Configuration Status plugin
configStatus.pluginTitle=Configuration Status
diff --git a/webconsole/src/main/resources/res/ui/obr.js b/webconsole/src/main/resources/res/ui/obr.js
index 7c40daa..58e5ffb 100644
--- a/webconsole/src/main/resources/res/ui/obr.js
+++ b/webconsole/src/main/resources/res/ui/obr.js
@@ -137,7 +137,14 @@
blockElement.appendChild(titleElement);
titleElement.appendChild(inputElement);
titleElement.appendChild(text(" "));
- titleElement.appendChild(text(res.presentationname ? res.presentationname : res.symbolicname));
+ if (res.presentationname) {
+ titleElement.appendChild(text(res.presentationname));
+ titleElement.appendChild(text(" ("));
+ titleElement.appendChild(text(res.symbolicname));
+ titleElement.appendChild(text(")"));
+ } else {
+ titleElement.appendChild(text(res.symbolicname));
+ }
$(titleElement).click(function() {showVersions(res.symbolicname)});
_tr = tr( null, { 'id' : 'row' + _id } , [
@@ -426,11 +433,17 @@
$('#detailsTable').removeClass('ui-helper-hidden');
for (var i in obrData.resources ) {
renderDetailedResource( obrData.resources[i] );
- }
- } else {
+ }
+ } else if (obrData.resources) {
for (var i in obrData.resources ) {
renderResource( obrData.resources[i] );
- }
+ }
+ } else if (obrData.error) {
+ _tr = tr( "ui-state-error", null , [
+ td( "ui-state-error-text", { 'colspan': '2' },
+ [ text(i18n.error + ": " + obrData.error) ] )
+ ]);
+ resTable.append( _tr );
}
} else {
$('.statline').html(i18n.status_no);
diff --git a/webconsole/src/main/resources/templates/obr.html b/webconsole/src/main/resources/templates/obr.html
index 19a89f5..e54283d 100644
--- a/webconsole/src/main/resources/templates/obr.html
+++ b/webconsole/src/main/resources/templates/obr.html
@@ -3,7 +3,8 @@
var i18n = {
status_ok : '${obr.status.ok}',
status_no : '${obr.status.no}',
- selectVersion : '${obr.version.select}'
+ selectVersion : '${obr.version.select}',
+ error : '${obr.error}'
}
var obrData = ${__data__};
</script>
@@ -75,7 +76,7 @@
<a href="${pluginRoot}?list=z">Z</a>
<a href="${pluginRoot}?list=-">?</a>
</span>
- <input type="text" id="searchField"/>
+ <input type="text" id="searchField" title="${obr.action.search.description}"/>
<button id="searchBtn">${obr.action.search}</button>
</div>