Reactivate OBR refresh action and add GUI elements to
add and remove repository URLs
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@671484 13f79535-47bb-0310-9956-ffa450edef68
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 222c368..58494cc 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
@@ -137,6 +137,7 @@
pw.println( "<input type='hidden' name='" + RefreshRepoAction.PARAM_REPO + "' value='" + repo.getURL()
+ "'>" );
pw.println( "<input class='submit' type='submit' value='Refresh'>" );
+ pw.println( "<input class='submit' type='submit' name='remove' value='Remove'>" );
pw.println( "</form>" );
pw.println( "</td>" );
pw.println( "</tr>" );
@@ -165,6 +166,20 @@
}
}
+ // entry of a new repository
+ pw.println( "<form>" );
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content'> </td>" );
+ pw.println( "<td class='content' colspan='2'>" );
+ pw.println( " <input class='input' type='text' name='" + RefreshRepoAction.PARAM_REPO + "' value='' size='80'>" );
+ pw.println( "</td>" );
+ pw.println( "<td class='content'>" );
+ pw.println( "<input type='hidden' name='" + Util.PARAM_ACTION + "' value='" + RefreshRepoAction.NAME + "'>" );
+ pw.println( "<input class='submit' type='submit' value='Add'>" );
+ pw.println( "</td>" );
+ pw.println( "</tr>" );
+ pw.println( "</form>" );
+
this.footer( pw );
this.listResources( pw, repos );
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/RefreshRepoAction.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/RefreshRepoAction.java
index aa495a1..7129a96 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/RefreshRepoAction.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/RefreshRepoAction.java
@@ -17,10 +17,17 @@
package org.apache.felix.webconsole.internal.obr;
+import java.net.URL;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.felix.webconsole.Action;
+import org.osgi.service.obr.Repository;
+import org.osgi.service.obr.RepositoryAdmin;
-public abstract class RefreshRepoAction extends AbstractObrPlugin implements Action
+public class RefreshRepoAction extends AbstractObrPlugin implements Action
{
public static final String NAME = "refreshOBR";
@@ -38,57 +45,86 @@
{
return NAME;
}
- /*
- public boolean performAction(HttpServletRequest request,
- HttpServletResponse response) {
- BundleRepositoryAdmin repoAdmin = getBundleRepositoryAdmin();
- if (repoAdmin != null) {
- String repositoryURL = request.getParameter("repository");
- Iterator<Repository> repos = repoAdmin.getRepositories();
- Repository repo = this.getRepository(repos, repositoryURL);
- URL repoURL = null;
- if (repo != null) {
- repoURL = repo.getURL();
- } else {
- try {
- repoURL = new URL(repositoryURL);
- } catch (Throwable t) {
- // don't care, just ignore
+ public boolean performAction( HttpServletRequest request, HttpServletResponse response )
+ {
+
+ RepositoryAdmin repoAdmin = getRepositoryAdmin();
+ if ( repoAdmin != null )
+ {
+ String repositoryURL = request.getParameter( "repository" );
+ Repository[] repos = repoAdmin.listRepositories();
+ Repository repo = this.getRepository( repos, repositoryURL );
+
+ URL repoURL = null;
+ if ( repo != null )
+ {
+ repoURL = repo.getURL();
+ }
+ else
+ {
+ try
+ {
+ repoURL = new URL( repositoryURL );
+ }
+ catch ( Throwable t )
+ {
+ // don't care, just ignore
+ }
+ }
+
+ // log.log(LogService.LOG_DEBUG, "Refreshing " + repo.getURL());
+ if ( repoURL != null )
+ {
+ if ( request.getParameter( "remove" ) != null )
+ {
+ try
+ {
+ repoAdmin.removeRepository( repoURL );
+ }
+ catch ( Exception e )
+ {
+ // TODO: log.log(LogService.LOG_ERROR, "Cannot refresh
+ // Repository " + repo.getURL());
}
}
-
- // log.log(LogService.LOG_DEBUG, "Refreshing " + repo.getURL());
- if (repoURL != null) {
- try {
- repoAdmin.addRepository(repoURL);
- } catch (Exception e) {
+ else
+ {
+ try
+ {
+ repoAdmin.addRepository( repoURL );
+ }
+ catch ( Exception e )
+ {
// TODO: log.log(LogService.LOG_ERROR, "Cannot refresh
// Repository " + repo.getURL());
}
}
}
-
- return true;
}
- // ---------- internal -----------------------------------------------------
+ return true;
+ }
- private Repository getRepository(Iterator<Repository> repos,
- String repositoryUrl) {
- if (repositoryUrl == null || repositoryUrl.length() == 0) {
- return null;
- }
- while (repos.hasNext()) {
- Repository repo = repos.next();
- if (repositoryUrl.equals(repo.getURL().toString())) {
- return repo;
- }
- }
+ // ---------- internal -----------------------------------------------------
+ private Repository getRepository( Repository[] repos, String repositoryUrl )
+ {
+ if ( repositoryUrl == null || repositoryUrl.length() == 0 )
+ {
return null;
}
- */
+
+ for ( int i = 0; i < repos.length; i++ )
+ {
+ if ( repositoryUrl.equals( repos[i].getURL().toString() ) )
+ {
+ return repos[i];
+ }
+ }
+
+ return null;
+ }
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index a45fd0b..59fbd7c 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -49,6 +49,7 @@
import org.apache.felix.webconsole.internal.misc.ConfigurationRender;
import org.apache.felix.webconsole.internal.misc.LicenseServlet;
import org.apache.felix.webconsole.internal.obr.BundleRepositoryRender;
+import org.apache.felix.webconsole.internal.obr.RefreshRepoAction;
import org.apache.felix.webconsole.internal.system.GCAction;
import org.apache.felix.webconsole.internal.system.ShutdownAction;
import org.apache.felix.webconsole.internal.system.ShutdownRender;
@@ -128,7 +129,7 @@
{ ComponentConfigurationPrinter.class, ComponentsServlet.class, ConfigManager.class, BundlesServlet.class,
InstallAction.class, SetStartLevelAction.class, ConfigurationRender.class, GCAction.class,
ShutdownAction.class, ShutdownRender.class, VMStatRender.class, BundleRepositoryRender.class,
- LicenseServlet.class };
+ LicenseServlet.class, RefreshRepoAction.class };
private BundleContext bundleContext;