Created
July 27, 2014 05:28
-
-
Save deoxxa/0c14cf3b7ffe796f3021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dom | |
import ( | |
"strings" | |
) | |
type Document struct { | |
Node | |
DOMImplementation *DOMImplementation | |
DocumentType *DocumentType | |
DocumentElement *Element | |
} | |
func (this *Document) InsertBefore(newChild INode, refChild INode) INode { | |
if this.DocumentElement == nil { | |
this.DocumentElement = newChild.(*Element) | |
} | |
return this.Node.InsertBefore(newChild, refChild) | |
} | |
func (this *Document) RemoveChild(oldChild INode) INode { | |
panic("unimplemented") | |
} | |
func (this *Document) AppendChild(newChild INode) INode { | |
return this.InsertBefore(newChild, nil) | |
} | |
func (this *Document) ImportNode(importedNode INode, deep bool) { | |
panic("unimplemented") | |
} | |
func (this *Document) GetElementById(id string) INode { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateElement(tagName string) *Element { | |
return &Element{ | |
Node: Node{ | |
OwnerDocument: this, | |
NodeName: tagName, | |
}, | |
TagName: tagName, | |
} | |
} | |
func (this *Document) CreateDocumentFragment() *DocumentFragment { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateTextNode(data string) *TextNode { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateComment(data string) *Comment { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateCDATASection(data string) *CDATASection { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateProcessingInstruction(target string, data string) *ProcessingInstruction { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateAttribute(name string) *Attr { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateEntityReference(name string) *EntityReference { | |
panic("unimplemented") | |
} | |
func (this *Document) CreateElementNS(namespaceURI string, qualifiedName string) *Element { | |
index := strings.LastIndex(qualifiedName, ":") | |
var prefix, localName string | |
if index != -1 { | |
prefix = qualifiedName[0:index] | |
localName = qualifiedName[index+1:] | |
} else { | |
prefix = "" | |
localName = qualifiedName | |
} | |
return &Element{ | |
Node: Node{ | |
OwnerDocument: this, | |
NamespaceURI: namespaceURI, | |
Prefix: prefix, | |
LocalName: localName, | |
NodeName: qualifiedName, | |
}, | |
TagName: qualifiedName, | |
} | |
} | |
func (this *Document) CreateAttributeNS(namespaceURI string, qualifiedName string) *Attr { | |
panic("unimplemented") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dom | |
type INode interface { | |
InsertBefore(newChild INode, refChild INode) INode | |
ReplaceChild(newChild INode, oldChild INode) INode | |
RemoveChild(oldChild INode) INode | |
AppendChild(newchild INode) INode | |
HasChildINodes() bool | |
CloneINode(deep bool) INode | |
Normalize() | |
IsSupported(feature string, version string) bool | |
HasAttributes(oldChild INode) bool | |
LookupPrefix(namespaceURI string) string | |
LookupNamespaceURI(prefix string) string | |
IsDefaultNamespace(namespaceURI string) bool | |
getFirstChild() INode | |
getLastChild() INode | |
getPreviousSibling() INode | |
getNextSibling() INode | |
getAttributes() NamedNodeMap | |
getParentNode() INode | |
getChildNodes() NodeList | |
getOwnerDocument() *Document | |
getNodeName() string | |
getNodeValue() string | |
getNamespaceURI() string | |
getPrefix() string | |
getLocalName() string | |
setFirstChild(FirstChild INode) | |
setLastChild(LastChild INode) | |
setPreviousSibling(PreviousSibling INode) | |
setNextSibling(NextSibling INode) | |
setAttributes(Attributes NamedNodeMap) | |
setParentNode(ParentNode INode) | |
setChildNodes(ChildNodes NodeList) | |
setOwnerDocument(OwnerDocument *Document) | |
setNodeName(NodeName string) | |
setNodeValue(NodeValue string) | |
setNamespaceURI(NamespaceURI string) | |
setPrefix(Prefix string) | |
setLocalName(LocalName string) | |
} | |
type Node struct { | |
FirstChild INode | |
LastChild INode | |
PreviousSibling INode | |
NextSibling INode | |
Attributes NamedNodeMap | |
ParentNode INode | |
ChildNodes NodeList | |
OwnerDocument *Document | |
NodeName string | |
NodeValue string | |
NamespaceURI string | |
Prefix string | |
LocalName string | |
} | |
func (this *Node) getFirstChild() INode { return this.FirstChild } | |
func (this *Node) getLastChild() INode { return this.LastChild } | |
func (this *Node) getPreviousSibling() INode { return this.PreviousSibling } | |
func (this *Node) getNextSibling() INode { return this.NextSibling } | |
func (this *Node) getAttributes() NamedNodeMap { return this.Attributes } | |
func (this *Node) getParentNode() INode { return this.ParentNode } | |
func (this *Node) getChildNodes() NodeList { return this.ChildNodes } | |
func (this *Node) getOwnerDocument() *Document { return this.OwnerDocument } | |
func (this *Node) getNodeName() string { return this.NodeName } | |
func (this *Node) getNodeValue() string { return this.NodeValue } | |
func (this *Node) getNamespaceURI() string { return this.NamespaceURI } | |
func (this *Node) getPrefix() string { return this.Prefix } | |
func (this *Node) getLocalName() string { return this.LocalName } | |
func (this *Node) setFirstChild(FirstChild INode) { this.FirstChild = FirstChild } | |
func (this *Node) setLastChild(LastChild INode) { this.LastChild = LastChild } | |
func (this *Node) setPreviousSibling(PreviousSibling INode) { this.PreviousSibling = PreviousSibling } | |
func (this *Node) setNextSibling(NextSibling INode) { this.NextSibling = NextSibling } | |
func (this *Node) setAttributes(Attributes NamedNodeMap) { this.Attributes = Attributes } | |
func (this *Node) setParentNode(ParentNode INode) { this.ParentNode = ParentNode } | |
func (this *Node) setChildNodes(ChildNodes NodeList) { this.ChildNodes = ChildNodes } | |
func (this *Node) setOwnerDocument(OwnerDocument *Document) { this.OwnerDocument = OwnerDocument } | |
func (this *Node) setNodeName(NodeName string) { this.NodeName = NodeName } | |
func (this *Node) setNodeValue(NodeValue string) { this.NodeValue = NodeValue } | |
func (this *Node) setNamespaceURI(NamespaceURI string) { this.NamespaceURI = NamespaceURI } | |
func (this *Node) setPrefix(Prefix string) { this.Prefix = Prefix } | |
func (this *Node) setLocalName(LocalName string) { this.LocalName = LocalName } | |
func (this *Node) InsertBefore(newChild INode, refChild INode) INode { | |
if newChild.getParentNode() != nil { | |
newChild.getParentNode().RemoveChild(newChild) | |
} | |
var previousSibling INode | |
if refChild != nil { | |
previousSibling = refChild.getPreviousSibling() | |
} else { | |
previousSibling = this.LastChild | |
} | |
newChild.setPreviousSibling(previousSibling) | |
newChild.setNextSibling(refChild) | |
if previousSibling != nil { | |
previousSibling.setNextSibling(newChild) | |
} else { | |
this.FirstChild = newChild | |
} | |
if refChild != nil { | |
refChild.setPreviousSibling(newChild) | |
} else { | |
this.LastChild = newChild | |
} | |
newChild.setParentNode(this) | |
this.ChildNodes = append(this.ChildNodes, newChild) | |
return newChild | |
} | |
func (this *Node) ReplaceChild(newChild INode, oldChild INode) INode { | |
this.InsertBefore(newChild, oldChild) | |
if oldChild != nil { | |
this.RemoveChild(oldChild) | |
} | |
return newChild | |
} | |
func (this *Node) RemoveChild(oldChild INode) INode { | |
previousSibling := oldChild.getPreviousSibling() | |
nextSibling := oldChild.getNextSibling() | |
if previousSibling != nil { | |
previousSibling.setNextSibling(nextSibling) | |
} else { | |
this.setFirstChild(nextSibling) | |
} | |
if nextSibling != nil { | |
nextSibling.setPreviousSibling(previousSibling) | |
} else { | |
this.setLastChild(previousSibling) | |
} | |
return oldChild | |
} | |
func (this *Node) AppendChild(newChild INode) INode { | |
return this.InsertBefore(newChild, nil) | |
} | |
func (this *Node) HasChildINodes() bool { | |
panic("unimplemented") | |
} | |
func (this *Node) CloneINode(deep bool) INode { | |
panic("unimplemented") | |
} | |
func (this *Node) Normalize() { | |
panic("unimplemented") | |
} | |
func (this *Node) IsSupported(feature string, version string) bool { | |
panic("unimplemented") | |
} | |
func (this *Node) HasAttributes(oldChild INode) bool { | |
panic("unimplemented") | |
} | |
func (this *Node) LookupPrefix(namespaceURI string) string { | |
panic("unimplemented") | |
} | |
func (this *Node) LookupNamespaceURI(prefix string) string { | |
panic("unimplemented") | |
} | |
func (this *Node) IsDefaultNamespace(namespaceURI string) bool { | |
panic("unimplemented") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment