Exemplo n.º 1
0
//======================================================================
// CJM 4/17/03 ..Needed to update an attribute list... for ContentGuard
//======================================================================
bool XMLDocument::setAttributeList(char* path, DataTypeAttribute** dtAttributes)
{
	if (mDoc == NULL)
		return false;

	if (path == NULL)
		return false;

	DOM_Node child = getNode(mRootNode, path, NULL);
	char* value = getString(path);

	if (child == NULL)
		return false;

	short nType = child.getNodeType();

	DOM_Node parent = child.getParentNode();
	if (parent == NULL)
		return false;

	char* childName = child.getNodeName().transcode();
	DOM_NamedNodeMap nnodeMap = child.getAttributes();

	parent.removeChild(child);
	DOM_Element childElement = mDoc.createElement(childName);
  delete[] childName;

	int a = 0;
	DataTypeAttribute* dtAttribute;
	while ((dtAttribute = (DataTypeAttribute*)dtAttributes[a++]) != (DataTypeAttribute*)NULL)
	{

		childElement.setAttribute(dtAttribute->getName(), dtAttribute->getValue());
	}

	if (nType == DOM_Node::TEXT_NODE)
	{
		DOM_Text childText = mDoc.createTextNode((value == NULL)?"":value);
		childElement.appendChild(childText);
	}
	else
	{
		if (nType == DOM_Node::CDATA_SECTION_NODE)
		{
			DOM_CDATASection childCData = mDoc.createCDATASection((value == NULL)?"":value);
			childElement.appendChild(childCData);
		}
	}

	parent.appendChild(childElement);

	return true;

}
Exemplo n.º 2
0
/**
 * Traverses the "left boundary" of this range and
 * operates on each "boundary node" according to the
 * how parameter.  It is a-priori assumed
 * by this method that the left boundary does
 * not contain the range's end container.
 *
 * A "left boundary" is best visualized by thinking
 * of a sample tree:
 *
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 *
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 *
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 *
 * The "left boundary" is the highest subtree node
 * that contains the starting container.  The root of
 * this subtree is always partially selected.
 *
 * In this example, the nodes that are traversed
 * as "left boundary" nodes are: F, G, and B.
 *
 */
