Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.felix.webconsole.internal.obr;
 
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 import  org.osgi.framework.Bundle;
 import  org.osgi.framework.BundleContext;
 import  org.osgi.framework.Constants;
 import  org.osgi.framework.Version;
 import  org.osgi.service.obr.Repository;
 import  org.osgi.service.obr.RepositoryAdmin;
 import  org.osgi.service.obr.Resource;
 
 
 {
 
     public static final String LABEL = "bundlerepo";
 
     public static final String TITLE = "OSGi Repository";
 
     public static final String PARAM_REPO_ID = "repositoryId";
 
     public static final String PARAM_REPO_URL = "repositoryURL";
 
     private static final String REPOSITORY_PROPERTY = "obr.repository.url";
 
     private static final String ALL_CATEGORIES_OPTION = "*";
 
     private static final String PAR_CATEGORIES = "category";
 
     private String[] repoURLs;
 
 
     public void activate( BundleContext bundleContext )
     {
         super.activatebundleContext );
 
         String urlStr = bundleContext.getProperty(  );
         List urlList = new ArrayList();
 
         if ( urlStr != null )
         {
             StringTokenizer st = new StringTokenizerurlStr );
             while ( st.hasMoreTokens() )
             {
                 urlList.addst.nextToken() );
             }
         }
 
         this. = ( String[] ) urlList.toArraynew String[urlList.size()] );
     }
 
 
     public String getLabel()
     {
         return ;
     }
 
 
     public String getTitle()
     {
         return ;
     }
 
    protected void renderContentHttpServletRequest requestHttpServletResponse response ) throws IOException
    {
        PrintWriter pw = response.getWriter();
        this.headerpw );
        RepositoryAdmin repoAdmin = getRepositoryAdmin();
        if ( repoAdmin == null )
        {
            pw.println"<tr class='content'>" );
            pw.println"<td class='content' colspan='4'>RepositoryAdmin Service not available</td>" );
            pw.println"</tr>" );
            footerpw );
            return;
        }
        Repository[] repos = repoAdmin.listRepositories();
        Set activeURLs = new HashSet();
        if ( repos == null || repos.length == 0 )
        {
            pw.println"<tr class='content'>" );
            pw.println"<td class='content' colspan='4'>No Active Repositories</td>" );
            pw.println"</tr>" );
        }
        else
        {
            for ( int i = 0; i < repos.length; i++ )
            {
                Repository repo = repos[i];
                activeURLs.addrepo.getURL().toString() );
                pw.println"<tr class='content'>" );
                pw.println"<td class='content'>" + repo.getName() + "</td>" );
                pw.print"<td class='content'>" );
                pw.print"<a href='" + repo.getURL() + "' target='_blank' title='Show Repository " + repo.getURL()
                    + "'>" + repo.getURL() + "</a>" );
                pw.println"</td>" );
                pw.println"<td class='content'>" + new Daterepo.getLastModified() ) + "</td>" );
                pw.println"<td class='content'>" );
                pw.println"<form>" );
                pw.println"<input type='hidden' name='" + . + "' value='" + .
                    + "'>" );
                pw.println"<input type='hidden' name='" + . + "' 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>" );
            }
        }
        // list any repositories configured but not active
        for ( int i = 0; i < this..lengthi++ )
        {
            if ( !activeURLs.containsthis.[i] ) )
            {
                pw.println"<tr class='content'>" );
                pw.println"<td class='content'>-</td>" );
                pw.println"<td class='content'>" + this.[i] + "</td>" );
                pw.println"<td class='content'>[inactive, click Refresh to activate]</td>" );
                pw.println"<td class='content'>" );
                pw.println"<form>" );
                pw.println"<input type='hidden' name='" + . + "' value='" + .
                    + "'>" );
                pw.println"<input type='hidden' name='" + . + "' value='"
                    + this.[i] + "'>" );
                pw.println"<input class='submit' type='submit' value='Refresh'>" );
                pw.println"</form>" );
                pw.println"</td>" );
                pw.println"</tr>" );
            }
        }
        // entry of a new repository
        pw.println"<form>" );
        pw.println"<tr class='content'>" );
        pw.println"<td class='content'>&nbsp;</td>" );
        pw.println"<td class='content' colspan='2'>" );
        pw.println"  <input class='input' type='text' name='" + .
            + "' value='' size='80'>" );
        pw.println"</td>" );
        pw.println"<td class='content'>" );
        pw.println"<input type='hidden' name='" + . + "' value='" + . + "'>" );
        pw.println"<input class='submit' type='submit' value='Add'>" );
        pw.println"</td>" );
        pw.println"</tr>" );
        pw.println"</form>" );
        this.footerpw );
        this.listResourcespwreposrequest.getParameter ) );
    }
    private void headerPrintWriter pw )
    {
        pw.println"<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
        pw.println"<tr class='content'>" );
        pw.println"<th class='content container' colspan='4'>Bundle Repositories</th>" );
        pw.println"</tr>" );
        pw.println"<tr class='content'>" );
        pw.println"<th class='content'>Name</th>" );
        pw.println"<th class='content'>URL</th>" );
        pw.println"<th class='content'>Last Modification Time</th>" );
        pw.println"<th class='content'>&nbsp;</th>" );
        pw.println"</tr>" );
    }
    private void footerPrintWriter pw )
    {
        pw.println"</table>" );
    }
    private void listResourcesPrintWriter pw, Repository[] reposString category )
    {
        // assume no category if the all option
        if ( .equalscategory ) )
        {
            category = null;
        }
        Map bundles = this.getBundles();
        Map resSet = new HashMap();
        SortedSet categories = new TreeSet();
        SortedSet labels = new TreeSet();
        for ( int i = 0; i < repos.length; i++ )
        {
            Resource[] resources = repos[i].getResources();
            for ( int j = 0; resources != null && j < resources.length; j++ )
            {
                Resource res = resources[j];
                // get categories and check whether we should actually
                // ignore this resource
                boolean useResource = false;
                String[] cats = res.getCategories();
                for ( int ci = 0; cats != null && ci < cats.lengthci++ )
                {
                    String cat = cats[ci];
                    categories.addcat );
                    useResource |= ( category == null || cat.equalscategory ) );
                }
                if ( useResource )
                {
                    String symbolicName = res.getSymbolicName();
                    Version version = res.getVersion();
                    Version installedVersion = ( Version ) bundles.getsymbolicName );
                    if ( installedVersion == null || installedVersion.compareTo( version ) < 0 )
                    {
                        Collection versions = ( Collection ) resSet.getsymbolicName );
                        if ( versions == null )
                        {
                            // order versions, hence use a TreeSet
                            versions = new TreeSet();
                            resSet.putsymbolicNameversions );
                        }
                        versions.addversion );
                        labels.addres.getPresentationName() + "§" + symbolicName );
                    }
                }
            }
        }
        boolean doForm = !resSet.isEmpty();
        this.resourcesHeaderpwdoFormcategorycategories );
        for ( Iterator ri = labels.iterator(); ri.hasNext(); )
        {
            String label = (Stringri.next();
            String[] parts = label.split"§" );
            Collection versions = (CollectionresSet.remove(parts[1]);
            if (versions != null) {
                this.printResourcepwparts[1], parts[0], versions );
            }
        }
        this.resourcesFooterpwdoForm );
    }
    private void resourcesHeaderPrintWriter pwboolean doFormString currentCategoryCollection categories )
    {
        if ( doForm )
        {
            pw.println"<form method='post'>" );
            pw.println"<input type='hidden' name='" + . + "' value='" + .
                + "'>" );
        }
        pw.println"<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
        pw.println"<tr class='content'>" );
        pw.println"<th class='content container'>Available Resources</th>" );
        if ( categories != null && !categories.isEmpty() )
        {
            pw.println"<th class='content container' style='text-align:right'>Limit to Bundle Category:</th>" );
            pw.println"<th class='content container'>" );
            Util.startScriptpw );
            pw.println"function reloadWithCat(field) {" );
            pw.println"  var query = '?" +  + "=' + field.value;" );
            pw
                .println"  var dest = document.location.protocol + '//' + document.location.host + document.location.pathname + query;" );
            pw.println"  document.location = dest;" );
            pw.println"}" );
            Util.endScriptpw );
            pw.println"<select class='select' name='__ignoreoption__' onChange='reloadWithCat(this);'>" );
            pw.print"<option value='" +  + "'>all</option>" );
            for ( Iterator ci = categories.iterator(); ci.hasNext(); )
            {
                String category = ( String ) ci.next();
                pw.print"<option value='" + category + "'" );
                if ( category.equalscurrentCategory ) )
                {
                    pw.print" selected" );
                }
                pw.print'>' );
                pw.printcategory );
                pw.println"</option>" );
            }
            pw.println"</select>" );
            pw.println"</th>" );
        }
        else
        {
            pw.println"<th class='content container'>&nbsp;</th>" );
        }
        pw.println"</tr>" );
        pw.println"<tr class='content'>" );
        pw.println"<th class='content'>Deploy Version</th>" );
        pw.println"<th class='content' colspan='2'>Name</th>" );
        pw.println"</tr>" );
    }
    private void printResourcePrintWriter pwString symbolicNameString presentationNameCollection versions )
    {
        pw.println"<tr class='content'>" );
        pw.println"<td class='content' valign='top' align='center'>" );
        pw.println"<select class='select' name='bundle'>" );
        pw.print"<option value='" + . + "'>Select Version...</option>" );
        for ( Iterator vi = versions.iterator(); vi.hasNext(); )
        {
            Version version = ( Version ) vi.next();
            pw.print"<option value='" + symbolicName + "," + version + "'>" );
            pw.printversion );
            pw.println"</option>" );
        }
        pw.println"</select>" );
        pw.println"</td>" );
        pw.println"<td class='content'  colspan='2'>" + presentationName + " (" + symbolicName + ")</td>" );
        pw.println"</tr>" );
    }
    private void resourcesButtonsPrintWriter pw )
    {
        pw.println"<tr class='content'>" );
        pw.println"<td class='content'>&nbsp;</td>" );
        pw.println"<td class='content'>" );
        pw.println"<input class='submit' style='width:auto' type='submit' name='deploy' value='Deploy Selected'>" );
        pw.println"&nbsp;&nbsp;&nbsp;" );
        pw
            .println"<input class='submit' style='width:auto' type='submit' name='deploystart' value='Deploy and Start Selected'>" );
        pw.println"</td></tr>" );
    }
    private void resourcesFooterPrintWriter pwboolean doForm )
    {
        if ( doForm )
        {
            this.resourcesButtonspw );
        }
        pw.println"</table></form>" );
    }
    private Map getBundles()
    {
        Map bundles = new HashMap();
        Bundle[] installed = getBundleContext().getBundles();
        for ( int i = 0; i < installed.length; i++ )
        {
            String ver = ( String ) installed[i].getHeaders().get( Constants.BUNDLE_VERSION );
            Version bundleVersion = Version.parseVersion( ver );
            // assume one bundle instance per symbolic name !!
            // only add if there is a symbolic name !
            if ( installed[i].getSymbolicName() != null )
            {
                bundles.putinstalled[i].getSymbolicName(), bundleVersion );
            }
        }
        return bundles;
    }
    protected RepositoryAdmin getRepositoryAdmin()
    {
        return ( RepositoryAdmin ) getService"org.osgi.service.obr.RepositoryAdmin" );
    }
New to GrepCode? Check out our FAQ X