1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.webapp;
20
21
22 import java.net.URI;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.concurrent.TimeUnit;
31 import java.util.jar.JarEntry;
32
33 import org.eclipse.jetty.util.log.Log;
34 import org.eclipse.jetty.util.log.Logger;
35 import org.eclipse.jetty.util.resource.Resource;
36
37
38
39
40
41
42
43
44
45
46
47 public class MetaInfConfiguration extends AbstractConfiguration
48 {
49 private static final Logger LOG = Log.getLogger(MetaInfConfiguration.class);
50
51 public static final String METAINF_TLDS = TagLibConfiguration.TLD_RESOURCES;
52 public static final String METAINF_FRAGMENTS = FragmentConfiguration.FRAGMENT_RESOURCES;
53 public static final String METAINF_RESOURCES = WebInfConfiguration.RESOURCE_DIRS;
54
55 @Override
56 public void preConfigure(final WebAppContext context) throws Exception
57 {
58
59 ArrayList<Resource> jars = new ArrayList<Resource>();
60 jars.addAll(context.getMetaData().getContainerResources());
61 jars.addAll(context.getMetaData().getWebInfJars());
62
63
64 if (jars != null)
65 {
66 for (Resource r : jars)
67 {
68 URI uri = r.getURI();
69 Resource fragXml = Resource.newResource("jar:"+uri+"!/META-INF/web-fragment.xml");
70 if (fragXml.exists())
71 {
72
73 Map<Resource, Resource> fragments = (Map<Resource,Resource>)context.getAttribute(METAINF_FRAGMENTS);
74 if (fragments == null)
75 {
76 fragments = new HashMap<Resource, Resource>();
77 context.setAttribute(METAINF_FRAGMENTS, fragments);
78 }
79 fragments.put(r, fragXml);
80 }
81
82 Resource resourcesDir = Resource.newResource("jar:"+uri+"!/META-INF/resources");
83 if (resourcesDir.exists())
84 {
85
86 Set<Resource> dirs = (Set<Resource>)context.getAttribute(METAINF_RESOURCES);
87 if (dirs == null)
88 {
89 dirs = new HashSet<Resource>();
90 context.setAttribute(METAINF_RESOURCES, dirs);
91 }
92 dirs.add(resourcesDir);
93 }
94 }
95 }
96 }
97
98 @Override
99 public void postConfigure(WebAppContext context) throws Exception
100 {
101 context.setAttribute(METAINF_FRAGMENTS, null);
102 context.setAttribute(METAINF_RESOURCES, null);
103 context.setAttribute(METAINF_TLDS, null);
104 }
105 }