use of nu.xom.Document in project CoreNLP by stanfordnlp.
the class CoreNLPServlet method init.
@Override
public void init() throws ServletException {
pipeline = new StanfordCoreNLP();
String xslPath = getServletContext().getRealPath("/WEB-INF/data/CoreNLP-to-HTML.xsl");
try {
Builder builder = new Builder();
Document stylesheet = builder.build(new File(xslPath));
corenlpTransformer = new XSLTransform(stylesheet);
} catch (Exception e) {
throw new ServletException(e);
}
}
use of nu.xom.Document in project android-selector-chapek by inmite.
the class SelectorGenerator method generate.
public static void generate(VirtualFile newFile, List<SelectorDetector.Result> detectorResults) {
Log.d("generating XML:");
Element root = new Element("selector");
root.addNamespaceDeclaration(NS, SCHEMA);
List<String> allStatesWithoutNormal = new ArrayList<String>();
for (SelectorDetector.Result result : detectorResults) {
for (String state : result.states) {
if (!state.equals(Constants.NORMAL) && !allStatesWithoutNormal.contains(state)) {
allStatesWithoutNormal.add(state);
}
}
}
for (SelectorDetector.Result result : detectorResults) {
Log.d("fileName=" + result.drawableName + ", states:" + result.states);
Element item = new Element("item");
Attribute attribute = new Attribute("drawable", "@drawable/" + result.drawableName);
attribute.setNamespace(NS, SCHEMA);
item.addAttribute(attribute);
for (String state : allStatesWithoutNormal) {
boolean defaultValue = Constants.sMapping.get(state).defaultValue;
addState(item, Constants.sMapping.get(state).attributeName, result.states.contains(state) ? (!defaultValue) : defaultValue);
}
Log.d("row=" + item.toXML());
root.appendChild(item);
}
Document doc = new Document(root);
OutputStream os = null;
try {
os = newFile.getOutputStream(null);
Serializer serializer = new Serializer(os);
serializer.setIndent(4);
serializer.write(doc);
} catch (IOException e) {
Log.e(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
Log.e(e);
}
}
}
}
use of nu.xom.Document in project teiid by teiid.
the class BinaryXMLCodec method readElementF.
/**
* Iterative pull parser reading an entire element subtree (using NodeFactory).
*/
private void readElementF(ArrayByteList src, Element current, InputStream input) throws BinaryParsingException, IOException {
// final ArrayList stack = new ArrayList();
final FastStack stack = new FastStack();
stack.push(current);
boolean addAttributesAndNamespaces = true;
while (true) {
Nodes nodes = null;
// look ahead
int type = src.get();
switch(// three low bits indicate node type
type & 0x07) {
case TEXT:
{
nodes = readTextF(src, type);
break;
}
case ATTRIBUTE:
{
Element elem = addAttributesAndNamespaces ? current : null;
nodes = readAttributeF(src, elem, type);
break;
}
case BEGIN_ELEMENT:
{
Element elem = readStartTagF(src, type, false);
// even if it's null
stack.push(elem);
if (elem != null) {
current.insertChild(elem, current.getChildCount());
// recurse down
current = elem;
}
addAttributesAndNamespaces = elem != null;
continue;
}
case END_ELEMENT:
{
Element elem = stack.pop();
if (elem == null) {
// skip element
continue;
}
ParentNode parent = elem.getParent();
if (parent == null)
throwTamperedWithParent();
if (parent instanceof Document) {
// we're done with the root element
return;
}
// recurse up
current = (Element) parent;
nodes = factory.finishMakingElement(elem);
if (nodes.size() == 1 && nodes.get(0) == elem) {
// optimization: no need to remove and then readd same element
continue;
}
if (current.getChildCount() - 1 < 0)
throwTamperedWithParent();
current.removeChild(current.getChildCount() - 1);
break;
}
case COMMENT:
{
nodes = readCommentF(src, type);
break;
}
case NAMESPACE_DECLARATION:
{
Element elem = addAttributesAndNamespaces ? current : null;
readNamespaceDeclaration(src, elem, type);
continue;
}
case PROCESSING_INSTRUCTION:
{
nodes = readProcessingInstructionF(src);
break;
}
case DOC_TYPE:
{
// surrogate hack for BEGIN_PAGE
readPage(src, input);
continue;
}
}
appendNodes(current, nodes);
}
}
use of nu.xom.Document in project wildfly by wildfly.
the class PermissionUtils method createPermissionsXmlAsset.
public static Asset createPermissionsXmlAsset(Permission... permissions) {
final Element permissionsElement = new Element("permissions");
permissionsElement.setNamespaceURI("http://xmlns.jcp.org/xml/ns/javaee");
permissionsElement.addAttribute(new Attribute("version", "7"));
for (Permission permission : permissions) {
final Element permissionElement = new Element("permission");
final Element classNameElement = new Element("class-name");
final Element nameElement = new Element("name");
classNameElement.appendChild(permission.getClass().getName());
nameElement.appendChild(permission.getName());
permissionElement.appendChild(classNameElement);
permissionElement.appendChild(nameElement);
final String actions = permission.getActions();
if (actions != null && !actions.isEmpty()) {
final Element actionsElement = new Element("actions");
actionsElement.appendChild(actions);
permissionElement.appendChild(actionsElement);
}
permissionsElement.appendChild(permissionElement);
}
Document document = new Document(permissionsElement);
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
final NiceSerializer serializer = new NiceSerializer(stream);
serializer.setIndent(4);
serializer.setLineSeparator("\n");
serializer.write(document);
serializer.flush();
return new StringAsset(stream.toString("UTF-8"));
} catch (IOException e) {
throw new IllegalStateException("Generating permissions.xml failed", e);
}
}
use of nu.xom.Document in project tetrad by cmu-phil.
the class SaveBayesImXmlAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
try {
File outfile = EditorUtils.getSaveFile("bayesim", "xml", this.bayesImEditor, false, "Save Bayes IM as XML...");
BayesIm bayesIm = bayesImEditor.getWizard().getBayesIm();
FileOutputStream out = new FileOutputStream(outfile);
Element element = BayesXmlRenderer.getElement(bayesIm);
Document document = new Document(element);
Serializer serializer = new Serializer(out);
serializer.setLineSeparator("\n");
serializer.setIndent(2);
serializer.write(document);
out.close();
} catch (IOException e1) {
throw new RuntimeException(e1);
}
}
Aggregations