Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Sonatype Nexus (TM) Open Source Version Copyright (c) 2007-2012 Sonatype, Inc. All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the Eclipse Foundation. All other trademarks are the property of their respective owners.
 
 package org.sonatype.nexus.rest;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.restlet.Context;
 import  org.restlet.data.MediaType;
 import  org.restlet.data.Request;
 import  org.restlet.data.Response;
 import  org.restlet.data.Status;
 import  org.restlet.resource.Representation;
 import  org.restlet.resource.ResourceException;
 import  org.restlet.resource.Variant;
 
 @Component( role = ManagedPlexusResource.class, hint = "indexTemplate" )
     extends AbstractPlexusResource
     implements ManagedPlexusResource,
         Initializable
 {
     @Requirement
     private Nexus nexus;
 
     @Requirement( role = NexusIndexHtmlCustomizer.class )
     
     @Configuration( value = "${index.template.file}" )
 
     public IndexTemplatePlexusResource()
     {
         super();
 
         setReadabletrue );
 
         setModifiablefalse );
     }
 
     @Override
     public Object getPayloadInstance()
     {
         // RO resource
         return null;
     }
 
     @Override
     public String getResourceUri()
     {
         return "/index.html";
     }
 
     @Override
     {
         // unprotected
         return null;
     }
 
     public List<Variant> getVariants()
     {
         List<Variant> result = super.getVariants();
 
         result.clear();
 
         result.add( new Variant( MediaType.APPLICATION_XHTML_XML ) );
 
        return result;
    }
    public Representation get( Context context, Request request, Response response, Variant variant )
        throws ResourceException
    {
        return rendercontextrequestresponsevariant );
    }
    protected VelocityRepresentation render( Context context, Request request, Response response, Variant variant )
        throws ResourceException
    {
        Map<StringObjecttemplatingContext = new HashMap<StringObject>();
        templatingContext.put"serviceBase""service/local" );
        templatingContext.put"contentBase""content" );
        templatingContext.put"nexusVersion".getSystemStatus().getVersion() );
        templatingContext.put"nexusRoot"request.getRootRef().toString() );
        VelocityRepresentation templateRepresentation = new VelocityRepresentation(
            context,
            ,
            MediaType.TEXT_HTML );
        // gather plugin stuff
        Map<StringObjecttopContext = new HashMap<StringObject>( templatingContext );
        Map<StringObjectpluginContext = null;
        List<StringpluginPreHeadContributions = new ArrayList<String>();
        List<StringpluginPostHeadContributions = new ArrayList<String>();
        List<StringpluginPreBodyContributions = new ArrayList<String>();
        List<StringpluginPostBodyContributions = new ArrayList<String>();
        for ( String key : .keySet() )
        {
            pluginContext = new HashMap<StringObject>( topContext );
            NexusIndexHtmlCustomizer bundle = .getkey );
            pluginContext.put"bundle"bundle );
            // pre HEAD
            String preHeadTemplate = bundle.getPreHeadContributionpluginContext );
            evaluateIfNeeded(
                templateRepresentation.getEngine(),
                pluginContext,
                preHeadTemplate,
                pluginPreHeadContributions );
            // post HEAD
            String postHeadTemplate = bundle.getPostHeadContributionpluginContext );
            evaluateIfNeeded(
                templateRepresentation.getEngine(),
                pluginContext,
                postHeadTemplate,
                pluginPostHeadContributions );
            // pre BODY
            String preBodyTemplate = bundle.getPreBodyContributionpluginContext );
            evaluateIfNeeded(
                templateRepresentation.getEngine(),
                pluginContext,
                preBodyTemplate,
                pluginPreBodyContributions );
            // post BODY
            String postBodyTemplate = bundle.getPostBodyContributionpluginContext );
            evaluateIfNeeded(
                templateRepresentation.getEngine(),
                pluginContext,
                postBodyTemplate,
                pluginPostBodyContributions );
        }
        
        templatingContext.put"appName".getSystemStatus().getAppName() );
        templatingContext.put"formattedAppName".getSystemStatus().getFormattedAppName() );
        templatingContext.put"pluginPreHeadContributions"pluginPreHeadContributions );
        templatingContext.put"pluginPostHeadContributions"pluginPostHeadContributions );
        templatingContext.put"pluginPreBodyContributions"pluginPreBodyContributions );
        templatingContext.put"pluginPostBodyContributions"pluginPostBodyContributions );
        templateRepresentation.setDataModeltemplatingContext );
        return templateRepresentation;
    }
    protected void evaluateIfNeededVelocityEngine engineMap<StringObjectcontextString template,
        List<Stringresults )
        throws ResourceException
    {
        if ( !StringUtils.isEmptytemplate ) )
        {
            StringWriter result = new StringWriter();
            try
            {
                if ( engine.evaluatenew VelocityContextcontext ), resultgetClass().getName(), template ) )
                {
                    results.addresult.toString() );
                }
                else
                {
                    throw new ResourceException(
                        Status.SERVER_ERROR_INTERNAL,
                        "Was not able to interpolate (check the logs for Velocity messages about the reason)!" );
                }
            }
            catch ( IOException e )
            {
                throw new ResourceException(
                    Status.SERVER_ERROR_INTERNAL,
                    "Got IO exception during Velocity invocation!",
                    e );
            }
            catch ( ParseErrorException e )
            {
                throw new ResourceException(
                    Status.SERVER_ERROR_INTERNAL,
                    "Got ParseErrorException exception during Velocity invocation!",
                    e );
            }
            catch ( MethodInvocationException e )
            {
                throw new ResourceException(
                    Status.SERVER_ERROR_INTERNAL,
                    "Got MethodInvocationException exception during Velocity invocation!",
                    e );
            }
            catch ( ResourceNotFoundException e )
            {
                throw new ResourceException(
                    Status.SERVER_ERROR_INTERNAL,
                    "Got ResourceNotFoundException exception during Velocity invocation!",
                    e );
            }
        }
    }
    
    public void initialize()
        throws InitializationException
    {
        //Hasn't been interpolated
        if ( "${index.template.file}".equals ) )
        {
             = "templates/index.vm";
        }
    }
New to GrepCode? Check out our FAQ X