Package org.apache.xindice.xml.dom

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

/*
* 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: EntityReferenceImpl.java,v 1.12 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.Signatures;
import org.apache.xindice.xml.SymbolTable;
import org.apache.xindice.xml.XMLCompressedInput;

import org.w3c.dom.EntityReference;
import org.w3c.dom.Node;

/**
* EntityReferenceImpl
*
* @version CVS $Revision: 1.12 $, $Date: 2004/02/08 03:11:56 $
*/
public final class EntityReferenceImpl extends NodeImpl implements EntityReference {

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

    private short symbolID = -1;


    public EntityReferenceImpl() {
    }

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

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

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

    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);

                byte signature = xci.readByte();
                byte entityType = (byte) (signature & 0x1F);
                switch (entityType) {

                    case Signatures.EntUnknown:
                        nodeName = null;
                        break;

                    case Signatures.EntDefined:
                        symbolID = xci.readShort();
                        nodeName = st.getName(symbolID);
                        break;

                    case Signatures.EntAmp:
                        nodeName = "&";
                        break;

                    case Signatures.EntLt:
                        nodeName = "<";
                        break;

                    case Signatures.EntGt:
                        nodeName = ">";
                        break;

                    case Signatures.EntQuot:
                        nodeName = """;
                        break;

                    case Signatures.EntApos:
                        nodeName = "'";
                        break;

                    case Signatures.EntUnicode:
                        nodeName = "";
                        // TODO: This
                        break;

                    default:
                        if (log.isWarnEnabled()) {
                            log.warn("invalid entity type : " + entityType);
                        }
                }
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
                log.warn("ignored exception", e);
            }
        }
    }

    public short getNodeType() {
        return Node.ENTITY_REFERENCE_NODE;
    }
}
TOP

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

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.