String sNodeName;
Object oColValue;
Class oColClass, ClassString = null, ClassDateTime = null, ClassTimeStamp = null,
ClassBigDecimal = null, ClassDouble = null, ClassFloat = null;
SimpleDateFormat oXMLDate;
DecimalFormat oDecFmt = null;
if (sDateFormat==null)
oXMLDate = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
else if (sDateFormat.length()==0)
oXMLDate = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
else
oXMLDate = new SimpleDateFormat(sDateFormat);
if (null!=sDecimalFormat) {
if (sDecimalFormat.length()>0)
oDecFmt = new DecimalFormat(sDecimalFormat);
} // fi
if (DebugFile.trace) {
DebugFile.writeln("Begin DBSubset.toXML(" + sNode + ")");
DebugFile.incIdent();
}
try {
ClassString = Class.forName("java.lang.String");
ClassDateTime = Class.forName("java.util.Date");
ClassTimeStamp = Class.forName("java.sql.Timestamp");
ClassBigDecimal = Class.forName("java.math.BigDecimal");
ClassDouble = Class.forName("java.lang.Double");
ClassFloat = Class.forName("java.lang.Float");
} catch (ClassNotFoundException ignore) { }
if (oResults!=null) {
sNodeName = (null!=sNode ? sNode : sTable);
iRowCount = oResults.size();
strBuff = new StringBuffer(256*iRowCount);
strTok = new StringTokenizer(sColList,",");
iTokCount = strTok.countTokens();
String[] Labels = new String[iTokCount];
for (int iTok=0; iTok<iTokCount; iTok++) {
sLabel = strTok.nextToken();
iAs = sLabel.toUpperCase().indexOf(" AS ");
if (-1!=iAs) sLabel = sLabel.substring(iAs+4);
iDot = sLabel.indexOf('.');
if (-1!=iDot) sLabel = sLabel.substring(++iDot);
Labels[iTok] = sLabel.trim();
} // next
for (int iRow=0; iRow<iRowCount; iRow++)
{
vRow = (Vector) oResults.get(iRow);
iCol = 0;
strBuff.append(sIdent + "<" + sNodeName + ">\n");
while (iCol<iColCount)
{
strBuff.append(sIdent + " <" + Labels[iCol] + ">");
oColValue = vRow.get(iCol);
if (null!=oColValue) {
oColClass = oColValue.getClass();
if (oColClass.equals(ClassString) && !Labels[iCol].startsWith("gu_"))
strBuff.append("<![CDATA[" + oColValue + "]]>");
else if (oColClass.equals(ClassDateTime))
strBuff.append (oXMLDate.format((java.util.Date) oColValue));
else if (oColClass.equals(ClassTimeStamp))
strBuff.append (oXMLDate.format(new Date (((java.sql.Timestamp) oColValue).getTime())));
else if (oColClass.equals(ClassBigDecimal) && (oDecFmt!=null))
strBuff.append (oDecFmt.format((java.math.BigDecimal) oColValue));
else if (oColClass.equals(ClassDouble) && (oDecFmt!=null))
strBuff.append (oDecFmt.format(((java.lang.Double) oColValue).doubleValue()));
else if (oColClass.equals(ClassFloat) && (oDecFmt!=null))
strBuff.append (oDecFmt.format((double)((java.lang.Float) oColValue).floatValue()));
else if (oColClass.equals(getClass()))
strBuff.append ("<"+getColumnName(iCol)+"s>\n"+((DBSubset)oColValue).toXML(sIdent+" ", getColumnName(iCol), sDateFormat, sDecimalFormat)+"\n</"+getColumnName(iCol)+"s>\n");
else