Package org.apache.xindice.xml.dom

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

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: ProcessingInstructionImpl.java 571948 2007-09-02 10:51:37Z vgritsenko $
*/

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 $Revision: 571948 $, $Date: 2007-09-02 06:51:37 -0400 (Sun, 02 Sep 2007) $
*/
public final class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction {

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


    public ProcessingInstructionImpl() {
    }

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

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

    public ProcessingInstructionImpl(NodeImpl parent, String nodeName, String nodeValue) {
        super(parent, 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.