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  org.osgi.framework.ServiceReference;


The WebConsolePluginAdapter is an adapter to the 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 plugin title rendered in the top bar
     private final String title;
 
     // the actual plugin to forward rendering requests to
     private final Servlet plugin;
 
     // the CSS references (null if none)
     private final String[] cssReferences;
 
 
     public WebConsolePluginAdapterString labelString titleServlet plugin, ServiceReference serviceReference )
     {
         this. = label;
         this. = title;
         this. = plugin;
         this. = toStringArrayserviceReference.getProperty( . ) );
     }
 
 
     //---------- 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 in the constructor.
 
     public String getTitle()
     {
         return ;
     }


    
Returns the CSS references from the felix.webconsole.css service registration property of the plugin.
 
     protected String[] getCssReferences()
     {
         return ;
     }


    
Call the plugin servlet's service method to render the content of this page.
    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
    {
        // base classe initialization
        super.initconfig );
        // plugin initialization
        .initconfig );
    }

    
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(HttpServletRequest, HttpServletResponse) method is called without any decorations and without setting any response headers.
    protected boolean isHtmlRequestfinal HttpServletRequest request )
    {
        final String requestUri = request.getRequestURI();
        return requestUri.endsWith".html" ) || requestUri.lastIndexOf'.' ) < 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(HttpServletRequest, 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()
    {
        .destroy();
        super.destroy();
    }
    //---------- 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