use of nu.xom.Document in project apn-proxy by apn-proxy.
the class ApnProxyAbstractXmlConfigReader method read.
public final void read(InputStream xmlConfigFileInputStream) {
Document doc = null;
try {
Builder parser = new Builder();
doc = parser.build(xmlConfigFileInputStream);
} catch (ParsingException ex) {
logger.error(ex.getMessage(), ex);
} catch (IOException ex) {
logger.error(ex.getMessage(), ex);
}
if (doc == null) {
return;
}
Element rootElement = doc.getRootElement();
realReadProcess(rootElement);
}
use of nu.xom.Document in project tetrad by cmu-phil.
the class LoadBayesImXsdlXmlAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (bayesImWrapper == null) {
throw new RuntimeException("Not a Bayes IM.");
}
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
Preferences.userRoot().put("fileSaveLocation", file.getParent());
}
try {
Builder builder = new Builder();
Document document = builder.build(file);
printDocument(document);
XdslXmlParser parser = new XdslXmlParser();
BayesIm bayesIm = parser.getBayesIm(document.getRootElement());
System.out.println(bayesIm);
boolean allSpecified = true;
for (edu.cmu.tetrad.graph.Node node : bayesIm.getBayesPm().getDag().getNodes()) {
if (node.getCenterX() == -1 || node.getCenterY() == -1) {
allSpecified = false;
}
}
if (!allSpecified) {
GraphUtils.circleLayout(bayesIm.getBayesPm().getDag(), 200, 200, 150);
}
bayesImWrapper.setBayesIm(bayesIm);
bayesImEditor.getBayesIm(bayesIm);
} catch (ParsingException e2) {
e2.printStackTrace();
throw new RuntimeException("Had trouble parsing that...");
} catch (IOException e2) {
e2.printStackTrace();
throw new RuntimeException("Had trouble reading the file...");
}
}
use of nu.xom.Document in project tetrad by cmu-phil.
the class LoadBayesImXmlAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (bayesImWrapper == null) {
throw new RuntimeException("Not a Bayes IM.");
}
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
Preferences.userRoot().put("fileSaveLocation", file.getParent());
}
try {
Builder builder = new Builder();
Document document = builder.build(file);
printDocument(document);
BayesXmlParser parser = new BayesXmlParser();
BayesIm bayesIm = parser.getBayesIm(document.getRootElement());
System.out.println(bayesIm);
boolean allSpecified = true;
for (edu.cmu.tetrad.graph.Node node : bayesIm.getBayesPm().getDag().getNodes()) {
if (node.getCenterX() == -1 || node.getCenterY() == -1) {
allSpecified = false;
}
}
if (!allSpecified) {
GraphUtils.circleLayout(bayesIm.getBayesPm().getDag(), 200, 200, 150);
}
bayesImWrapper.setBayesIm(bayesIm);
bayesImEditor.getBayesIm(bayesIm);
} catch (ParsingException e2) {
e2.printStackTrace();
throw new RuntimeException("Had trouble parsing that...");
} catch (IOException e2) {
e2.printStackTrace();
throw new RuntimeException("Had trouble reading the file...");
}
}
use of nu.xom.Document in project tetrad by cmu-phil.
the class GraphUtils method getRootElement.
public static Element getRootElement(File file) throws ParsingException, IOException {
Builder builder = new Builder();
Document document = builder.build(file);
return document.getRootElement();
}
use of nu.xom.Document in project teiid by teiid.
the class BinaryXMLCodec method readDocument.
/**
* Parses document from encoded src buffer; tokens appear in document order.
*/
private Document readDocument(ArrayByteList src, InputStream input) throws BinaryParsingException, IOException {
if (DEBUG)
System.err.println("reading document");
readPage(src, input);
Document doc = factory.startMakingDocument();
// doc.setBaseURI(symbols[src.getInt()]);
doc.setBaseURI(getInternedName(src.getInt()));
boolean hasRootElement = false;
int i = 0;
// add children of document, retaining the exact same order found in input
while (src.remaining() > 0) {
Nodes nodes;
// look ahead
int type = src.get();
if (DEBUG)
System.err.println("reading type = " + toString(type));
switch(// three low bits indicate node type
type & 0x07) {
case TEXT:
{
throw new BinaryParsingException("Unreachable text");
}
case ATTRIBUTE:
{
throw new BinaryParsingException("Unreachable attribute");
}
case BEGIN_ELEMENT:
{
if (factory.getClass() == NodeFactory.class) {
// fast path
Element root = readStartTag(src, type);
// reads entire subtree
readElement(src, root, input);
nodes = new Nodes(root);
} else {
// slow path
Element root = readStartTagF(src, type, true);
if (root == null) {
throw new NullPointerException("Factory failed to create root element.");
}
doc.setRootElement(root);
readElementF(src, root, input);
nodes = factory.finishMakingElement(root);
}
break;
}
case END_ELEMENT:
{
throw new BinaryParsingException("Unreachable end of element");
}
case COMMENT:
{
nodes = readCommentF(src, type);
break;
}
case NAMESPACE_DECLARATION:
{
throw new BinaryParsingException("Unreachable namespace declaration");
}
case PROCESSING_INSTRUCTION:
{
nodes = readProcessingInstructionF(src);
break;
}
case DOC_TYPE:
{
nodes = readDocTypeF(src);
break;
}
default:
{
throw new BinaryParsingException("Illegal node type code=" + type);
}
}
// append nodes:
for (int j = 0; j < nodes.size(); j++) {
Node node = nodes.get(j);
if (node instanceof Element) {
// replace fake root with real root
if (hasRootElement) {
throw new IllegalAddException("Factory returned multiple root elements");
}
doc.setRootElement((Element) node);
hasRootElement = true;
} else {
doc.insertChild(node, i);
}
i++;
}
}
if (!hasRootElement)
throw new WellformednessException("Factory attempted to remove the root element");
factory.finishMakingDocument(doc);
if (DEBUG)
System.err.println("finished reading document");
return doc;
}
Aggregations