com.caucho.quercus.lib.simplexml
Class SimpleXMLElement

java.lang.Object
  extended by com.caucho.quercus.lib.simplexml.SimpleXMLElement
All Implemented Interfaces:
java.util.Map.Entry<java.lang.String,java.lang.Object>
Direct Known Subclasses:
SelectedXMLElement, SimpleXMLAttribute, SimpleXMLAttributeList, SimpleXMLChildren, SimpleXMLText

public class SimpleXMLElement
extends java.lang.Object
implements java.util.Map.Entry<java.lang.String,java.lang.Object>

SimpleXMLElement object oriented API facade. Also acts as the DOM document.


Field Summary
protected  java.util.ArrayList<SimpleXMLElement> _attributes
           
protected  java.util.ArrayList<SimpleXMLElement> _children
           
protected  QuercusClass _cls
           
protected  Env _env
           
protected  java.lang.String _name
           
protected  java.lang.String _namespace
           
protected  java.util.LinkedHashMap<java.lang.String,java.lang.String> _namespaceMap
           
protected  SimpleXMLElement _parent
           
protected  java.lang.String _prefix
           
protected  StringValue _text
           
 
Constructor Summary
protected SimpleXMLElement(Env env, QuercusClass cls)
           
protected SimpleXMLElement(Env env, QuercusClass cls, SimpleXMLElement parent, java.lang.String name)
           
protected SimpleXMLElement(Env env, QuercusClass cls, SimpleXMLElement parent, java.lang.String name, java.lang.String namespace)
           
 
Method Summary
static Value __construct(Env env, Value data, int options, boolean dataIsUrl, Value namespaceV, boolean isPrefix)
          Returns a new instance based on the xml from 'data'.
 int __count(Env env)
          Implementation for getting the indices of this class.
 Value __get(Env env, Value indexV)
          Implementation for getting the indices of this class.
 Value __getField(java.lang.String name)
          Implementation for getting the fields of this class.
 void __set(java.lang.String name, StringValue value)
          Implementation for setting the indices of this class.
 void __setField(java.lang.String name, Value value)
          Implementation for setting the fields of this class.
 StringValue __toString(Env env)
           
 void addAttribute(Env env, java.lang.String name, StringValue value, java.lang.String namespace)
          Adds an attribute to this node.
protected  void addAttribute(SimpleXMLElement attr)
          Adds an attribute to this node.
 Value addChild(Env env, java.lang.String name, java.lang.String value, Value namespaceV)
          Adds a child to this node.
protected  void addNamespace(java.lang.String prefix, java.lang.String namespace)
           
protected  void addNamespaceAttribute(Env env, java.lang.String name, java.lang.String namespace)
          Adds a namespace attribute to this node.
protected  void addText(StringValue text)
           
 StringValue asXML(Env env)
          Converts node tree to a valid xml string.
 Value attributes(Env env, Value namespaceV, boolean isPrefix)
          Returns the attributes of this node.
 Value children(Env env, Value namespaceV, boolean isPrefix)
          Returns all the children of this node, including the attributes of this node.
protected static Value create(Env env, QuercusClass cls, Value data, int options, boolean dataIsUrl, Value namespaceV, boolean isPrefix)
           
 java.util.Set<java.util.Map.Entry<Value,Value>> entrySet()
           
protected  SimpleXMLElement getAttribute(java.lang.String name)
           
 Value getDocNamespaces(Env env, boolean isRecursive)
          Alias of getNamespaces().
 java.lang.String getKey()
           
protected  java.lang.String getName()
           
protected  java.lang.String getNamespace()
           
protected  java.lang.String getNamespace(java.lang.String prefix)
           
 Value getNamespaces(Env env, boolean isRecursive)
          Returns the namespaces used in this document.
protected  SimpleXMLElement getOwner()
           
protected  QuercusClass getQuercusClass()
           
 java.lang.Object getValue()
           
protected  boolean hasNamespace(java.lang.String prefix, java.lang.String namespace)
           
