001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml;
030:
031: import org.w3c.dom.EntityReference;
032: import org.w3c.dom.Node;
033:
034: import java.io.IOException;
035:
036: public class QEntityReference extends QNode implements EntityReference {
037: String _name;
038:
039: public QEntityReference(String name) {
040: _name = name;
041: }
042:
043: protected QEntityReference(QDocument owner, String name) {
044: super (owner);
045:
046: _name = name;
047: }
048:
049: public String getNodeName() {
050: return _name;
051: }
052:
053: public String getTagName() {
054: return _name;
055: }
056:
057: public short getNodeType() {
058: return ENTITY_REFERENCE_NODE;
059: }
060:
061: private void lazyEvaluateChild() {
062: if (_owner == null || _owner._dtd == null)
063: return;
064:
065: QEntity entity = _owner._dtd.getEntity(_name);
066: if (entity == null || entity._firstChild == null)
067: return;
068:
069: _firstChild = entity._firstChild;
070: _lastChild = entity._lastChild;
071: }
072:
073: public Node getFirstChild() {
074: if (_firstChild != null)
075: return _firstChild;
076:
077: lazyEvaluateChild();
078:
079: return _firstChild;
080: }
081:
082: public Node getLastChild() {
083: if (_lastChild != null)
084: return _lastChild;
085:
086: lazyEvaluateChild();
087:
088: return _lastChild;
089: }
090:
091: public void print(XmlPrinter os) throws IOException {
092: if (os.finishAttributes())
093: os.print(">");
094:
095: os.print("&");
096: os.print(getNodeName());
097: os.print(";");
098: }
099:
100: public String toString() {
101: return "EntityRef[" + getNodeName() + "]";
102: }
103: }
|