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.misc;
 
 
 import java.io.Reader;
 import java.net.URL;
 
 
 import  org.osgi.framework.Bundle;
 import  org.osgi.service.component.ComponentContext;


The LicenseServlet TODO
 
 public class LicenseServlet extends AbstractWebConsolePlugin implements OsgiManagerPlugin
 {
 
     private static final String[] CSS_REFS =
         { "res/ui/license.css" };
 
 
     public String getLabel()
     {
         return "licenses";
     }
 
 
     public String getTitle()
     {
         return "Licenses";
     }
 
 
     protected String[] getCssReferences()
     {
         return ;
     }
 
 
     protected void renderContentHttpServletRequest reqHttpServletResponse res ) throws IOException
     {
         PrintWriter pw = res.getWriter();
 
         final String appRoot = ( String ) req.getAttribute. );
         Util.scriptpwappRoot"license.js" );
 
         Bundle[] bundles = getBundleContext().getBundles();
         Util.sortbundles );
 
         Util.startScriptpw );
         pw.print"bundleData = " );
         JSONWriter jw = new JSONWriterpw );
         try
         {
             jw.object();
             for ( int i = 0; i < bundles.length; i++ )
             {
                 Bundle bundle = bundles[i];
                 jw.key( String.valueOfbundle.getBundleId() ) );
 
                 jw.object();
 
                 jw.key"title" );
                 jw.value( Util.getNamebundle ) );
 
                jw.key"files" );
                jw.object();
                findResourcejwbundlenew String[]
                    { "README""DISCLAIMER""LICENSE""NOTICE" } );
                jw.endObject();
                jw.endObject();
            }
            jw.endObject();
            pw.println";" );
        }
        catch ( JSONException je )
        {
            throw new IOExceptionje.toString() );
        }
        Util.endScriptpw );
        pw.println"<div id='licenseContent'>" );
        pw.println"<div id='licenseLeft'>" );
        for ( int i = 0; i < bundles.length; i++ )
        {
            Bundle bundle = bundles[i];
            String link = "displayBundle( \"" + bundle.getBundleId() + "\" );";
            pw.println"<a href='javascript:" + link + "'>" + Util.getNamebundle ) + "</a><br />" );
        }
        pw.println"</div>" );
        pw.println"<div id='licenseRight'>" );
        pw.println"<div id='licenseButtons' class='licenseButtons'>&nbsp;</div>" );
        pw.println"<br />" );
        pw.println"<div id='licenseDetails' class='licenseDetails'>&nbsp;</div>" );
        pw.println"</div>" );
        pw.println"<div id='licenseClear'>&nbsp;</div>" );
        pw.println"</div>" ); // licenseContent
        Util.startScriptpw );
        pw.println"displayBundle( '0' );" );
        Util.endScriptpw );
    }
    private String getNameString path )
    {
        return path.substringpath.lastIndexOf'/' ) + 1 );
    }
    private void findResourceJSONWriter jw, Bundle bundleString[] patterns ) throws IOExceptionJSONException
    {
        jw.key"Bundle Resources" ); // aka the bundle files
        jw.array();
        for ( int i = 0; i < patterns.lengthi++ )
        {
            Enumeration entries = bundle.findEntries( "/"patterns[i] + "*"true );
            if ( entries != null )
            {
                while ( entries.hasMoreElements() )
                {
                    URL url = ( URL ) entries.nextElement();
                    jw.object();
                    jw.key"url" );
                    jw.valuegetNameurl.getPath() ) );
                    jw.key"data" );
                    jw.valuereadResourceurl ) );
                    jw.endObject();
                }
            }
        }
        jw.endArray();
        Enumeration entries = bundle.findEntries( "/""*.jar"true );
        if ( entries != null )
        {
            while ( entries.hasMoreElements() )
            {
                URL url = ( URL ) entries.nextElement();
                jw.key"Embedded " + getNameurl.getPath() ) );
                jw.array();
                for ( int i = 0; i < patterns.lengthi++ )
                {
                    String pattern = ".*/" + patterns[i] + "[^/]*$";
                    InputStream ins = null;
                    try
                    {
                        ins = url.openStream();
                        ZipInputStream zin = new ZipInputStreamins );
                        ZipEntry zentry = zin.getNextEntry();
                        while ( zentry != null )
                        {
                            String name = zentry.getName();
                            if ( !name.endsWith"/" ) && "/".concatname ).matchespattern ) )
                            {
                                jw.object();
                                jw.key"url" );
                                jw.valuegetNamename ) );
                                jw.key"data" );
                                jw.valuereadResourcenew FilterInputStreamzin )
                                {
                                    public void close()
                                    {
                                        // nothing for now
                                    }
                                } ) );
                                jw.endObject();
                            }
                            zentry = zin.getNextEntry();
                        }
                    }
                    finally
                    {
                        if ( ins != null )
                        {
                            try
                            {
                                ins.close();
                            }
                            catch ( IOException ignore )
                            {
                            }
                        }
                    }
                }
                jw.endArray();
            }
        }
    }
    private String getResource( Bundle bundleString[] path ) throws IOException
    {
        for ( int i = 0; i < path.lengthi++ )
        {
            URL resource = bundle.getResource( path[i] );
            if ( resource != null )
            {
                return readResourceresource );
            }
        }
        return null;
    }
    private String readResourceURL resource ) throws IOException
    {
        return readResourceresource.openStream() );
    }
    private String readResourceInputStream resource ) throws IOException
    {
        Reader r = null;
        StringBuffer buffer = new StringBuffer();
        try
        {
            char[] buf = new char[1024];
            r = new InputStreamReaderresource"ISO-8859-1" );
            int num;
            while ( ( num = r.readbuf ) ) >= 0 )
            {
                buffer.appendbuf, 0, num );
            }
        }
        finally
        {
            if ( r != null )
            {
                try
                {
                    r.close();
                }
                catch ( IOException ignore )
                {
                }
            }
        }
        return buffer.toString();
    }
    protected void activate( ComponentContext context )
    {
        activatecontext.getBundleContext() );
    }
    protected void deactivate( ComponentContext context )
    {
        deactivate();
    }
New to GrepCode? Check out our FAQ X