/*
* 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: EntityReferenceImpl.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.Signatures;
import org.apache.xindice.xml.SymbolTable;
import org.apache.xindice.xml.XMLCompressedInput;
import org.w3c.dom.EntityReference;
import org.w3c.dom.Node;
import java.io.IOException;
/**
* EntityReferenceImpl
*
* @version $Revision: 571948 $, $Date: 2007-09-02 06:51:37 -0400 (Sun, 02 Sep 2007) $
*/
public final class EntityReferenceImpl extends NodeImpl
implements EntityReference {
private static final Log log = LogFactory.getLog(EntityReferenceImpl.class);
public EntityReferenceImpl() {
}
public EntityReferenceImpl(NodeImpl parent, byte[] data, int pos, int len) {
super(parent, data, pos, len);
}
public EntityReferenceImpl(NodeImpl parent, boolean dirty) {
super(parent, dirty);
}
public EntityReferenceImpl(NodeImpl parent, String nodeName) {
super(parent, true);
this.nodeName = nodeName;
}
protected void checkLoaded() {
if (loaded) {
return;
}
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.ENT_DEFINED:
nodeName = st.getName(xci.readShort());
break;
case Signatures.ENT_AMP:
nodeName = "&";
break;
case Signatures.ENT_LT:
nodeName = "<";
break;
case Signatures.ENT_GT:
nodeName = ">";
break;
case Signatures.ENT_QUOT:
nodeName = """;
break;
case Signatures.ENT_APOS:
nodeName = "'";
break;
case Signatures.ENT_UNICODE:
// TODO: Convert symbol to &#...;
nodeName = "";
break;
default:
if (log.isWarnEnabled()) {
log.warn("invalid entity type : " + entityType);
}
}
}
} catch (IOException e) {
if (log.isWarnEnabled()) {
log.warn("ignored exception", e);
}
}
}
public short getNodeType() {
return Node.ENTITY_REFERENCE_NODE;
}
}