use of javax.xml.stream.XMLReporter in project aalto-xml by FasterXML.
the class CharSourceBootstrapper method verifyXmlEncoding.
/*
////////////////////////////////////////////////////
// Internal methods, main xml decl processing
////////////////////////////////////////////////////
*/
/**
* @return Normalized encoding name
*/
protected String verifyXmlEncoding(String enc) throws XMLStreamException {
enc = CharsetNames.normalize(enc);
// Probably no point in comparing at all... is there?
// But we can report a possible problem?
String extEnc = _config.getExternalEncoding();
if (extEnc != null && enc != null && !extEnc.equalsIgnoreCase(enc)) {
XMLReporter rep = _config.getXMLReporter();
if (rep != null) {
Location loc = getLocation();
rep.report(MessageFormat.format(ErrorConsts.W_MIXED_ENCODINGS, new Object[] { extEnc, enc }), ErrorConsts.WT_XML_DECL, this, loc);
}
}
return enc;
}
use of javax.xml.stream.XMLReporter in project gephi by gephi.
the class ImportUtils method getXMLReader.
public static XMLStreamReader getXMLReader(Reader reader) {
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 {
throw new RuntimeException("Error:" + errorType + ", message : " + message);
// System.out.println("Error:" + errorType + ", message : " + message);
}
});
return inputFactory.createXMLStreamReader(reader);
} catch (XMLStreamException ex) {
throw new RuntimeException(NbBundle.getMessage(ImportUtils.class, "ImportUtils.error_io"));
}
}
use of javax.xml.stream.XMLReporter in project gephi by gephi.
the class LoadTask method readProject.
private ProjectImpl readProject(ZipFile zipFile) throws Exception {
ZipEntry entry = zipFile.getEntry("Project_xml");
if (entry == null) {
// Try legacy
entry = zipFile.getEntry("Project");
}
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);
ProjectControllerImpl projectController = Lookup.getDefault().lookup(ProjectControllerImpl.class);
ProjectsImpl projects = projectController.getProjects();
ProjectImpl project = GephiReader.readProject(reader, projects);
project.getLookup().lookup(ProjectInformationImpl.class).setFile(file);
return project;
} finally {
if (reader != null) {
reader.close();
}
if (filterReader != null) {
filterReader.close();
}
}
} finally {
if (is != null) {
is.close();
}
}
}
return null;
}
use of javax.xml.stream.XMLReporter in project gephi by gephi.
the class LoadTask method readWorkspaceChildrenXML.
private void readWorkspaceChildrenXML(WorkspaceXMLPersistenceProvider persistenceProvider, Workspace workspace, ZipFile zipFile) throws Exception {
String identifier = persistenceProvider.getIdentifier();
ZipEntry entry = zipFile.getEntry("Workspace_" + workspace.getId() + "_" + identifier + "_xml");
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);
persistenceProvider.readXML(reader, workspace);
} finally {
if (reader != null) {
reader.close();
}
if (filterReader != null) {
filterReader.close();
}
if (isReader != null) {
isReader.close();
}
}
} finally {
if (is != null) {
is.close();
}
}
}
}
use of javax.xml.stream.XMLReporter 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;
}
Aggregations