001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: //
007: package com.sun.portal.ffj.util;
008:
009: import java.util.StringTokenizer;
010:
011: import org.w3c.dom.Attr;
012: import org.w3c.dom.Document;
013: import org.w3c.dom.Element;
014: import org.w3c.dom.NamedNodeMap;
015: import org.w3c.dom.Node;
016: import org.w3c.dom.NodeList;
017:
018: //
019: public class ParEntryScanner {
020: private Document document = null;
021: private ParEntry parEntry = null;
022:
023: public ParEntryScanner(Document document, ParEntry pe) {
024: this .document = document;
025: this .parEntry = pe;
026: }
027:
028: public void visitDocument() {
029: //
030: Element element = document.getDocumentElement();
031:
032: //
033: if ((element != null)
034: && element.getTagName().equals("ParEntry")) {
035: visitElement_ParEntry(element);
036: }
037: if ((element != null)
038: && element.getTagName().equals("Description")) {
039: visitElement_Description(element);
040: }
041: if ((element != null)
042: && element.getTagName().equals("Provider")) {
043: visitElement_Provider(element);
044: }
045: if ((element != null) && element.getTagName().equals("Extends")) {
046: visitElement_Extends(element);
047: }
048: if ((element != null)
049: && element.getTagName().equals("Reference")) {
050: visitElement_Reference(element);
051: }
052: if ((element != null)
053: && element.getTagName().equals("Properties")) {
054: visitElement_Properties(element);
055: }
056: if ((element != null)
057: && element.getTagName().equals("Collection")) {
058: visitElement_Collection(element);
059: }
060: if ((element != null) && element.getTagName().equals("Integer")) {
061: visitElement_Integer(element);
062: }
063: if ((element != null) && element.getTagName().equals("String")) {
064: visitElement_String(element);
065: }
066: if ((element != null) && element.getTagName().equals("Boolean")) {
067: visitElement_Boolean(element);
068: }
069: if ((element != null) && element.getTagName().equals("Locale")) {
070: visitElement_Locale(element);
071: }
072: if ((element != null) && element.getTagName().equals("Channel")) {
073: visitElement_Channel(element);
074: }
075: }
076:
077: private void visitElement_ParEntry(Element element) { // <ParEntry>
078: // element.getValue();
079:
080: //
081: NamedNodeMap attrs = element.getAttributes();
082:
083: for (int i = 0; i < attrs.getLength(); i++) {
084: Attr attr = (Attr) attrs.item(i);
085: if (attr.getName().equals("xmlns:ParEntry")) { // <ParEntry xmlns:ParEntry="???">
086: // attr.getValue();
087: }
088: if (attr.getName().equals("name")) { // <ParEntry name="???">
089: // attr.getValue();
090: }
091: if (attr.getName().equals("version")) { // <ParEntry version="???">
092: // attr.getValue();
093: }
094: if (attr.getName().equals("date")) { // <ParEntry date="???">
095: // attr.getValue();
096: }
097: if (attr.getName().equals("author")) { // <ParEntry author="???">
098: // attr.getValue();
099: }
100:
101: // This won't matter if we have a document which contains a
102: // provider - the provider will override this.
103:
104: if (attr.getName().equals("requiredClass")) { // <ParEntry requiredClass="???">
105: String providerClass = attr.getValue();
106: parEntry.setProviderClass(providerClass);
107: }
108: }
109:
110: //
111: NodeList nodes = element.getChildNodes();
112: for (int i = 0; i < nodes.getLength(); i++) {
113: Node node = nodes.item(i);
114:
115: switch (node.getNodeType()) {
116: case Node.CDATA_SECTION_NODE:
117: // ((CDATASection)node).getData();
118:
119: break;
120:
121: case Node.ELEMENT_NODE:
122: Element nodeElement = (Element) node;
123:
124: if (nodeElement.getTagName().equals("Description")) {
125: visitElement_Description(nodeElement);
126: }
127: if (nodeElement.getTagName().equals("Provider")) {
128: visitElement_Provider(nodeElement);
129: }
130: if (nodeElement.getTagName().equals("Channel")) {
131: visitElement_Channel(nodeElement);
132: }
133: if (nodeElement.getTagName().equals("Workspace")) {
134: visitElement_Workspace(nodeElement);
135: }
136:
137: break;
138:
139: case Node.PROCESSING_INSTRUCTION_NODE:
140: // ((ProcessingInstruction)node).getTarget();
141: // ((ProcessingInstruction)node).getData();
142:
143: break;
144: }
145: }
146: }
147:
148: private void visitElement_Description(Element element) { // <Description>
149: // element.getValue();
150:
151: //
152: NodeList nodes = element.getChildNodes();
153:
154: for (int i = 0; i < nodes.getLength(); i++) {
155: Node node = nodes.item(i);
156:
157: switch (node.getNodeType()) {
158: case Node.CDATA_SECTION_NODE:
159: // ((CDATASection)node).getData();
160:
161: break;
162:
163: case Node.ELEMENT_NODE:
164: Element nodeElement = (Element) node;
165:
166: break;
167:
168: case Node.PROCESSING_INSTRUCTION_NODE:
169: // ((ProcessingInstruction)node).getTarget();
170: // ((ProcessingInstruction)node).getData();
171:
172: break;
173:
174: case Node.TEXT_NODE:
175: // ((Text)node).getData();
176:
177: break;
178: }
179: }
180: }
181:
182: private void visitElement_Provider(Element element) { // <Provider>
183: //
184: NamedNodeMap attrs = element.getAttributes();
185:
186: for (int i = 0; i < attrs.getLength(); i++) {
187: Attr attr = (Attr) attrs.item(i);
188:
189: if (attr.getName().equals("name")) { // <Provider name="???">
190: // attr.getValue();
191: }
192: if (attr.getName().equals("class")) { // <Provider class="???">
193: String providerClass = attr.getValue();
194: parEntry.setProviderClass(providerClass);
195: }
196: if (attr.getName().equals("merge")) { // <Provider merge="???">
197: // attr.getValue();
198: }
199: if (attr.getName().equals("lock")) { // <Provider lock="???">
200: // attr.getValue();
201: }
202: }
203:
204: //
205: NodeList nodes = element.getChildNodes();
206:
207: for (int i = 0; i < nodes.getLength(); i++) {
208: Node node = nodes.item(i);
209: switch (node.getNodeType()) {
210: case Node.CDATA_SECTION_NODE:
211: // ((CDATASection)node).getData();
212:
213: break;
214:
215: case Node.ELEMENT_NODE:
216: Element nodeElement = (Element) node;
217: if (nodeElement.getTagName().equals("Extends")) {
218: visitElement_Extends(nodeElement);
219: }
220: if (nodeElement.getTagName().equals("Properties")) {
221: visitElement_Properties(nodeElement);
222: }
223:
224: break;
225:
226: case Node.PROCESSING_INSTRUCTION_NODE:
227: // ((ProcessingInstruction)node).getTarget();
228: // ((ProcessingInstruction)node).getData();
229:
230: break;
231: }
232: }
233: }
234:
235: private void visitElement_Extends(Element element) { // <Extends>
236: // element.getValue();
237:
238: //
239: NodeList nodes = element.getChildNodes();
240:
241: for (int i = 0; i < nodes.getLength(); i++) {
242: Node node = nodes.item(i);
243:
244: switch (node.getNodeType()) {
245: case Node.CDATA_SECTION_NODE:
246: // ((CDATASection)node).getData();
247:
248: break;
249:
250: case Node.ELEMENT_NODE:
251: Element nodeElement = (Element) node;
252: if (nodeElement.getTagName().equals("Reference")) {
253: visitElement_Reference(nodeElement);
254: }
255:
256: break;
257: case Node.PROCESSING_INSTRUCTION_NODE:
258: // ((ProcessingInstruction)node).getTarget();
259: // ((ProcessingInstruction)node).getData();
260:
261: break;
262: }
263: }
264: }
265:
266: private void visitElement_Reference(Element element) { // <Reference>
267: // element.getValue();
268:
269: //
270: NamedNodeMap attrs = element.getAttributes();
271:
272: for (int i = 0; i < attrs.getLength(); i++) {
273: Attr attr = (Attr) attrs.item(i);
274:
275: if (attr.getName().equals("value")) { // <Reference value="???">
276: // attr.getValue();
277: }
278: if (attr.getName().equals("merge")) { // <Reference merge="???">
279: // attr.getValue();
280: }
281: if (attr.getName().equals("lock")) { // <Reference lock="???">
282: // attr.getValue();
283: }
284: if (attr.getName().equals("propagate")) { // <Reference propagate="???">
285: // attr.getValue();
286: }
287: }
288:
289: //
290: NodeList nodes = element.getChildNodes();
291:
292: for (int i = 0; i < nodes.getLength(); i++) {
293: Node node = nodes.item(i);
294:
295: switch (node.getNodeType()) {
296: case Node.CDATA_SECTION_NODE:
297: // ((CDATASection)node).getData();
298:
299: break;
300:
301: case Node.ELEMENT_NODE:
302: Element nodeElement = (Element) node;
303:
304: break;
305:
306: case Node.PROCESSING_INSTRUCTION_NODE:
307: // ((ProcessingInstruction)node).getTarget();
308: // ((ProcessingInstruction)node).getData();
309:
310: break;
311: }
312: }
313: }
314:
315: private void visitElement_Properties(Element element) { // <Properties>
316: // element.getValue();
317:
318: //
319: NamedNodeMap attrs = element.getAttributes();
320:
321: for (int i = 0; i < attrs.getLength(); i++) {
322: Attr attr = (Attr) attrs.item(i);
323:
324: if (attr.getName().equals("name")) { // <Properties name="???">
325: // attr.getValue();
326: }
327: if (attr.getName().equals("merge")) { // <Properties merge="???">
328: // attr.getValue();
329: }
330: if (attr.getName().equals("lock")) { // <Properties lock="???">
331: // attr.getValue();
332: }
333: if (attr.getName().equals("propagate")) { // <Properties propagate="???">
334: // attr.getValue();
335: }
336: }
337:
338: //
339: NodeList nodes = element.getChildNodes();
340:
341: for (int i = 0; i < nodes.getLength(); i++) {
342: Node node = nodes.item(i);
343:
344: switch (node.getNodeType()) {
345: case Node.CDATA_SECTION_NODE:
346: // ((CDATASection)node).getData();
347:
348: break;
349:
350: case Node.ELEMENT_NODE:
351: Element nodeElement = (Element) node;
352:
353: if (nodeElement.getTagName().equals("Collection")) {
354: visitElement_Collection(nodeElement);
355: }
356: if (nodeElement.getTagName().equals("Integer")) {
357: visitElement_Integer(nodeElement);
358: }
359: if (nodeElement.getTagName().equals("String")) {
360: visitElement_String(nodeElement);
361: }
362: if (nodeElement.getTagName().equals("Boolean")) {
363: visitElement_Boolean(nodeElement);
364: }
365: if (nodeElement.getTagName().equals("Locale")) {
366: visitElement_Locale(nodeElement);
367: }
368:
369: break;
370:
371: case Node.PROCESSING_INSTRUCTION_NODE:
372: // ((ProcessingInstruction)node).getTarget();
373: // ((ProcessingInstruction)node).getData();
374:
375: break;
376: }
377: }
378: }
379:
380: private void visitElement_Collection(Element element) { // <Collection>
381: // element.getValue();
382:
383: //
384: NamedNodeMap attrs = element.getAttributes();
385:
386: for (int i = 0; i < attrs.getLength(); i++) {
387: Attr attr = (Attr) attrs.item(i);
388:
389: if (attr.getName().equals("name")) { // <Collection name="???">
390: // attr.getValue();
391: }
392: if (attr.getName().equals("merge")) { // <Collection merge="???">
393: // attr.getValue();
394: }
395: if (attr.getName().equals("lock")) { // <Collection lock="???">
396: // attr.getValue();
397: }
398: if (attr.getName().equals("propagate")) { // <Collection propagate="???">
399: // attr.getValue();
400: }
401: }
402:
403: //
404: NodeList nodes = element.getChildNodes();
405:
406: for (int i = 0; i < nodes.getLength(); i++) {
407: Node node = nodes.item(i);
408:
409: switch (node.getNodeType()) {
410: case Node.CDATA_SECTION_NODE:
411: // ((CDATASection)node).getData();
412:
413: break;
414:
415: case Node.ELEMENT_NODE:
416: Element nodeElement = (Element) node;
417:
418: if (nodeElement.getTagName().equals("Collection")) {
419: visitElement_Collection(nodeElement);
420: }
421: if (nodeElement.getTagName().equals("Integer")) {
422: visitElement_Integer(nodeElement);
423: }
424: if (nodeElement.getTagName().equals("String")) {
425: visitElement_String(nodeElement);
426: }
427: if (nodeElement.getTagName().equals("Boolean")) {
428: visitElement_Boolean(nodeElement);
429: }
430:
431: break;
432:
433: case Node.PROCESSING_INSTRUCTION_NODE:
434: // ((ProcessingInstruction)node).getTarget();
435: // ((ProcessingInstruction)node).getData();
436:
437: break;
438: }
439: }
440: }
441:
442: private void visitElement_Integer(Element element) { // <Integer>
443: // element.getValue();
444:
445: //
446: NamedNodeMap attrs = element.getAttributes();
447:
448: for (int i = 0; i < attrs.getLength(); i++) {
449: Attr attr = (Attr) attrs.item(i);
450:
451: if (attr.getName().equals("name")) { // <Integer name="???">
452: // attr.getValue();
453: }
454: if (attr.getName().equals("value")) { // <Integer value="???">
455: // attr.getValue();
456: }
457: if (attr.getName().equals("merge")) { // <Integer merge="???">
458: // attr.getValue();
459: }
460: if (attr.getName().equals("lock")) { // <Integer lock="???">
461: // attr.getValue();
462: }
463: if (attr.getName().equals("propagate")) { // <Integer propagate="???">
464: // attr.getValue();
465: }
466: }
467:
468: //
469: NodeList nodes = element.getChildNodes();
470:
471: for (int i = 0; i < nodes.getLength(); i++) {
472: Node node = nodes.item(i);
473:
474: switch (node.getNodeType()) {
475: case Node.CDATA_SECTION_NODE:
476: // ((CDATASection)node).getData();
477:
478: break;
479:
480: case Node.ELEMENT_NODE:
481: Element nodeElement = (Element) node;
482:
483: break;
484:
485: case Node.PROCESSING_INSTRUCTION_NODE:
486: // ((ProcessingInstruction)node).getTarget();
487: // ((ProcessingInstruction)node).getData();
488:
489: break;
490: }
491: }
492: }
493:
494: private void visitElement_String(Element element) { // <String>
495: //
496: String name = null;
497: String value = null;
498:
499: //
500: NamedNodeMap attrs = element.getAttributes();
501:
502: for (int i = 0; i < attrs.getLength(); i++) {
503: Attr attr = (Attr) attrs.item(i);
504:
505: if (attr.getName().equals("name")) { // <String name="???">
506: name = attr.getValue();
507: }
508: if (attr.getName().equals("value")) { // <String value="???">
509: value = attr.getValue();
510: }
511: if (attr.getName().equals("merge")) { // <String merge="???">
512: // attr.getValue();
513: }
514: if (attr.getName().equals("lock")) { // <String lock="???">
515: // attr.getValue();
516: }
517: if (attr.getName().equals("propagate")) { // <String propagate="???">
518: // attr.getValue();
519: }
520:
521: }
522:
523: // Handle contentPage, editPage, processPage properties,
524: // if they are present.
525: if (name != null) {
526: if (name.equals("contentPage")) {
527: parEntry.setContentPage(value);
528: } else if (name.equals("editPage")) {
529: parEntry.setEditPage(value);
530: } else if (name.equals("processPage")) {
531: parEntry.setProcessPage(value);
532: }
533: }
534:
535: //
536: NodeList nodes = element.getChildNodes();
537:
538: for (int i = 0; i < nodes.getLength(); i++) {
539: Node node = nodes.item(i);
540:
541: switch (node.getNodeType()) {
542: case Node.CDATA_SECTION_NODE:
543: // ((CDATASection)node).getData();
544:
545: break;
546:
547: case Node.ELEMENT_NODE:
548: Element nodeElement = (Element) node;
549:
550: break;
551:
552: case Node.PROCESSING_INSTRUCTION_NODE:
553: // ((ProcessingInstruction)node).getTarget();
554: // ((ProcessingInstruction)node).getData();
555:
556: break;
557:
558: case Node.TEXT_NODE:
559: // ((Text)node).getData();
560:
561: break;
562: }
563: }
564: }
565:
566: private void visitElement_Boolean(Element element) { // <Boolean>
567: // element.getValue();
568:
569: //
570: NamedNodeMap attrs = element.getAttributes();
571:
572: for (int i = 0; i < attrs.getLength(); i++) {
573: Attr attr = (Attr) attrs.item(i);
574:
575: if (attr.getName().equals("name")) { // <Boolean name="???">
576: // attr.getValue();
577: }
578: if (attr.getName().equals("value")) { // <Boolean value="???">
579: // attr.getValue();
580: }
581: if (attr.getName().equals("merge")) { // <Boolean merge="???">
582: // attr.getValue();
583: }
584: if (attr.getName().equals("lock")) { // <Boolean lock="???">
585: // attr.getValue();
586: }
587: if (attr.getName().equals("propagate")) { // <Boolean propagate="???">
588: // attr.getValue();
589: }
590: }
591:
592: //
593: NodeList nodes = element.getChildNodes();
594:
595: for (int i = 0; i < nodes.getLength(); i++) {
596: Node node = nodes.item(i);
597:
598: switch (node.getNodeType()) {
599: case Node.CDATA_SECTION_NODE:
600: // ((CDATASection)node).getData();
601:
602: break;
603:
604: case Node.ELEMENT_NODE:
605: Element nodeElement = (Element) node;
606:
607: break;
608:
609: case Node.PROCESSING_INSTRUCTION_NODE:
610: // ((ProcessingInstruction)node).getTarget();
611: // ((ProcessingInstruction)node).getData();
612:
613: break;
614: }
615: }
616: }
617:
618: private void visitElement_Locale(Element element) { // <Locale>
619: // element.getValue();
620:
621: //
622: NamedNodeMap attrs = element.getAttributes();
623:
624: for (int i = 0; i < attrs.getLength(); i++) {
625: Attr attr = (Attr) attrs.item(i);
626:
627: if (attr.getName().equals("language")) { // <Locale language="???">
628: // attr.getValue();
629: }
630: if (attr.getName().equals("country")) { // <Locale country="???">
631: // attr.getValue();
632: }
633: if (attr.getName().equals("variant")) { // <Locale variant="???">
634: // attr.getValue();
635: }
636: if (attr.getName().equals("merge")) { // <Locale merge="???">
637: // attr.getValue();
638: }
639: if (attr.getName().equals("lock")) { // <Locale lock="???">
640: // attr.getValue();
641: }
642: if (attr.getName().equals("propagate")) { // <Locale propagate="???">
643: // attr.getValue();
644: }
645: }
646:
647: //
648: NodeList nodes = element.getChildNodes();
649:
650: for (int i = 0; i < nodes.getLength(); i++) {
651: Node node = nodes.item(i);
652:
653: switch (node.getNodeType()) {
654: case Node.CDATA_SECTION_NODE:
655: // ((CDATASection)node).getData();
656:
657: break;
658:
659: case Node.ELEMENT_NODE:
660: Element nodeElement = (Element) node;
661:
662: if (nodeElement.getTagName().equals("String")) {
663: visitElement_String(nodeElement);
664: }
665:
666: break;
667:
668: case Node.PROCESSING_INSTRUCTION_NODE:
669: // ((ProcessingInstruction)node).getTarget();
670: // ((ProcessingInstruction)node).getData();
671:
672: break;
673: }
674: }
675: }
676:
677: private void visitElement_Channel(Element element) { // <Channel>
678: // element.getValue();
679:
680: //
681: NamedNodeMap attrs = element.getAttributes();
682:
683: for (int i = 0; i < attrs.getLength(); i++) {
684: Attr attr = (Attr) attrs.item(i);
685:
686: if (attr.getName().equals("name")) { // <Channel name="???">
687: // attr.getValue();
688: }
689: if (attr.getName().equals("provider")) { // <Channel provider="???">
690: // attr.getValue();
691: }
692: if (attr.getName().equals("merge")) { // <Channel merge="???">
693: // attr.getValue();
694: }
695: if (attr.getName().equals("lock")) { // <Channel lock="???">
696: // attr.getValue();
697: }
698: }
699:
700: //
701: NodeList nodes = element.getChildNodes();
702:
703: for (int i = 0; i < nodes.getLength(); i++) {
704: Node node = nodes.item(i);
705:
706: switch (node.getNodeType()) {
707: case Node.CDATA_SECTION_NODE:
708: // ((CDATASection)node).getData();
709:
710: break;
711:
712: case Node.ELEMENT_NODE:
713: Element nodeElement = (Element) node;
714:
715: if (nodeElement.getTagName().equals("Extends")) {
716: visitElement_Extends(nodeElement);
717: }
718: if (nodeElement.getTagName().equals("Properties")) {
719: visitElement_Properties(nodeElement);
720: }
721:
722: break;
723:
724: case Node.PROCESSING_INSTRUCTION_NODE:
725: // ((ProcessingInstruction)node).getTarget();
726: // ((ProcessingInstruction)node).getData();
727:
728: break;
729: }
730: }
731: }
732:
733: private void visitElement_Workspace(Element element) {
734: NodeList nodes = element.getChildNodes();
735:
736: for (int i = 0; i < nodes.getLength(); i++) {
737: Node node = nodes.item(i);
738:
739: switch (node.getNodeType()) {
740: case Node.CDATA_SECTION_NODE:
741: // ((CDATASection)node).getData();
742:
743: break;
744:
745: case Node.ELEMENT_NODE:
746: Element nodeElement = (Element) node;
747:
748: if (nodeElement.getTagName().equals("Classes")) {
749: visitElement_Classes(nodeElement);
750: }
751: if (nodeElement.getTagName().equals("Desktop")) {
752: visitElement_Desktop(nodeElement);
753: }
754:
755: break;
756:
757: case Node.PROCESSING_INSTRUCTION_NODE:
758: // ((ProcessingInstruction)node).getTarget();
759: // ((ProcessingInstruction)node).getData();
760:
761: break;
762: }
763: }
764: }
765:
766: private void visitElement_Classes(Element element) {
767:
768: String types = ".class";
769: String root = null;
770: String subdir = null;
771:
772: NamedNodeMap attrs = element.getAttributes();
773:
774: for (int i = 0; i < attrs.getLength(); i++) {
775: Attr attr = (Attr) attrs.item(i);
776:
777: if (attr.getName().equals("root")) {
778: root = attr.getValue();
779: }
780: if (attr.getName().equals("subdir")) {
781: subdir = attr.getValue();
782: }
783: if (attr.getName().equals("types")) {
784: types = attr.getValue();
785: }
786: }
787:
788: TransferClassDirectory td = new TransferClassDirectory(root,
789: subdir);
790: StringTokenizer toks = new StringTokenizer(types, ",");
791: while (toks.hasMoreTokens()) {
792: td.addType(toks.nextToken());
793: }
794:
795: parEntry.addTransfer(td);
796: }
797:
798: private void visitElement_Desktop(Element element) {
799:
800: String targetdir = "default";
801: String fromdir = null;
802: String filename = "unknown.file";
803:
804: NamedNodeMap attrs = element.getAttributes();
805:
806: for (int i = 0; i < attrs.getLength(); i++) {
807: Attr attr = (Attr) attrs.item(i);
808:
809: if (attr.getName().equals("targetdir")) {
810: targetdir = attr.getValue();
811: }
812: if (attr.getName().equals("fromdir")) {
813: fromdir = attr.getValue();
814: }
815: if (attr.getName().equals("filename")) {
816: filename = attr.getValue();
817: }
818: }
819:
820: parEntry.addTransfer(new TransferDesktopFile(targetdir,
821: fromdir, filename));
822: }
823: }
|