1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.annotations;
15
16 import java.net.URI;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.eclipse.jetty.util.Loader;
21 import org.eclipse.jetty.util.log.Log;
22 import org.eclipse.jetty.util.resource.Resource;
23 import org.eclipse.jetty.webapp.Configuration;
24 import org.eclipse.jetty.webapp.WebAppContext;
25 import org.eclipse.jetty.webapp.WebXmlProcessor;
26 import org.eclipse.jetty.webapp.WebXmlProcessor.Descriptor;
27 import org.eclipse.jetty.webapp.WebInfConfiguration;
28
29
30 public abstract class AbstractConfiguration implements Configuration
31 {
32 public static final String CONTAINER_JAR_RESOURCES = WebInfConfiguration.CONTAINER_JAR_RESOURCES;
33 public static final String WEB_INF_JAR_RESOURCES = WebInfConfiguration.WEB_INF_JAR_RESOURCES;
34 public static final String WEBXML_VERSION = WebXmlProcessor.WEBXML_VERSION;
35 public static final String METADATA_COMPLETE = WebXmlProcessor.METADATA_COMPLETE;
36 public static final String WEBXML_CLASSNAMES = WebXmlProcessor.WEBXML_CLASSNAMES;
37
38 public void parseContainerPath (final WebAppContext context, final AnnotationParser parser)
39 throws Exception
40 {
41
42 Log.debug("Scanning container jars");
43
44
45 ArrayList<URI> containerUris = new ArrayList<URI>();
46 List<Resource> jarResources = (List<Resource>)context.getAttribute(CONTAINER_JAR_RESOURCES);
47 for (Resource r : jarResources)
48 {
49 URI uri = r.getURI();
50 containerUris.add(uri);
51 }
52
53 parser.parse (containerUris.toArray(new URI[containerUris.size()]),
54 new ClassNameResolver ()
55 {
56 public boolean isExcluded (String name)
57 {
58 if (context.isSystemClass(name)) return false;
59 if (context.isServerClass(name)) return true;
60 return false;
61 }
62
63 public boolean shouldOverride (String name)
64 {
65
66 if (context.isParentLoaderPriority())
67 return true;
68 return false;
69 }
70 });
71 }
72
73
74 public void parseWebInfLib (final WebAppContext context, final AnnotationParser parser)
75 throws Exception
76 {
77 WebXmlProcessor webXmlProcessor = (WebXmlProcessor)context.getAttribute(WebXmlProcessor.WEB_PROCESSOR);
78 if (webXmlProcessor == null)
79 throw new IllegalStateException ("No processor for web xml");
80
81 List<Descriptor> frags = webXmlProcessor.getFragments();
82
83
84 ArrayList<URI> webInfUris = new ArrayList<URI>();
85 List<Resource> jarResources = (List<Resource>)context.getAttribute(WEB_INF_JAR_RESOURCES);
86
87 for (Resource r : jarResources)
88 {
89 URI uri = r.getURI();
90 Descriptor d = null;
91 for (Descriptor frag: frags)
92 {
93 Resource fragResource = frag.getResource();
94 if (Resource.isContainedIn(fragResource,r))
95 {
96 d = frag;
97 break;
98 }
99 }
100
101
102
103 if (d == null || (d != null && !d.isMetaDataComplete()))
104 webInfUris.add(uri);
105 }
106
107 parser.parse(webInfUris.toArray(new URI[webInfUris.size()]),
108 new ClassNameResolver()
109 {
110 public boolean isExcluded (String name)
111 {
112 if (context.isSystemClass(name)) return true;
113 if (context.isServerClass(name)) return false;
114 return false;
115 }
116
117 public boolean shouldOverride (String name)
118 {
119
120 if (context.isParentLoaderPriority())
121 return false;
122 return true;
123 }
124 });
125 }
126
127 public void parseWebInfClasses (final WebAppContext context, final AnnotationParser parser)
128 throws Exception
129 {
130 Log.debug("Scanning classes in WEB-INF/classes");
131 parser.parse(context.getWebInf().addPath("classes/"),
132 new ClassNameResolver()
133 {
134 public boolean isExcluded (String name)
135 {
136 if (context.isSystemClass(name)) return true;
137 if (context.isServerClass(name)) return false;
138 return false;
139 }
140
141 public boolean shouldOverride (String name)
142 {
143
144 if (context.isParentLoaderPriority())
145 return false;
146 return true;
147 }
148 });
149 }
150
151 public void parse25Classes (final WebAppContext context, final AnnotationParser parser)
152 throws Exception
153 {
154
155 if (Log.isDebugEnabled()) Log.debug("Scanning only classes from web.xml");
156 ArrayList<String> classNames = (ArrayList<String>)context.getAttribute(WEBXML_CLASSNAMES);
157 for (String s : classNames)
158 {
159 Class clazz = Loader.loadClass(null, s);
160 parser.parse(clazz, new ClassNameResolver()
161 {
162 public boolean isExcluded (String name)
163 {
164 if (context.isSystemClass(name)) return true;
165 if (context.isServerClass(name)) return false;
166 return false;
167 }
168
169 public boolean shouldOverride (String name)
170 {
171
172 if (context.isParentLoaderPriority())
173 return false;
174 return true;
175 }
176 }, true);
177 }
178
179 }
180 }