From: Jan T. <de...@us...> - 2003-05-31 22:39:37
|
Update of /cvsroot/net-script/netscript2/src/perl/XML/DAL In directory sc8-pr-cvs1:/tmp/cvs-serv4485/XML/DAL Modified Files: DAL.pm LibXMLDAL.pm README.html XMLDOM2DAL.pm Log Message: * finished XSLT implementation Index: DAL.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DAL/DAL.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DAL.pm 29 May 2003 16:00:02 -0000 1.1 --- DAL.pm 31 May 2003 22:39:34 -0000 1.2 *************** *** 5,9 **** # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... #-------------------------------------------------------- --- 5,9 ---- # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomae, insOMnia # mailto: ko...@in... #-------------------------------------------------------- *************** *** 53,56 **** --- 53,83 ---- + #/** + # Converts the given DOM to a string representation. + # @param the document element of the dom to convert to string. + # @return a string representation of the dom + #*/ + sub domToString { + + } + + #/** + # Returns nonzero if the current DAL supports XSLT functions. + # @return nonzero if XSLT is supported, zero if not. + #*/ + sub supportsXSLT { + + } + + #/** + # Applies the XSLT stylesheet dom to the given DOM. + # @param the document element of the dom to apply the stylesheet to + # @param the document element of the stylesheet dom + # @return the result dom. + #*/ + sub applyXSLT { + + } + # ---------------- Node Type Checking -------------------- *************** *** 263,266 **** --- 290,303 ---- } + #/** + # Sets the given attribute of the given node to the given value. + # @param an element node + # @param the name of the attribute + # @param the value of the attribute. + #*/ + sub setAttribute { + + } + # ---------------- CDATA functions -------------------- *************** *** 333,336 **** --- 370,382 ---- #/** + # Allows to set the document element of the given document. + # @param a document node + # @param the new document element. + #*/ + sub setDocumentElement { + + } + + #/** # Import the given node into the given document. # @param the document to import the node into *************** *** 343,346 **** --- 389,401 ---- } + #/** + # Creates a comment node using the given document. + # @param the document to use for node creation + # @param the text of the comment to be created + # @return the created node + #*/ + sub createComment { + + } Index: LibXMLDAL.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DAL/LibXMLDAL.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LibXMLDAL.pm 29 May 2003 16:00:02 -0000 1.1 --- LibXMLDAL.pm 31 May 2003 22:39:34 -0000 1.2 *************** *** 5,9 **** # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... #-------------------------------------------------------- --- 5,9 ---- # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomae, insOMnia # mailto: ko...@in... #-------------------------------------------------------- *************** *** 11,14 **** --- 11,15 ---- use XML::LibXML; + #use XML::LibXML::Document; #/** *************** *** 31,33 **** --- 32,409 ---- } + sub domToString { + my ( $this, $dom ) = @_; + $dom -> toString( 0 ); + } + + sub supportsXSLT { + if ( defined( eval{ + use XML::LibXSLT; + } ) ) { + return 1; + } + + return 0; + } + + + sub applyXSLT { + my ( $this, $sourcedom, $stylesheetdom ) = @_; + use XML::LibXSLT; # hardcoded import + my $xslt = XML::LibXSLT -> new(); + my $stylesheet = $xslt -> parse_stylesheet( $stylesheetdom ); + $stylesheet -> transform( $sourcedom ); + } + + # ---------------- Node Type Checking -------------------- + + #/** + # Returns nonzero if the given node is an element node. + # @param a node + #*/ + sub isElementNode { + my ( $this, $node ) = @_; + return 1 if $node -> nodeType == 1; # 1 = Element node + return 0; + } + + #/** + # Returns nonzero if the given node is a text node + # @param a node + #*/ + sub isTextNode { + my ( $this, $node ) = @_; + return 1 if $node -> nodeType == 3; # 3 = text node + return 0; + } + + #/** + # Returns nonzero, if the given node is a processing instruction node + # @param a node + #*/ + sub isProcessingInstructionNode { + my ( $this, $node ) = @_; + return 1 if $node -> nodeType == 7; # 7 =PI node + return 0; + } + + #/** + # Returns nonzero if the given node is a comment node. + # @param a node + #*/ + sub isCommentNode { + my ( $this, $node ) = @_; + return 1 if $node -> nodeType == 8; # 8 = comment node + return 0; + } + + #/** + # Returns nonzero if the given node is a document node. + # @param a node + #*/ + sub isDocumentNode { + my ( $this, $node ) = @_; + return 1 if $node -> nodeType == 9; # 9 = document node + return 0; + } + + # ---------------- Node Functions -------------------- + + #/** + # Appends the given child node to the given parent node. + # @param the parent node + # @param the node to append to the parent node. + #*/ + sub appendChild { + my ( $this, $parent, $node ) = @_; + $parent -> appendChild( $node ); + } + + #/** + # Inserts the given node before the given child node of the given parent node + # @param the parent node + # @param the reference node + # @param the node to insert + #*/ + sub insertBefore { + my ( $this, $parent, $ref, $node ) = @_; + $parent -> insertBefore( $node, $ref ); + } + + #/** + # Removes the given child node from the given parent node. + # @param the node to remove the child from + # @param the node to remove from the parent node. + # @return the removed node. + #*/ + sub removeChild { + my ( $this, $parent, $node ) = @_; + $parent -> removeChild( $node ); + } + + #/** + # Returns the first child of the given node. + # @param the node whichs first child should be returned. + # @return the first child of the given node or undef if the node has no child + # nodes. + #*/ + sub getFirstChild { + my ( $this, $node ) = @_; + $node -> firstChild; + } + + + #/** + # Returns the parent node of the given node. + # @param the node whichs parent should be returned. + # @return the parent node of the given node. + #*/ + sub getParentNode { + my ( $this, $node ) = @_; + $node -> parentNode; + } + + #/** + # Returns the next sibling of the given node. + # @param the node whichs next sibling should be returned. + # @return the next sibling of the given node or undef if there is no next + # sibling. + #*/ + sub getNextSibling { + my ( $this, $node ) = @_; + $node -> nextSibling(); + } + + + #/** + # Returns the previous sibling of the given node. + # @param the node whichs previous sibling should be returned. + # @return the previous sibling or undef if there is no previous sibling. + #*/ + sub getPreviousSibling { + my ( $this, $node ) = @_; + $node -> previousSibling(); + } + + #/** + # Returns a NodeList containing the child nodes of the given node. + # @param the node whichs childnodes should be returned + # @return a node list + #*/ + sub getChildNodes { + my ( $this, $node ) = @_; + my @childNodes = $node -> childNodes; + \@childNodes; + } + + #/** + # Returns the attributes of the given node as a NodeList. + # @param the node + # @return a nodelist containing the attributes of this node. + #*/ + sub getAttributes { + my ( $this, $node ) = @_; + my @attributes = $node -> attributes; + \@attributes; + } + + #/** + # Returns the fully qualified node name of the given node. + # @param a node + # @return the node name of the given node. + #*/ + sub getNodeName { + my ( $this, $node ) = @_; + $node -> nodeName; + } + + #/** + # Returns the namespace URI of the given node. + # @param a node + # @return the namespace uri of the given node + #*/ + sub getNamespaceURI { + my ( $this, $node ) = @_; + $node -> namespaceURI(); + } + + #/** + # Returns the local name of the given node. + # @param a node + # @return the local (non-prefixed) name of the node + #*/ + sub getLocalName { + my ( $this, $node ) = @_; + $node -> localname; + } + + # ---------------- PI functions -------------------- + + #/** + # Returns the target of a processing instruction. + # @param the processing instruction node + # @return a string holding the target of the PI + #*/ + sub getPITarget { + my ( $this, $node ) = @_; + $node -> nodeName; + } + + #/** + # Returns the data of a processing instruction + # @param the processing instruction node + # @return a string holding the data of the PI + #*/ + sub getPIData { + my ( $this , $node ) = @_; + $node -> getData(); + } + + # ---------------- Attr functions -------------------- + + #/** + # Returns the node value of the given Attr. + # @param an Attr + # @return a string holding the value of the node + #*/ + sub getAttrValue { + my ( $this, $attr ) = @_; + $attr -> getValue(); + } + + #/** + # Sets the node value of the given node. + # @param a node + # @param a string holding the new value of the given node. + #*/ + sub setAttrValue { + my ( $this, $attr, $value ) = @_; + $attr -> setValue( $value ); + } + + # ---------------- Element functions -------------------- + + #/** + # Returns the value of the given attribute of the given element. + # @param an element node + # @param the name of the attribute to return + # @return a string holding the attribute's value + #*/ + sub getAttribute { + my ( $this, $element, $name ) = @_; + $element -> getAttribute( $name ); + } + + sub setAttribute { + my ( $this, $element, $name, $value ) = @_; + $element -> setAttribute( $name, $value ); + } + + + # ---------------- CDATA functions -------------------- + + #/** + # Returns the data of the given CDATA/Text node. + # @param a node + # @return a string holding the data of the node. + #*/ + sub getCData { + my ( $this, $node ) = @_; + $node -> data; + } + + + #/** + # Sets the data of the given CDATA/Text node. + # @param a node + # @param the new value for the node. + #*/ + sub setCData { + my ( $this, $node, $data ) = @_; + $node -> setData( $data ); + } + + # ---------------- NodeList functions -------------------- + + #/** + # Returns the length of a nodelist + # @param a NodeList + # @return the length of a node list + #*/ + sub getLength { + my ( $this, $list ) = @_; + scalar( @{$list} ); + } + + + #/** + # Return the item at the given index from the node list. + # @param the list to retrieve the item from. + # @param the index of the item (zero-based) + # @return a node from the given index + #*/ + sub getItemAt { + my ( $this, $list, $index ) = @_; + my @theList = @{$list}; + $theList[$index]; + } + + + + # ---------------- Document Functions -------------------- + + #/** + # Creates a new document. + # @param the namespace uri of the document element + # @param the fully qualified name of the document element. + # @return a document node + #*/ + sub createDocument { + my ( $this, $ns, $fqName ) = @_; + my $document = XML::LibXML::Document -> createDocument(); + my $element = $document -> createElementNS( $ns, $fqName ); + $document -> setDocumentElement( $element ); + $document; + } + + + #/** + # Returns the document element of the given document. + # @param a document node + # @return an element node - the document element of the given document. + #*/ + sub getDocumentElement { + my ( $this, $document ) = @_; + $document -> documentElement(); + } + + + sub setDocumentElement { + my ( $this, $document, $element ) = @_; + $document -> setDocumentElement( $element ); + } + + #/** + # Import the given node into the given document. + # @param the document to import the node into + # @param the node to import + # @param set nonzero to do a deep (recursive) import, zero to do a shallow import + # @return the imported node. + #*/ + sub importNode { + my ( $this, $document, $node, $deep ) = @_; + my $clone = $node -> cloneNode( $deep ); + return $document -> importNode( $clone ); + } + + #/** + # Creates a comment node using the given document. + # @param the document to use for node creation + # @param the text of the comment to be created + # @return the created node + #*/ + sub createComment { + my ( $this, $document, $text ) = @_; + $document -> createComment( $text ); + } 1; Index: README.html =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DAL/README.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README.html 29 May 2003 16:00:02 -0000 1.1 --- README.html 31 May 2003 22:39:34 -0000 1.2 *************** *** 5,9 **** | are protected under the terms and conditions of the Artistic License. | ! | (C) 2000-2002 by Jan Thomä, insOMnia (ko...@in...) \---------------------------------------------------------------------/ --- 5,9 ---- | are protected under the terms and conditions of the Artistic License. | ! | (C) 2000-2002 by Jan Thomae, insOMnia (ko...@in...) \---------------------------------------------------------------------/ Index: XMLDOM2DAL.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DAL/XMLDOM2DAL.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XMLDOM2DAL.pm 29 May 2003 16:00:02 -0000 1.1 --- XMLDOM2DAL.pm 31 May 2003 22:39:34 -0000 1.2 *************** *** 5,9 **** # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... #-------------------------------------------------------- --- 5,9 ---- # DOM2 and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. ! # (C) 2000-2002 by Jan Thomae, insOMnia # mailto: ko...@in... #-------------------------------------------------------- *************** *** 30,33 **** --- 30,391 ---- return $parser -> parseString( $string ); } + + + sub domToString { + my ( $this, $dom ) = @_; + my $writer = XML::DOM2::DOMWriter -> new(); + my $style = XML::DOM2::XMLDOMWriterStyle -> new(); + $writer -> writeDOMToString( $dom, $style ); + } + + sub supportsXSLT { + 0; + } + + sub applyXSLT { + undef; + } + + # ---------------- Node Type Checking -------------------- + + #/** + # Returns nonzero if the given node is an element node. + # @param a node + #*/ + sub isElementNode { + my ( $this, $node ) = @_; + return 1 if ($node -> getNodeType() == $XML::DOM2::Node::ELEMENT_NODE ); + return 0; + } + + #/** + # Returns nonzero if the given node is a text node + # @param a node + #*/ + sub isTextNode { + my ( $this, $node ) = @_; + return 1 if ( $node -> getNodeType() == $XML::DOM2::Node::TEXT_NODE ); + return 0; + } + + #/** + # Returns nonzero, if the given node is a processing instruction node + # @param a node + #*/ + sub isProcessingInstructionNode { + my ( $this, $node ) = @_; + return 1 if ( $node -> getNodeType() == $XML::DOM2::Node::PROCESSING_INSTRUCTION_NODE ); + return 0; + } + + #/** + # Returns nonzero if the given node is a comment node. + # @param a node + #*/ + sub isCommentNode { + my ( $this, $node ) = @_; + return 1 if ( $node -> getNodeType() == $XML::DOM2::Node::COMMENT_NODE ); + return 0; + } + + #/** + # Returns nonzero if the given node is a document node. + # @param a node + #*/ + sub isDocumentNode { + my ( $this, $node ) = @_; + return 1 if ( $node -> getNodeType() == $XML::DOM2::Node::DOCUMENT_NODE ); + return 0; + } + + # ---------------- Node Functions -------------------- + + #/** + # Appends the given child node to the given parent node. + # @param the parent node + # @param the node to append to the parent node. + #*/ + sub appendChild { + my ( $this, $parent, $node ) = @_; + $parent -> appendChild( $node ); + } + + #/** + # Inserts the given node before the given child node of the given parent node + # @param the parent node + # @param the reference node + # @param the node to insert + #*/ + sub insertBefore { + my ( $this, $parent, $ref, $node ) = @_; + $parent -> insertBefore( $node, $ref ); + } + + #/** + # Removes the given child node from the given parent node. + # @param the node to remove the child from + # @param the node to remove from the parent node. + # @return the removed node. + #*/ + sub removeChild { + my ( $this, $parent, $node ) = @_; + $parent -> removeChild( $node ); + } + + #/** + # Returns the first child of the given node. + # @param the node whichs first child should be returned. + # @return the first child of the given node or undef if the node has no child + # nodes. + #*/ + sub getFirstChild { + my ( $this, $node ) = @_; + $node -> getFirstChild(); + } + + + #/** + # Returns the parent node of the given node. + # @param the node whichs parent should be returned. + # @return the parent node of the given node. + #*/ + sub getParentNode { + my ( $this, $node ) = @_; + $node -> getParentNode(); + } + + #/** + # Returns the next sibling of the given node. + # @param the node whichs next sibling should be returned. + # @return the next sibling of the given node or undef if there is no next + # sibling. + #*/ + sub getNextSibling { + my ( $this, $node ) = @_; + $node -> getNextSibling(); + } + + + #/** + # Returns the previous sibling of the given node. + # @param the node whichs previous sibling should be returned. + # @return the previous sibling or undef if there is no previous sibling. + #*/ + sub getPreviousSibling { + my ( $this, $node ) = @_; + $node -> getPreviousSibling(); + } + + #/** + # Returns a NodeList containing the child nodes of the given node. + # @param the node whichs childnodes should be returned + # @return a node list + #*/ + sub getChildNodes { + my ( $this, $node ) = @_; + $node -> getChildNodes(); + } + + #/** + # Returns the attributes of the given node as a NodeList. + # @param the node + # @return a nodelist containing the attributes of this node. + #*/ + sub getAttributes { + my ( $this, $node ) = @_; + $node -> getAttributes(); + } + + #/** + # Returns the fully qualified node name of the given node. + # @param a node + # @return the node name of the given node. + #*/ + sub getNodeName { + my ( $this, $node ) = @_; + $node -> getNodeName(); + } + + #/** + # Returns the namespace URI of the given node. + # @param a node + # @return the namespace uri of the given node + #*/ + sub getNamespaceURI { + my ( $this, $node ) = @_; + $node -> getNamespaceURI(); + } + + #/** + # Returns the local name of the given node. + # @param a node + # @return the local (non-prefixed) name of the node + #*/ + sub getLocalName { + my ( $this, $node ) = @_; + $node -> getLocalName(); + } + + # ---------------- PI functions -------------------- + + #/** + # Returns the target of a processing instruction. + # @param the processing instruction node + # @return a string holding the target of the PI + #*/ + sub getPITarget { + my ( $this, $node ) = @_; + $node -> getTarget(); + } + + #/** + # Returns the data of a processing instruction + # @param the processing instruction node + # @return a string holding the data of the PI + #*/ + sub getPIData { + my ( $this, $node ) = @_; + $node -> getData(); + } + + # ---------------- Attr functions -------------------- + + #/** + # Returns the node value of the given Attr. + # @param an Attr + # @return a string holding the value of the node + #*/ + sub getAttrValue { + my ( $this, $node ) = @_; + $node -> getValue(); + } + + #/** + # Sets the node value of the given node. + # @param a node + # @param a string holding the new value of the given node. + #*/ + sub setAttrValue { + my ( $this, $node, $value ) = @_; + $node -> setValue( $value ); + } + + # ---------------- Element functions -------------------- + + #/** + # Returns the value of the given attribute of the given element. + # @param an element node + # @param the name of the attribute to return + # @return a string holding the attribute's value + #*/ + sub getAttribute { + my ( $this, $node, $attrname ) = @_; + $node -> getAttribute( $attrname ); + } + + sub setAttribute { + my ( $this, $node, $name, $value ) = @_; + $node -> setAttribute( $name, $value ); + } + + + # ---------------- CDATA functions -------------------- + + #/** + # Returns the data of the given CDATA/Text node. + # @param a node + # @return a string holding the data of the node. + #*/ + sub getCData { + my ( $this, $node ) = @_; + $node -> getData(); + } + + + #/** + # Sets the data of the given CDATA/Text node. + # @param a node + # @param the new value for the node. + #*/ + sub setCData { + my ( $this, $node, $data ) = @_; + $node -> setData( $data ); + } + + # ---------------- NodeList functions -------------------- + + #/** + # Returns the length of a nodelist + # @param a NodeList + # @return the length of a node list + #*/ + sub getLength { + my ( $this, $list ) = @_; + $list -> getLength(); + } + + + #/** + # Return the item at the given index from the node list. + # @param the list to retrieve the item from. + # @param the index of the item (zero-based) + # @return a node from the given index + #*/ + sub getItemAt { + my ( $this, $list, $pos ) = @_; + $list -> item( $pos ); + } + + + + # ---------------- Document Functions -------------------- + + #/** + # Creates a new document. + # @param the namespace uri of the document element + # @param the fully qualified name of the document element. + # @return a document node + #*/ + sub createDocument { + my ( $this, $namespace, $fqname ) = @_; + my $di = XML::DOM2::DOMImplementation -> new(); + $di -> createDocument( $namespace, $fqname ); + } + + + #/** + # Returns the document element of the given document. + # @param a document node + # @return an element node - the document element of the given document. + #*/ + sub getDocumentElement { + my ( $this, $document ) = @_; + $document -> getDocumentElement(); + } + + + #/** + # Import the given node into the given document. + # @param the document to import the node into + # @param the node to import + # @param set nonzero to do a deep (recursive) import, zero to do a shallow import + # @return the imported node. + #*/ + sub importNode { + my ( $this, $document, $node, $deep ) = @_; + $document -> importNode( $node, $deep ); + } + + #/** + # Creates a comment node using the given document. + # @param the document to use for node creation + # @param the text of the comment to be created + # @return the created node + #*/ + sub createComment { + my ( $this, $document, $text ) = @_; + $document -> createComment( $text ); + } + 1; |