if(filePath == null)
return;
}
eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(filePath));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
XMLEvent tab2 = eventFactory.createDTD("\t\t");
XMLEvent tab3 = eventFactory.createDTD("\t\t\t");
XMLEvent tab4 = eventFactory.createDTD("\t\t\t\t");
XMLEvent tab5 = eventFactory.createDTD("\t\t\t\t\t");
XMLEvent tab6 = eventFactory.createDTD("\t\t\t\t\t\t");
StartDocument startDocument = eventFactory.createStartDocument();
eventWriter.add(startDocument);
eventWriter.add(end);
// Create config open tag
Namespace ns = eventFactory.createNamespace("n0", "urn:nsit");
Namespace ns2 = eventFactory.createNamespace("urn:nsit");
Set<Namespace> nspaces = new HashSet();
nspaces.add(ns);
nspaces.add(ns2);
StartElement dbse = eventFactory.createStartElement("", "urn:nsit", "policyDB", null, nspaces.iterator());
eventWriter.add(tab);
eventWriter.add(dbse);
eventWriter.add(end);
// Lists
eventWriter.add(tab2);
eventWriter.add(eventFactory.createStartElement("", "", "lists"));
eventWriter.add(end);
for (int i = 0; i < lists.size(); i++) {
ReceiverListModel list = lists.get(i);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "list"));
eventWriter.add(end);
createNode(eventWriter, "id", new Integer(list.getId()).toString(), 4);
createNode(eventWriter, "name", list.getName(), 4);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createStartElement("", "", "receivers"));
eventWriter.add(end);
List<ReceiverModel> receivers = list.getReceivers();
for (int j = 0; j < receivers.size(); j++) {
ReceiverModel receiver = receivers.get(j);
eventWriter.add(tab5);
eventWriter.add(eventFactory.createStartElement("", "", "receiver"));
eventWriter.add(end);
createNode(eventWriter, "id", new Integer(receiver.getId()).toString(), 6);
createNode(eventWriter, "name", receiver.getName(), 6);
eventWriter.add(tab5);
eventWriter.add(eventFactory.createEndElement("", "", "receiver"));
eventWriter.add(end);
}
eventWriter.add(tab4);
eventWriter.add(eventFactory.createEndElement("", "", "receivers"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "list"));
eventWriter.add(end);
}
eventWriter.add(tab2);
eventWriter.add(eventFactory.createEndElement("", "", "lists"));
eventWriter.add(end);
// Apps
eventWriter.add(tab2);
eventWriter.add(eventFactory.createStartElement("", "", "apps"));
eventWriter.add(end);
for (int i = 0; i < apps.size(); i++) {
ApplicationModel app = apps.get(i);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "app"));
eventWriter.add(end);
createNode(eventWriter, "id", new Integer(app.getId()).toString(), 4);
createNode(eventWriter, "name", app.getName(), 4);
createNode(eventWriter, "expectRequestEncrypted", new Integer(PolicyUtilities.boolToInt(app.isExpectRequestEncrypted())).toString(), 4);
createNode(eventWriter, "a-level", new Integer(ApplicationBaseToInt(app.getBaseA())).toString(), 4);
createNode(eventWriter, "c-level", new Integer(ApplicationBaseToInt(app.getBaseC())).toString(), 4);
createNode(eventWriter, "i-level", new Integer(ApplicationBaseToInt(app.getBaseI())).toString(), 4);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createStartElement("", "", "applists"));
eventWriter.add(end);
List<ReceiverListModel> applists = app.getReceiverLists();
for (int j = 0; j < applists.size(); j++) {
createNode(eventWriter, "listID", new Integer(applists.get(j).getId()).toString(), 5);
}
eventWriter.add(tab4);
eventWriter.add(eventFactory.createEndElement("", "", "applists"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "app"));
eventWriter.add(end);
}
eventWriter.add(tab2);
eventWriter.add(eventFactory.createEndElement("", "", "apps"));
eventWriter.add(end);
// Mapping
eventWriter.add(tab2);
eventWriter.add(eventFactory.createStartElement("", "", "level2policyMapping"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "level1"));
eventWriter.add(end);
if((low != null) && (low.getABasePolicy() != null))
createNode(eventWriter, "a", new Integer(low.getABasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "a", "-1", 4);
if((low != null) && (low.getCBasePolicy() != null))
createNode(eventWriter, "c", new Integer(low.getCBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "c", "-1", 4);
if((low != null) && (low.getIBasePolicy() != null))
createNode(eventWriter, "i", new Integer(low.getIBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "i", "-1", 4);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "level1"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "level2"));
eventWriter.add(end);
if((normal != null) && (normal.getABasePolicy() != null))
createNode(eventWriter, "a", new Integer(normal.getABasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "a", "-1", 4);
if((normal != null) && (normal.getCBasePolicy() != null))
createNode(eventWriter, "c", new Integer(normal.getCBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "c", "-1", 4);
if((normal != null) && (normal.getIBasePolicy() != null))
createNode(eventWriter, "i", new Integer(normal.getIBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "i", "-1", 4);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "level2"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "level3"));
eventWriter.add(end);
if((high != null) && (high.getABasePolicy() != null))
createNode(eventWriter, "a", new Integer(high.getABasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "a", "-1", 4);
if((high != null) && (high.getCBasePolicy() != null))
createNode(eventWriter, "c", new Integer(high.getCBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "c", "-1", 4);
if((high != null) && (high.getIBasePolicy() != null))
createNode(eventWriter, "i", new Integer(high.getIBasePolicy().getId()).toString(), 4);
else createNode(eventWriter, "i", "-1", 4);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "level3"));
eventWriter.add(end);
eventWriter.add(tab2);
eventWriter.add(eventFactory.createEndElement("", "", "level2policyMapping"));
eventWriter.add(end);
// Policies
eventWriter.add(tab2);
eventWriter.add(eventFactory.createStartElement("", "", "policies"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "a-policies"));
eventWriter.add(end);
for (int i = 0; i < apolicies.size(); i++) {
PolicyModel policy = apolicies.get(i);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createStartElement("", "", "policy"));
eventWriter.add(end);
createNode(eventWriter, "name", policy.getName(), 5);
createNode(eventWriter, "id", new Integer(policy.getId()).toString(), 5);
if(policy.getFallback() != null)
createNode(eventWriter, "fallback", new Integer(policy.getFallback().getId()).toString(), 5);
else createNode(eventWriter, "fallback", "-1", 5);
if(policy.getAction() != null)
createNode(eventWriter, "action", policy.getAction().getId(), 5);
else
createNode(eventWriter, "action", "-1", 5);
createNode(eventWriter, "useToken", new Integer(PolicyUtilities.boolToInt(policy.isUseToken())).toString(), 5);
createNode(eventWriter, "rank", new Integer(policy.getRank()).toString(), 5);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createEndElement("", "", "policy"));
eventWriter.add(end);
}
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "a-policies"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "c-policies"));
eventWriter.add(end);
for (int i = 0; i < cpolicies.size(); i++) {
PolicyModel policy = cpolicies.get(i);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createStartElement("", "", "policy"));
eventWriter.add(end);
createNode(eventWriter, "name", policy.getName(), 5);
createNode(eventWriter, "id", new Integer(policy.getId()).toString(), 5);
if(policy.getFallback() != null)
createNode(eventWriter, "fallback", new Integer(policy.getFallback().getId()).toString(), 5);
else createNode(eventWriter, "fallback", "-1", 5);
createNode(eventWriter, "action", policy.getAction().getId(), 5);
createNode(eventWriter, "useToken", new Integer(PolicyUtilities.boolToInt(policy.isUseToken())).toString(), 5);
createNode(eventWriter, "rank", new Integer(policy.getRank()).toString(), 5);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createEndElement("", "", "policy"));
eventWriter.add(end);
}
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "c-policies"));
eventWriter.add(end);
eventWriter.add(tab3);
eventWriter.add(eventFactory.createStartElement("", "", "i-policies"));
eventWriter.add(end);
for (int i = 0; i < ipolicies.size(); i++) {
PolicyModel policy = ipolicies.get(i);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createStartElement("", "", "policy"));
eventWriter.add(end);
createNode(eventWriter, "name", policy.getName(), 5);
createNode(eventWriter, "id", new Integer(policy.getId()).toString(), 5);
if(policy.getFallback() != null)
createNode(eventWriter, "fallback", new Integer(policy.getFallback().getId()).toString(), 5);
else createNode(eventWriter, "fallback", "-1", 5);
createNode(eventWriter, "action", policy.getAction().getId(), 5);
createNode(eventWriter, "useToken", new Integer(PolicyUtilities.boolToInt(policy.isUseToken())).toString(), 5);
createNode(eventWriter, "rank", new Integer(policy.getRank()).toString(), 5);
eventWriter.add(tab4);
eventWriter.add(eventFactory.createEndElement("", "", "policy"));
eventWriter.add(end);
}
eventWriter.add(tab3);
eventWriter.add(eventFactory.createEndElement("", "", "i-policies"));
eventWriter.add(end);
eventWriter.add(tab2);
eventWriter.add(eventFactory.createEndElement("", "", "policies"));
eventWriter.add(end);
eventWriter.add(tab);
eventWriter.add(eventFactory.createEndElement("", "", "policyDB"));
eventWriter.add(end);
eventWriter.add(eventFactory.createEndDocument());
eventWriter.close();
unsignedXmlFile = new File(filePath);
unsignedXMLFileInputStream = new FileInputStream(unsignedXmlFile);
input = new byte[(int) unsignedXmlFile.length()];