03-01-2011 05:17 PM - edited 03-02-2011 11:33 AM
I decided to try myself creating an Licence Key extenstion. Java base applications are albe to use dynamic/sign/poll AppWorld licence. I would like to create an extension which alow WebWorks user to get information about that licence code.
LicenceKeyExtension.java
package licenceCode;
import org.w3c.dom.Document;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.script.ScriptEngine;
import net.rim.device.api.web.WidgetConfig;
import net.rim.device.api.web.WidgetExtension;
public final class LicenceKeyExtension implements WidgetExtension {
public String[] getFeatureList() {
String[] result = new String[1];
result[0] = "showapp.licencekey";
return result;
}
public void loadFeature(String feature, String version, Document doc,
ScriptEngine scriptEngine) throws Exception {
if (feature == "showapp.licencekey") {
scriptEngine.addExtension("showapp.licencekey", new LicenceKeyNamespace());
}
}
public void register(WidgetConfig widgetConfig, BrowserField browserField) {
// TODO Auto-generated method stub
}
public void unloadFeatures(Document doc) {
// TODO Auto-generated method stub
}
}
LicenceKeyFunction.java
package licenceCode;
import net.rim.device.api.script.ScriptableFunction;
import net.rim.device.api.system.CodeModuleGroup;
import net.rim.device.api.system.CodeModuleManager;
public class LicenceKeyFunction extends ScriptableFunction {
CodeModuleGroup applicencekeys = net.rim.device.api.system.CodeModuleGroupManager.load("RIM_APP_WORLD_LICENSE_KEY");
}
LicenceKeyNamespace.java
package licenceCode;
import net.rim.device.api.script.Scriptable;
public class LicenceKeyNamespace extends Scriptable {
public static final String FIELD_LICENCEKEYRESULT = "applicencekeys";
private LicenceKeyFunction showlicencekey;
public LicenceKeyNamespace() {
this.showlicencekey = new LicenceKeyFunction();
}
}
library.xml
<?xml version="1.0" encoding="UTF-8"?>
<library>
<extension>
<entryClass>licenceCode.LicenceKeyExtension</entryClass>
</extension>
<features>
<feature id="showapp.licencekey" version="1.0.0" ></feature>
</features>
</library>
This is first time I'm writting something in java so I think that will not work. With your help we can create working extension which I really need
Thank you for your help.
Usage:
I would like to validate if my application is legal and have the licence key. It should look like this:
<script type="text/javascript">
function checklicence()
{
licencealgorithm = (blackberry.app.licencekey*2);
// very simple algorithm
//blackberry.app.licencekey is licence key provided by AppWorld using dynamic/single/pool licence key.
if (licencealgorithm != blackberry.app.licencekey)
{
// Notify user that licence key is not valid
alert("Licence key invalid. Please provide valid licence key);
window.location.href = "licence.html";
}
}
</script>
03-02-2011 09:48 AM
Hi ddluk,
This looks like a good start ![]()
What we are trying to do for API contributions is make sure that we start with what the API signature/interface should look like to start. We can then come to an agreement on where it should be placed, proper naming and interaction model that would suit developers and then fill in the Java code under the sheets.
So let's start off with a couple of things.
1) Get you signed up with a github accound and as a contributor to the project. That way we can make sure that all the ideas and code that you contribute are all part of the project. This is common in pretty much all Open Source projects
2) Have you start by outlining in this thread the use case scenario that you want to accomplish with the API and how you would expect to use it. I'm guessing that this is around AppWorld Licensing correct?
I'll start and provide a link to this thread from our Enhancements Candidates list so that others can know about, and participate in the conversation.
Then we'll work through each of the different steps and help you along the way to build the extension and contribute it back to the project
Sound good?
03-02-2011 10:23 AM
03-02-2011 10:28 AM
Yes, you'll need to sign and send in the IICL. If you work for a company you may also want to make sure that they sign off on a CCLA to make sure you are in the clear with your employer.
I see your updated description. So next lets start off with how you would like to interact with this API in your JavaScript code and where you would expect it to be....
Maybe a part of "blackberry.app"?
Litterally pop up some code samples on how you would expect to call the functions from JavaScript and interact with the API. We can then provide some advice and suggestions from our background knowledge as well.
03-02-2011 11:14 AM
IICL sent. Information about usage included to first post. That will be grat to include it into blackberry.app
03-02-2011 12:10 PM
Looking at Mike Kirkup's post on the topic.. it looks like the following Java code would be best suited to grab the proper code module group
CodeModuleGroup group = null;
CodeModuleGroup[] groupArray = CodeModuleGroupManager.loadAll();
String moduleName = ApplicationDescriptor.currentApplicationDescriptor ().getModuleName();
for( int i = 0; i < groupArray.length; i++ ) {
if( groupArray[i].containsModule( moduleName )) {
group = groupArray[i];
break;
}
}
if ( group != null ) {
String key = group.getProperty( "RIM_APP_WORLD_LICENSE_KEY" );
return key;
}
It also looks like the key is a string, so I'm curious about the intent your line of code in JavaScript that looks like the following:
licencealgorithm = (blackberry.app.licencekey*2);
03-02-2011 05:44 PM
Ok. That algorithm in JavaScript was only an example, very bad example. So right know I know the code how to get that information from java, now I need to undestand how to display that information using JavaScript which will be hard to understand for me because I never write in Java. The second problem is testing, as far as I know I can't test App World licence on simulator. Any ideas?
03-02-2011 09:32 PM
We'll help you through that ![]()
FYI... I'll be offline for the next couple of days. I just didn't want you to think we were leaving you hanging.
We'll be pushing up the API code for all our latest source into a branch in github in the next couple of days. What we'll do is get you to fork that code and walk you through how to add the functionality you're looking for.
I'll update this thread once the code is up. Have you walked through the API extension tutorials at all yet? That will give you a bit more background on how to create a function that will return the result back into JavaScript. It would be good background to investigate while the source code is getting prepared to be pushed up to github.
03-03-2011 04:08 AM
Yes, I already looked into that API extension tutorial. Now I will wait for your source. When I get it I will find similer function in it and I will try to do the same with my.
03-09-2011 10:23 AM
Good news!!
The source code for the v2.0 release is now available in github. You can take a look at the "rtm2.0" branch to see how everything works inside the blackberry.app API.
Feel free to fork the code and add in your licensing parts. Code for the blackberry.app API can be found here:
https://github.com/blackberry/WebWorks/tree/rtm2.0