protected  boolean isElement()
           
protected  boolean isNamespaceAttribute()
           
protected  boolean isSameNamespace(java.lang.String namespace)
           
protected  boolean isSamePrefix(java.lang.String prefix)
           
 java.util.Iterator iterator()
          Required for 'foreach'.
 void jsonEncode(Env env, StringValue sb)
           
protected  void jsonEncodeImpl(Env env, StringValue sb, boolean isTop)
           
protected  void printDepth(WriteStream out, int depth)
           
protected  void setQuercusClass(QuercusClass cls)
           
protected  void setText(StringValue text)
           
 java.lang.Object setValue(java.lang.Object value)
           
 java.lang.String simplexml_getName()
          Returns the name of the node.
 StringValue toXML(Env env)
           
protected  void toXMLImpl(StringValue sb)
           
 void varDumpImpl(Env env, Value obj, WriteStream out, int depth, java.util.IdentityHashMap<Value,java.lang.String> valueSet)
          var_dump() implementation
protected static Value wrapJava(Env env, QuercusClass cls, SimpleXMLElement element)
           
 Value xpath(Env env, java.lang.String expression)
          Runs an XPath expression on this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map.Entry
equals, hashCode
 

Field Detail

_parent

protected SimpleXMLElement _parent

_name

protected java.lang.String _name

_text

protected StringValue _text

_children

protected java.util.ArrayList<SimpleXMLElement> _children

_attributes

protected java.util.ArrayList<SimpleXMLElement> _attributes

_namespace

protected java.lang.String _namespace

_prefix

protected java.lang.String _prefix

_namespaceMap

protected java.util.LinkedHashMap<java.lang.String,java.lang.String> _namespaceMap

_env

protected Env _env

_cls

protected QuercusClass _cls
Constructor Detail

SimpleXMLElement

protected SimpleXMLElement(Env env,
                           QuercusClass cls)

SimpleXMLElement

protected SimpleXMLElement(Env env,
                           QuercusClass cls,
                           SimpleXMLElement parent,
                           java.lang.String name)

SimpleXMLElement

protected SimpleXMLElement(Env env,
                           QuercusClass cls,
                           SimpleXMLElement parent,
                           java.lang.String name,
                           java.lang.String namespace)
Method Detail

create

protected static Value create(Env env,
                              QuercusClass cls,
                              Value data,
                              int options,
                              boolean dataIsUrl,
                              Value namespaceV,
                              boolean isPrefix)

wrapJava

protected static Value wrapJava(Env env,
                                QuercusClass cls,
                                SimpleXMLElement element)

getQuercusClass

protected QuercusClass getQuercusClass()

setQuercusClass

protected void setQuercusClass(QuercusClass cls)

addNamespace

protected void addNamespace(java.lang.String prefix,
                            java.lang.String namespace)

hasNamespace

protected boolean hasNamespace(java.lang.String prefix,
                               java.lang.String namespace)

getNamespace

protected java.lang.String getNamespace(java.lang.String prefix)

__construct

public static Value __construct(Env env,
                                Value data,
                                int options,
                                boolean dataIsUrl,
                                Value namespaceV,
                                boolean isPrefix)
Returns a new instance based on the xml from 'data'.

Parameters:
env -
data - xml data
options -
dataIsUrl -
namespaceV -
isPrefix -

getName

protected java.lang.String getName()

getNamespace

protected java.lang.String getNamespace()

getOwner

protected SimpleXMLElement getOwner()

isElement

protected boolean isElement()

isNamespaceAttribute

protected boolean isNamespaceAttribute()

setText

protected void setText(StringValue text)

addText

protected void addText(StringValue text)

isSameNamespace

protected boolean isSameNamespace(java.lang.String namespace)

isSamePrefix

protected boolean isSamePrefix(java.lang.String prefix)

getAttribute

protected SimpleXMLElement getAttribute(java.lang.String name)

getKey

