这个java代码有什么问题?我无法在XPage中调用它。
我正在尝试创建一个JSON字符串,以便我可以在我的Javascript变量中引用它进行客户端排序。
/**
*
*/
package com.company.apse.AccReq;
/**
* @author Arun
*
*/
import java.io.*;
import lotus.domino.*;
import com.ibm.domino.services.util.JsonWriter;
import com.ibm.xsp.extlib.util.ExtLibUtil;
public class AccReqJson {
/**
* @param args
*/
public static String mainly(String[] args) {
// TODO Auto-generated method stub
try{
System.out.println("calling mainly");
Database database = ExtLibUtil.getCurrentDatabase();
View view = database.getView("(All_AccessRequests_SingleEntry)");
//get access request document
Document document = view.getFirstDocument();
StringWriter sw = new StringWriter();
JsonWriter g = new JsonWriter(sw,true);
//we need to loop through all the documents
while (document != null){
int j = 0;
//now loop through all the 80 fields for user name/email/access
for (j=1;j<=80;j++){
//System.out.println(document.getItemValueString((String) ("UserName_"+j)));
if (!document.getItemValueString((String) ("UserName_"+j)).equalsIgnoreCase("")){
//now begin writing JSON
g.startArrayItem();
g.startObject();
//finally add unid of document
g.startProperty("UNID");
g.outStringLiteral(document.getUniversalID());
g.endProperty();
//finally add unid of document
g.startProperty("J");
g.outStringLiteral((String)(""+ j));
g.endProperty();
//Get Access Type Type (Existing HCL, New HCL, New Client, Change Access)
g.startProperty("AccessRequestFor");
if (j<=40){
g.outStringLiteral("Existing HCL");
}
else if(j<=50){
g.outStringLiteral("New Client");
}
else if(j<=60){
g.outStringLiteral("New HCL");
}
else{
g.outStringLiteral("Change Access");
}
g.endProperty();
//get APSE Name
g.startProperty("APSE");
g.outStringLiteral(document.getItemValueString("APSEName"));
g.endProperty();
//get User Name
g.startProperty("UserName");
g.outStringLiteral(document.getItemValueString((String) ("UserName_"+j)));
g.endProperty();
//get Email
g.startProperty("UserEmail");
g.outStringLiteral(document.getItemValueString((String) ("Email_"+j)));
g.endProperty();
//get Access Type
String tmpAccess="";
String tmpExtraAccess="";
tmpAccess = document.getItemValueString((String) ("UserAccess_"+j));
if (tmpAccess.indexOf("<br />")!=-1)
{
if (tmpAccess.lastIndexOf("<br />")!= tmpAccess.indexOf("<br />")){
tmpExtraAccess = tmpAccess.substring(tmpAccess.indexOf("<br />")+6, tmpAccess.length()-1);
}
tmpAccess = tmpAccess.substring(0, tmpAccess.indexOf("<br />"));
}
g.startProperty("UserAccess");
g.outStringLiteral(tmpAccess);
g.endProperty();
g.startProperty("UserExtraAccess");
g.outStringLiteral(tmpExtraAccess.replaceAll("<br />",", "));
g.endProperty();
//Raised Date
g.startProperty("AccessRequestDate");
g.outStringLiteral(document.getItemValueDateTimeArray("ACCESSREQUESTEDDATE").firstElement().toString());
g.endProperty();
//Raised By
g.startProperty("AccessRequestor");
g.outStringLiteral(document.getItemValueString("ACCESSREQUESTER"));
g.endProperty();
//Remedy Ticket Number
g.startProperty("RemedyRef");
g.outStringLiteral(document.getItemValueString("MagicRef"));
g.endProperty();
g.endObject();
g.endArrayItem();
}
}
//get next document
document = view.getNextDocument(document);
}
System.out.println(sw.toString());
return sw.toString();
}
catch(Exception ex) {
// tbd: handle exception
System.out.println(ex.getStackTrace().toString());
return "An Error occured. Check with IT team.";
}
}
}
答案 0 :(得分:0)
您是否尝试从对象调用静态函数?你有没有关键字静态尝试过吗? 你可以删除&#34; String [] args&#34; ....