本文整理匯總了Java中org.w3c.dom.ls.LSInput.getCharacterStream方法的典型用法代碼示例。如果您正苦於以下問題:Java LSInput.getCharacterStream方法的具體用法?Java LSInput.getCharacterStream怎麽用?Java LSInput.getCharacterStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.ls.LSInput
的用法示例。
在下文中一共展示了LSInput.getCharacterStream方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves the given resource and adapts the <code>LSInput</code>
* returned into an <code>InputSource</code>.
*/
public InputSource resolveEntity(String name, String publicId,
String baseURI, String systemId) throws SAXException, IOException {
if (fEntityResolver != null) {
LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
if (lsInput != null) {
final String pubId = lsInput.getPublicId();
final String sysId = lsInput.getSystemId();
final String baseSystemId = lsInput.getBaseURI();
final Reader charStream = lsInput.getCharacterStream();
final InputStream byteStream = lsInput.getByteStream();
final String data = lsInput.getStringData();
final String encoding = lsInput.getEncoding();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId. For consistency
* with the DOM Level 3 Load and Save Recommendation
* use the same lookup order here.
*/
InputSource inputSource = new InputSource();
inputSource.setPublicId(pubId);
inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);
if (charStream != null) {
inputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
inputSource.setByteStream(byteStream);
}
else if (data != null && data.length() != 0) {
inputSource.setCharacterStream(new StringReader(data));
}
inputSource.setEncoding(encoding);
return inputSource;
}
}
return null;
}
示例2: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves the given resource and adapts the <code>LSInput</code>
* returned into an <code>InputSource</code>.
*/
public InputSource resolveEntity(String name, String publicId,
String baseURI, String systemId) throws SAXException, IOException {
if (fEntityResolver != null) {
LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
if (lsInput != null) {
final String pubId = lsInput.getPublicId();
final String sysId = lsInput.getSystemId();
final String baseSystemId = lsInput.getBaseURI();
final Reader charStream = lsInput.getCharacterStream();
final InputStream byteStream = lsInput.getByteStream();
final String data = lsInput.getStringData();
final String encoding = lsInput.getEncoding();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId. For consistency
* with the DOM Level 3 Load and Save Recommendation
* use the same lookup order here.
*/
InputSource inputSource = new InputSource();
inputSource.setPublicId(pubId);
inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId);
if (charStream != null) {
inputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
inputSource.setByteStream(byteStream);
}
else if (data != null && data.length() != 0) {
inputSource.setCharacterStream(new StringReader(data));
}
inputSource.setEncoding(encoding);
return inputSource;
}
}
return null;
}
示例3: dom2xmlInputSource
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
XMLInputSource dom2xmlInputSource(LSInput is) {
// need to wrap the LSInput with an XMLInputSource
XMLInputSource xis = null;
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId. For consistency
* have the same behaviour for XSLoader.
*/
// check whether there is a Reader
// according to DOM, we need to treat such reader as "UTF-16".
if (is.getCharacterStream() != null) {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI(), is.getCharacterStream(),
"UTF-16");
}
// check whether there is an InputStream
else if (is.getByteStream() != null) {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI(), is.getByteStream(),
is.getEncoding());
}
// if there is a string data, use a StringReader
// according to DOM, we need to treat such data as "UTF-16".
else if (is.getStringData() != null && is.getStringData().length() != 0) {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI(), new StringReader(is.getStringData()),
"UTF-16");
}
// otherwise, just use the public/system/base Ids
else {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI());
}
return xis;
}
示例4: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves the given resource and adapts the <code>LSInput</code>
* returned into an <code>InputSource</code>.
*/
public InputSource resolveEntity(String name, String publicId,
String baseURI, String systemId) throws SAXException, IOException {
if (fEntityResolver != null) {
LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
if (lsInput != null) {
final String pubId = lsInput.getPublicId();
final String sysId = lsInput.getSystemId();
final String baseSystemId = lsInput.getBaseURI();
final Reader charStream = lsInput.getCharacterStream();
final InputStream byteStream = lsInput.getByteStream();
final String data = lsInput.getStringData();
final String encoding = lsInput.getEncoding();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId. For consistency
* with the DOM Level 3 Load and Save Recommendation
* use the same lookup order here.
*/
InputSource inputSource = new InputSource();
inputSource.setPublicId(pubId);
inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId);
if (charStream != null) {
inputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
inputSource.setByteStream(byteStream);
}
else if (data != null && data.length() != 0) {
inputSource.setCharacterStream(new StringReader(data));
}
inputSource.setEncoding(encoding);
return inputSource;
}
}
return null;
}
示例5: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier description of the resource to be revsoved
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// resolve entity using DOM entity resolver
if (fEntityResolver != null) {
// For entity resolution the type of the resource would be XML TYPE
// DOM L3 LS spec mention only the XML 1.0 recommendation right now
LSInput inputSource =
resourceIdentifier == null
? fEntityResolver.resolveResource(
null,
null,
null,
null,
null)
: fEntityResolver.resolveResource(
getType(resourceIdentifier),
resourceIdentifier.getNamespace(),
resourceIdentifier.getPublicId(),
resourceIdentifier.getLiteralSystemId(),
resourceIdentifier.getBaseSystemId());
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = inputSource.getBaseURI();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
String data = inputSource.getStringData();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId.
*/
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
if (charStream != null) {
xmlInputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
xmlInputSource.setByteStream((InputStream) byteStream);
}
else if (data != null && data.length() != 0) {
xmlInputSource.setCharacterStream(new StringReader(data));
}
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// unable to resolve entity
return null;
}
示例6: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier description of the resource to be revsoved
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// resolve entity using DOM entity resolver
if (fEntityResolver != null) {
// For entity resolution the type of the resource would be XML TYPE
// DOM L3 LS spec mention only the XML 1.0 recommendation right now
LSInput inputSource =
resourceIdentifier == null
? fEntityResolver.resolveResource(
null,
null,
null,
null,
null)
: fEntityResolver.resolveResource(
getType(resourceIdentifier),
resourceIdentifier.getNamespace(),
resourceIdentifier.getPublicId(),
resourceIdentifier.getLiteralSystemId(),
resourceIdentifier.getBaseSystemId());
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = inputSource.getBaseURI();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
String data = inputSource.getStringData();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId.
*/
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId, true);
if (charStream != null) {
xmlInputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
xmlInputSource.setByteStream((InputStream) byteStream);
}
else if (data != null && data.length() != 0) {
xmlInputSource.setCharacterStream(new StringReader(data));
}
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// unable to resolve entity
return null;
}
示例7: dom2xmlInputSource
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* NON-DOM: convert LSInput to XNIInputSource
*
* @param is
* @return
*/
XMLInputSource dom2xmlInputSource (LSInput is) {
// need to wrap the LSInput with an XMLInputSource
XMLInputSource xis = null;
// check whether there is a Reader
// according to DOM, we need to treat such reader as "UTF-16".
if (is.getCharacterStream () != null) {
xis = new XMLInputSource (is.getPublicId (), is.getSystemId (),
is.getBaseURI (), is.getCharacterStream (),
"UTF-16");
}
// check whether there is an InputStream
else if (is.getByteStream () != null) {
xis = new XMLInputSource (is.getPublicId (), is.getSystemId (),
is.getBaseURI (), is.getByteStream (),
is.getEncoding ());
}
// if there is a string data, use a StringReader
// according to DOM, we need to treat such data as "UTF-16".
else if (is.getStringData () != null && is.getStringData().length() > 0) {
xis = new XMLInputSource (is.getPublicId (), is.getSystemId (),
is.getBaseURI (), new StringReader (is.getStringData ()),
"UTF-16");
}
// otherwise, just use the public/system/base Ids
else if ((is.getSystemId() != null && is.getSystemId().length() > 0) ||
(is.getPublicId() != null && is.getPublicId().length() > 0)) {
xis = new XMLInputSource (is.getPublicId (), is.getSystemId (),
is.getBaseURI ());
}
else {
// all inputs are null
if (fErrorHandler != null) {
DOMErrorImpl error = new DOMErrorImpl();
error.fType = "no-input-specified";
error.fMessage = "no-input-specified";
error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
fErrorHandler.getErrorHandler().handleError(error);
}
throw new LSException(LSException.PARSE_ERR, "no-input-specified");
}
return xis;
}
示例8: createResolver
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
public static Resolver createResolver(final LSResourceResolver resourceResolver) {
return new AbstractResolver() {
public void resolve(Identifier id, Input input) throws IOException, ResolverException {
if (input.isResolved())
return;
String base = id.getBase();
String publicId = null;
String type = null;
if (id instanceof ExternalIdentifier) {
publicId = ((ExternalIdentifier)id).getPublicId();
type = XML_TYPE;
}
else if (id instanceof XMLDocumentIdentifier)
type = ((XMLDocumentIdentifier)id).getNamespaceUri();
if (type == null) {
String mediaType = id.getMediaType();
if (mediaType.indexOf('*') < 0)
type = IANA_MEDIA_TYPE_URI + mediaType;
}
String targetNamespace = null;
if (id instanceof TargetNamespaceIdentifier)
targetNamespace = ((TargetNamespaceIdentifier)id).getTargetNamespace();
LSInput lsInput = resourceResolver.resolveResource(type, targetNamespace, publicId, id.getUriReference(), base);
if (lsInput == null)
return;
input.setEncoding(lsInput.getEncoding());
input.setUri(lsInput.getSystemId());
final Reader characterStream = lsInput.getCharacterStream();
if (characterStream != null) {
input.setCharacterStream(characterStream);
return;
}
final InputStream byteStream = lsInput.getByteStream();
if (byteStream != null) {
input.setByteStream(byteStream);
return;
}
final String stringData = lsInput.getStringData();
if (stringData != null) {
input.setCharacterStream(new StringReader(stringData));
return;
}
// we don't support redirecting to a public ID
}
};
}
示例9: resolveEntity
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
/**
* Resolves an external parsed entity. If the entity cannot be
* resolved, this method should return null.
*
* @param resourceIdentifier description of the resource to be revsoved
* @throws XNIException Thrown on general error.
* @throws IOException Thrown if resolved entity stream cannot be
* opened or some other i/o error occurs.
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
// resolve entity using DOM entity resolver
if (fEntityResolver != null) {
// For entity resolution the type of the resource would be XML TYPE
// DOM L3 LS spec mention only the XML 1.0 recommendation right now
LSInput inputSource =
resourceIdentifier == null
? fEntityResolver.resolveResource(
null,
null,
null,
null,
null)
: fEntityResolver.resolveResource(
getType(resourceIdentifier),
resourceIdentifier.getNamespace(),
resourceIdentifier.getPublicId(),
resourceIdentifier.getLiteralSystemId(),
resourceIdentifier.getBaseSystemId());
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = inputSource.getBaseURI();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
String data = inputSource.getStringData();
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId.
*/
XMLInputSource xmlInputSource =
new XMLInputSource(publicId, systemId, baseSystemId);
if (charStream != null) {
xmlInputSource.setCharacterStream(charStream);
}
else if (byteStream != null) {
xmlInputSource.setByteStream((InputStream) byteStream);
}
else if (data != null && data.length() != 0) {
xmlInputSource.setCharacterStream(new StringReader(data));
}
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
}
// unable to resolve entity
return null;
}