use of org.apache.xerces.xni.parser.XMLInputSource in project gocd by gocd.
the class XmlReader method setInput.
private void setInput(ThreadContext context, InputStream in, IRubyObject url, Options options) {
this.setState(XML_TEXTREADER_MODE_READING);
config = this.createReader(context.getRuntime(), options);
InputSource inputSource = new InputSource();
ParserContext.setUrl(context, inputSource, url);
XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null, in, null);
try {
config.setInputSource(xmlInputSource);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
this.setState(XML_TEXTREADER_MODE_CLOSED);
}
use of org.apache.xerces.xni.parser.XMLInputSource in project nokogiri by sparklemotion.
the class XmlReader method setInput.
private void setInput(ThreadContext context, InputStream in, IRubyObject url, Options options) {
this.setState(XML_TEXTREADER_MODE_READING);
config = this.createReader(context.getRuntime(), options);
InputSource inputSource = new InputSource();
ParserContext.setUrl(context, inputSource, url);
XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null, in, null);
try {
config.setInputSource(xmlInputSource);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
this.setState(XML_TEXTREADER_MODE_CLOSED);
}
use of org.apache.xerces.xni.parser.XMLInputSource in project intellij-community by JetBrains.
the class XmlResourceResolver method resolveEntity.
@Override
@Nullable
public XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException, IOException {
String publicId = xmlResourceIdentifier.getLiteralSystemId() != null ? xmlResourceIdentifier.getLiteralSystemId() : xmlResourceIdentifier.getNamespace();
if (publicId != null) {
try {
String userDir = new File(System.getProperty("user.dir")).toURI().getPath();
String publicIdPath = new URI(publicId).getPath();
if (publicIdPath.startsWith(userDir)) {
publicId = publicIdPath.substring(publicIdPath.indexOf(userDir) + userDir.length());
}
} catch (Exception e) {
}
}
PsiFile psiFile = resolve(xmlResourceIdentifier.getBaseSystemId(), publicId);
if (psiFile == null && xmlResourceIdentifier.getBaseSystemId() != null) {
psiFile = ExternalResourceManager.getInstance().getResourceLocation(xmlResourceIdentifier.getBaseSystemId(), myFile, null);
}
if (psiFile == null && xmlResourceIdentifier.getLiteralSystemId() != null && xmlResourceIdentifier.getNamespace() != null) {
psiFile = resolve(xmlResourceIdentifier.getBaseSystemId(), publicId = xmlResourceIdentifier.getNamespace());
}
if (psiFile == null) {
if (publicId != null && publicId.contains(":/")) {
try {
myErrorReporter.processError(new SAXParseException(XmlErrorMessages.message("xml.validate.external.resource.is.not.registered", publicId), publicId, null, 0, 0), ValidateXmlActionHandler.ProblemType.ERROR);
} catch (SAXException ignore) {
}
final XMLInputSource source = new XMLInputSource(xmlResourceIdentifier);
source.setPublicId(publicId);
source.setCharacterStream(new StringReader(""));
return source;
}
return null;
}
XMLInputSource source = new XMLInputSource(xmlResourceIdentifier);
if (xmlResourceIdentifier.getLiteralSystemId() == null) {
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
final String url = VfsUtilCore.fixIDEAUrl(virtualFile.getUrl());
source.setBaseSystemId(url);
source.setSystemId(url);
}
}
source.setPublicId(publicId);
source.setCharacterStream(new StringReader(psiFile.getText()));
return source;
}
Aggregations