|
Lines 20-25
Link Here
|
| 20 |
import java.util.Map; |
20 |
import java.util.Map; |
| 21 |
import java.util.jar.JarEntry; |
21 |
import java.util.jar.JarEntry; |
| 22 |
import java.util.jar.JarFile; |
22 |
import java.util.jar.JarFile; |
|
|
23 |
import java.util.regex.Pattern; |
| 23 |
|
24 |
|
| 24 |
import javax.xml.parsers.ParserConfigurationException; |
25 |
import javax.xml.parsers.ParserConfigurationException; |
| 25 |
|
26 |
|
|
Lines 31-36
Link Here
|
| 31 |
import org.eclipse.jdt.core.IJavaProject; |
32 |
import org.eclipse.jdt.core.IJavaProject; |
| 32 |
import org.eclipse.jdt.core.JavaCore; |
33 |
import org.eclipse.jdt.core.JavaCore; |
| 33 |
import org.eclipse.jdt.core.JavaModelException; |
34 |
import org.eclipse.jdt.core.JavaModelException; |
|
|
35 |
import org.eclipse.jst.jsf.common.internal.strategy.SimpleStrategyComposite; |
| 34 |
import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin; |
36 |
import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin; |
| 35 |
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibDefn; |
37 |
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibDefn; |
| 36 |
import org.xml.sax.SAXException; |
38 |
import org.xml.sax.SAXException; |
|
Lines 41-81
Link Here
|
| 41 |
* @author cbateman |
43 |
* @author cbateman |
| 42 |
* |
44 |
* |
| 43 |
*/ |
45 |
*/ |
| 44 |
/* package */class JarFileFaceletTaglibLocator extends |
46 |
public class JarFileFaceletTaglibLocator extends AbstractFaceletTaglibLocator |
| 45 |
AbstractFaceletTaglibLocator |
|
|
| 46 |
{ |
47 |
{ |
|
|
48 |
/** |
| 49 |
* Default taglib finder that looks in meta-inf |
| 50 |
*/ |
| 51 |
public static final TaglibJarEntryFinder _taglibMetaInfFinder = new TaglibJarEntryFinder( |
| 52 |
Pattern.compile("META-INF/.*\\.taglib\\.xml")); //$NON-NLS-1$ |
| 53 |
/** |
| 54 |
* Default finder that looks in the glassfish package. |
| 55 |
*/ |
| 56 |
public static final TaglibJarEntryFinder _taglibGlassfishFinder = new TaglibJarEntryFinder( |
| 57 |
Pattern.compile("com/sun/faces/metadata/taglib/.*\\.taglib\\.xml")); //$NON-NLS-1$ |
| 47 |
|
58 |
|
| 48 |
private final IProject _project; |
59 |
private static final String DISPLAYNAME = Messages.JarFileFaceletTaglibLocator_0; |
| 49 |
private final TagRecordFactory _factory; |
60 |
private static final String ID = JarFileFaceletTaglibLocator.class |
|
|
61 |
.getCanonicalName(); |
| 62 |
private final TagRecordFactory _factory; |
| 50 |
private Map<String, IFaceletTagRecord> _records; |
63 |
private Map<String, IFaceletTagRecord> _records; |
|
|
64 |
private final SimpleStrategyComposite<JarEntry, JarEntry, JarEntry, String, TaglibFinder<JarEntry, JarEntry>> _finder; |
| 51 |
|
65 |
|
| 52 |
public JarFileFaceletTaglibLocator(final IProject project, |
66 |
/** |
| 53 |
final TagRecordFactory factory) |
67 |
* @param factory |
|
|
68 |
*/ |
| 69 |
public JarFileFaceletTaglibLocator(final TagRecordFactory factory) |
| 54 |
{ |
70 |
{ |
| 55 |
_project = project; |
71 |
super(ID, DISPLAYNAME); |
| 56 |
_factory = factory; |
72 |
_factory = factory; |
| 57 |
_records = new HashMap<String, IFaceletTagRecord>(); |
73 |
_records = new HashMap<String, IFaceletTagRecord>(); |
|
|
74 |
|
| 75 |
List<TaglibFinder<JarEntry, JarEntry>> finders = new ArrayList<TaglibFinder<JarEntry, JarEntry>>(); |
| 76 |
finders.add(_taglibMetaInfFinder); |
| 77 |
finders.add(_taglibGlassfishFinder); |
| 78 |
|
| 79 |
_finder = new SimpleStrategyComposite<JarEntry, JarEntry, JarEntry, String, TaglibFinder<JarEntry, JarEntry>>( |
| 80 |
finders); |
| 81 |
|
| 58 |
} |
82 |
} |
| 59 |
|
83 |
|
| 60 |
@Override |
84 |
@Override |
| 61 |
public Map<String, ? extends IFaceletTagRecord> locate() |
85 |
public Map<String, ? extends IFaceletTagRecord> doLocate( |
|
|
86 |
final IProject project) |
| 62 |
{ |
87 |
{ |
| 63 |
try |
88 |
try |
| 64 |
{ |
89 |
{ |
| 65 |
return findInJars(); |
90 |
return findInJars(project); |
| 66 |
} |
91 |
} catch (JavaModelException e) |
| 67 |
catch (JavaModelException e) |
|
|
| 68 |
{ |
92 |
{ |
| 69 |
FaceletCorePlugin |
93 |
FaceletCorePlugin |
| 70 |
.log( |
94 |
.log( |
| 71 |
"Couldn't locate jar file taglibs: " + _project.getProject(), e); //$NON-NLS-1$ |
95 |
"Couldn't locate jar file taglibs: " + project.getProject(), e); //$NON-NLS-1$ |
| 72 |
} |
96 |
} |
| 73 |
return Collections.EMPTY_MAP; |
97 |
return Collections.EMPTY_MAP; |
| 74 |
} |
98 |
} |
| 75 |
|
99 |
|
| 76 |
private Map<String, ? extends IFaceletTagRecord> findInJars() throws JavaModelException |
100 |
private Map<String, ? extends IFaceletTagRecord> findInJars( |
|
|
101 |
final IProject project) throws JavaModelException |
| 77 |
{ |
102 |
{ |
| 78 |
final IJavaProject javaProject = JavaCore.create(_project); |
103 |
final IJavaProject javaProject = JavaCore.create(project); |
| 79 |
|
104 |
|
| 80 |
final IClasspathEntry[] entries = javaProject |
105 |
final IClasspathEntry[] entries = javaProject |
| 81 |
.getResolvedClasspath(true); |
106 |
.getResolvedClasspath(true); |
|
Lines 87-130
Link Here
|
| 87 |
|
112 |
|
| 88 |
switch (entry.getEntryKind()) |
113 |
switch (entry.getEntryKind()) |
| 89 |
{ |
114 |
{ |
| 90 |
// this entry describes a source root in its project |
115 |
// this entry describes a source root in its project |
| 91 |
case IClasspathEntry.CPE_SOURCE: |
116 |
case IClasspathEntry.CPE_SOURCE: |
| 92 |
|
117 |
|
| 93 |
break; |
118 |
break; |
| 94 |
// - this entry describes a folder or JAR containing |
119 |
// - this entry describes a folder or JAR containing |
| 95 |
// binaries |
120 |
// binaries |
| 96 |
case IClasspathEntry.CPE_LIBRARY: |
121 |
case IClasspathEntry.CPE_LIBRARY: |
| 97 |
{ |
122 |
{ |
| 98 |
tagLibsFound.addAll(processJar(entry)); |
123 |
tagLibsFound.addAll(processJar(entry)); |
| 99 |
} |
124 |
} |
| 100 |
break; |
125 |
break; |
| 101 |
// - this entry describes another project |
126 |
// - this entry describes another project |
| 102 |
case IClasspathEntry.CPE_PROJECT: |
127 |
case IClasspathEntry.CPE_PROJECT: |
| 103 |
// { |
128 |
// { |
| 104 |
// final IPath pathToProject = entry.getPath(); |
129 |
// final IPath pathToProject = entry.getPath(); |
| 105 |
// IWorkspace wkspace = ResourcesPlugin.getWorkspace(); |
130 |
// IWorkspace wkspace = ResourcesPlugin.getWorkspace(); |
| 106 |
// IResource res = |
131 |
// IResource res = |
| 107 |
// wkspace.getRoot().findMember(pathToProject); |
132 |
// wkspace.getRoot().findMember(pathToProject); |
| 108 |
// if (res instanceof IProject) |
133 |
// if (res instanceof IProject) |
| 109 |
// { |
134 |
// { |
| 110 |
// tagLibsFound.addAll(); |
135 |
// tagLibsFound.addAll(); |
| 111 |
// } |
136 |
// } |
| 112 |
// } |
137 |
// } |
| 113 |
break; |
138 |
break; |
| 114 |
// - this entry describes a project or library indirectly |
139 |
// - this entry describes a project or library indirectly |
| 115 |
// via a |
140 |
// via a |
| 116 |
// classpath variable in the first segment of the path * |
141 |
// classpath variable in the first segment of the path * |
| 117 |
case IClasspathEntry.CPE_VARIABLE: |
142 |
case IClasspathEntry.CPE_VARIABLE: |
| 118 |
break; |
143 |
break; |
| 119 |
// - this entry describes set of entries referenced |
144 |
// - this entry describes set of entries referenced |
| 120 |
// indirectly |
145 |
// indirectly |
| 121 |
// via a classpath container |
146 |
// via a classpath container |
| 122 |
case IClasspathEntry.CPE_CONTAINER: |
147 |
case IClasspathEntry.CPE_CONTAINER: |
| 123 |
break; |
148 |
break; |
| 124 |
} |
149 |
} |
| 125 |
} |
150 |
} |
| 126 |
|
151 |
|
| 127 |
for (final FaceletTaglibDefn tag : tagLibsFound) |
152 |
for (final FaceletTaglibDefn tag : tagLibsFound) |
| 128 |
{ |
153 |
{ |
| 129 |
IFaceletTagRecord record = _factory.createRecords(tag); |
154 |
IFaceletTagRecord record = _factory.createRecords(tag); |
| 130 |
if (record != null) |
155 |
if (record != null) |
|
Lines 132-138
Link Here
|
| 132 |
_records.put(record.getURI(), record); |
157 |
_records.put(record.getURI(), record); |
| 133 |
} |
158 |
} |
| 134 |
} |
159 |
} |
| 135 |
|
160 |
|
| 136 |
return _records; |
161 |
return _records; |
| 137 |
} |
162 |
} |
| 138 |
|
163 |
|
|
Lines 185-253
Link Here
|
| 185 |
final Enumeration<JarEntry> jarEntries = jarFile.entries(); |
210 |
final Enumeration<JarEntry> jarEntries = jarFile.entries(); |
| 186 |
while (jarEntries.hasMoreElements()) |
211 |
while (jarEntries.hasMoreElements()) |
| 187 |
{ |
212 |
{ |
| 188 |
final JarEntry jarEntry = jarEntries.nextElement(); |
213 |
JarEntry jarEntry = jarEntries.nextElement(); |
| 189 |
final String name = jarEntry.getName(); |
214 |
|
|
|
215 |
jarEntry = _finder.perform(jarEntry); |
| 190 |
|
216 |
|
| 191 |
if (name.startsWith("META-INF/") //$NON-NLS-1$ |
217 |
if (jarEntry != null && jarEntry != _finder.getNoResult()) |
| 192 |
&& name.endsWith(".taglib.xml")) //$NON-NLS-1$ |
|
|
| 193 |
{ |
218 |
{ |
| 194 |
InputStream is = null; |
219 |
// if ((name.startsWith("META-INF/") //$NON-NLS-1$ |
| 195 |
try |
220 |
// && name.endsWith(".taglib.xml")) //$NON-NLS-1$ |
|
|
221 |
// || (name.startsWith("com/sun/faces/metadata/taglib/") //$NON-NLS-1$ //ludo GlassFish v3 |
| 222 |
// && name.endsWith(".taglib.xml"))) //$NON-NLS-1$ |
| 196 |
{ |
223 |
{ |
| 197 |
is = jarFile.getInputStream(jarEntry); |
224 |
InputStream is = null; |
|
|
225 |
try |
| 226 |
{ |
| 227 |
is = jarFile.getInputStream(jarEntry); |
| 198 |
|
228 |
|
| 199 |
FaceletTaglibDefn tagLib = TagModelParser.loadFromInputStream(is, null); |
229 |
FaceletTaglibDefn tagLib = TagModelParser |
|
|
230 |
.loadFromInputStream(is, null); |
| 200 |
|
231 |
|
| 201 |
if (tagLib != null) |
232 |
if (tagLib != null) |
|
|
233 |
{ |
| 234 |
tagLibsFound.add(tagLib); |
| 235 |
} |
| 236 |
} catch (final ParserConfigurationException e) |
| 202 |
{ |
237 |
{ |
| 203 |
tagLibsFound.add(tagLib); |
238 |
FaceletCorePlugin |
| 204 |
} |
239 |
.log( |
| 205 |
} |
240 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
| 206 |
catch (final ParserConfigurationException e) |
241 |
e); |
| 207 |
{ |
242 |
} catch (final IOException ioe) |
| 208 |
FaceletCorePlugin |
243 |
{ |
| 209 |
.log( |
244 |
FaceletCorePlugin |
| 210 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
245 |
.log( |
| 211 |
e); |
246 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
| 212 |
} |
247 |
ioe); |
| 213 |
catch (final IOException ioe) |
248 |
} catch (final SAXException ioe) |
| 214 |
{ |
|
|
| 215 |
FaceletCorePlugin |
| 216 |
.log( |
| 217 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
| 218 |
ioe); |
| 219 |
} |
| 220 |
catch (final SAXException ioe) |
| 221 |
{ |
| 222 |
FaceletCorePlugin |
| 223 |
.log( |
| 224 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
| 225 |
ioe); |
| 226 |
} |
| 227 |
finally |
| 228 |
{ |
| 229 |
if (is != null) |
| 230 |
{ |
249 |
{ |
| 231 |
// is.close(); |
250 |
FaceletCorePlugin |
|
|
251 |
.log( |
| 252 |
"Error initializing facelet registry entry", //$NON-NLS-1$ |
| 253 |
ioe); |
| 254 |
} finally |
| 255 |
{ |
| 256 |
if (is != null) |
| 257 |
{ |
| 258 |
// is.close(); |
| 259 |
} |
| 232 |
} |
260 |
} |
| 233 |
} |
261 |
} |
| 234 |
} |
262 |
} |
| 235 |
} |
263 |
} |
| 236 |
} |
264 |
} |
| 237 |
} |
265 |
} catch (final IOException e) |
| 238 |
catch (final IOException e) |
|
|
| 239 |
{ |
266 |
{ |
| 240 |
FaceletCorePlugin.log("Error opening classpath jar file", e); //$NON-NLS-1$ |
267 |
FaceletCorePlugin.log( |
| 241 |
} |
268 |
"Error opening classpath jar file: " + entry, e); //$NON-NLS-1$ |
| 242 |
finally |
269 |
} finally |
| 243 |
{ |
270 |
{ |
| 244 |
if (jarFile != null) |
271 |
if (jarFile != null) |
| 245 |
{ |
272 |
{ |
| 246 |
try |
273 |
try |
| 247 |
{ |
274 |
{ |
| 248 |
jarFile.close(); |
275 |
jarFile.close(); |
| 249 |
} |
276 |
} catch (final IOException ioe) |
| 250 |
catch (final IOException ioe) |
|
|
| 251 |
{ |
277 |
{ |
| 252 |
FaceletCorePlugin.log("Error closing jar file", ioe); //$NON-NLS-1$ |
278 |
FaceletCorePlugin.log("Error closing jar file", ioe); //$NON-NLS-1$ |
| 253 |
} |
279 |
} |
|
Lines 255-273
Link Here
|
| 255 |
} |
281 |
} |
| 256 |
return tagLibsFound; |
282 |
return tagLibsFound; |
| 257 |
} |
283 |
} |
| 258 |
|
|
|
| 259 |
@Override |
| 260 |
public void startLocating() |
| 261 |
{ |
| 262 |
// TODO Auto-generated method stub |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
@Override |
| 267 |
public void stopLocating() |
| 268 |
{ |
| 269 |
// TODO Auto-generated method stub |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
} |
284 |
} |