Hi guys,
I am using the artifact.js module provided by jaggery core to insert JSON
based javascript objects to the registry. Internally it converts them to
xml before using the GenericArtifactManager to insert them to Greg.
We are passing all the attributes to a method that converts them to xml -
Below is the array -
var screenshot1 = files['screenshot1File'];
screenshot1 = saveFile(screenshot1);
var screenshot2 = files['screenshot2File'];
screenshot2 = saveFile(screenshot2);
var screenshot3 = files['screenshot3File'];
screenshot3 = saveFile(screenshot3);
var screenshots = [screenshot1, screenshot2, screenshot3];
Link <https://gist.github.com/dulichan/6171023#file-gistfile2-js>
Below is the method that creates the artifact (from json to xml in
artifact.js)
var createArtifact = function (manager, options) {
var name, attribute, i, length, lc,
artifact = manager.newGovernanceArtifact(new QName(options.name)),
attributes = options.attributes;
for (name in attributes) {
if (attributes.hasOwnProperty(name)) {
attribute = attributes[name];
if (attribute instanceof Array) {
/*length = attribute.length;
for (i = 0; i < length; i++) {
artifact.addAttribute(name, attribute[i]);
}*/
artifact.setAttributes(name, attribute);
} else {
artifact.setAttribute(name, attribute);
}
}
}
if (options.id) {
artifact.id = options.id;
}
if (options.content) {
if (options.content instanceof Stream) {
artifact.setContent(IOUtils.toByteArray(options.content.getStream()));
} else {
artifact.setContent(new
java.lang.String(options.content).getBytes());
}
}
lc = options.lifecycles;
if (lc) {
length = lc.length;
for (i = 0; i < length; i++) {
artifact.attachLifecycle(lc[i]);
}
}
return artifact;
};
Link <https://gist.github.com/dulichan/6171023#file-gistfile1-js>
The culprit method here is the setAttributes - it saves the xml as
<screenshots>one</screenshots>
<screenshots>two</screenshots>
<screenshots>three</screenshots>
Link <https://gist.github.com/dulichan/6171023#file-gistfile3-xml>
Temporarily I concatenated the array with commas -
var screenshots = screenshot1+","+screenshot2+","+screenshot3;
And convert them to an array with a utility method from my side. This
should ideally be handled in the artifact.js module. WTDY?
Thanks.
--
Chan (Dulitha Wijewantha)
Software Engineer - Mobile Development
WSO2Mobile
Lean.Enterprise.Mobileware
* ~Email [email protected] <[email protected]>*
* ~Mobile +94712112165*
* ~Website dulithawijewantha.com
*
* ~Blog blog.dulithawijewantha.com<http://dulichan.github.io/chan/>
*
* ~Twitter @dulitharw <https://twitter.com/dulitharw>*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev