1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.eclipse.jetty.webapp;
16
17 import java.util.List;
18
19 import org.eclipse.jetty.util.resource.Resource;
20
21
22
23
24
25
26
27
28 public class FragmentConfiguration extends AbstractConfiguration
29 {
30 public final static String FRAGMENT_RESOURCES="org.eclipse.jetty.webFragments";
31
32 @Override
33 public void preConfigure(WebAppContext context) throws Exception
34 {
35 if (!context.isConfigurationDiscovered())
36 return;
37
38
39 findWebFragments(context, context.getMetaData());
40
41 }
42
43 @Override
44 public void configure(WebAppContext context) throws Exception
45 {
46 if (!context.isConfigurationDiscovered())
47 return;
48
49
50 context.getMetaData().orderFragments();
51 }
52
53 @Override
54 public void postConfigure(WebAppContext context) throws Exception
55 {
56 context.setAttribute(FRAGMENT_RESOURCES, null);
57 }
58
59
60
61
62
63
64
65 public void findWebFragments (final WebAppContext context, final MetaData metaData) throws Exception
66 {
67 @SuppressWarnings("unchecked")
68 List<Resource> frags = (List<Resource>)context.getAttribute(FRAGMENT_RESOURCES);
69 if (frags!=null)
70 {
71 for (Resource frag : frags)
72 {
73 if (frag.isDirectory())
74 {
75 metaData.addFragment(frag, Resource.newResource(frag.getURL()+"/META-INF/web-fragment.xml"));
76 }
77 else
78 {
79 metaData.addFragment(frag, Resource.newResource("jar:"+frag.getURL()+"!/META-INF/web-fragment.xml"));
80 }
81 }
82 }
83 }
84 }