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);
}
}
Aggregations