Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/events/EntityDeclarationImpl.java
86414 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.xml.internal.stream.events;2627import javax.xml.stream.events.EntityDeclaration;28import javax.xml.stream.events.XMLEvent;29import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;3031/**32*33* This class store all the information for a particular EntityDeclaration. EntityDeclaration interface34* has various get* functiosn to retirve information about a particular EntityDeclaration.35*36* @author Neeraj Bajaj, Sun Microsystems.37*/38public class EntityDeclarationImpl extends DummyEvent implements EntityDeclaration {3940private XMLResourceIdentifier fXMLResourceIdentifier ;41private String fEntityName;42private String fReplacementText;43private String fNotationName;4445/** Creates a new instance of EntityDeclarationImpl */46public EntityDeclarationImpl() {47init();48}4950public EntityDeclarationImpl(String entityName , String replacementText){51this(entityName,replacementText,null);5253}5455public EntityDeclarationImpl(String entityName, String replacementText, XMLResourceIdentifier resourceIdentifier){56init();57fEntityName = entityName;58fReplacementText = replacementText;59fXMLResourceIdentifier = resourceIdentifier;60}6162public void setEntityName(String entityName){63fEntityName = entityName;64}6566public String getEntityName(){67return fEntityName;68}6970public void setEntityReplacementText(String replacementText){71fReplacementText = replacementText;72}7374public void setXMLResourceIdentifier(XMLResourceIdentifier resourceIdentifier){75fXMLResourceIdentifier = resourceIdentifier ;76}7778public XMLResourceIdentifier getXMLResourceIdentifier(){79return fXMLResourceIdentifier;80}8182public String getSystemId(){83if(fXMLResourceIdentifier != null)84return fXMLResourceIdentifier.getLiteralSystemId();85return null;86}8788public String getPublicId(){89if(fXMLResourceIdentifier != null)90return fXMLResourceIdentifier.getPublicId();9192return null;93}9495public String getBaseURI() {96if(fXMLResourceIdentifier != null)97return fXMLResourceIdentifier.getBaseSystemId();98return null;99}100101public String getName(){102return fEntityName;103}104105public String getNotationName() {106return fNotationName;107}108109public void setNotationName(String notationName){110fNotationName = notationName;111}112113public String getReplacementText() {114return fReplacementText;115}116117protected void init(){118setEventType(XMLEvent.ENTITY_DECLARATION);119}120121protected void writeAsEncodedUnicodeEx(java.io.Writer writer)122throws java.io.IOException123{124writer.write("<!ENTITY ");125writer.write(fEntityName);126if (fReplacementText != null) {127//internal entity128//escape quotes, lt and amps129writer.write(" \"");130charEncode(writer, fReplacementText);131} else {132//external entity133String pubId = getPublicId();134if (pubId != null) {135writer.write(" PUBLIC \"");136writer.write(pubId);137} else {138writer.write(" SYSTEM \"");139writer.write(getSystemId());140}141}142writer.write("\"");143if (fNotationName != null) {144writer.write(" NDATA ");145writer.write(fNotationName);146}147writer.write(">");148}149}150151152