001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.platforms.servers.instances.tomcat;
009:
010: //base classes
011: import java.io.ByteArrayInputStream;
012: import java.io.ByteArrayOutputStream;
013: import java.io.File;
014: import java.io.FileOutputStream;
015: import java.io.IOException;
016: import java.io.InputStream;
017: import java.io.StringWriter;
018: import java.math.BigDecimal;
019: import java.net.HttpURLConnection;
020: import java.net.MalformedURLException;
021: import java.net.URL;
022: import java.net.URLConnection;
023: import java.sql.Connection;
024: import java.sql.PreparedStatement;
025: import java.sql.ResultSet;
026: import java.sql.SQLException;
027: import java.sql.Statement;
028: import java.util.ArrayList;
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.StringTokenizer;
032: import java.util.zip.ZipOutputStream;
033: import javax.naming.Context;
034: import javax.naming.InitialContext;
035: import javax.naming.NamingException;
036: import javax.rmi.PortableRemoteObject;
037: import javax.sql.DataSource;
038: import org.w3c.dom.Attr;
039: import org.w3c.dom.CDATASection;
040: import org.w3c.dom.Document;
041: import org.w3c.dom.Element;
042: import org.w3c.dom.Node;
043: import org.w3c.dom.NodeList;
044: import org.w3c.dom.Text;
045:
046: //project specific classes
047: import org.jfolder.common.UnexpectedSystemException;
048: import org.jfolder.common.files.BaseVirtualFileSystemHolder;
049: import org.jfolder.common.files.SimpleVirtualFileSystemProperties;
050: import org.jfolder.common.files.VirtualFileSystemDirectory;
051: import org.jfolder.common.files.VirtualFileSystemFile;
052: import org.jfolder.common.files.VirtualFileSystemHelper;
053: import org.jfolder.common.files.VirtualFileSystemHolder;
054: import org.jfolder.common.files.VirtualFileSystemRoot;
055: import org.jfolder.common.files.memory.MemoryFileSystemRootHelper;
056: import org.jfolder.common.function.BaseCompoundWebPageTag;
057: import org.jfolder.common.function.BaseStaticWebPageTag;
058: import org.jfolder.common.function.UnknownWebPageTag;
059: import org.jfolder.common.tagging.ConceptRollupTag;
060: import org.jfolder.common.tagging.ConceptTag;
061: import org.jfolder.common.tagging.ConceptTagCharacteristic;
062: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
063: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
064: import org.jfolder.common.tagging.ConceptTagPreferences;
065: import org.jfolder.common.tagging.ConceptTagProperties;
066: import org.jfolder.common.tagging.ConceptTagSetHolder;
067: import org.jfolder.common.tagging.RootConceptTagHolder;
068: import org.jfolder.common.tagging.SelectionCriteriaForConceptTag;
069: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
070: import org.jfolder.common.utils.misc.MiscHelper;
071: import org.jfolder.common.utils.xml.XMLHelper;
072: import org.jfolder.platforms.servers.base.SpecializedWebPageWriterHandler;
073: import org.jfolder.platforms.servers.base.SystemServer;
074: import org.jfolder.project.model.ProjectSystem;
075: import org.jfolder.services.config.ApplicationStoreSet;
076: import org.jfolder.services.config.ConfigService;
077: import org.jfolder.services.config.ConfigServiceCallerFactory;
078:
079: //other classes
080:
081: public class TomcatServer extends SystemServer {
082:
083: private final static String TOMCAT = "Tomcat";
084:
085: public TomcatServer() {
086: //this.conn = getConnection();
087: }
088:
089: public static String getDisplayName() {
090: return TomcatServer.TOMCAT;
091: }
092:
093: public String getActualWebTemplateLocation(String inHandle) {
094: return ("/WEB-INF/jsps/apps" + inHandle);
095: }
096:
097: public void restartServer() {
098: throw UnexpectedSystemException.notImplemented();
099: }
100:
101: public void deployProject(ProjectSystem inPs,
102: ConceptTagPreferences inCtp) {
103:
104: try {
105: //final String WAR_FILE = "./application.war";
106: //
107: //URL url = new URL(
108: // "http://localhost:8080/manager/install?path=" + inPs.getName()
109: // + "war=file:" + WAR_FILE);
110: //
111: String warLocalDir = MiscHelper.literalReplace(inPs
112: .getName(), "/", "_");
113: String warDir = "../webapps/" + warLocalDir;
114: //
115: VirtualFileSystemRoot rootDir = MemoryFileSystemRootHelper
116: .newInstance();
117: //BaseVirtualFileSystemHolder.copyDirectory(
118: // inPs.getWebDocs(), rootDir);
119: //
120: addFiles(inPs, inPs.getWebDocs(), inPs
121: .getWebDocsProperties(), rootDir);
122: //rootDir.createFile(
123: // "index.html", MiscHelper.fromStringToBytes(
124: // "<html><body>Hi</body></html>"));
125: //
126: VirtualFileSystemDirectory webInfDir = rootDir
127: .createDirectory("WEB-INF");
128: //
129: VirtualFileSystemDirectory tldsDir = webInfDir
130: .createDirectory("tlds");
131: HashMap tlNs = addTagLibs(inCtp, inCtp.getSetHolder(),
132: tldsDir);
133: //
134: webInfDir.createFile("web.xml", MiscHelper
135: .fromStringToBytes(getWebXmlFile(inPs, tlNs)));
136: //
137: VirtualFileSystemDirectory jspsDir = webInfDir
138: .createDirectory("jsps");
139: //
140: VirtualFileSystemDirectory appsDir = jspsDir
141: .createDirectory("apps");
142: addJsps(inPs, inPs.getWebDocs(), inPs
143: .getWebDocsProperties(), appsDir);
144: //
145: VirtualFileSystemDirectory metaInfDir = rootDir
146: .createDirectory("META-INF");
147: metaInfDir.createFile("context.xml", MiscHelper
148: .fromStringToBytes(getContextXmlFile(warLocalDir)));
149: //
150: ByteArrayOutputStream baos = new ByteArrayOutputStream();
151: ZipOutputStream zos = new ZipOutputStream(baos);
152: rootDir.zip(zos);
153: zos.flush();
154: zos.close();
155: baos.flush();
156: baos.close();
157: //
158: ByteArrayInputStream bais = new ByteArrayInputStream(baos
159: .toByteArray());
160: MiscHelper.parseZipInfo(bais, new File(warDir));
161: } catch (MalformedURLException mue) {
162: throw new UnexpectedSystemException(mue);
163: } catch (IOException ioe) {
164: throw new UnexpectedSystemException(ioe);
165: }
166: }
167:
168: private void addFiles(ProjectSystem inPs,
169: VirtualFileSystemHolder inFileSource,
170: VirtualFileSystemHolder inPropSource,
171: VirtualFileSystemHolder inDestination) {
172: //
173:
174: ArrayList localFiles = inFileSource.getLocalFiles();
175: for (int i = 0; i < localFiles.size(); i++) {
176: VirtualFileSystemFile nextSourceFile = (VirtualFileSystemFile) localFiles
177: .get(i);
178: VirtualFileSystemFile nextSourceProp = inPropSource
179: .getFile(nextSourceFile.getName());
180: SimpleVirtualFileSystemProperties nextSourceSvfsp = SimpleVirtualFileSystemProperties
181: .newInstance(nextSourceProp.getContent());
182:
183: if (inPs.isWebDocFile(nextSourceSvfsp)) {
184: inDestination.createFile(nextSourceFile.getName(),
185: nextSourceFile.getContent());
186: }
187: }
188:
189: ArrayList localDirectories = inFileSource.getLocalDirectories();
190: for (int i = 0; i < localDirectories.size(); i++) {
191: //
192: VirtualFileSystemDirectory nextFileSourceDir = (VirtualFileSystemDirectory) localDirectories
193: .get(i);
194: VirtualFileSystemDirectory nextPropSourceDir = inPropSource
195: .getDirectory(nextFileSourceDir.getName());
196: //
197: VirtualFileSystemDirectory nextDestinationDir = inDestination
198: .createDirectory(nextFileSourceDir.getName());
199: addFiles(inPs, nextFileSourceDir, nextPropSourceDir,
200: nextDestinationDir);
201: }
202: }
203:
204: private void addJsps(ProjectSystem inPs,
205: VirtualFileSystemHolder inFileSource,
206: VirtualFileSystemHolder inPropSource,
207: VirtualFileSystemHolder inDestination) {
208: //
209:
210: ArrayList localFiles = inFileSource.getLocalFiles();
211: for (int i = 0; i < localFiles.size(); i++) {
212: VirtualFileSystemFile nextSourceFile = (VirtualFileSystemFile) localFiles
213: .get(i);
214: VirtualFileSystemFile nextSourceProp = inPropSource
215: .getFile(nextSourceFile.getName());
216: SimpleVirtualFileSystemProperties nextSourceSvfsp = SimpleVirtualFileSystemProperties
217: .newInstance(nextSourceProp.getContent());
218:
219: if (inPs.isWebDocPage(nextSourceSvfsp)) {
220: //
221: RootConceptTagHolder nextSourceRcth = ConceptRollupTag
222: .getRootHolderFromList(nextSourceFile
223: .getContent());
224: //
225: //
226: //
227: String s = SpecializedWebPageWriterHandler
228: .reformatWebPage(nextSourceRcth, true);
229: //String s = nextSourceRcth.getXMLRepButReplaceRootElement(
230: // "http://java.sun.com/JSP/Page", "jsp", "root",
231: // new String[]{null}, new String[]{"version"},
232: // new String[]{null}, new String[]{"1.2"});
233: inDestination.createFile(
234: (nextSourceFile.getName() + ".jsp"), MiscHelper
235: .fromStringToBytes(s));
236: } else if (inPs.isWebDocTemplate(nextSourceSvfsp)
237: || inPs.isWebDocMacro(nextSourceSvfsp)
238: || inPs.isWebDocBinary(nextSourceSvfsp)) {
239: //
240: RootConceptTagHolder nextSourceRcth = ConceptRollupTag
241: .getRootHolderFromList(nextSourceFile
242: .getContent());
243: //
244: //
245: //
246: String s = SpecializedWebPageWriterHandler
247: .reformatWebPage(nextSourceRcth, false);
248: //
249: inDestination.createFile(nextSourceFile.getName(),
250: MiscHelper.fromStringToBytes(s));
251: }
252: }
253:
254: ArrayList localDirectories = inFileSource.getLocalDirectories();
255: for (int i = 0; i < localDirectories.size(); i++) {
256: //
257: VirtualFileSystemDirectory nextFileSourceDir = (VirtualFileSystemDirectory) localDirectories
258: .get(i);
259: VirtualFileSystemDirectory nextPropSourceDir = inPropSource
260: .getDirectory(nextFileSourceDir.getName());
261: //
262: VirtualFileSystemDirectory nextDestinationDir = inDestination
263: .createDirectory(nextFileSourceDir.getName());
264: addJsps(inPs, nextFileSourceDir, nextPropSourceDir,
265: nextDestinationDir);
266: }
267: }
268:
269: //private final static void reformatTextForWebPage(
270: // Document inDoc, Element inParentElement, Node inNode,
271: // String inValue) {
272: // //
273: //
274: // //make sure Windows newline doesn't show up twice
275: // String nextData = inValue.replaceAll("\\r\\n", "\n");
276: //
277: // //
278: // ArrayList futureData = new ArrayList();
279: // StringTokenizer st = new StringTokenizer(nextData, "\r\n ", true);
280: // while (st.hasMoreTokens()) {
281: // futureData.add(st.nextToken());
282: // }
283: //
284: // //
285: // Node referenceNode = inNode;
286: // for (int j = futureData.size() - 1; j >= 0; j--) {
287: // //
288: // Node updateNode = null;
289: // String updateData = (String)futureData.get(j);
290: // //
291: // if (updateData.equals("\n") || updateData.equals("\r")) {
292: // updateNode = inDoc.createElement("br");
293: // }
294: // else if (updateData.equals(" ")) {
295: // updateNode = inDoc.createTextNode(XMLHelper.NBSP_XML);
296: // }
297: // else {
298: // updateNode = inDoc.createTextNode(updateData);
299: // }
300: // //
301: // if (j == (futureData.size() - 1)) {
302: // inParentElement.replaceChild(updateNode, referenceNode);
303: // }
304: // else {
305: // inParentElement.insertBefore(updateNode, referenceNode);
306: // }
307: // referenceNode = updateNode;
308: // }
309: //}
310:
311: public void undeployProject(ProjectSystem inPs) {
312:
313: //try {
314: String warFile = "../webapps/"
315: + MiscHelper.literalReplace(inPs.getName(), "/", "_");
316: //
317: File warFileFile = new File(warFile);
318: if (warFileFile.exists()) {
319: MiscHelper.deleteFileOrDirectory(warFileFile);
320: }
321: //URL url = new URL(
322: // "http://localhost:8080/manager/remove?path="
323: // + inPs.getName());
324: //MiscHelper.println("TomcatServer undeploy = "
325: // + MiscHelper.fromBytesToString(doGet(url)));
326: //}
327: //catch (MalformedURLException mue) {
328: // throw new UnexpectedSystemException(mue);
329: //}
330: //catch (IOException ioe) {
331: // throw new UnexpectedSystemException(ioe);
332: //}
333: }
334:
335: //
336: //private final static String getWebXmlFile() {
337: //
338: // StringBuffer outValue = new StringBuffer();
339: //
340: // outValue.append("<!DOCTYPE web-app\n");
341: // outValue.append(" PUBLIC \"-//Sun Microsystems, Inc.//"
342: // + "DTD Web Application 2.3//EN\"\n");
343: // outValue.append(" \"http://java.sun.com/dtd/web-app_2_3.dtd\">\n");
344: // outValue.append("<web-app>\n");
345: // outValue.append("</web-app>\n");
346: //
347: // return outValue.toString();
348: //}
349: private byte[] doGet(URL inUrl) throws IOException {
350:
351: ByteArrayOutputStream outValue = new ByteArrayOutputStream();
352:
353: HttpURLConnection urlc = (HttpURLConnection) inUrl
354: .openConnection();
355: urlc.connect();
356: InputStream is = urlc.getInputStream();
357: byte buffer[] = new byte[1024];
358: int nextRead = 0;
359: while ((nextRead = is.read(buffer, 0, buffer.length)) != -1) {
360: outValue.write(buffer, 0, nextRead);
361: }
362: is.close();
363: urlc.disconnect();
364:
365: return outValue.toByteArray();
366: }
367:
368: public String getActualDataSourceName(String inHandle) {
369:
370: String outValue = null;
371:
372: outValue = "/jdbc/JFolder/" + inHandle;
373:
374: return outValue;
375: }
376:
377: private String getContextXmlFile(String inFile) {
378:
379: StringBuffer outValue = new StringBuffer();
380:
381: ConfigService cs = ConfigServiceCallerFactory
382: .getConfigService();
383: ApplicationStoreSet ass = ApplicationStoreSet.newInstance(cs);
384:
385: //outValue.append("<Context path=\"" + inPa + "\" docBase=\"./" + inFile
386: outValue.append("<Context override=\"true\" docBase=\"./"
387: + inFile + "\" antiResourceLocking=\"true\">\n");
388: for (int i = 0; i < ass.getDataSourceCount(); i++) {
389: outValue
390: .append("<ResourceLink global=\""
391: + getActualDataSourceName(ass
392: .getReferenceHandle(i))
393: + "\" name=\""
394: + getActualDataSourceName(ass
395: .getActualName(i))
396: + "\" type=\"javax.sql.DataSource\" />");
397: }
398: outValue.append(" <Manager pathname=\"\"/>\n");
399: outValue.append("</Context>\n");
400:
401: return outValue.toString();
402: }
403:
404: private void appendTagLibrary(StringBuffer inSb,
405: String inNamespace, String inFile) {
406:
407: inSb.append(" <taglib>\n");
408: inSb.append(" <taglib-uri>\n");
409: inSb.append(" " + inNamespace + "\n");
410: inSb.append(" </taglib-uri>\n");
411: inSb.append(" <taglib-location>\n");
412: inSb.append(" /WEB-INF/tlds/" + inFile + "\n");
413: inSb.append(" </taglib-location>\n");
414: inSb.append(" </taglib>\n");
415: }
416:
417: //private final static String getWebXmlFile(
418: // ProjectApplication inApplication, HashMap inWebTagLibs,
419: // String inStaticNamespace, String inCompoundNamespace,
420: // boolean inSameStaticCompoundNamespace) {
421: private String getWebXmlFile(ProjectSystem inPs, HashMap inH) {
422:
423: //
424: final String START = "<!DOCTYPE web-app\n"
425: + " PUBLIC \"-//Sun Microsystems, Inc."
426: + "//DTD Web Application 2.3//EN\"\n"
427: + " \"http://java.sun.com/dtd/web-app_2_3.dtd\">\n"
428: + "\n" + "<web-app>\n";
429: final String END = "</web-app>\n";
430:
431: //
432: //
433: StringBuffer outValue = new StringBuffer();
434:
435: outValue.append(START);
436:
437: outValue.append(" <servlet>\n");
438: outValue.append(" <servlet-name>\n");
439: outValue.append(" "
440: + TomcatWebPageServlet.class.getName() + "\n");
441: outValue.append(" </servlet-name>\n");
442: outValue.append(" <servlet-class>\n");
443: outValue.append(" "
444: + TomcatWebPageServlet.class.getName() + "\n");
445: outValue.append(" </servlet-class>\n");
446: outValue.append(" </servlet>\n");
447: //
448: outValue.append(" <servlet>\n");
449: outValue.append(" <servlet-name>\n");
450: outValue.append(" "
451: + TomcatWebPageBinaryServlet.class.getName() + "\n");
452: outValue.append(" </servlet-name>\n");
453: outValue.append(" <servlet-class>\n");
454: outValue.append(" "
455: + TomcatWebPageBinaryServlet.class.getName() + "\n");
456: outValue.append(" </servlet-class>\n");
457: outValue.append(" </servlet>\n");
458:
459: addServletMappings(inPs, "/", inPs.getWebDocs(), inPs
460: .getWebDocsProperties(), outValue);
461:
462: Iterator webTagLibIter = inH.keySet().iterator();
463: for (int i = 0; webTagLibIter.hasNext(); i++) {
464: String nextNs = (String) webTagLibIter.next();
465: appendTagLibrary(outValue, nextNs, (String) inH.get(nextNs));
466: }
467: //
468: addResourceRefs(outValue);
469: //
470: //if (!inSameStaticCompoundNamespace) {
471: // appendTagLibrary(outValue, inStaticNamespace, "z" + 0 + ".tld");
472: // appendTagLibrary(outValue, inCompoundNamespace, "z" + 1 + ".tld");
473: //}
474: //else {
475: // appendTagLibrary(outValue, inStaticNamespace, "z" + 0 + ".tld");
476: //}
477:
478: outValue.append(END);
479:
480: return outValue.toString();
481: }
482:
483: private void addResourceRefs(StringBuffer inSb) {
484: //
485: ConfigService cs = ConfigServiceCallerFactory
486: .getConfigService();
487: ApplicationStoreSet ass = ApplicationStoreSet.newInstance(cs);
488:
489: for (int i = 0; i < ass.getDataSourceCount(); i++) {
490: inSb.append(" <resource-ref>\n");
491: inSb.append(" <res-ref-name>"
492: + getActualDataSourceName(ass.getActualName(i))
493: + "</res-ref-name>\n");
494: inSb
495: .append(" <res-type>javax.sql.DataSource</res-type>\n");
496: inSb.append(" <res-auth>Container</res-auth>\n");
497: inSb.append(" </resource-ref>\n");
498: }
499: }
500:
501: private void addServletMappings(ProjectSystem inPs,
502: String inCurrentDir, VirtualFileSystemHolder inFileVfsh,
503: VirtualFileSystemHolder inPropVfsh, StringBuffer inSb) {
504: //
505:
506: ArrayList localFiles = inFileVfsh.getLocalFiles();
507: for (int i = 0; i < localFiles.size(); i++) {
508: VirtualFileSystemFile nextFile = (VirtualFileSystemFile) localFiles
509: .get(i);
510: VirtualFileSystemFile nextProp = inPropVfsh
511: .getFile(nextFile.getName());
512: //
513: SimpleVirtualFileSystemProperties nextSourceSvfsp = SimpleVirtualFileSystemProperties
514: .newInstance(nextProp.getContent());
515:
516: if (inPs.isWebDocBinary(nextSourceSvfsp)) {
517: //
518: inSb.append(" <servlet-mapping>\n");
519: inSb.append(" <servlet-name>\n");
520: inSb.append(" "
521: + TomcatWebPageBinaryServlet.class.getName()
522: + "\n");
523: inSb.append(" </servlet-name>\n");
524: inSb.append(" <url-pattern>\n");
525: inSb.append(" " + inCurrentDir
526: + nextFile.getName() + "\n");
527: inSb.append(" </url-pattern>\n");
528: inSb.append(" </servlet-mapping>\n");
529: } else if (inPs.isWebDocPage(nextSourceSvfsp)) {
530: //
531: inSb.append(" <servlet-mapping>\n");
532: inSb.append(" <servlet-name>\n");
533: inSb.append(" "
534: + TomcatWebPageServlet.class.getName() + "\n");
535: inSb.append(" </servlet-name>\n");
536: inSb.append(" <url-pattern>\n");
537: inSb.append(" " + inCurrentDir
538: + nextFile.getName() + "\n");
539: inSb.append(" </url-pattern>\n");
540: inSb.append(" </servlet-mapping>\n");
541: }
542: }
543:
544: ArrayList localDirectories = inFileVfsh.getLocalDirectories();
545: for (int i = 0; i < localDirectories.size(); i++) {
546: VirtualFileSystemDirectory nextFileDir = (VirtualFileSystemDirectory) localDirectories
547: .get(i);
548: VirtualFileSystemDirectory nextPropDir = inPropVfsh
549: .getDirectory(nextFileDir.getName());
550: //
551: addServletMappings(inPs, (inCurrentDir
552: + nextFileDir.getName() + "/"), nextFileDir,
553: nextPropDir, inSb);
554: }
555: }
556:
557: private String getTagLibraryDescriptor(String inNamespace,
558: ArrayList inNames, ConceptTagSetHolder inWebCtsh) {
559:
560: String outValue = null;
561:
562: HashMap nameAndClass = new HashMap();
563: for (int i = 0; i < inNames.size(); i++) {
564: String nextName = (String) inNames.get(i);
565: String nextClass = inWebCtsh.getConceptTagClass(
566: inNamespace, nextName).getName();
567:
568: nameAndClass.put(nextName, nextClass);
569: }
570:
571: outValue = getTagLibraryDescriptor(inNamespace, nameAndClass);
572:
573: return outValue;
574: }
575:
576: private String getTagLibraryDescriptor(String inNamespace,
577: HashMap inNameAndClass) {
578:
579: String START = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
580: + "<!DOCTYPE taglib\n"
581: + " PUBLIC \"-//Sun Microsystems, Inc."
582: + "//DTD JSP Tag Library 1.2//EN\"\n"
583: + " \"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd\">\n"
584: + "<taglib>\n"
585: + " <tlib-version>1.0</tlib-version>\n"
586: + " <jsp-version>1.2</jsp-version>\n"
587: + " <short-name>" + inNamespace + "</short-name>\n";
588: String END = "</taglib>\n";
589:
590: StringBuffer outValue = new StringBuffer();
591:
592: outValue.append(START);
593:
594: Iterator iter = inNameAndClass.keySet().iterator();
595:
596: while (iter.hasNext()) {
597: String nextName = (String) iter.next();
598: String nextClass = (String) inNameAndClass.get(nextName);
599:
600: outValue.append(" <tag>\n");
601: outValue.append(" <name>" + nextName + "</name>\n");
602: outValue.append(" <tag-class>" + nextClass
603: + "</tag-class>\n");
604: outValue
605: .append(" <body-content>JSP</body-content>\n");
606: outValue.append(" <description>" + nextName
607: + "</description>\n");
608: outValue.append(" <attribute>\n");
609: outValue.append(" <name>constraint</name>\n");
610: outValue.append(" <required>false</required>\n");
611: outValue
612: .append(" <rtexprvalue>false</rtexprvalue>\n");
613: outValue.append(" </attribute>\n");
614: outValue.append(" </tag>\n");
615: }
616:
617: outValue.append(END);
618:
619: return outValue.toString();
620: }
621:
622: public HashMap addTagLibs(ConceptTagPreferences inCtp,
623: ConceptTagSetHolder inWebCtsh,
624: VirtualFileSystemHolder inTldsDir) {
625:
626: HashMap outValue = new HashMap();
627:
628: //tab library deployment descriptors
629: //determine entries for 'compound' and 'static' types
630: //
631: String staticNamespace = inCtp.getStaticNamespace();
632: String staticName = inCtp.getStaticName();
633: //String staticClass = BaseStaticWebTag.class.getName();
634: String staticClass = BaseStaticWebPageTag.class.getName();
635: String compoundNamespace = inCtp.getCompoundNamespace();
636: String compoundName = inCtp.getCompoundName();
637: //String compoundClass = BaseCompoundWebTag.class.getName();
638: String compoundClass = BaseCompoundWebPageTag.class.getName();
639: boolean sameStaticCompoundNamespace = staticNamespace
640: .equals(compoundNamespace);
641: //
642: //ArrayList staticNameList = new ArrayList();
643: //ArrayList compoundNameList = new ArrayList();
644: HashMap staticNameAndClass = new HashMap();
645: HashMap compoundNameAndClass = new HashMap();
646: //
647: if (!sameStaticCompoundNamespace) {
648: //staticNameList.add(staticName);
649: //compoundNameList.add(compoundName);
650: staticNameAndClass.put(staticName, staticClass);
651: compoundNameAndClass.put(compoundName, compoundClass);
652: } else {
653: //staticNameList.add(staticName);
654: //staticNameList.add(compoundName);
655: staticNameAndClass.put(staticName, staticClass);
656: staticNameAndClass.put(compoundName, compoundClass);
657: }
658: //
659: //
660:
661: ArrayList webTagNamespaces = inWebCtsh
662: .getRegisteredNameSpaces();
663:
664: HashMap webTagLibs = new HashMap();
665:
666: for (int i = 0; i < webTagNamespaces.size(); i++) {
667: String nextWebTagNamespace = (String) webTagNamespaces
668: .get(i);
669: ArrayList nextWebTagNames = inWebCtsh
670: .getRegisteredNames(nextWebTagNamespace);
671: ArrayList nextAvailableWebTagNames = new ArrayList();
672: for (int j = 0; j < nextWebTagNames.size(); j++) {
673: String nextWebTagName = (String) nextWebTagNames.get(j);
674: Class nextWebTagClass = inWebCtsh.getConceptTagClass(
675: nextWebTagNamespace, nextWebTagName);
676: //MiscHelper.println("apps.GenJbProApp = " + nextWebTagClass);
677: //MiscHelper.println("isStudioOnly = "
678: // + inWebCtsh.isStudioOnly(nextWebTagClass));
679: //ConceptTagProperties nextWebTagProps =
680: // inWebCtsh.getConceptTagProperties(
681: // nextWebTagClass.getName());
682: //
683: //MiscHelper.println("TomcatServer find rep for isActsAsText");
684: ConceptTag nextWebTagCt = inWebCtsh
685: .getConceptTagFromClass(nextWebTagClass);
686: //SelectionCriteriaForConceptTag scfct =
687: // inWebCtsh.getSelectionCriteria(nextWebTagClass);
688: //nextWebTagCt.appraise(scfct);
689: if (!ConceptTagFlagsHelper
690: .isConceptTagUndeployable(nextWebTagCt)) {
691: //
692: nextAvailableWebTagNames.add(nextWebTagName);
693: }
694: }
695: if (nextAvailableWebTagNames.size() > 0) {
696: webTagLibs.put(nextWebTagNamespace,
697: nextAvailableWebTagNames);
698: }
699: }
700: Iterator webTagLibsIter = webTagLibs.keySet().iterator();
701: for (int i = 0; webTagLibsIter.hasNext(); i++) {
702: String nextNamespace = (String) webTagLibsIter.next();
703: ArrayList nextNames = (ArrayList) webTagLibs
704: .get(nextNamespace);
705: String nextTlDesc = getTagLibraryDescriptor(nextNamespace,
706: nextNames, inWebCtsh);
707: //MiscHelper.println("nextTagLibDescriptor= "
708: // + nextTagLibDescriptor);
709: String f = ("a" + i + ".tld");
710: outValue.put(nextNamespace, f);
711: inTldsDir.createFile(f, MiscHelper
712: .fromStringToBytes(nextTlDesc));
713: }
714: //
715: if (!sameStaticCompoundNamespace) {
716: String staticTlDesc = getTagLibraryDescriptor(
717: staticNamespace, staticNameAndClass);
718: String f = ("z" + 0 + ".tld");
719: outValue.put(staticNamespace, f);
720: inTldsDir.createFile(f, MiscHelper
721: .fromStringToBytes(staticTlDesc));
722: //
723: String compTlDesc = getTagLibraryDescriptor(
724: compoundNamespace, compoundNameAndClass);
725: String g = ("z" + 1 + ".tld");
726: outValue.put(compoundNamespace, g);
727: inTldsDir.createFile(g, MiscHelper
728: .fromStringToBytes(compTlDesc));
729: } else {
730: //both static and compound in same HashMap, same namespace
731: String staticTlDesc = getTagLibraryDescriptor(
732: staticNamespace, staticNameAndClass);
733: String f = ("z" + 0 + ".tld");
734: outValue.put(staticNamespace, f);
735: inTldsDir.createFile(f, MiscHelper
736: .fromStringToBytes(staticTlDesc));
737: }
738: //
739: return outValue;
740: }
741:
742: public String getRelativeWebPageLocation(String inName) {
743:
744: StringBuffer outValue = new StringBuffer();
745:
746: outValue.append("/WEB-INF/jsps/apps/");
747: outValue.append(inName);
748: outValue.append(".jsp");
749:
750: return outValue.toString();
751: }
752: }
|