public java.lang.String getKey()
Specified by:
getKey in interface java.util.Map.Entry<java.lang.String,java.lang.Object>

getValue

public java.lang.Object getValue()
Specified by:
getValue in interface java.util.Map.Entry<java.lang.String,java.lang.Object>

setValue

public java.lang.Object setValue(java.lang.Object value)
Specified by:
setValue in interface java.util.Map.Entry<java.lang.String,java.lang.Object>

addAttribute

public void addAttribute(Env env,
                         java.lang.String name,
                         StringValue value,
                         java.lang.String namespace)
Adds an attribute to this node.


addNamespaceAttribute

protected void addNamespaceAttribute(Env env,
                                     java.lang.String name,
                                     java.lang.String namespace)
Adds a namespace attribute to this node.


addAttribute

protected void addAttribute(SimpleXMLElement attr)
Adds an attribute to this node.


addChild

public Value addChild(Env env,
                      java.lang.String name,
                      java.lang.String value,
                      Value namespaceV)
Adds a child to this node.

Parameters:
env -
name - of the child node
value - of the text node of the child
namespace -
Returns:

attributes

public Value attributes(Env env,
                        Value namespaceV,
                        boolean isPrefix)
Returns the attributes of this node.

Parameters:
env -
namespaceV -
isPrefix -

children

public Value children(Env env,
                      Value namespaceV,
                      boolean isPrefix)
Returns all the children of this node, including the attributes of this node.

Parameters:
env -
namespaceV -
isPrefix -

asXML

public StringValue asXML(Env env)
Converts node tree to a valid xml string.

Returns:
xml string

toXML

public StringValue toXML(Env env)

toXMLImpl

protected void toXMLImpl(StringValue sb)

simplexml_getName

public java.lang.String simplexml_getName()
Returns the name of the node.

Returns:
name of the node

getDocNamespaces

public Value getDocNamespaces(Env env,
                              boolean isRecursive)
Alias of getNamespaces().


getNamespaces

public Value getNamespaces(Env env,
                           boolean isRecursive)
Returns the namespaces used in this document.


xpath

public Value xpath(Env env,
                   java.lang.String expression)
Runs an XPath expression on this node.

Parameters:
env -
expression -
Returns:
array of results
Throws:
javax.xml.xpath.XPathExpressionException

__get

public Value __get(Env env,
                   Value indexV)
Implementation for getting the indices of this class. i.e. $a->foo[0]


__set

public void __set(java.lang.String name,
                  StringValue value)
Implementation for setting the indices of this class. i.e. $a->foo[0] = "hello"


__count

public int __count(Env env)
Implementation for getting the indices of this class. i.e. count($a->foo[0])


__getField

public Value __getField(java.lang.String name)
Implementation for getting the fields of this class. i.e. $a->foo


__setField

public void __setField(java.lang.String name,
                       Value value)
Implementation for setting the fields of this class. i.e. $a->foo = "hello"


iterator

public java.util.Iterator iterator()
Required for 'foreach'. When only values are specified in the loop foreach($a as $b), this method should return an iterator that contains Java objects that will be wrapped in a Value. When a 'foreach' loop with name/value pairs i.e. foreach($a as $b=>$c) invokes this method, it expects an iterator that contains objects that implement Map.Entry.


entrySet

public java.util.Set<java.util.Map.Entry<Value,Value>> entrySet()

varDumpImpl

public void varDumpImpl(Env env,
                        Value obj,
                        WriteStream out,
                        int depth,
                        java.util.IdentityHashMap<Value,java.lang.String> valueSet)
                 throws java.io.IOException
var_dump() implementation

Throws:
java.io.IOException

jsonEncode

public void jsonEncode(Env env,
                       StringValue sb)

jsonEncodeImpl

protected void jsonEncodeImpl(Env env,
                              StringValue sb,
                              boolean isTop)

printDepth

protected void printDepth(WriteStream out,
                          int depth)
                   throws java.io.IOException
Throws:
java.io.IOException

__toString

public StringValue __toString(Env env)