use of javax.xml.stream.Location in project cxf by apache.
the class StaxUtils method addLocation.
private static boolean addLocation(Document doc, Node node, Location loc, boolean recordLoc) {
if (recordLoc && loc != null && (loc.getColumnNumber() != 0 || loc.getLineNumber() != 0)) {
try {
final int charOffset = loc.getCharacterOffset();
final int colNum = loc.getColumnNumber();
final int linNum = loc.getLineNumber();
final String pubId = loc.getPublicId() == null ? doc.getDocumentURI() : loc.getPublicId();
final String sysId = loc.getSystemId() == null ? doc.getDocumentURI() : loc.getSystemId();
Location loc2 = new Location() {
public int getCharacterOffset() {
return charOffset;
}
public int getColumnNumber() {
return colNum;
}
public int getLineNumber() {
return linNum;
}
public String getPublicId() {
return pubId;
}
public String getSystemId() {
return sysId;
}
};
node.setUserData("location", loc2, LocationUserDataHandler.INSTANCE);
} catch (Throwable ex) {
// possibly not DOM level 3, won't be able to record this then
return false;
}
}
return recordLoc;
}
use of javax.xml.stream.Location in project gephi by gephi.
the class LoadTask method readWorkspace.
private WorkspaceImpl readWorkspace(ProjectImpl project, String entryName, ZipFile zipFile) throws Exception {
ZipEntry entry = zipFile.getEntry(entryName);
if (entry != null) {
InputStream is = null;
try {
is = zipFile.getInputStream(entry);
InputStreamReader isReader = null;
Xml10FilterReader filterReader = null;
XMLStreamReader reader = null;
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
}
inputFactory.setXMLReporter(new XMLReporter() {
@Override
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
}
});
isReader = new InputStreamReader(is, "UTF-8");
filterReader = new Xml10FilterReader(isReader);
reader = inputFactory.createXMLStreamReader(filterReader);
return GephiReader.readWorkspace(reader, project);
} finally {
if (reader != null) {
reader.close();
}
if (filterReader != null) {
filterReader.close();
}
if (isReader != null) {
isReader.close();
}
}
} finally {
if (is != null) {
is.close();
}
}
}
return null;
}
use of javax.xml.stream.Location in project gephi by gephi.
the class ImporterGraphML method execute.
@Override
public boolean execute(ContainerLoader container) {
this.container = container;
this.report = new Report();
Progress.start(progress);
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
}
inputFactory.setXMLReporter(new XMLReporter() {
@Override
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
}
});
xmlReader = inputFactory.createXMLStreamReader(reader);
while (xmlReader.hasNext()) {
Integer eventType = xmlReader.next();
if (eventType.equals(XMLEvent.START_ELEMENT)) {
String name = xmlReader.getLocalName();
if (GRAPHML.equalsIgnoreCase(name)) {
} else if (GRAPH.equalsIgnoreCase(name)) {
readGraph(xmlReader);
} else if (NODE.equalsIgnoreCase(name)) {
readNode(xmlReader, null);
} else if (EDGE.equalsIgnoreCase(name)) {
readEdge(xmlReader);
} else if (ATTRIBUTE.equalsIgnoreCase(name)) {
readAttribute(xmlReader);
}
} else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
String name = xmlReader.getLocalName();
if (NODE.equalsIgnoreCase(name)) {
}
}
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
} finally {
try {
xmlReader.close();
} catch (XMLStreamException e) {
}
}
Progress.finish(progress);
return !cancel;
}
use of javax.xml.stream.Location in project camel by apache.
the class StaxStreamXMLReader method handleDtd.
private void handleDtd() throws SAXException {
if (getLexicalHandler() != null) {
javax.xml.stream.Location location = reader.getLocation();
getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
}
if (getLexicalHandler() != null) {
getLexicalHandler().endDTD();
}
}
use of javax.xml.stream.Location in project camel by apache.
the class StaxStreamXMLReader method handleStartDocument.
private void handleStartDocument() throws SAXException {
if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) {
String xmlVersion = reader.getVersion();
if (ObjectHelper.isNotEmpty(xmlVersion)) {
this.xmlVersion = xmlVersion;
}
this.encoding = reader.getCharacterEncodingScheme();
}
if (getContentHandler() != null) {
final Location location = reader.getLocation();
getContentHandler().setDocumentLocator(new Locator2() {
public int getColumnNumber() {
return location != null ? location.getColumnNumber() : -1;
}
public int getLineNumber() {
return location != null ? location.getLineNumber() : -1;
}
public String getPublicId() {
return location != null ? location.getPublicId() : null;
}
public String getSystemId() {
return location != null ? location.getSystemId() : null;
}
public String getXMLVersion() {
return xmlVersion;
}
public String getEncoding() {
return encoding;
}
});
getContentHandler().startDocument();
if (reader.standaloneSet()) {
setStandalone(reader.isStandalone());
}
}
}
Aggregations