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;
 
 
 import java.util.*;
 
 
The WebConsolePluginAdapter is an adapter to the org.apache.felix.webconsole.AbstractWebConsolePlugin for regular servlets registered with the org.apache.felix.webconsole.WebConsoleConstants.PLUGIN_TITLE service attribute.
 
 {

    
serial UID
 
     private static final long serialVersionUID = 1L;
 
     // the plugin label (aka address)
     private final String label;
 
     // the actual plugin to forward rendering requests to
     private final Servlet plugin;
 
     // the CSS references (null if none)
     private final String[] cssReferences;

    
Creates a new wrapper for a Web Console Plugin

Parameters:
label the label
plugin the plugin itself
serviceReference reference to the plugin
 
     public WebConsolePluginAdapterString labelServlet pluginServiceReference serviceReference )
     {
         this. = label;
         this. = plugin;
         this. = toStringArrayserviceReference.getProperty. ) );
 
         // activate this abstract plugin (mainly to set the bundle context)
         activateserviceReference.getBundle().getBundleContext() );
     }
 
 
     //---------- AbstractWebConsolePlugin API
 
    
Returns the label of this plugin page as defined in the constructor.

 
     public String getLabel()
     {
         return ;
     }


    
Returns the title of this plugin page as defined by the org.apache.felix.webconsole.WebConsoleConstants.PLUGIN_TITLE service registration attribute which is exposed as the servlet name in the servlet configuration.

 
     public String getTitle()
     {
         // return the servlet name from the configuration but don't call
         // the base class implementation, which calls getTitle()
         return getServletConfig().getServletName();
     }


    
Returns the CSS references from the felix.webconsole.css service registration property of the plugin.

    protected String[] getCssReferences()
    {
        return ;
    }


    
    protected void renderContentHttpServletRequest reqHttpServletResponse res ) throws ServletException,
        IOException
    {
        .servicereqres );
    }


    
Returns the registered plugin class to be able to call the getResource() method on that object for this plugin to provide additional resources.

    protected Object getResourceProvider()
    {
        return ;
    }
    //---------- Servlet API overwrite

    
Initializes this servlet as well as the plugin servlet.

    public void initServletConfig config ) throws ServletException
    {
        // no need to activate the plugin, this has already been done
        // when the instance was setup
        try
        {
            // base classe initialization
            super.initconfig );
            // plugin initialization
            .initconfig );
        }
        catch ( ServletException se )
        {
            // if init fails, the plugin will not be destroyed and thus
            // the plugin not deactivated. Do it here
            deactivate();
            // rethrow the exception
            throw se;
        }
    }


    
Detects whether this request is intended to have the headers and footers of this plugin be rendered or not. The decision is taken based on whether and what extension the request URI has: If the request URI has no extension or the the extension is .html, the request is assumed to be rendered with header and footer. Otherwise the headers and footers are omitted and the renderContent(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) method is called without any decorations and without setting any response headers.

    protected boolean isHtmlRequestfinal HttpServletRequest request )
    {
        final String requestUri = request.getRequestURI();
        if ( requestUri.endsWith".html" ) ) {
            return true;
        }
        // check if there is an extension
        final int lastSlash = requestUri.lastIndexOf('/');
        final int lastDot = requestUri.indexOf('.'lastSlash + 1);
        return lastDot < 0;
    }


    
Directly refer to the plugin's service method unless the request method is GET in which case we defer the call into the service method until the abstract web console plugin calls the renderContent(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) method.

    public void serviceServletRequest reqServletResponse resp ) throws ServletExceptionIOException
    {
        if ( ( req instanceof HttpServletRequest ) && ( ( HttpServletRequest ) req ).getMethod().equals"GET" ) )
        {
            // handle the GET request here and call into plugin on renderContent
            super.servicereqresp );
        }
        else
        {
            // not a GET request, have the plugin handle it directly
            .servicereqresp );
        }
    }


    
Destroys this servlet as well as the plugin servlet.

    public void destroy()
    {
        try
        {
            .destroy();
            super.destroy();
        }
        finally
        {
            deactivate();
        }
    }
    //---------- internal
    private String[] toStringArrayfinal Object value )
    {
        if ( value instanceof String )
        {
            return new String[]
                { ( String ) value };
        }
        else if ( value != null )
        {
            final Collection cssListColl;
            if ( value.getClass().isArray() )
            {
                cssListColl = Arrays.asList( ( Object[] ) value );
            }
            else if ( value instanceof Collection )
            {
                cssListColl = ( Collection ) value;
            }
            else
            {
                cssListColl = null;
            }
            if ( cssListColl != null && !cssListColl.isEmpty() )
            {
                String[] entries = new String[cssListColl.size()];
                int i = 0;
                for ( Iterator cli = cssListColl.iterator(); cli.hasNext(); i++ )
                {
                    entries[i] = String.valueOfcli.next() );
                }
                return entries;
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X