Java Javascript Mozilla Library objectToXMLString(Object xml)

Here you can find the source of objectToXMLString(Object xml)

Description

object To XML String

License

Open Source License

Declaration

public static String objectToXMLString(Object xml) 

Method Source Code


//package com.java2s;
/*//w ww. ja va2s. c  om
 * Helma License Notice
 *
 * The contents of this file are subject to the Helma License
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://adele.helma.org/download/helma/license.txt
 *
 * Copyright 1998-2003 Helma Software. All Rights Reserved.
 *
 * $RCSfile: XmlUtils.java,v $
 * $Author: hannes $
 * $Revision: 1.4 $
 * $Date: 2003/10/22 16:34:06 $
 */

import org.mozilla.javascript.Context;

import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class Main {
    public static String objectToXMLString(Object xml) {
        String xmlStr;

        if (xml instanceof String) {
            xmlStr = (String) xml;
        } else if (xml instanceof Scriptable) {
            Scriptable xmls = (Scriptable) xml;
            Context cx = Context.getCurrentContext();
            boolean exitContext = false;
            if (cx == null) {
                cx = Context.enter();
                exitContext = true;
            }

            try {
                Object func = ScriptableObject.getProperty(xmls, "toXMLString");
                xmlStr = (String) ((Function) func).call(cx, xmls, xmls, new Object[] {});
            } catch (Exception ex) {
                xmlStr = "";
            } finally {
                if (exitContext) {
                    Context.exit();
                }
            }
        } else {
            xmlStr = xml.toString();
        }

        return xmlStr;
    }
}

Related

  1. mapToNativeObject(Map map)
  2. nativeArrayToString(Object scriptObject)
  3. newObject()
  4. numberArg(Object[] args, int pos)
  5. objArg(Object[] args, int pos, Class type, boolean required)
  6. omitLineBreak(AstNode node)
  7. oneLineStringOf(AstNode node)
  8. parentOfAnyTypes(AstNode node, Set types, boolean isStrict)
  9. parentOfType(AstNode node, Class type)