Search in sources :

Example 6 with Element

use of nu.xom.Element 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);
    }
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Attribute(nu.xom.Attribute) Element(nu.xom.Element) Permission(java.security.Permission) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(nu.xom.Document)

Aggregations

Element (nu.xom.Element)6 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Document (nu.xom.Document)3 Elements (nu.xom.Elements)3 Attribute (nu.xom.Attribute)2 Builder (nu.xom.Builder)2 ParsingException (nu.xom.ParsingException)2 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1 Annotation (edu.stanford.nlp.pipeline.Annotation)1 Tree (edu.stanford.nlp.trees.Tree)1 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)1 ArrayCoreMap (edu.stanford.nlp.util.ArrayCoreMap)1 CoreMap (edu.stanford.nlp.util.CoreMap)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 Permission (java.security.Permission)1