Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.opentext.api.LAPI_DOCUMENTS;
- import com.opentext.api.LLNameEnumeration;
- import com.opentext.api.LLNameEnumerationEx;
- import com.opentext.api.LLSession;
- import com.opentext.api.LLValue;
- import com.opentext.api.LLValueEnumeration;
- import java.io.IOException;
- import java.io.OutputStream;
- import org.jdom.Element;
- import org.jdom.output.Format;
- import org.jdom.output.XMLOutputter;
- public class LLValueExplorer {
- public static String toSensibleString(LLValue item) {
- XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat());
- Element e = toElement(item);
- return xo.outputString(e);
- }
- public void dumpTo(LLValue item, OutputStream out) throws IOException {
- XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat());
- Element e = toElement(item);
- xo.output(e, out);
- }
- private static Element toElement(LLValue llValue) {
- Element e;
- if (llValue.isAssoc()) {
- e = new Element("assoc");
- LLNameEnumerationEx names = llValue.enumerateNamesEx();
- while (names.hasMoreElements()) {
- LLValue key = names.nextName();
- Element val = toElement(llValue.toValue(key));
- val.setAttribute("key", key.toString());
- e.addContent(val);
- }
- } else if (llValue.isBoolean()) {
- e = new Element("boolean");
- e.setText(llValue.toString());
- } else if (llValue.isDate()) {
- e = new Element("date");
- e.setText(llValue.toString());
- } else if (llValue.isDouble()) {
- e = new Element("double");
- e.setText(Double.toString(llValue.toDouble()));
- } else if (llValue.isError()) {
- e = new Element("error");
- e.setText(llValue.toString());
- } else if (llValue.isInteger()) {
- e = new Element("integer");
- e.setText(Integer.toString(llValue.toInteger()));
- } else if (llValue.isList()) {
- e = new Element("list");
- LLValueEnumeration values = llValue.enumerateValues();
- while (values.hasMoreElements()) {
- e.addContent(toElement(values.nextValue()));
- }
- } else if (llValue.isLong()) {
- e = new Element("long");
- e.setText(Long.toString(llValue.toLong()));
- } else if (llValue.isUndefined()) {
- e = new Element("undefined");
- } else if (llValue.isString()) {
- e = new Element("string");
- e.setText(llValue.toString());
- } else if (llValue.isRecord()) {
- e = new Element("record");
- LLNameEnumeration names = llValue.enumerateNames();
- while (names.hasMoreElements()) {
- String key = names.nextName();
- Element val = toElement(llValue.toValue(key));
- val.setAttribute("key", key);
- e.addContent(val);
- }
- } else if (llValue.isPoint()) {
- e = new Element("point");
- e.setText(llValue.toString());
- } else if (llValue.isSet()) {
- e = new Element("set");
- LLValueEnumeration values = llValue.enumerateValues();
- while (values.hasMoreElements()) {
- e.addContent(toElement(values.nextValue()));
- }
- } else if (llValue.isTable()) {
- e = new Element("table");
- e.setText(llValue.toString());
- } else {
- e = new Element("unknown");
- {
- e.setText(llValue.toString());
- }
- }
- return e;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment