Package org.apache.xindice.xml.dom

Source Code of org.apache.xindice.xml.dom.ProcessingInstructionImpl

/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* CVS $Id: ProcessingInstructionImpl.java,v 1.14 2004/02/08 03:11:56 vgritsenko Exp $
*/

package org.apache.xindice.xml.dom;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xindice.util.ByteArrayInput;
import org.apache.xindice.xml.SymbolTable;
import org.apache.xindice.xml.XMLCompressedInput;

import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;

/**
* ProcessingInstructionImpl
*
* @version CVS $Revision: 1.14 $, $Date: 2004/02/08 03:11:56 $
*/
public final class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction {

    private static final Log log = LogFactory.getLog(ProcessingInstructionImpl.class);


    public ProcessingInstructionImpl() {
    }

    public ProcessingInstructionImpl(NodeImpl parentNode, byte[] data, int pos, int len) {
        super(parentNode, data, pos, len);
    }

    public ProcessingInstructionImpl(NodeImpl parentNode, boolean dirty) {
        super(parentNode, dirty);
    }

    public ProcessingInstructionImpl(NodeImpl parentNode, String nodeName, String nodeValue) {
        super(parentNode, true);
        this.nodeName = nodeName;
        this.nodeValue = nodeValue;
    }

    protected void checkLoaded() {
        if (loaded) {
            return;
        } else {
            loaded = true;
        }
       
        try {
            if (data != null) {
                DocumentImpl doc = (DocumentImpl) getOwnerDocument();
                SymbolTable st = doc.getSymbols();

                ByteArrayInput bis = new ByteArrayInput(data, pos, len);
                XMLCompressedInput xci = new XMLCompressedInput(bis, st);

                xci.readSignature(); // Skip The Signature
                xci.readInt(); // Skip size

                byte[] buf = new byte[bis.available()];
                xci.read(buf);

                String value = new String(buf, "UTF-8");
                int i = value.indexOf(' ');
                nodeName = value.substring(0, i);
                nodeValue = value.substring(i + 1);
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
                log.warn("ignored exception", e);
            }
        }
    }

    public short getNodeType() {
        return Node.PROCESSING_INSTRUCTION_NODE;
    }

    public void setNodeValue(String nodeValue) throws DOMException {
        checkLoaded();
        checkReadOnly();
        this.nodeValue = nodeValue;
        setDirty();
    }

    /**
     * The target of this processing instruction. XML defines this as being the
     * first token following the markup that begins the processing instruction.
     */
    public String getTarget() {
        return getNodeName();
    }

    /**
     * The content of this processing instruction. This is from the first non
     * white space character after the target to the character immediately
     * preceding the <code>?&gt;</code>.
     * @exception DOMException
     *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
     */
    public String getData() {
        return getNodeValue();
    }

    public void setData(String data) throws DOMException {
        setNodeValue(data);
    }
}
TOP

Related Classes of org.apache.xindice.xml.dom.ProcessingInstructionImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.