cancel
Showing results for 
Search instead for 
Did you mean: 

javascript array to java

buurd
Champ in-the-making
Champ in-the-making
Hi!

I've got a java class that performs a couple of services that I would like to reach from a webscript (javascript). I have almost reched the goal using simple datatypes, like strings and numbers. But now I need to send an array with noderefs to my javacode and here I'm stuck.

My javascript: (sba is the variable that holds the java object).

var nodeRefArray = new Array();
for(var i = 0; i < argsM.nodeRef.length; i++){
        var documentNode = search.findNode(argsM.nodeRef[i]);
        nodeRefArray.push(documentNode);
        sba.createZipArchive(nodeRefArray)
}

Please inform me about how the signature of the (java) method createZipArchive should be written?

Thanks in advance
Roland
1 REPLY 1

buurd
Champ in-the-making
Champ in-the-making
Got a solution to the problem.


public List<NodeRef> toNodeRefList(org.mozilla.javascript.NativeArray nodeReferences){
      List<NodeRef> nodeList = new ArrayList<NodeRef>();
      Object[] propIds = nodeReferences.getIds();
      if(isArray(propIds)){
         for (int i=0; i<propIds.length; i++)
            {
                Object propId = propIds[i];
                if (propId instanceof Integer)
                {
                    Object value = nodeReferences.get((Integer)propId, nodeReferences);
                    NativeJavaObject njo = (NativeJavaObject) value;
                    Object unwrapped = njo.unwrap();
                    if(unwrapped instanceof ScriptNode){
                       ScriptNode scriptNode = (ScriptNode) njo.unwrap();
                       NodeRef nodeRef = scriptNode.getNodeRef();
                       nodeList.add(nodeRef);
                   
                    }
                }
            }
       return nodeList;
   }

//Roland