DOM_Node RangeImpl::traverseLeftBoundary( DOM_Node root, int how )
{
    DOM_Node next = getSelectedNode( getStartContainer(), getStartOffset() );
    bool isFullySelected = ( next!=getStartContainer() );

    if ( next==root )
        return traverseNode( next, isFullySelected, true, how );

    DOM_Node parent = next.getParentNode();
    DOM_Node clonedParent = traverseNode( parent, false, true, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            DOM_Node nextSibling = next.getNextSibling();
            DOM_Node clonedChild =
                traverseNode( next, isFullySelected, true, how );
            if ( how!=DELETE_CONTENTS )
                clonedParent.appendChild(clonedChild);
            isFullySelected = true;
            next = nextSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getNextSibling();
        parent = parent.getParentNode();
        DOM_Node clonedGrandParent = traverseNode( parent, false, true, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;

}
Exemplo n.º 3
0
//======================================================================
//======================================================================
bool XMLDocument::setValue(DOM_Node currNode, char* path, DataTypeAttribute** dtAttributes, char* value)
{
	if (mDoc == NULL)
		return false;

	if (path == NULL)
		return false;

	DOM_Node child = getNode(currNode, path, dtAttributes);
	if (child == NULL)
		return false;
	DOM_Node parent = child.getParentNode();
	if (parent == NULL)
		return false;

	DOM_Node grandChild = child.getFirstChild();
	short nType = DOM_Node::TEXT_NODE;
	if (grandChild != NULL)
	{
		nType = grandChild.getNodeType();
		if (nType != DOM_Node::TEXT_NODE && nType != DOM_Node::CDATA_SECTION_NODE)
			return false;
	}

	char* childName = child.getNodeName().transcode();
	DOM_NamedNodeMap nnodeMap = child.getAttributes();

	parent.removeChild(child);
	DOM_Element childElement = mDoc.createElement(childName);
  delete[] childName;
	for (unsigned int i = 0; i < nnodeMap.getLength(); i++)
	{
		DOM_Node attNode = nnodeMap.item(i);
		childElement.setAttribute(attNode.getNodeName(), attNode.getNodeValue());
	}

	if (nType == DOM_Node::TEXT_NODE)
	{
		DOM_Text childText = mDoc.createTextNode((value == NULL)?"":value);
		childElement.appendChild(childText);
	}
	else
	{
		DOM_CDATASection childCData = mDoc.createCDATASection((value == NULL)?"":value);
		childElement.appendChild(childCData);
	}
	parent.appendChild(childElement);

	return true;
}
Exemplo n.º 4
0
void RangeImpl::surroundContents(DOM_Node& newParent)
{
    if (newParent==null) return;

    //check for elimination criteria
    if( fDetached) {
        throw DOM_DOMException(
            DOM_DOMException::INVALID_STATE_ERR, null);
    }

    if (newParent.getOwnerDocument() !=fDocument) {
        throw DOM_DOMException(
            DOM_DOMException::WRONG_DOCUMENT_ERR, null);
    }

    int type = newParent.getNodeType();
    if ( !isLegalContainedNode(newParent)
            || type == DOM_Node::DOCUMENT_TYPE_NODE)
    {
        throw DOM_RangeException(
            DOM_RangeException::INVALID_NODE_TYPE_ERR, null);
    }

    DOM_Node root = getCommonAncestorContainer();

    DOM_Node realStart = fStartContainer;
    DOM_Node realEnd = fEndContainer;

    if (fStartContainer.getNodeType() == DOM_Node::TEXT_NODE) {
        realStart = fStartContainer.getParentNode();
    }
    if (fEndContainer.getNodeType() == DOM_Node::TEXT_NODE) {
        realEnd = fEndContainer.getParentNode();
    }

    if (realStart != realEnd) {
        throw DOM_RangeException(
            DOM_RangeException::BAD_BOUNDARYPOINTS_ERR, null);
    }

    DOM_DocumentFragment frag = extractContents();
    insertNode(newParent);
    newParent.appendChild(frag);
    selectNode(newParent);
}
Exemplo n.º 5
0
/**
 * Traverses the "right boundary" of this range and
 * operates on each "boundary node" according to the
 * how parameter.  It is a-priori assumed
 * by this method that the right boundary does
 * not contain the range's start container.
 *
 * A "right boundary" is best visualized by thinking
 * of a sample tree:
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 *
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 *
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 *
 * The "right boundary" is the highest subtree node
 * that contains the ending container.  The root of
 * this subtree is always partially selected.
 *
 * In this example, the nodes that are traversed
 * as "right boundary" nodes are: H, I, and D.
 *
 */
DOM_Node RangeImpl::traverseRightBoundary( DOM_Node root, int how )
{
    DOM_Node next = getSelectedNode( fEndContainer, fEndOffset-1 );
    bool isFullySelected = ( next!=fEndContainer );

    if ( next==root )
        return traverseNode( next, isFullySelected, false, how );

    DOM_Node parent = next.getParentNode();
    DOM_Node clonedParent = traverseNode( parent, false, false, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            DOM_Node prevSibling = next.getPreviousSibling();
            DOM_Node clonedChild =
                traverseNode( next, isFullySelected, false, how );
            if ( how!=DELETE_CONTENTS )
            {
                clonedParent.insertBefore(
                    clonedChild,
                    clonedParent.getFirstChild()
                );
            }
            isFullySelected = true;
            next = prevSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getPreviousSibling();
        parent = parent.getParentNode();
        DOM_Node clonedGrandParent = traverseNode( parent, false, false, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;
}
Exemplo n.º 6
0
void RangeImpl::insertNode(DOM_Node& newNode)
{
    if (newNode == null) return; //don't have to do anything

    for (DOM_Node aNode = fStartContainer; aNode!=null; aNode = aNode.getParentNode()) {
        if (aNode.fImpl->isReadOnly()) {
            throw DOM_DOMException(
                DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
        }
    }

    if (fDocument != newNode.getOwnerDocument()) {
        throw DOM_DOMException(
            DOM_DOMException::WRONG_DOCUMENT_ERR, null);
    }

    // Prevent cycles in the tree.
    //isKidOK() is not checked here as its taken care by insertBefore() function
    if (isAncestorOf( newNode, fStartContainer)) {
        throw DOM_DOMException(
            DOM_DOMException::HIERARCHY_REQUEST_ERR, null);
    }

    if( fDetached) {
        throw DOM_DOMException(
            DOM_DOMException::INVALID_STATE_ERR, null);
    }

    int type = newNode.getNodeType();
    if (type == DOM_Node::ATTRIBUTE_NODE
            || type == DOM_Node::ENTITY_NODE
            || type == DOM_Node::NOTATION_NODE
            || type == DOM_Node::DOCUMENT_NODE)
    {
        throw DOM_RangeException(
            DOM_RangeException::INVALID_NODE_TYPE_ERR, null);
    }


    DOM_Node parent;
    DOM_Node next;

    if (fStartContainer.getNodeType() == DOM_Node::TEXT_NODE) {

        //set 'parent' and 'next' here
        parent = fStartContainer.getParentNode();

        //split the text nodes
        if (fStartOffset > 0)
            ((DOM_Text &)fStartContainer).splitText(fStartOffset);

        //update the new start information later. After inserting the first newNode
        if (fStartOffset == 0)
            next = fStartContainer;
        else
            next = fStartContainer.getNextSibling();

    } // end of text handling
    else {
        parent = fStartContainer;

        next = fStartContainer.getFirstChild();
        for(unsigned int i = 0; (i < fStartOffset) && (next != null); i++) {
            next=next.getNextSibling();
        }
    }

    if (parent != null) {
        if (next != null)
            parent.insertBefore(newNode, next);
        else
            parent.appendChild(newNode);
    }
}