|
|
|
|
|
*/ |
|
/* |
|
* 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. |
|
*/ |
|
|
|
|
|
package com.sun.xml.internal.stream; |
|
|
|
import java.io.InputStream; |
|
import java.io.Reader; |
|
import java.io.IOException; |
|
|
|
import com.sun.xml.internal.stream.util.BufferAllocator; |
|
import com.sun.xml.internal.stream.util.ThreadLocalBufferAllocator; |
|
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public abstract class Entity { |
|
|
|
// |
|
// Data |
|
// |
|
|
|
//xxx why dont we declare the type of entities, like assign integer for external/ internal etc.. |
|
|
|
|
|
public String name; |
|
|
|
// whether this entity's declaration was found in the internal |
|
|
|
public boolean inExternalSubset; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
public Entity() { |
|
clear(); |
|
} // <init>() |
|
|
|
|
|
public Entity(String name, boolean inExternalSubset) { |
|
this.name = name; |
|
this.inExternalSubset = inExternalSubset; |
|
} // <init>(String) |
|
|
|
// |
|
// Public methods |
|
// |
|
|
|
|
|
public boolean isEntityDeclInExternalSubset() { |
|
return inExternalSubset; |
|
} |
|
|
|
|
|
public abstract boolean isExternal(); |
|
|
|
|
|
public abstract boolean isUnparsed(); |
|
|
|
|
|
public void clear() { |
|
name = null; |
|
inExternalSubset = false; |
|
} // clear() |
|
|
|
|
|
public void setValues(Entity entity) { |
|
name = entity.name; |
|
inExternalSubset = entity.inExternalSubset; |
|
} // setValues(Entity) |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static class InternalEntity |
|
extends Entity { |
|
|
|
// |
|
// Data |
|
// |
|
|
|
|
|
public String text; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
public InternalEntity() { |
|
clear(); |
|
} // <init>() |
|
|
|
|
|
public InternalEntity(String name, String text, boolean inExternalSubset) { |
|
super(name,inExternalSubset); |
|
this.text = text; |
|
} // <init>(String,String) |
|
|
|
// |
|
// Entity methods |
|
// |
|
|
|
|
|
public final boolean isExternal() { |
|
return false; |
|
} // isExternal():boolean |
|
|
|
|
|
public final boolean isUnparsed() { |
|
return false; |
|
} // isUnparsed():boolean |
|
|
|
|
|
public void clear() { |
|
super.clear(); |
|
text = null; |
|
} // clear() |
|
|
|
|
|
public void setValues(Entity entity) { |
|
super.setValues(entity); |
|
text = null; |
|
} // setValues(Entity) |
|
|
|
|
|
public void setValues(InternalEntity entity) { |
|
super.setValues(entity); |
|
text = entity.text; |
|
} // setValues(InternalEntity) |
|
|
|
} // class InternalEntity |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static class ExternalEntity |
|
extends Entity { |
|
|
|
// |
|
// Data |
|
// |
|
|
|
|
|
public XMLResourceIdentifier entityLocation; |
|
|
|
|
|
public String notation; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
public ExternalEntity() { |
|
clear(); |
|
} // <init>() |
|
|
|
|
|
public ExternalEntity(String name, XMLResourceIdentifier entityLocation, |
|
String notation, boolean inExternalSubset) { |
|
super(name,inExternalSubset); |
|
this.entityLocation = entityLocation; |
|
this.notation = notation; |
|
} // <init>(String,XMLResourceIdentifier, String) |
|
|
|
// |
|
// Entity methods |
|
// |
|
|
|
|
|
public final boolean isExternal() { |
|
return true; |
|
} // isExternal():boolean |
|
|
|
|
|
public final boolean isUnparsed() { |
|
return notation != null; |
|
} // isUnparsed():boolean |
|
|
|
|
|
public void clear() { |
|
super.clear(); |
|
entityLocation = null; |
|
notation = null; |
|
} // clear() |
|
|
|
|
|
public void setValues(Entity entity) { |
|
super.setValues(entity); |
|
entityLocation = null; |
|
notation = null; |
|
} // setValues(Entity) |
|
|
|
|
|
public void setValues(ExternalEntity entity) { |
|
super.setValues(entity); |
|
entityLocation = entity.entityLocation; |
|
notation = entity.notation; |
|
} // setValues(ExternalEntity) |
|
|
|
} // class ExternalEntity |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static class ScannedEntity |
|
extends Entity { |
|
|
|
|
|
|
|
public static final int DEFAULT_BUFFER_SIZE = 8192; |
|
//4096; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int fBufferSize = DEFAULT_BUFFER_SIZE; |
|
|
|
|
|
public static final int DEFAULT_XMLDECL_BUFFER_SIZE = 28; |
|
|
|
|
|
public static final int DEFAULT_INTERNAL_BUFFER_SIZE = 1024; |
|
|
|
// |
|
// Data |
|
// |
|
|
|
// i/o |
|
|
|
|
|
* Input stream. */ |
|
public InputStream stream; |
|
|
|
|
|
* Reader. */ |
|
public Reader reader; |
|
|
|
// locator information |
|
|
|
|
|
public XMLResourceIdentifier entityLocation; |
|
|
|
// encoding |
|
|
|
|
|
public String encoding; |
|
|
|
// status |
|
|
|
|
|
public boolean literal; |
|
|
|
|
|
public boolean isExternal; |
|
|
|
|
|
public String version ; |
|
|
|
// buffer |
|
|
|
|
|
public char[] ch = null; |
|
|
|
|
|
public int position; |
|
|
|
|
|
public int count; |
|
|
|
|
|
public int lineNumber = 1; |
|
|
|
|
|
public int columnNumber = 1; |
|
|
|
|
|
boolean declaredEncoding = false; |
|
|
|
// status |
|
|
|
|
|
|
|
|
|
*/ |
|
boolean externallySpecifiedEncoding = false; |
|
|
|
|
|
public String xmlVersion = "1.0"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int fTotalCountTillLastLoad ; |
|
|
|
|
|
|
|
*/ |
|
public int fLastCount ; |
|
|
|
|
|
public int baseCharOffset; |
|
|
|
|
|
public int startPosition; |
|
|
|
|
|
public boolean mayReadChunks; |
|
|
|
|
|
public boolean xmlDeclChunkRead = false; |
|
|
|
|
|
public boolean isGE = false; |
|
|
|
|
|
|
|
*/ |
|
public String getEncodingName(){ |
|
return encoding ; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String getEntityVersion(){ |
|
return version ; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void setEntityVersion(String version){ |
|
this.version = version ; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Reader getEntityReader(){ |
|
return reader; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public InputStream getEntityInputStream(){ |
|
return stream; |
|
} |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
public ScannedEntity(boolean isGE, String name, |
|
XMLResourceIdentifier entityLocation, |
|
InputStream stream, Reader reader, |
|
String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) { |
|
this.isGE = isGE; |
|
this.name = name ; |
|
this.entityLocation = entityLocation; |
|
this.stream = stream; |
|
this.reader = reader; |
|
this.encoding = encoding; |
|
this.literal = literal; |
|
this.mayReadChunks = mayReadChunks; |
|
this.isExternal = isExternal; |
|
final int size = isExternal ? fBufferSize : DEFAULT_INTERNAL_BUFFER_SIZE; |
|
BufferAllocator ba = ThreadLocalBufferAllocator.getBufferAllocator(); |
|
ch = ba.getCharBuffer(size); |
|
if (ch == null) { |
|
this.ch = new char[size]; |
|
} |
|
} // <init>(StringXMLResourceIdentifier,InputStream,Reader,String,boolean, boolean) |
|
|
|
|
|
|
|
*/ |
|
public void close() throws IOException { |
|
BufferAllocator ba = ThreadLocalBufferAllocator.getBufferAllocator(); |
|
ba.returnCharBuffer(ch); |
|
ch = null; |
|
reader.close(); |
|
} |
|
|
|
// |
|
// Entity methods |
|
// |
|
|
|
|
|
public boolean isEncodingExternallySpecified() { |
|
return externallySpecifiedEncoding; |
|
} |
|
|
|
|
|
public void setEncodingExternallySpecified(boolean value) { |
|
externallySpecifiedEncoding = value; |
|
} |
|
|
|
public boolean isDeclaredEncoding() { |
|
return declaredEncoding; |
|
} |
|
|
|
public void setDeclaredEncoding(boolean value) { |
|
declaredEncoding = value; |
|
} |
|
|
|
|
|
public final boolean isExternal() { |
|
return isExternal; |
|
} // isExternal():boolean |
|
|
|
|
|
public final boolean isUnparsed() { |
|
return false; |
|
} // isUnparsed():boolean |
|
|
|
// |
|
// Object methods |
|
// |
|
|
|
|
|
public String toString() { |
|
|
|
StringBuffer str = new StringBuffer(); |
|
str.append("name=\""+name+'"'); |
|
str.append(",ch="+ new String(ch)); |
|
str.append(",position="+position); |
|
str.append(",count="+count); |
|
return str.toString(); |
|
|
|
} // toString():String |
|
|
|
} // class ScannedEntity |
|
|
|
} // class Entity |