001: package com.calipso.xmleditor;
002:
003: import java.util.*;
004: import org.jdom.*;
005: import org.jdom.output.*;
006: import java.io.*;
007: import java.awt.Color;
008:
009: import net.sf.jasperreports.engine.base.JRBaseReport;
010: import net.sf.jasperreports.engine.*;
011:
012: public class XMLWriter {
013:
014: static final String DTD_URL = "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd";
015: Document doc = null;
016:
017: public XMLWriter(JRBaseReport d) {
018:
019: doc = new Document();
020: createRootElement(d);
021: DocType docType = new DocType("jasperReport",
022: "-//JasperReports//DTD Report Design//EN", DTD_URL);
023: doc.setDocType(docType);
024: }
025:
026: public Document getDocument() {
027: return doc;
028: }
029:
030: public void saveDocument(String aFileName) throws IOException {
031:
032: XMLOutputter xmlOut = new XMLOutputter();
033: FileWriter writer = new java.io.FileWriter(aFileName);
034: xmlOut.output(doc, writer);
035: writer.flush();
036: writer.close();
037: }
038:
039: void createRootElement(JRBaseReport d) {
040:
041: Element r = new Element("jasperReport");
042: doc.setRootElement(r);
043: r.setAttribute("name", d.getName());
044: r.setAttribute("columnCount", "" + d.getColumnCount());
045: if (d.getPrintOrder() != JRReport.PRINT_ORDER_VERTICAL) {
046: r.setAttribute("printOrder", "Horizontal");
047: }
048: r.setAttribute("pageWidth", "" + d.getPageWidth());
049: r.setAttribute("pageHeight", "" + d.getPageHeight());
050: if (d.getOrientation() != JRReport.ORIENTATION_PORTRAIT) {
051: r.setAttribute("orientation", "Landscape");
052: }
053: if (d.getWhenNoDataType() == JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL) {
054: r.setAttribute("whenNoDataType", "AllSectionsNoDetail");
055: } else if (d.getWhenNoDataType() == JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE) {
056: r.setAttribute("whenNoDataType", "BlankPage");
057: }
058: r.setAttribute("columnWidth", "" + d.getColumnWidth());
059: r.setAttribute("columnSpacing", "" + d.getColumnSpacing());
060: r.setAttribute("leftMargin", "" + d.getLeftMargin());
061: r.setAttribute("rightMargin", "" + d.getRightMargin());
062: r.setAttribute("topMargin", "" + d.getTopMargin());
063: r.setAttribute("bottomMargin", "" + d.getBottomMargin());
064: if (d.isTitleNewPage()) {
065: r.setAttribute("isTitleNewPage", "true");
066: }
067: if (d.isSummaryNewPage()) {
068: r.setAttribute("isSummaryNewPage", "true");
069: }
070: if (d.getScriptletClass() != null) {
071: r.setAttribute("scriptletClass", d.getScriptletClass());
072: }
073:
074: addReportFonts(d, r);
075: addParameters(d, r);
076: addQueryString(d, r);
077: addFields(d, r);
078: addVariables(d, r);
079: JRGroup groups[] = d.getGroups();
080: if (groups != null && groups.length > 0) {
081: addGroups(d, r);
082: }
083: addTitle(d, r);
084: addPageHeader(d, r);
085: addColumnHeader(d, r);
086: addDetail(d, r);
087: addColumnFooter(d, r);
088: addPageFooter(d, r);
089: addSummary(d, r);
090: }
091:
092: void addReportFonts(JRBaseReport d, Element r) {
093: JRReportFont fonts[] = d.getFonts();
094: if (fonts != null) {
095: for (int i = 0; i < fonts.length; i++) {
096: addReportFont(r, fonts[i]);
097: }
098: }
099: }
100:
101: void addReportFont(Element parent, JRReportFont font) {
102: Element e = new Element("reportFont");
103: e.setAttribute("name", font.getName());
104: if (font.isDefault()) {
105: e.setAttribute("isDefault", "true");
106: }
107: setFontAttributes(e, font);
108: parent.addContent(e);
109: }
110:
111: void setFontAttributes(Element e, JRFont font) {
112: e.setAttribute("fontName", font.getFontName());
113: e.setAttribute("size", "" + font.getSize());
114: if (font.isBold()) {
115: e.setAttribute("isBold", "true");
116: }
117: if (font.isItalic()) {
118: e.setAttribute("isItalic", "true");
119: }
120: if (font.isUnderline()) {
121: e.setAttribute("isUnderline", "true");
122: }
123: if (font.isStrikeThrough()) {
124: e.setAttribute("isStrikeThrough", "true");
125: }
126: if (font.getPdfFontName() != null
127: && font.getPdfFontName().trim().length() > 0) {
128: e.setAttribute("pdfFontName", font.getPdfFontName());
129: }
130: if (font.getPdfEncoding() != null
131: && font.getPdfEncoding().trim().length() > 0) {
132: e.setAttribute("pdfEncoding", font.getPdfEncoding());
133: }
134: e.setAttribute("isPdfEmbedded", "" + font.isPdfEmbedded());
135:
136: }
137:
138: void addParameters(JRBaseReport d, Element r) {
139: JRParameter parms[] = d.getParameters();
140: for (int i = 0; i < parms.length; i++) {
141: if (!parms[i].isSystemDefined()) {
142: addParameter(r, parms[i]);
143: }
144: }
145: }
146:
147: void addParameter(Element r, JRParameter parm) {
148: Element e = new Element("parameter");
149: e.setAttribute("name", parm.getName());
150: e.setAttribute("class", parm.getValueClass().getName());
151: if (!parm.isForPrompting()) {
152: e.setAttribute("isForPrompting", "false");
153: }
154: r.addContent(e);
155: condCData(e, "parameterDescription", parm.getDescription());
156: if (parm.getDefaultValueExpression() != null) {
157: addExpression(e, "defaultValueExpression", parm
158: .getDefaultValueExpression());
159: }
160: }
161:
162: void addQueryString(JRBaseReport d, Element r) {
163: Element e = new Element("queryString");
164: JRQuery query = d.getQuery();
165:
166: // queryString is optional in DTD
167: if (query == null)
168: return;
169:
170: JRQueryChunk chunks[] = query.getChunks();
171: // queryString is optional in DTD
172: if (chunks == null)
173: return;
174:
175: JRQueryChunk chunk = null;
176: StringBuffer buff = new StringBuffer("");
177: for (int i = 0; i < chunks.length; i++) {
178: chunk = chunks[i];
179: if (chunk.getType() == JRQueryChunk.TYPE_TEXT) {
180: buff.append(chunk.getText());
181: } else {
182: buff.append("$P{" + chunk.getText() + "}");
183: }
184: }
185: e.addContent(new CDATA(buff.toString()));
186: r.addContent(e);
187: }
188:
189: void addFields(JRBaseReport d, Element r) {
190: // can't use field map because we need to maintain field order
191: // due to a bug in the Microsoft's @#$% SQLServer JDBC Driver
192: // "[Microsoft][SQLServer JDBC Driver]ResultSet can not re-read row data for column X"
193: JRField[] fields = d.getFields();
194: for (int i = 0; i < fields.length; i++) {
195: addField(r, fields[i]);
196: }
197: }
198:
199: void addField(Element r, JRField field) {
200: Element e = new Element("field");
201: e.setAttribute("name", field.getName());
202: e.setAttribute("class", field.getValueClass().getName());
203: condCData(e, "fieldDescription", field.getDescription());
204: r.addContent(e);
205: }
206:
207: void addVariables(JRBaseReport d, Element r) {
208: JRVariable vars[] = d.getVariables();
209: for (int i = 0; i < vars.length; i++) {
210: if (!vars[i].isSystemDefined()) {
211: addVariable(r, vars[i]);
212: }
213: }
214:
215: /* Iterator iter = d.getVariablesMap().values().iterator();
216: JRVariable variable = null;
217: while( iter.hasNext() ) {
218: variable = (JRVariable)iter.next();
219: if( !variable.isSystemDefined() ) {
220: addVariable( r, variable );
221: }
222: }
223: */
224: }
225:
226: void addVariable(Element r, JRVariable variable) {
227: Element e = new Element("variable");
228: e.setAttribute("name", variable.getName());
229: e.setAttribute("class", variable.getValueClass().getName());
230: e.setAttribute("resetType", RW.getResetTypeName(variable
231: .getResetType()));
232: JRGroup resetGroup = variable.getResetGroup();
233: if (resetGroup != null && resetGroup.getName() != null) {
234: e.setAttribute("resetGroup", resetGroup.getName());
235: }
236: e.setAttribute("calculation", RW.getCalculationName(variable
237: .getCalculation()));
238: JRExpression exp = variable.getExpression();
239: if (exp != null) {
240: addExpression(e, "variableExpression", exp);
241: }
242: exp = null;
243: exp = variable.getInitialValueExpression();
244: if (exp != null) {
245: addExpression(e, "initialValueExpression", exp);
246: }
247: r.addContent(e);
248: }
249:
250: void addExpression(Element element, String nm, JRExpression exp) {
251: Element e = new Element(nm);
252:
253: // "variableExpression" and "initialValueExpression" are optional for variable
254: // however, this is also called for "groupExpression" which isn't optional
255: // if groupExpression is null, we will generate invalid XML
256:
257: String expressionText = RW.getExpressionText(exp);
258: if (expressionText != null) {
259: e.addContent(RW.getExpressionText(exp));
260: element.addContent(e);
261: }
262: }
263:
264: void addGroups(JRBaseReport d, Element r) {
265: JRGroup grps[] = d.getGroups();
266: JRGroup group = null;
267: for (int i = 0; i < grps.length; i++) {
268: addGroup(r, grps[i]);
269: }
270: }
271:
272: void addTitle(JRBaseReport d, Element r) {
273: if ((JRBand) d.getTitle() != null) {
274: addFormatSection(r, "title", (JRBand) d.getTitle());
275: }
276: }
277:
278: void addPageHeader(JRBaseReport d, Element r) {
279: if ((JRBand) d.getPageHeader() != null) {
280: addFormatSection(r, "pageHeader", (JRBand) d
281: .getPageHeader());
282: }
283: }
284:
285: void addColumnHeader(JRBaseReport d, Element r) {
286: if ((JRBand) d.getColumnHeader() != null) {
287: addFormatSection(r, "columnHeader", (JRBand) d
288: .getColumnHeader());
289: }
290: }
291:
292: void addDetail(JRBaseReport d, Element r) {
293: if ((JRBand) d.getDetail() != null) {
294: addFormatSection(r, "detail", (JRBand) d.getDetail());
295: }
296: }
297:
298: void addColumnFooter(JRBaseReport d, Element r) {
299: if ((JRBand) d.getColumnFooter() != null) {
300: addFormatSection(r, "columnFooter", (JRBand) d
301: .getColumnFooter());
302: }
303: }
304:
305: void addPageFooter(JRBaseReport d, Element r) {
306: if ((JRBand) d.getPageFooter() != null) {
307: addFormatSection(r, "pageFooter", (JRBand) d
308: .getPageFooter());
309: }
310: }
311:
312: void addSummary(JRBaseReport d, Element r) {
313: if ((JRBand) d.getSummary() != null) {
314: addFormatSection(r, "summary", (JRBand) d.getSummary());
315: }
316: }
317:
318: void addGroup(Element r, JRGroup group) {
319: Element e = new Element("group");
320: e.setAttribute("name", group.getName());
321: if (group.isStartNewColumn()) {
322: e.setAttribute("isStartNewColumn", "true");
323: }
324: if (group.isStartNewPage()) {
325: e.setAttribute("isStartNewPage", "true");
326: }
327: if (group.isResetPageNumber()) {
328: e.setAttribute("isResetPageNumber", "true");
329: }
330: if (group.isReprintHeaderOnEachPage()) {
331: e.setAttribute("isReprintHeaderOnEachPage", "true");
332: }
333: if (group.getMinHeightToStartNewPage() != 0) {
334: e.setAttribute("minHeightToStartNewPage", ""
335: + group.getMinHeightToStartNewPage());
336: }
337: addExpression(e, "groupExpression", group.getExpression());
338: if ((JRBand) group.getGroupHeader() != null) {
339: addFormatSection(e, "groupHeader", (JRBand) group
340: .getGroupHeader());
341: }
342: if ((JRBand) group.getGroupFooter() != null) {
343: addFormatSection(e, "groupFooter", (JRBand) group
344: .getGroupFooter());
345: }
346: r.addContent(e);
347: }
348:
349: void addFormatSection(Element parent, String nm, JRBand band) {
350: Element e = new Element(nm);
351: parent.addContent(e);
352: addBand(e, band);
353: }
354:
355: void addBand(Element parent, JRBand band) {
356: Element e = new Element("band");
357: parent.addContent(e);
358: e.setAttribute("height", "" + band.getHeight());
359: if (band.getPrintWhenExpression() != null) {
360: addExpression(e, "printWhenExpression", band
361: .getPrintWhenExpression());
362: }
363: addElementGroupElements(e, band);
364: }
365:
366: void addElementGroup(Element parent, JRElementGroup grp) {
367: Element e = new Element("elementGroup");
368: parent.addContent(e);
369: addElementGroupElements(e, grp);
370: }
371:
372: void addElementGroupElements(Element parent, JRElementGroup grp) {
373: Iterator iter = grp.getChildren().iterator();
374: Object element = null;
375: while (iter.hasNext()) {
376: element = iter.next();
377: if (element instanceof JRElementGroup) {
378: addElementGroup(parent, (JRElementGroup) element);
379: } else if (element instanceof JRLine) {
380: addLine(parent, (JRLine) element);
381: } else if (element instanceof JRRectangle) {
382: addRectangle(parent, (JRRectangle) element);
383: } else if (element instanceof JRImage) {
384: addImage(parent, (JRImage) element);
385: } else if (element instanceof JRStaticText) {
386: addStaticText(parent, (JRStaticText) element);
387: } else if (element instanceof JRTextField) {
388: addTextField(parent, (JRTextField) element);
389: } else if (element instanceof JRSubreport) {
390: addSubreport(parent, (JRSubreport) element);
391: }
392: }
393: }
394:
395: void addSubreport(Element parent, JRSubreport subreport) {
396: Element e = new Element("subreport");
397: parent.addContent(e);
398: addReportElement(e, subreport);
399: for (int i = 0; i < subreport.getParameters().length; i++) {
400: addSubreportParameter(e, subreport.getParameters()[i]);
401: }
402: addExpression(e, "connectionExpression", subreport
403: .getConnectionExpression());
404: addExpression(e, "subreportExpression", subreport
405: .getExpression());
406: }
407:
408: void addSubreportParameter(Element parent,
409: JRSubreportParameter element) {
410: Element e = new Element("subreportParameter");
411: parent.addContent(e);
412: e.setAttribute("name", element.getName());
413: addExpression(e, "subreportParameterExpression", element
414: .getExpression());
415: }
416:
417: void addLine(Element parent, JRLine line) {
418:
419: Element e = new Element("line");
420: parent.addContent(e);
421: if (line.getDirection() != JRLine.DIRECTION_TOP_DOWN) {
422: e.setAttribute("direction", "BottomUp");
423: }
424: addReportElement(e, line);
425: addGraphicElement(e, line);
426: }
427:
428: void addRectangle(Element parent, JRRectangle rectangle) {
429: Element e = new Element("rectangle");
430: parent.addContent(e);
431:
432: addReportElement(e, rectangle);
433: addGraphicElement(e, rectangle);
434: }
435:
436: void addImage(Element parent, JRImage image) {
437: Element e = new Element("image");
438: parent.addContent(e);
439:
440: String scale = "RetainShape";
441: switch (image.getScaleImage()) {
442: case JRImage.SCALE_IMAGE_CLIP:
443: scale = "Clip";
444: break;
445: case JRImage.SCALE_IMAGE_FILL_FRAME:
446: scale = "FillFrame";
447: break;
448: }
449: e.setAttribute("scaleImage", scale);
450: if (image.getHorizontalAlignment() != JRAlignment.HORIZONTAL_ALIGN_LEFT) {
451: e.setAttribute("hAlign", RW
452: .getHorizontalAlignmentName(image
453: .getHorizontalAlignment()));
454: }
455: if (image.getVerticalAlignment() != JRAlignment.VERTICAL_ALIGN_TOP) {
456: e.setAttribute("vAlign", RW.getVerticalAlignmentName(image
457: .getVerticalAlignment()));
458: }
459: if (!image.isUsingCache()) {
460: e.setAttribute("isUsingCache", "false");
461: }
462:
463: addReportElement(e, image);
464: addGraphicElement(e, image);
465: Element expElement = new Element("imageExpression");
466: e.addContent(expElement);
467: expElement.setAttribute("class", image.getExpression()
468: .getValueClass().getName());
469: expElement.addContent(RW.getExpressionText(image
470: .getExpression()));
471: setHyperlinkType(e, image);
472: condCData(e, "anchorNameExpression", RW.getExpressionText(image
473: .getAnchorNameExpression()));
474: condCData(e, "hyperlinkReferenceExpression", RW
475: .getExpressionText(image
476: .getHyperlinkReferenceExpression()));
477: condCData(e, "hyperlinkAnchorExpression",
478: RW.getExpressionText(image
479: .getHyperlinkAnchorExpression()));
480: condCData(e, "hyperlinkPageExpression", RW
481: .getExpressionText(image.getHyperlinkPageExpression()));
482: }
483:
484: void addStaticText(Element parent, JRStaticText text) {
485: Element e = new Element("staticText");
486: parent.addContent(e);
487: addReportElement(e, text);
488: addTextElement(e, text);
489: Element textElement = new Element("text");
490: e.addContent(textElement);
491: textElement.addContent(text.getText());
492: }
493:
494: void addTextField(Element parent, JRTextField field) {
495: Element e = new Element("textField");
496: parent.addContent(e);
497: if (field.isStretchWithOverflow()) {
498: e.setAttribute("isStretchWithOverflow", "true");
499: }
500: if (field.getEvaluationTime() != JRExpression.EVALUATION_TIME_NOW) {
501: e.setAttribute("evaluationTime", RW
502: .getEvaluationTimeName(field.getEvaluationTime()));
503: }
504: JRGroup evalGroup = field.getEvaluationGroup();
505: if (evalGroup != null && evalGroup.getName() != null) {
506: e.setAttribute("evaluationGroup", evalGroup.getName());
507: }
508: if (field.getPattern() != null
509: && field.getPattern().trim().length() > 0) {
510: e.setAttribute("pattern", field.getPattern());
511: }
512: if (field.isBlankWhenNull()) {
513: e.setAttribute("isBlankWhenNull", "true");
514: }
515: setHyperlinkType(e, field);
516: addReportElement(e, field);
517: addTextElement(e, field);
518: Element expElement = new Element("textFieldExpression");
519: e.addContent(expElement);
520: if (field.getExpression() != null) {
521: if (field.getExpression().getValueClass() != null) {
522: expElement.setAttribute("class", field.getExpression()
523: .getValueClass().getName());
524: } else {
525: expElement.setAttribute("class", "java.lang.String");
526: }
527: }
528: expElement.addContent(RW.getExpressionText(field
529: .getExpression()));
530: condCData(e, "anchorNameExpression", RW.getExpressionText(field
531: .getAnchorNameExpression()));
532: condCData(e, "hyperlinkReferenceExpression", RW
533: .getExpressionText(field
534: .getHyperlinkReferenceExpression()));
535: condCData(e, "hyperlinkAnchorExpression",
536: RW.getExpressionText(field
537: .getHyperlinkAnchorExpression()));
538: condCData(e, "hyperlinkPageExpression", RW
539: .getExpressionText(field.getHyperlinkPageExpression()));
540: }
541:
542: void setHyperlinkType(Element e, JRHyperlink h) {
543: String hlType = RW.getHyperlinkTypeName(h.getHyperlinkType());
544: if (!"None".equals(hlType)) {
545: e.setAttribute("hyperlinkType", hlType);
546: }
547: }
548:
549: void addReportElement(Element parent, JRElement element) {
550: Element e = new Element("reportElement");
551: String s = "";
552: switch (element.getPositionType()) {
553: case JRElement.POSITION_TYPE_FLOAT:
554: e.setAttribute("positionType", "Float");
555: break;
556: case JRElement.POSITION_TYPE_FIX_RELATIVE_TO_BOTTOM:
557: e.setAttribute("positionType", "FixRelativeToBottom");
558: break;
559: }
560: if (!element.isPrintRepeatedValues()) {
561: e.setAttribute("isPrintRepeatedValues", "false");
562: }
563: if (element.getMode() == JRElement.MODE_TRANSPARENT) {
564: e.setAttribute("mode", "Transparent");
565: } else {
566: e.setAttribute("mode", "Opaque");
567: }
568: e.setAttribute("x", "" + element.getX());
569: e.setAttribute("y", "" + element.getY());
570: e.setAttribute("width", "" + element.getWidth());
571: e.setAttribute("height", "" + element.getHeight());
572: if (element.isRemoveLineWhenBlank()) {
573: e.setAttribute("isRemoveLineWhenBlank", "true");
574: }
575: if (element.isPrintInFirstWholeBand()) {
576: e.setAttribute("isPrintInFirstWholeBand", "true");
577: }
578: if (element.isPrintWhenDetailOverflows()) {
579: e.setAttribute("isPrintWhenDetailOverflows", "true");
580: }
581:
582: JRGroup changeGroup = element.getPrintWhenGroupChanges();
583: if (changeGroup != null) {
584: e.setAttribute("printWhenGroupChanges", changeGroup
585: .getName());
586: }
587:
588: java.awt.Color color = element.getForecolor();
589: if (color.getRGB() != Color.black.getRGB()) {
590: s = Integer.toHexString(color.getRGB());
591: s = "#" + s.substring(2);
592: e.setAttribute("forecolor", s);
593: }
594: color = element.getBackcolor();
595: if (color.getRGB() != Color.white.getRGB()) {
596: s = Integer.toHexString(color.getRGB());
597: s = "#" + s.substring(2);
598: e.setAttribute("backcolor", s);
599: }
600: JRExpression exp = element.getPrintWhenExpression();
601: if (exp != null) {
602: addExpression(e, "printWhenExpression", element
603: .getPrintWhenExpression());
604: }
605: parent.addContent(e);
606: }
607:
608: void addGraphicElement(Element parent, JRGraphicElement element) {
609: Element e = new Element("graphicElement");
610: switch (element.getStretchType()) {
611: case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT:
612: e.setAttribute("stretchType", "RelativeToBandHeight");
613: break;
614: case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT:
615: e.setAttribute("stretchType", "RelativeToTallestObject");
616: break;
617: }
618: switch (element.getPen()) {
619: case JRGraphicElement.PEN_2_POINT:
620: e.setAttribute("pen", "2Point");
621: break;
622: case JRGraphicElement.PEN_4_POINT:
623: e.setAttribute("pen", "4Point");
624: break;
625: case JRGraphicElement.PEN_DOTTED:
626: e.setAttribute("pen", "Dotted");
627: break;
628: case JRGraphicElement.PEN_NONE:
629: e.setAttribute("pen", "None");
630: break;
631: }
632: parent.addContent(e);
633: }
634:
635: void addTextElement(Element parent, JRTextElement element) {
636: Element e = new Element("textElement");
637: switch (element.getTextAlignment()) {
638: case JRTextElement.TEXT_ALIGN_CENTER:
639: e.setAttribute("textAlignment", "Center");
640: break;
641: case JRTextElement.TEXT_ALIGN_RIGHT:
642: e.setAttribute("textAlignment", "Right");
643: break;
644: case JRTextElement.TEXT_ALIGN_JUSTIFIED:
645: e.setAttribute("textAlignment", "Justified");
646: break;
647: }
648: switch (element.getLineSpacing()) {
649: case JRTextElement.LINE_SPACING_DOUBLE:
650: e.setAttribute("textAlignment", "Double");
651: break;
652: case JRTextElement.LINE_SPACING_1_1_2:
653: e.setAttribute("textAlignment", "1_1_2");
654: break;
655: }
656: JRFont font = element.getFont();
657: if (font != null) {
658: Element fontElement = new Element("font");
659:
660: if (font instanceof JRReportFont) {
661: JRReportFont rf = (JRReportFont) font;
662: // unsure if this fix is correct or just masking the real problem
663: String fontName = rf.getName();
664: if (fontName != null) {
665: e.addContent(fontElement);
666: fontElement.setAttribute("reportFont", fontName);
667: }
668: } else {
669: e.addContent(fontElement);
670: setFontAttributes(fontElement, font);
671: }
672: }
673: parent.addContent(e);
674:
675: }
676:
677: void condCData(Element e, String nm, String val) {
678: if (val != null && val.trim().length() > 0) {
679: addCData(e, nm, val);
680: }
681: }
682:
683: void addCData(Element e, String nm, String val) {
684: Element r = new Element(nm);
685: r.addContent(new CDATA(val));
686: e.addContent(r);
687: }
688:
689: }
|