ossiejhmoore

LLValueExplorer.java

Jan 13th, 2015
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.66 KB | None | 0 0
  1. import com.opentext.api.LAPI_DOCUMENTS;
  2. import com.opentext.api.LLNameEnumeration;
  3. import com.opentext.api.LLNameEnumerationEx;
  4. import com.opentext.api.LLSession;
  5. import com.opentext.api.LLValue;
  6. import com.opentext.api.LLValueEnumeration;
  7. import java.io.IOException;
  8. import java.io.OutputStream;
  9. import org.jdom.Element;
  10. import org.jdom.output.Format;
  11. import org.jdom.output.XMLOutputter;
  12.  
  13. public class LLValueExplorer {
  14.  
  15.     public static String toSensibleString(LLValue item) {
  16.         XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat());
  17.         Element e = toElement(item);
  18.         return xo.outputString(e);
  19.     }
  20.  
  21.     public void dumpTo(LLValue item, OutputStream out) throws IOException {
  22.         XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat());
  23.         Element e = toElement(item);
  24.         xo.output(e, out);
  25.     }
  26.  
  27.     private static Element toElement(LLValue llValue) {
  28.         Element e;
  29.         if (llValue.isAssoc()) {
  30.             e = new Element("assoc");
  31.             LLNameEnumerationEx names = llValue.enumerateNamesEx();
  32.             while (names.hasMoreElements()) {
  33.                 LLValue key = names.nextName();
  34.                 Element val = toElement(llValue.toValue(key));
  35.                 val.setAttribute("key", key.toString());
  36.                 e.addContent(val);
  37.             }
  38.         } else if (llValue.isBoolean()) {
  39.             e = new Element("boolean");
  40.             e.setText(llValue.toString());
  41.         } else if (llValue.isDate()) {
  42.             e = new Element("date");
  43.             e.setText(llValue.toString());
  44.         } else if (llValue.isDouble()) {
  45.             e = new Element("double");
  46.             e.setText(Double.toString(llValue.toDouble()));
  47.         } else if (llValue.isError()) {
  48.             e = new Element("error");
  49.             e.setText(llValue.toString());
  50.         } else if (llValue.isInteger()) {
  51.             e = new Element("integer");
  52.             e.setText(Integer.toString(llValue.toInteger()));
  53.         } else if (llValue.isList()) {
  54.             e = new Element("list");
  55.             LLValueEnumeration values = llValue.enumerateValues();
  56.             while (values.hasMoreElements()) {
  57.                 e.addContent(toElement(values.nextValue()));
  58.             }
  59.         } else if (llValue.isLong()) {
  60.             e = new Element("long");
  61.             e.setText(Long.toString(llValue.toLong()));
  62.         } else if (llValue.isUndefined()) {
  63.             e = new Element("undefined");
  64.         } else if (llValue.isString()) {
  65.             e = new Element("string");
  66.             e.setText(llValue.toString());
  67.         } else if (llValue.isRecord()) {
  68.             e = new Element("record");
  69.             LLNameEnumeration names = llValue.enumerateNames();
  70.             while (names.hasMoreElements()) {
  71.                 String key = names.nextName();
  72.                 Element val = toElement(llValue.toValue(key));
  73.                 val.setAttribute("key", key);
  74.                 e.addContent(val);
  75.             }
  76.         } else if (llValue.isPoint()) {
  77.             e = new Element("point");
  78.             e.setText(llValue.toString());
  79.         } else if (llValue.isSet()) {
  80.             e = new Element("set");
  81.             LLValueEnumeration values = llValue.enumerateValues();
  82.             while (values.hasMoreElements()) {
  83.                 e.addContent(toElement(values.nextValue()));
  84.             }
  85.         } else if (llValue.isTable()) {
  86.             e = new Element("table");
  87.             e.setText(llValue.toString());
  88.         } else {
  89.             e = new Element("unknown");
  90.             {
  91.                 e.setText(llValue.toString());
  92.             }
  93.         }
  94.         return e;
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment