org.eclipse.jetty.quickstart.QuickStartDescriptorProcessor Maven / Gradle / Ivy
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.quickstart;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import javax.servlet.ServletContext;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.webapp.Descriptor;
import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlParser;
/**
* QuickStartDescriptorProcessor
*
* Handle extended elements for quickstart-web.xml
*/
public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
{
/**
*
*/
public QuickStartDescriptorProcessor()
{
try
{
registerVisitor("context-param", this.getClass().getMethod("visitContextParam", __signature));
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
}
/**
* @see org.eclipse.jetty.webapp.IterativeDescriptorProcessor#start(org.eclipse.jetty.webapp.WebAppContext, org.eclipse.jetty.webapp.Descriptor)
*/
@Override
public void start(WebAppContext context, Descriptor descriptor)
{
}
/**
* @see org.eclipse.jetty.webapp.IterativeDescriptorProcessor#end(org.eclipse.jetty.webapp.WebAppContext, org.eclipse.jetty.webapp.Descriptor)
*/
@Override
public void end(WebAppContext context, Descriptor descriptor)
{
}
/**
* @param context
* @param descriptor
* @param node
*/
public void visitContextParam (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
throws Exception
{
String name = node.getString("param-name", false, true);
String value = node.getString("param-value", false, true);
List values = new ArrayList<>();
// extract values
switch(name)
{
case ServletContext.ORDERED_LIBS:
case AnnotationConfiguration.CONTAINER_INITIALIZERS:
case MetaInfConfiguration.METAINF_TLDS:
case MetaInfConfiguration.METAINF_RESOURCES:
context.removeAttribute(name);
QuotedStringTokenizer tok = new QuotedStringTokenizer(value,",");
while(tok.hasMoreElements())
values.add(tok.nextToken().trim());
break;
default:
values.add(value);
}
// handle values
switch(name)
{
case ServletContext.ORDERED_LIBS:
{
List