<%@ include file = "/util/cacheControl.jsp"%><%-- __________________________________________________________________________________________ Common code used for creating XML files __________________________________________________________________________________________ --%><%! String XML_COMMON_VERSION = "09-20-2012"; String TAB = " "; //XML indent characters String EOL = "\r\n"; //newline displays source better on IE windows String CDATA_NEWLINE = "@@@"; //no indent if line starts with this marker String xml = null; ArrayList attr = null; ArrayList openTags = null; Vector logData = null; %><% initXML(rz); %><%! /** * **/ void initXML(RZTagSupport rz) { xml = ""; attr = new ArrayList(); openTags = new ArrayList(); logData = new Vector(); } /** * **/ void addTopXML(String tag, String version) { addTopXML(tag, null, version); } /** * **/ void addTopXML(String tag, ArrayList attr, String version) { if (attr == null) attr = new ArrayList(); attr.add("version=" + version); attr.add("xml_common_version=" + XML_COMMON_VERSION); //attr.add("published=" + rz1.today("MM-dd-yyyy hh:mm aa")); attr.add("published=" + org.apache.commons.lang.time.DateFormatUtils.format(new GregorianCalendar(), "MM-dd-yyyy hh:mm aa")); addXML(tag,attr,null); } /* Error: Ambiguous invocation of method "addXML". At least two methods are accessible from here: "void addXML(java.lang.String name, java.lang.String value);" "void addXML(java.lang.String name, java.util.ArrayList attr);" declared in type "_work/__0calendar_0app/_calendar_0app/_db/_calendar_0db_0calendarid_0names__jsp" declared in type "_work/__0calendar_0app/_calendar_0app/_db/_calendar_0db_0calendarid_0names__jsp". */ /** * Open tag with no attributes **/ void addXML(String name) { addXML(name, null, null, false); } /** * Open tag with no attributes, value as innerText, then close tag **/ void addXML(String name, String value) { addXML(name, null, value, false); } /** * Open tag with attributes specified by attr, leave open **/ void addXML(String name, ArrayList attr) { addXML(name, attr, null, false); } /** * Open tag with no attributes, value as innerText/HTML, then close tag **/ void addXML(String name, String value, boolean isHTML) { addXML(name, null, value, isHTML); } /** * Open tag with specified attributes, value as innerText then close tag **/ void addXML(String name, ArrayList attr, String value) { addXML(name, attr, value, false); } /** * Open tag with specified attributes, if value null, leave tag open; * otherwise use value as either innerText or innerHTML based on isHTML * close tag if HTML or value is null **/ void addXML(String name, ArrayList attr, String value, boolean isHTML) { ArrayList lines = new ArrayList(); String line = ""; String attrStr = ""; if (attr != null) { for (int i=0;i 1) ? keyValue[1] : ""; attrStr += " " + key + "=\"" + val + "\""; } attr.clear(); } //----- If value not null, use for tag innerHTML and close tag boolean isCloseIt = true; //----- Otherwise open tag if (value == null) { value = ""; isCloseIt = false; } //----- If value is not html, encode if (!isHTML || value.length()==0) { value = StringUtils.encodeSpecialChars(value); line = "<" + name + attrStr + ">"; if (isCloseIt) { if (value.length() == 0) line = line.substring(0,line.length()-1) + " />"; else line += value + ""; } lines.add(line); } //----- If value is html, wrap with cdata (tag always closed) else { lines.add("<" + name + attrStr + ">"); value = value.replaceAll("[\r\n]+","\n"); String[] values = StringUtils.split(value,"\n"); line = tabs(1) + " 0 for (int i=1;i"); lines.add(""); isCloseIt = true; } // add all lines to xml addLines( (String[])lines.toArray( new String[0] ) ); if (!isCloseIt) openTags.add(name); } /** * close prior open tag * * arguments: * tag (optional) specified open tag name * if not specified last open tag closed * log note if specified and does not match last open tag **/ void closeXML() { closeXML(""); } void closeXML(String tag) { String tagNote = ""; if (tag.length() > 0) tagNote = " expected to close: " + tag; if (openTags.size() == 0) addLine("***** no open tags" + tagNote); else { String closeTag = openTags.remove(openTags.size()-1) + ""; if (tag.length() > 0 && !tag.equals(closeTag)) addLine("***** closing " + closeTag + " but" + tagNote); else addLine(""); } } /** * **/ void addLine(String line) { String[] lines = {line}; addLines(lines); } /** * **/ void addLines(String[] lines) { if (lines.length == 0) return; String padding = tabs(openTags.size()); for (int i=0;i