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