Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Adding new rim:header attribute to the packager parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ejzn committed Nov 5, 2012
1 parent 618b90c commit 550de86
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/config-parser.js
Expand Up @@ -140,11 +140,18 @@ function processBuildID(widgetConfig, session) {
}

function processWidgetData(data, widgetConfig, session, extManager) {
var localFeatures, attribs, featureArray;
var localFeatures, attribs, featureArray, header;

if (data["@"]) {
widgetConfig.version = data["@"].version;
widgetConfig.id = data["@"].id;

if (data["@"]["rim:header"]) {
widgetConfig.customHeaders = {};
header = data["@"]["rim:header"].split(":");
// Just set it for now, in the future we can append them
widgetConfig.customHeaders[header[0]] = header[1];
}
}

//Default values
Expand Down
3 changes: 2 additions & 1 deletion test/config.xml
Expand Up @@ -2,7 +2,8 @@
<widget xmlns=" http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0"
id="My WidgetId">
id="My WidgetId"
rim:header="RIM-Widget:rim/widget">
<name>Demo</name>
<content src="local:///startPage.html"/>
<author rim:copyright="No Copyright"
Expand Down
27 changes: 27 additions & 0 deletions test/unit/lib/config-parser.js
Expand Up @@ -35,6 +35,7 @@ describe("config parser", function () {
configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.content).toEqual("local:///startPage.html");
expect(configObj.id).toEqual("My WidgetId");
expect(configObj.customHeaders).toEqual({ 'RIM-Widget' : 'rim/widget'});
expect(configObj.version).toEqual("1.0.0");
expect(configObj.license).toEqual("My License");
expect(configObj.licenseURL).toEqual("http://www.apache.org/licenses/LICENSE-2.0");
Expand Down Expand Up @@ -1063,5 +1064,31 @@ describe("config parser", function () {
configParser.parse(configPath, session, extManager, {});
}).toThrow(localize.translate("EXCEPTION_BGCOLOR_INVALID", "$UI*@@$"));
});

it("can properly parse the custom RIM-Wiget:rim/wiget element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.customHeaders).toEqual({ 'RIM-Widget' : 'rim/widget'});
});
});

it("can properly parse the custom attributes but ignores improper headers", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"] = {
"xmlns": " http://www.w3.org/ns/widgets",
"xmlns:rim": "http://www.blackberry.com/ns/widgets",
"version": "1.0.0",
"id": "myID"
};

mockParsing(data);

configParser.parse(configPath, session, extManager, function (configObj) {
expect(configObj.id).toEqual("myID");
expect(configObj.customHeaders).toEqual(undefined);
});
});
});
});
5 changes: 3 additions & 2 deletions test/unit/lib/test-data.js
Expand Up @@ -37,7 +37,7 @@ module.exports = {
"author": 'Research In Motion Ltd.',
"description": 'This is a test!',
"image": 'test.png',
"autoOrientation": true
"autoOrientation": true,
},
accessList: [{
uri: "http://google.com",
Expand Down Expand Up @@ -65,7 +65,8 @@ module.exports = {
"xmlns": " http://www.w3.org/ns/widgets",
"xmlns:rim": "http://www.blackberry.com/ns/widgets",
"version": "1.0.0",
"id": "myID"
"id": "myID",
"rim:header" : "RIM-Widget:rim/widget"
},
"name": "Demo",
"content": {
Expand Down

0 comments on commit 550de86

Please sign in to comment.