本文整理汇总了Java中mf.org.w3c.dom.Node.insertBefore方法的典型用法代码示例。如果您正苦于以下问题:Java Node.insertBefore方法的具体用法?Java Node.insertBefore怎么用?Java Node.insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.insertBefore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCellIndex
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public void setCellIndex( int cellIndex )
{
Node parent;
Node child;
parent = getParentNode();
if ( parent instanceof HTMLTableRowElement )
{
child = parent.getFirstChild();
while ( child != null )
{
if ( child instanceof HTMLTableCellElement )
{
if ( cellIndex == 0 )
{
if ( this != child )
parent.insertBefore( this, child );
return;
}
-- cellIndex;
}
child = child.getNextSibling();
}
}
parent.appendChild( this );
}
示例2: expandEntityRef
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
protected final void expandEntityRef (Node parent, Node reference){
Node kid, next;
for (kid = reference.getFirstChild(); kid != null; kid = next) {
next = kid.getNextSibling();
parent.insertBefore(kid, reference);
}
}
示例3: replaceRenameElement
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
private ElementImpl replaceRenameElement(ElementImpl el, String namespaceURI, String name) {
// we need to create a new object
ElementNSImpl nel = (ElementNSImpl)createElementNS(namespaceURI, name);
// register event listeners on new node
copyEventListeners(el, nel);
// remove user data from old node
Hashtable data = removeUserDataTable(el);
// remove old node from parent if any
Node parent = el.getParentNode();
Node nextSib = el.getNextSibling();
if (parent != null) {
parent.removeChild(el);
}
// move children to new node
Node child = el.getFirstChild();
while (child != null) {
el.removeChild(child);
nel.appendChild(child);
child = el.getFirstChild();
}
// move specified attributes to new node
nel.moveSpecifiedAttributes(el);
// attach user data to new node
setUserDataTable(nel, data);
// and fire user data NODE_RENAMED event
callUserDataHandlers(el, nel,
UserDataHandler.NODE_RENAMED);
// insert new node where old one was
if (parent != null) {
parent.insertBefore(nel, nextSib);
}
return nel;
}
示例4: splitText
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Break a text node into two sibling nodes. (Note that if the current node
* has no parent, they won't wind up as "siblings" -- they'll both be
* orphans.)
*
* @param offset
* The offset at which to split. If offset is at the end of the
* available data, the second node will be empty.
*
* @return A reference to the new node (containing data after the offset
* point). The original node will contain data up to that point.
*
* @throws DOMException(INDEX_SIZE_ERR)
* if offset is <0 or >length.
*
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
* if node is read-only.
*/
public Text splitText(int offset)
throws DOMException {
if (isReadOnly()) {
throw new DOMException(
DOMException.NO_MODIFICATION_ALLOWED_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
}
if (needsSyncData()) {
synchronizeData();
}
if (offset < 0 || offset > data.length() ) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
// split text into two separate nodes
Text newText =
getOwnerDocument().createTextNode(data.substring(offset));
setNodeValue(data.substring(0, offset));
// insert new text node
Node parentNode = getParentNode();
if (parentNode != null) {
parentNode.insertBefore(newText, nextSibling);
}
return newText;
}
示例5: writeToDOM
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
private synchronized void writeToDOM(Node target, short type) {
Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT) ?
target.getOwnerDocument() : (Document)target;
DOMParser parser = fGrammar.getDOMParser();
StringReader aReader = new StringReader(fData);
InputSource aSource = new InputSource(aReader);
try {
parser.parse(aSource);
}
catch (SAXException e) {
// this should never happen!
// REVISIT: what to do with this?; should really not
// eat it...
}
catch (IOException i) {
// ditto with above
}
Document aDocument = parser.getDocument();
parser.dropDocumentReferences();
Element annotation = aDocument.getDocumentElement();
Node newElem = null;
if (futureOwner instanceof CoreDocumentImpl) {
newElem = futureOwner.adoptNode(annotation);
// adoptNode will return null when the DOM implementations are not compatible.
if (newElem == null) {
newElem = futureOwner.importNode(annotation, true);
}
}
else {
newElem = futureOwner.importNode(annotation, true);
}
target.insertBefore(newElem, target.getFirstChild());
}
示例6: getHead
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Obtains the <HEAD> element in the document, creating one if does
* not exist before. The <HEAD> element is the first element in the
* <HTML> in the document. The <HTML> element is obtained by
* calling {@link #getDocumentElement}. If the element does not exist, one
* is created.
* <P>
* Called by {@link #getTitle}, {@link #setTitle}, {@link #getBody} and
* {@link #setBody} to assure the document has the <HEAD> element
* correctly placed.
*
* @return The <HEAD> element
*/
public synchronized HTMLElement getHead()
{
Node head;
Node html;
Node child;
Node next;
// Call getDocumentElement() to get the HTML element that is also the
// top-level element in the document. Get the first element in the
// document that is called HEAD. Work with that.
html = getDocumentElement();
synchronized ( html )
{
head = html.getFirstChild();
while ( head != null && ! ( head instanceof HTMLHeadElement ) )
head = head.getNextSibling();
// HEAD exists but might not be first element in HTML: make sure
// it is and return it.
if ( head != null )
{
synchronized ( head )
{
child = html.getFirstChild();
while ( child != null && child != head )
{
next = child.getNextSibling();
head.insertBefore( child, head.getFirstChild() );
child = next;
}
}
return (HTMLElement) head;
}
// Head does not exist, create a new one, place it at the top of the
// HTML element and return it.
head = new HTMLHeadElementImpl( this, "HEAD" );
html.insertBefore( head, html.getFirstChild() );
}
return (HTMLElement) head;
}
示例7: getBody
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public synchronized HTMLElement getBody()
{
Node html;
Node head;
Node body;
Node child;
Node next;
// Call getDocumentElement() to get the HTML element that is also the
// top-level element in the document. Get the first element in the
// document that is called BODY. Work with that.
html = getDocumentElement();
head = getHead();
synchronized ( html )
{
body = head.getNextSibling();
while ( body != null && ! ( body instanceof HTMLBodyElement )
&& ! ( body instanceof HTMLFrameSetElement ) )
body = body.getNextSibling();
// BODY/FRAMESET exists but might not be second element in HTML
// (after HEAD): make sure it is and return it.
if ( body != null )
{
synchronized ( body )
{
child = head.getNextSibling();
while ( child != null && child != body )
{
next = child.getNextSibling();
body.insertBefore( child, body.getFirstChild() );
child = next;
}
}
return (HTMLElement) body;
}
// BODY does not exist, create a new one, place it in the HTML element
// right after the HEAD and return it.
body = new HTMLBodyElementImpl( this, "BODY" );
html.appendChild( body );
}
return (HTMLElement) body;
}
示例8: setBody
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public synchronized void setBody( HTMLElement newBody )
{
Node html;
Node body;
Node head;
Node child;
NodeList list;
synchronized ( newBody )
{
// Call getDocumentElement() to get the HTML element that is also the
// top-level element in the document. Get the first element in the
// document that is called BODY. Work with that.
html = getDocumentElement();
head = getHead();
synchronized ( html )
{
list = this.getElementsByTagName( "BODY" );
if ( list.getLength() > 0 ) {
// BODY exists but might not follow HEAD in HTML. If not,
// make it so and replce it. Start with the HEAD and make
// sure the BODY is the first element after the HEAD.
body = list.item( 0 );
synchronized ( body )
{
child = head;
while ( child != null )
{
if ( child instanceof Element )
{
if ( child != body )
html.insertBefore( newBody, child );
else
html.replaceChild( newBody, body );
return;
}
child = child.getNextSibling();
}
html.appendChild( newBody );
}
return;
}
// BODY does not exist, place it in the HTML element
// right after the HEAD.
html.appendChild( newBody );
}
}
}