1 package org.apache.maven.archiva.web.tags;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.codehaus.plexus.PlexusConstants;
23 import org.codehaus.plexus.PlexusContainer;
24 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
26 import javax.servlet.ServletContext;
27 import javax.servlet.jsp.PageContext;
34 public class PlexusTagUtil
36 public static Object lookup( PageContext pageContext, Class clazz )
37 throws ComponentLookupException
39 return getContainer( pageContext ).lookup( clazz );
42 public static Object lookup( PageContext pageContext, String role )
43 throws ComponentLookupException
45 return getContainer( pageContext ).lookup( role );
48 public static Object lookup( PageContext pageContext, Class clazz, String hint )
49 throws ComponentLookupException
51 return getContainer( pageContext ).lookup( clazz, hint );
54 public static Object lookup( PageContext pageContext, String role, String hint )
55 throws ComponentLookupException
57 return getContainer( pageContext ).lookup( role, hint );
60 public static PlexusContainer getContainer( PageContext pageContext )
61 throws ComponentLookupException
63 ServletContext servletContext = pageContext.getServletContext();
65 PlexusContainer xworkContainer = (PlexusContainer) servletContext.getAttribute( "webwork.plexus.container" );
67 if ( xworkContainer != null )
69 servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, xworkContainer );
71 return xworkContainer;
74 PlexusContainer container = (PlexusContainer) servletContext.getAttribute( PlexusConstants.PLEXUS_KEY );
75 if ( container == null )
77 throw new ComponentLookupException( "PlexusContainer is null." );