source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DebugService.java@ 27165

Last change on this file since 27165 was 27165, checked in by sjm84, 11 years ago

Added a new call that resolves call-template calls

  • Property svn:executable set to *
File size: 22.1 KB
Line 
1package org.greenstone.gsdl3.service;
2
3import java.io.File;
4import java.io.FileWriter;
5import java.io.Serializable;
6import java.util.ArrayList;
7import java.util.HashMap;
8
9import javax.xml.transform.Transformer;
10import javax.xml.transform.TransformerFactory;
11import javax.xml.transform.dom.DOMSource;
12import javax.xml.transform.stream.StreamResult;
13
14import org.apache.log4j.Logger;
15import org.greenstone.gsdl3.util.GSXML;
16import org.greenstone.gsdl3.util.GSXSLT;
17import org.greenstone.gsdl3.util.UserContext;
18import org.greenstone.gsdl3.util.XMLConverter;
19import org.greenstone.util.GlobalProperties;
20import org.w3c.dom.Document;
21import org.w3c.dom.Element;
22import org.w3c.dom.NamedNodeMap;
23import org.w3c.dom.Node;
24import org.w3c.dom.NodeList;
25
26public class DebugService extends ServiceRack
27{
28 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.DebugService.class.getName());
29
30 /**********************************************************
31 * The list of services the utility service rack supports *
32 *********************************************************/
33 protected static final String GET_TEMPLATE_FROM_XML_FILE = "GetXMLTemplateFromFile";
34 protected static final String SAVE_TEMPLATE_TO_XML_FILE = "SaveXMLTemplateToFile";
35 protected static final String GET_TEMPLATE_LIST_FROM_FILE = "GetTemplateListFromFile";
36 protected static final String GET_XSLT_FILES_FOR_COLLECTION = "GetXSLTFilesForCollection";
37 protected static final String RESOLVE_CALL_TEMPLATE = "ResolveCallTemplate";
38 /*********************************************************/
39
40 String[] services = { GET_TEMPLATE_FROM_XML_FILE, SAVE_TEMPLATE_TO_XML_FILE, GET_TEMPLATE_LIST_FROM_FILE, GET_XSLT_FILES_FOR_COLLECTION, RESOLVE_CALL_TEMPLATE };
41
42 public boolean configure(Element info, Element extra_info)
43 {
44 if (!super.configure(info, extra_info))
45 {
46 return false;
47 }
48
49 logger.info("Configuring DebugServices...");
50 this.config_info = info;
51
52 for (int i = 0; i < services.length; i++)
53 {
54 Element service = this.doc.createElement(GSXML.SERVICE_ELEM);
55 service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
56 service.setAttribute(GSXML.NAME_ATT, services[i]);
57 this.short_service_info.appendChild(service);
58 }
59
60 return true;
61 }
62
63 protected Element getServiceDescription(String service_id, String lang, String subset)
64 {
65 for (int i = 0; i < services.length; i++)
66 {
67 if (service_id.equals(services[i]))
68 {
69 Element service_elem = this.doc.createElement(GSXML.SERVICE_ELEM);
70 service_elem.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
71 service_elem.setAttribute(GSXML.NAME_ATT, services[i]);
72 return service_elem;
73 }
74 }
75
76 return null;
77 }
78
79 protected Element processResolveCallTemplate(Element request)
80 {
81 Element result = GSXML.createBasicResponse(this.doc, RESOLVE_CALL_TEMPLATE);
82
83 if (request == null)
84 {
85 GSXML.addError(this.doc, result, RESOLVE_CALL_TEMPLATE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
86 return result;
87 }
88
89 UserContext context = new UserContext(request);
90 boolean found = false;
91 for (String group : context.getGroups())
92 {
93 if (group.equals("administrator"))
94 {
95 found = true;
96 }
97 }
98
99 if (!found)
100 {
101 GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
102 return result;
103 }
104
105 // Get the parameters of the request
106 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
107
108 if (param_list == null)
109 {
110 GSXML.addError(this.doc, result, RESOLVE_CALL_TEMPLATE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
111 return result;
112 }
113
114 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
115
116 String interfaceName = (String) params.get("interfaceName");
117 String siteName = (String) params.get("siteName");
118 String collectionName = (String) params.get("collectionName");
119 String fileName = (String) params.get("fileName");
120 String nameToGet = (String) params.get("templateName");
121
122 fileName = fileName.replace("\\", "/");
123
124 Document xslDoc = GSXSLT.mergedXSLTDocumentCascade(fileName, siteName, collectionName, interfaceName, new ArrayList<String>(), true);
125
126 int sepIndex = fileName.lastIndexOf("/");
127 String pathExtra = null;
128 if (sepIndex != -1)
129 {
130 pathExtra = fileName.substring(0, sepIndex + 1);
131 fileName = fileName.substring(sepIndex + 1);
132 }
133
134 GSXSLT.inlineImportAndIncludeFilesDebug(xslDoc, pathExtra, true, fileName, siteName, collectionName, interfaceName, new ArrayList<String>());
135
136 NodeList templateList = xslDoc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
137 for (int i = 0; i < templateList.getLength(); i++)
138 {
139 Element current = (Element) templateList.item(i);
140 if (current.hasAttribute("name") && current.getAttribute("name").equals(nameToGet))
141 {
142 Element debugElement = (Element) current.getElementsByTagName("debug").item(0);
143
144 Element requestedTemplate = this.doc.createElement("requestedTemplate");
145 requestedTemplate.setTextContent(debugElement.getAttribute("filename"));
146 result.appendChild(requestedTemplate);
147 }
148 }
149
150 return result;
151 }
152
153 protected Element processGetXMLTemplateFromFile(Element request)
154 {
155 Element result = GSXML.createBasicResponse(this.doc, GET_TEMPLATE_FROM_XML_FILE);
156
157 if (request == null)
158 {
159 GSXML.addError(this.doc, result, GET_TEMPLATE_FROM_XML_FILE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
160 return result;
161 }
162
163 UserContext context = new UserContext(request);
164 boolean found = false;
165 for (String group : context.getGroups())
166 {
167 if (group.equals("administrator"))
168 {
169 found = true;
170 }
171 }
172
173 if (!found)
174 {
175 GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
176 return result;
177 }
178
179 // Get the parameters of the request
180 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
181
182 if (param_list == null)
183 {
184 GSXML.addError(this.doc, result, GET_TEMPLATE_FROM_XML_FILE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
185 return result;
186 }
187
188 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
189
190 String locationName = (String) params.get("locationName");
191 String interfaceName = (String) params.get("interfaceName");
192 String siteName = (String) params.get("siteName");
193 String collectionName = (String) params.get("collectionName");
194 String fileName = (String) params.get("fileName");
195 String namespace = (String) params.get("namespace");
196 String nodeName = (String) params.get("nodename");
197 String nameToGet = (String) params.get("name");
198 String matchToGet = (String) params.get("match");
199
200 String fullNamespace;
201 if (namespace.toLowerCase().equals("gsf"))
202 {
203 fullNamespace = GSXML.GSF_NAMESPACE;
204 }
205 else if (namespace.toLowerCase().equals("xsl"))
206 {
207 fullNamespace = GSXML.XSL_NAMESPACE;
208 }
209 else
210 {
211 GSXML.addError(this.doc, result, "A valid namespace was not specified.");
212 return result;
213 }
214
215 File xslFile = createFileFromLocation(locationName, fileName, interfaceName, siteName, collectionName);
216 if (xslFile.exists())
217 {
218 XMLConverter converter = new XMLConverter();
219 Document xslDoc = converter.getDOM(xslFile, "UTF-8");
220
221 NodeList templateElems = xslDoc.getElementsByTagNameNS(fullNamespace, nodeName);
222
223 if (nameToGet != null && nameToGet.length() != 0)
224 {
225 for (int i = 0; i < templateElems.getLength(); i++)
226 {
227 Element template = (Element) templateElems.item(i);
228 if (template.getAttribute("name").equals(nameToGet))
229 {
230 fixAttributes(template);
231
232 Element requestedTemplate = this.doc.createElement("requestedNameTemplate");
233 requestedTemplate.appendChild(this.doc.importNode(template, true));
234 result.appendChild(requestedTemplate);
235 }
236 }
237 }
238
239 //Maybe should look for highest priority
240 if (matchToGet != null && matchToGet.length() != 0)
241 {
242 for (int i = 0; i < templateElems.getLength(); i++)
243 {
244 Element template = (Element) templateElems.item(i);
245 if (template.getAttribute("match").equals(matchToGet))
246 {
247 fixAttributes(template);
248
249 Element requestedTemplate = this.doc.createElement("requestedMatchTemplate");
250 requestedTemplate.appendChild(this.doc.importNode(template, true));
251 result.appendChild(requestedTemplate);
252 }
253 }
254 }
255 }
256
257 return result;
258 }
259
260 protected void fixAttributes(Element template)
261 {
262 NodeList nodes = template.getElementsByTagName("*");
263 for (int j = 0; j < nodes.getLength(); j++)
264 {
265 Node current = nodes.item(j);
266 NamedNodeMap attributes = current.getAttributes();
267 for (int k = 0; k < attributes.getLength(); k++)
268 {
269 Node currentAttr = attributes.item(k);
270 String value = currentAttr.getNodeValue();
271 if (value.contains("&") || value.contains("<") || value.contains(">") || value.contains("\""))
272 {
273 currentAttr.setNodeValue(value.replace("&", "&amp;amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;"));
274 }
275 }
276 }
277 }
278
279 protected Element processSaveXMLTemplateToFile(Element request)
280 {
281 Element result = GSXML.createBasicResponse(this.doc, SAVE_TEMPLATE_TO_XML_FILE);
282
283 if (request == null)
284 {
285 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
286 return result;
287 }
288
289 UserContext context = new UserContext(request);
290 boolean foundGroup = false;
291 for (String group : context.getGroups())
292 {
293 if (group.equals("administrator"))
294 {
295 foundGroup = true;
296 }
297 }
298
299 if (!foundGroup)
300 {
301 GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
302 return result;
303 }
304
305 // Get the parameters of the request
306 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
307
308 if (param_list == null)
309 {
310 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
311 return result;
312 }
313
314 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
315
316 String locationName = (String) params.get("locationName");
317 String fileName = (String) params.get("fileName");
318 String interfaceName = (String) params.get("interfaceName");
319 String siteName = (String) params.get("siteName");
320 String collectionName = (String) params.get("collectionName");
321 String namespace = (String) params.get("namespace");
322 String nodeName = (String) params.get("nodename");
323 String nameToSave = (String) params.get("name");
324 String matchToSave = (String) params.get("match");
325 String xml = (String) params.get("xml");
326
327 String fullNamespace;
328 if (namespace.toLowerCase().equals("gsf"))
329 {
330 fullNamespace = GSXML.GSF_NAMESPACE;
331 }
332 else if (namespace.toLowerCase().equals("xsl"))
333 {
334 fullNamespace = GSXML.XSL_NAMESPACE;
335 }
336 else
337 {
338 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + ": The specified namespace was not valid", GSXML.ERROR_TYPE_SYNTAX);
339 return result;
340 }
341
342 File xslFile = createFileFromLocation(locationName, fileName, interfaceName, siteName, collectionName);
343 if (xslFile.exists())
344 {
345 XMLConverter converter = new XMLConverter();
346 Document xslDoc = converter.getDOM(xslFile, "UTF-8");
347
348 NodeList templateElems = xslDoc.getElementsByTagNameNS(fullNamespace, nodeName);
349
350 boolean found = false;
351 if (nameToSave != null && nameToSave.length() != 0)
352 {
353 for (int i = 0; i < templateElems.getLength(); i++)
354 {
355 Element template = (Element) templateElems.item(i);
356 if (template.getAttribute("name").equals(nameToSave))
357 {
358 try
359 {
360 Element newTemplate = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"" + GSXML.XSL_NAMESPACE + "\" xmlns:java=\"" + GSXML.JAVA_NAMESPACE + "\" xmlns:util=\"" + GSXML.UTIL_NAMESPACE + "\" xmlns:gsf=\"" + GSXML.GSF_NAMESPACE + "\">" + xml + "</xsl:stylesheet>", "UTF-8").getDocumentElement().getElementsByTagNameNS(fullNamespace, nodeName).item(0);
361 template.getParentNode().replaceChild(xslDoc.importNode(newTemplate, true), template);
362 found = true;
363 }
364 catch (Exception ex)
365 {
366 ex.printStackTrace();
367 }
368 }
369 }
370 }
371 //Maybe should look for highest priority match
372 if (matchToSave != null && matchToSave.length() != 0)
373 {
374 for (int i = 0; i < templateElems.getLength(); i++)
375 {
376 Element template = (Element) templateElems.item(i);
377 if (template.getAttribute("match").equals(matchToSave))
378 {
379 Element newTemplate = (Element) converter.getDOM("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"" + GSXML.XSL_NAMESPACE + "\" xmlns:java=\"" + GSXML.JAVA_NAMESPACE + "\" xmlns:util=\"" + GSXML.UTIL_NAMESPACE + "\" xmlns:gsf=\"" + GSXML.GSF_NAMESPACE + "\">" + xml + "</xsl:stylesheet>", "UTF-8").getDocumentElement().getElementsByTagNameNS(fullNamespace, nodeName).item(0);
380 template.getParentNode().replaceChild(xslDoc.importNode(newTemplate, true), template);
381 found = true;
382 }
383 }
384 }
385
386 if (!found)
387 {
388 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + ": Could not save as the specified template could not be found", GSXML.ERROR_TYPE_SYNTAX);
389 }
390 else
391 {
392
393 try
394 {
395 Transformer transformer = TransformerFactory.newInstance().newTransformer();
396
397 //initialize StreamResult with File object to save to file
398 StreamResult sresult = new StreamResult(new FileWriter(xslFile));
399 DOMSource source = new DOMSource(xslDoc);
400 transformer.transform(source, sresult);
401 }
402 catch (Exception ex)
403 {
404 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + ": There was an error writing out the XML file", GSXML.ERROR_TYPE_SYNTAX);
405 }
406
407 }
408 }
409 else
410 {
411 GSXML.addError(this.doc, result, SAVE_TEMPLATE_TO_XML_FILE + "File: " + xslFile.getAbsolutePath() + " does not exist", GSXML.ERROR_TYPE_SYNTAX);
412 }
413
414 return result;
415 }
416
417 protected Element processGetTemplateListFromFile(Element request)
418 {
419 Element result = GSXML.createBasicResponse(this.doc, GET_TEMPLATE_LIST_FROM_FILE);
420
421 if (request == null)
422 {
423 GSXML.addError(this.doc, result, GET_TEMPLATE_LIST_FROM_FILE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
424 return result;
425 }
426
427 UserContext context = new UserContext(request);
428 boolean found = false;
429 for (String group : context.getGroups())
430 {
431 if (group.equals("administrator"))
432 {
433 found = true;
434 }
435 }
436
437 if (!found)
438 {
439 GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
440 return result;
441 }
442
443 // Get the parameters of the request
444 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
445
446 if (param_list == null)
447 {
448 GSXML.addError(this.doc, result, GET_TEMPLATE_FROM_XML_FILE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
449 return result;
450 }
451
452 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
453
454 String locationName = (String) params.get("locationName");
455 String siteName = (String) params.get("siteName");
456 String collectionName = (String) params.get("collectionName");
457 String interfaceName = (String) params.get("interfaceName");
458 String fileName = (String) params.get("fileName");
459
460 fileName.replace("/", File.separator);
461
462 if (locationName == null || locationName.length() == 0)
463 {
464 GSXML.addError(this.doc, result, "Parameter \"locationName\" was null or empty.");
465 return result;
466 }
467
468 File xslFile = createFileFromLocation(locationName, fileName, interfaceName, siteName, collectionName);
469
470 if (xslFile.exists())
471 {
472 XMLConverter converter = new XMLConverter();
473 Document xslDoc = converter.getDOM(xslFile, "UTF-8");
474
475 Element templateList = this.doc.createElement("templateList");
476 StringBuilder templateListString = new StringBuilder("[");
477
478 NodeList xslTemplateElems = xslDoc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
479 NodeList gsfTemplateElems = xslDoc.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "template");
480 for (int i = 0; i < xslTemplateElems.getLength() + gsfTemplateElems.getLength(); i++)
481 {
482 Element currentElem = (i < xslTemplateElems.getLength()) ? (Element) xslTemplateElems.item(i) : (Element) gsfTemplateElems.item(i - xslTemplateElems.getLength());
483 if (!currentElem.hasAttribute(GSXML.NAME_ATT) && !currentElem.hasAttribute(GSXML.MATCH_ATT))
484 {
485 continue;
486 }
487
488 templateListString.append("{");
489 templateListString.append("\"namespace\":\"" + ((i < xslTemplateElems.getLength()) ? "xsl" : "gsf") + "\",");
490 if (currentElem.hasAttribute(GSXML.NAME_ATT))
491 {
492 templateListString.append("\"name\":\"" + currentElem.getAttribute(GSXML.NAME_ATT) + "\",");
493 }
494 else if (currentElem.hasAttribute(GSXML.MATCH_ATT))
495 {
496 templateListString.append("\"match\":\"" + currentElem.getAttribute(GSXML.MATCH_ATT) + "\",");
497 }
498 templateListString.deleteCharAt(templateListString.length() - 1);
499 templateListString.append("},");
500 }
501
502 templateListString.deleteCharAt(templateListString.length() - 1);
503 templateListString.append("]");
504
505 templateList.setTextContent(templateListString.toString());
506 result.appendChild(templateList);
507 }
508 else
509 {
510 GSXML.addError(this.doc, result, "File: " + xslFile.getAbsolutePath() + " does not exist");
511 return result;
512 }
513
514 return result;
515 }
516
517 protected Element processGetXSLTFilesForCollection(Element request)
518 {
519 Element result = GSXML.createBasicResponse(this.doc, GET_XSLT_FILES_FOR_COLLECTION);
520
521 if (request == null)
522 {
523 GSXML.addError(this.doc, result, GET_XSLT_FILES_FOR_COLLECTION + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
524 return result;
525 }
526
527 UserContext context = new UserContext(request);
528 boolean found = false;
529 for (String group : context.getGroups())
530 {
531 if (group.equals("administrator"))
532 {
533 found = true;
534 }
535 }
536
537 if (!found)
538 {
539 GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
540 return result;
541 }
542
543 // Get the parameters of the request
544 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
545
546 if (param_list == null)
547 {
548 GSXML.addError(this.doc, result, GET_TEMPLATE_FROM_XML_FILE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
549 return result;
550 }
551
552 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
553
554 String interfaceName = (String) params.get("interfaceName");
555 String siteName = (String) params.get("siteName");
556 String collectionName = (String) params.get("collectionName");
557
558 Element fileList = this.doc.createElement("fileListJSON");
559 StringBuilder fileListString = new StringBuilder("[");
560
561 String[] placesToCheck = new String[] { GlobalProperties.getGSDL3Home() + File.separator + "interfaces" + File.separator + interfaceName + File.separator + "transform", //INTERFACE FILE PATH
562 GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "transform", //SITE FILE PATH
563 GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "collect" + File.separator + collectionName + File.separator + "transform", //COLLECTION FILE PATH
564 GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "collect" + File.separator + collectionName + File.separator + "etc" //COLLECTION CONFIG FILE PATH
565 };
566
567 String[] shortPlaceNames = new String[] { "interface", "site", "collection", "collectionConfig" };
568
569 for (int i = 0; i < placesToCheck.length; i++)
570 {
571 ArrayList<File> xslFiles = getXSLTFilesFromDirectoryRecursive(new File(placesToCheck[i]));
572 for (File f : xslFiles)
573 {
574 fileListString.append("{\"location\":\"" + shortPlaceNames[i] + "\",\"path\":\"" + f.getAbsolutePath().replace(placesToCheck[i] + File.separator, "") + "\"},");
575 }
576 }
577 fileListString.deleteCharAt(fileListString.length() - 1); //Remove the last , character
578 fileListString.append("]");
579
580 fileList.setTextContent(fileListString.toString());
581 result.appendChild(fileList);
582
583 return result;
584 }
585
586 protected File createFileFromLocation(String location, String filename, String interfaceName, String siteName, String collectionName)
587 {
588 String filePath = "";
589 if (location.equals("interface"))
590 {
591 filePath = GlobalProperties.getGSDL3Home() + File.separator + "interfaces" + File.separator + interfaceName + File.separator + "transform" + File.separator + filename;
592 }
593 else if (location.equals("site"))
594 {
595 filePath = GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "transform" + File.separator + filename;
596 }
597 else if (location.equals("collection"))
598 {
599 filePath = GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "collect" + File.separator + collectionName + File.separator + "transform" + File.separator + filename;
600 }
601 else if (location.equals("collectionConfig"))
602 {
603 filePath = GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + siteName + File.separator + "collect" + File.separator + collectionName + File.separator + "etc" + File.separator + filename;
604 }
605
606 return new File(filePath);
607 }
608
609 protected ArrayList<File> getXSLTFilesFromDirectoryRecursive(File dir)
610 {
611 ArrayList<File> result = new ArrayList<File>();
612
613 if (dir != null && dir.exists() && dir.isDirectory())
614 {
615 for (File f : dir.listFiles())
616 {
617 if (f.isDirectory())
618 {
619 result.addAll(getXSLTFilesFromDirectoryRecursive(f));
620 }
621 else if (f.getName().endsWith(".xsl") || f.getName().endsWith(".xml"))
622 {
623 result.add(f);
624 }
625 }
626 }
627
628 return result;
629 }
630}
Note: See TracBrowser for help on using the repository browser.