use of org.eclipse.kura.core.configuration.XmlSnapshotIdResult in project kura by eclipse.
the class XmlUtilTest method testXmlSnapshotIdResultMarshalling.
@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testXmlSnapshotIdResultMarshalling() {
try {
XmlSnapshotIdResult xmlSnapshotIdResult = getSampleXmlSnapshotIdResultObject();
String marshalledString = org.eclipse.kura.core.configuration.util.XmlUtil.marshal(xmlSnapshotIdResult);
for (Long value : xmlSnapshotIdResult.getSnapshotIds()) {
Assert.assertTrue(String.format(missingItemsMessage, value), marshalledString.contains(Long.toString(value)));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.eclipse.kura.core.configuration.XmlSnapshotIdResult in project kura by eclipse.
the class XmlUtilTest method getSampleXmlSnapshotIdResultObject.
private static XmlSnapshotIdResult getSampleXmlSnapshotIdResultObject() {
List<Long> snapshotIds = new ArrayList<Long>();
snapshotIds.add(102540L);
snapshotIds.add(27848415L);
snapshotIds.add(378485484848L);
XmlSnapshotIdResult xmlSnapshotIdResult = new XmlSnapshotIdResult();
xmlSnapshotIdResult.setSnapshotIds(snapshotIds);
return xmlSnapshotIdResult;
}
use of org.eclipse.kura.core.configuration.XmlSnapshotIdResult in project kura by eclipse.
the class CoreTestXmlUtil method unmarshalXmlSnapshotIdResult.
// unmarshal XmlSnapshotIdResult
@SuppressWarnings("unchecked")
public static <T> T unmarshalXmlSnapshotIdResult(Document doc) throws Exception {
XmlSnapshotIdResult xmlSnapshotIdResult = new XmlSnapshotIdResult();
List<Long> idList = new ArrayList<Long>();
// XML elements
Element snapshotIds = doc.getDocumentElement();
NodeList snapshotIdsChildren = snapshotIds.getChildNodes();
// Collect all bundles
for (int propIndex = 0; propIndex < snapshotIdsChildren.getLength(); propIndex++) {
Node currentNode = snapshotIdsChildren.item(propIndex);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element el = (Element) currentNode;
if (el.getNodeName().equals("esf:snapshotIds")) {
// Add ID to list
idList.add(Long.parseLong(el.getTextContent()));
}
}
}
// Add IDs
xmlSnapshotIdResult.setSnapshotIds(idList);
return (T) xmlSnapshotIdResult;
}
use of org.eclipse.kura.core.configuration.XmlSnapshotIdResult in project kura by eclipse.
the class XmlUtil method marshal.
public static void marshal(Object object, Writer w) throws Exception {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
doc.setXmlStandalone(true);
if (object instanceof XmlSnapshotIdResult) {
// Resulting xml:
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <esf:snapshot-ids xmlns:ocd="http://www.osgi.org/xmlns/metatype/v1.2.0"
// xmlns:esf="http://eurotech.com/esf/2.0">
// <esf:snapshotIds>1434122113492</esf:snapshotIds>
// <esf:snapshotIds>1434122124387</esf:snapshotIds>
// </esf:snapshot-ids>
new XmlJavaSnapshotIdResultMapper().marshal(doc, object);
} else if (object instanceof XmlComponentConfigurations) {
new XmlJavaComponentConfigurationsMapper().marshal(doc, object);
}
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc);
// System.out
StreamResult result = new StreamResult(w);
transformer.transform(source, result);
} catch (ParserConfigurationException pce) {
s_logger.warn("Parser Exception", pce);
} catch (TransformerException tfe) {
s_logger.warn("Transformer Exception", tfe);
}
}
use of org.eclipse.kura.core.configuration.XmlSnapshotIdResult in project kura by eclipse.
the class XmlJavaSnapshotIdResultMapper method marshal.
@Override
public Element marshal(Document doc, Object object) {
Element snapshotIDs = doc.createElement(ESF_NAMESPACE + ":" + SNAPSHOT_IDS);
// TODO:
snapshotIDs.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:esf", "http://eurotech.com/esf/2.0");
// add
// xml
// schema
// to
// EUROTECH
// site
snapshotIDs.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ocd", "http://www.osgi.org/xmlns/metatype/v1.2.0");
doc.appendChild(snapshotIDs);
XmlSnapshotIdResult xmlSnapshotIdResult = (XmlSnapshotIdResult) object;
List<Long> snapshotIdVals = xmlSnapshotIdResult.getSnapshotIds();
if (snapshotIdVals != null) {
for (Long snapId : snapshotIdVals) {
Element snapshotIds = doc.createElement(ESF_NAMESPACE + ":" + SNAPSHOTIDS);
snapshotIds.setTextContent(snapId.toString());
snapshotIDs.appendChild(snapshotIds);
}
}
return snapshotIDs;
}
Aggregations