286N/A/*
286N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
286N/A * This code is free software; you can redistribute it and/or modify it
286N/A * under the terms of the GNU General Public License version 2 only, as
286N/A * published by the Free Software Foundation. Oracle designates this
286N/A * particular file as subject to the "Classpath" exception as provided
286N/A * by Oracle in the LICENSE file that accompanied this code.
286N/A *
286N/A * This code is distributed in the hope that it will be useful, but WITHOUT
286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/A * version 2 for more details (a copy is included in the LICENSE file that
286N/A * accompanied this code).
286N/A *
286N/A * You should have received a copy of the GNU General Public License version
286N/A * 2 along with this work; if not, write to the Free Software Foundation,
286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A *
286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/A * or visit www.oracle.com if you need additional information or have any
286N/A * questions.
286N/A */
286N/A
286N/Apackage com.sun.xml.internal.stream.events;
286N/A
286N/Aimport javax.xml.stream.events.EntityDeclaration;
286N/Aimport javax.xml.stream.events.XMLEvent;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
286N/A
286N/A/**
286N/A *
286N/A * This class store all the information for a particular EntityDeclaration. EntityDeclaration interface
286N/A * has various get* functiosn to retirve information about a particular EntityDeclaration.
286N/A *
286N/A * @author Neeraj Bajaj, Sun Microsystems.
286N/A */
286N/Apublic class EntityDeclarationImpl extends DummyEvent implements EntityDeclaration {
286N/A
286N/A private XMLResourceIdentifier fXMLResourceIdentifier ;
286N/A private String fEntityName;
286N/A private String fReplacementText;
286N/A private String fNotationName;
286N/A
286N/A /** Creates a new instance of EntityDeclarationImpl */
286N/A public EntityDeclarationImpl() {
286N/A init();
286N/A }
286N/A
286N/A public EntityDeclarationImpl(String entityName , String replacementText){
286N/A this(entityName,replacementText,null);
286N/A
286N/A }
286N/A
286N/A public EntityDeclarationImpl(String entityName, String replacementText, XMLResourceIdentifier resourceIdentifier){
286N/A init();
286N/A fEntityName = entityName;
286N/A fReplacementText = replacementText;
286N/A fXMLResourceIdentifier = resourceIdentifier;
286N/A }
286N/A
286N/A public void setEntityName(String entityName){
286N/A fEntityName = entityName;
286N/A }
286N/A
286N/A public String getEntityName(){
286N/A return fEntityName;
286N/A }
286N/A
286N/A public void setEntityReplacementText(String replacementText){
286N/A fReplacementText = replacementText;
286N/A }
286N/A
286N/A public void setXMLResourceIdentifier(XMLResourceIdentifier resourceIdentifier){
286N/A fXMLResourceIdentifier = resourceIdentifier ;
286N/A }
286N/A
286N/A public XMLResourceIdentifier getXMLResourceIdentifier(){
286N/A return fXMLResourceIdentifier;
286N/A }
286N/A
286N/A public String getSystemId(){
286N/A if(fXMLResourceIdentifier != null)
286N/A return fXMLResourceIdentifier.getLiteralSystemId();
286N/A return null;
286N/A }
286N/A
286N/A public String getPublicId(){
286N/A if(fXMLResourceIdentifier != null)
286N/A return fXMLResourceIdentifier.getPublicId();
286N/A
286N/A return null;
286N/A }
286N/A
286N/A public String getBaseURI() {
286N/A if(fXMLResourceIdentifier != null)
286N/A return fXMLResourceIdentifier.getBaseSystemId();
286N/A return null;
286N/A }
286N/A
286N/A public String getName(){
286N/A return fEntityName;
286N/A }
286N/A
286N/A public String getNotationName() {
286N/A return fNotationName;
286N/A }
286N/A
286N/A public void setNotationName(String notationName){
286N/A fNotationName = notationName;
286N/A }
286N/A
286N/A public String getReplacementText() {
286N/A return fReplacementText;
286N/A }
286N/A
286N/A protected void init(){
286N/A setEventType(XMLEvent.ENTITY_DECLARATION);
286N/A }
286N/A
286N/A protected void writeAsEncodedUnicodeEx(java.io.Writer writer)
286N/A throws java.io.IOException
286N/A {
286N/A writer.write("<!ENTITY ");
286N/A writer.write(fEntityName);
286N/A if (fReplacementText != null) {
286N/A //internal entity
286N/A //escape quotes, lt and amps
286N/A writer.write(" \"");
286N/A charEncode(writer, fReplacementText);
286N/A } else {
286N/A //external entity
286N/A String pubId = getPublicId();
286N/A if (pubId != null) {
286N/A writer.write(" PUBLIC \"");
286N/A writer.write(pubId);
286N/A } else {
286N/A writer.write(" SYSTEM \"");
286N/A writer.write(getSystemId());
286N/A }
286N/A }
286N/A writer.write("\"");
286N/A if (fNotationName != null) {
286N/A writer.write(" NDATA ");
286N/A writer.write(fNotationName);
286N/A }
286N/A writer.write(">");
286N/A }
286N/A}