use of nu.xom.Attribute in project android-selector-chapek by inmite.
the class SelectorGenerator method addState.
private static void addState(Element item, String state, boolean value) {
Attribute attribute = new Attribute(state, String.valueOf(value));
attribute.setNamespace(NS, SCHEMA);
item.addAttribute(attribute);
}
use of nu.xom.Attribute 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.Attribute 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