本文整理汇总了Java中com.ibm.commons.util.io.json.JsonGenerator类的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator类的具体用法?Java JsonGenerator怎么用?Java JsonGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonGenerator类属于com.ibm.commons.util.io.json包,在下文中一共展示了JsonGenerator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: put
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
/**
* Send PUT request with authorization header
* @param url - The url of the POST request
* @param auth - String for authorization header
* @param putData - The body of the PUT
*/
public Response put(String url, String auth, JsonJavaObject putData) throws URISyntaxException, IOException, JsonException {
URI normUri = new URI(url).normalize();
Request putRequest = Request.Put(normUri);
//Add auth header
if(StringUtil.isNotEmpty(auth)) {
putRequest.addHeader("Authorization", auth);
}
//Add put data
String putDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, putData);
if(putData != null) {
putRequest = putRequest.bodyString(putDataString, ContentType.APPLICATION_JSON);
}
Response response = executor.execute(putRequest);
return response;
}
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:25,代码来源:RestUtil.java
示例2: post
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
/**
* Send POST request with authorization header and additional headers
* @param url - The url of the POST request
* @param auth - String for authorization header
* @param headers - Hashmap of headers to add to the request
* @param postData - The body of the POST
* @return the Response to the POST request
*/
public Response post(String url, String auth, HashMap<String, String> headers, JsonJavaObject postData) throws JsonException, IOException, URISyntaxException {
URI normUri = new URI(url).normalize();
Request postRequest = Request.Post(normUri);
//Add all headers
if(StringUtil.isNotEmpty(auth)) {
postRequest.addHeader("Authorization", auth);
}
if(headers != null && headers.size() > 0){
for (Map.Entry<String, String> entry : headers.entrySet()) {
postRequest.addHeader(entry.getKey(), entry.getValue());
}
}
String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
Response response = executor.execute(postRequest.bodyString(postDataString, ContentType.APPLICATION_JSON));
return response;
}
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:27,代码来源:RestUtil.java
示例3: axCreateTab
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
@SuppressWarnings("rawtypes") //$NON-NLS-1$
protected int axCreateTab(FacesContext context, StringBuilder b, Map params) throws IOException {
int errorCode = 200; // OK
// Create the new tab in the JSF tree
UIDojoTabPane pane = createTab();
if(pane!=null) {
JsonJavaObject json = new JsonJavaObject();
String id = pane.getClientId(context);
if(id!=null) {
json.putString("id", id); // $NON-NLS-1$
}
try {
// append {id="view:...:tabPane1"} to b
JsonGenerator.toJson(JsonJavaFactory.instance, b, json, true);
} catch(Exception ex) {}
ExtLibUtil.saveViewState(context);
}
return errorCode;
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:23,代码来源:UIDojoTabContainer.java
示例4: getDojoAttributesAsJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public static String getDojoAttributesAsJson(FacesContext context, UIComponent component, JsonJavaObject json) throws IOException {
try {
return JsonGenerator.toJson(JsonJavaFactory.instance,json,true);
} catch(JsonException ex) {
IOException e = new IOException();
e.initCause(ex);
throw e;
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:10,代码来源:DojoRendererUtil.java
示例5: generateJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
/**
* Generate a JSON object.
*/
protected void generateJson(StringBuilder b, JsonJavaObject o) {
try {
JsonGenerator.toJson(JsonJavaFactory.instance, b, o, true);
} catch(Exception e) {
throw new FacesExceptionEx(e,"Exception while generating JSON attributes"); // $NLX-AbstractDojoClientAction.ExceptionwhilegeneratingJSONattri-1$
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:11,代码来源:AbstractDojoClientAction.java
示例6: createNumberConstraintsAsJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String createNumberConstraintsAsJson() {
try {
JsonJavaObject jo = new JsonJavaObject();
double min = getMin();
if(!Double.isNaN(min)) {
jo.put("min", min); // $NON-NLS-1$
}
double max = getMax();
if(!Double.isNaN(max)) {
jo.put("max", max); // $NON-NLS-1$
}
// TODO convert Java locale code to Dojo locale code - see ViewRootRendererEx2.convertJavaLocaleToDojoLocale(String, boolean)
Locale loc = getLocale();
if( null != loc ){
jo.putString("locale", loc); // $NON-NLS-1$
}
String pat = getPattern();
if( null != pat ){
jo.putString("pattern", pat); // $NON-NLS-1$
}
int places = getPlaces();
if(places>=0) {
jo.putInt("places", places); // $NON-NLS-1$
}
boolean severe = isStrict();
if( false != severe ){
jo.putBoolean("strict", severe); // $NON-NLS-1$
}
String ty = getType();
if( null != ty ){
jo.putString("type", ty); // $NON-NLS-1$
}
return jo.isEmpty() ? null : JsonGenerator.toJson(JsonJavaFactory.instance,jo,true);
} catch(Exception e) {
throw new FacesExceptionEx(e);
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:38,代码来源:NumberConstraints.java
示例7: generateClientScript
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String generateClientScript() {
FacesContext context = FacesContext.getCurrentInstance();
StringBuilder b = new StringBuilder();
// TabContainer.js has:
// _removeTab: function(id,refreshId,params)
b.append("dijit.byId("); // $NON-NLS-1$
JavaScriptUtil.addString(b, container.getClientId(context));
b.append(")._removeTab("); // $NON-NLS-1$
JavaScriptUtil.addString(b, pane.getClientId(context));
String rid=ExtLibUtil.getClientId(context,container,refreshId,true);
if(StringUtil.isNotEmpty(rid)) {
b.append(",");
JavaScriptUtil.addString(b, rid);
Object params = refreshParams;
if(params!=null) {
b.append(",{");
try {
String json = JsonGenerator.toJson(JsonJavaFactory.instance,params,true);
b.append(json);
} catch(Exception ex) {
throw new FacesExceptionEx(ex);
}
b.append("}");
}
}
b.append(");");
if(b.length()>0) {
String script = b.toString();
return script;
}
return null;
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:37,代码来源:UIDojoTabContainer.java
示例8: renderService
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
@Override
public void renderService() throws ServiceException {
JsonFactory factory = getJsonFactory();
// Parse the body
try {
InputStream is = getHttpRequest().getInputStream();
Object o = (ObjectObject)JsonParser.fromJson(factory, new InputStreamReader(is,ENCODING_UTF8));
int id = (int)factory.getNumber(factory.getProperty(o, JSON_FACTORY_PROPERTY_ID));
String methodName = factory.getString((factory.getProperty(o, JSON_FACTORY_PROPERTY_METHOD)));
Object params = factory.getProperty(o, JSON_FACTORY_PROPERTY_PARAMS);
Object res = factory.createObject(null, null);
factory.setProperty(res, JSON_FACTORY_PROPERTY_ID, factory.createNumber(id));
RpcMethod method = findMethod(methodName);
if(method!=null) {
Object result = method.invoke(getHttpRequest(), id, params);
factory.setProperty(res, JSON_FACTORY_PROPERTY_RESULT, result);
} else {
factory.setProperty(res, JSON_FACTORY_PROPERTY_ERROR, factory.createString(StringUtil.format("Unknown method {0}", methodName))); // $NLX-RpcServiceEngine.Unknownmethod0-1$
}
getHttpResponse().setContentType(CONTENTTYPE_TEXT_JSON);
getHttpResponse().setCharacterEncoding(ENCODING_UTF8);
OutputStream os = getOutputStream();
Writer w = new OutputStreamWriter(os,ENCODING_UTF8);
JsonGenerator.toJson(factory, w, res, false); // last is "compact"
w.flush();
} catch(Exception ex) {
throw new ServiceException(ex,""); // $NON-NLS-1$
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:38,代码来源:RpcServiceEngine.java
示例9: toString
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String toString() {
try {
return JsonGenerator.toJson(JsonJavaFactory.instance, this);
} catch(Exception ex) {
Platform.getInstance().log(ex);
return "";
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:9,代码来源:JsonSortedObject.java
示例10: BoxItem
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public BoxItem(JsonJavaObject data) {
this();
if(data!=null) {
this.type="folder".equals(data.getAsString("type"))?ItemType.FOLDER:ItemType.FILE;
this.id=data.getAsString("id");
this.sequenceId=data.getAsString("sequence-id");
this.etag=data.getAsString("etag");
this.name = data.getAsString("name");
this.description=data.getAsString("description");
this.size = data.getAsLong("size");
try {
this.createdAt=JsonGenerator.stringToDate(data.getAsString("created-at"));
} catch (Exception e) {}
JsonJavaObject createdBy=data.getJsonObject("created_by");
if(createdBy!=null) this.creator=new BoxPerson(createdBy);
pathCollection=new ArrayList<BoxItem>();
JsonJavaObject pathObj=data.getJsonObject("path_collection");
if(pathObj!=null && pathObj.containsKey("entries")) {
JsonJavaArray entries=pathObj.getAsArray("entries");
for(Object path: entries) {
if(path instanceof JsonJavaObject) {
pathCollection.add(new BoxItem((JsonJavaObject) path));
}
}
}
JsonJavaObject sLink=data.getJsonObject("shared_link");
if(sLink!=null) this.url=sLink.getAsString("url");
}
}
开发者ID:sbasegmez,项目名称:Blogged,代码行数:39,代码来源:BoxItem.java
示例11: generateJavaScript
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
/**
*
* @param context
* @param dt
* @param rowCount
* @param state
* @param linkId
* @param computedDisabledFormat the result of a call to {@link #computeDisabledFormat(FacesContext, String, String)};
* @return
* @throws EvaluationException
* @throws MethodNotFoundException
*/
public static String generateJavaScript(FacesContext context, FacesDataIterator dt, int rowCount, boolean state, String linkId,
String computedDisabledFormat) throws EvaluationException, MethodNotFoundException {
StringBuilder b = new StringBuilder(256);
UIComponent c = (UIComponent)dt;
// Add the dojo module
ExtLibResources.addEncodeResource(context, ExtLibResources.extlibDataIterator);
// And generate the piece of script
String id = (c instanceof FacesDataIteratorAjax) ? ((FacesDataIteratorAjax)c).getAjaxContainerClientId(context) : c.getClientId(context);
String url = AjaxUtil.getAjaxUrl(context, c, UIDataEx.AJAX_GETROWS, c.getClientId(context));
url = context.getExternalContext().encodeActionURL(url);
int first = dt.getFirst()+dt.getRows();
int count = rowCount;
if(count<=0) {
// For SPR#MKEE8MHELJ, default to 30 rows
// instead of to dt.getRows(), to prevent duplicating
// the number of rows displayed on every click.
count = UIDataEx.DEFAULT_ROWS_PER_PAGE;
}
// partial workaround for SPR#LHEY8LNDZS, problem in the xpage runtime.
// The UIDataEx and UIDataIterator classes can't handle it when
// the number of rows to be added is < the rows property - they
// return too few rows. The client-side XSP.appendRows method
// thinks that, since too few rows are present, all the rows
// in the data set have been displayed, so it removes
// the "Show more" link, even though not all rows have been shown.
count = Math.min(count, dt.getRows());
try {
b.append("XSP.appendRows("); //$NON-NLS-1$
JsonJavaObject jo = new JsonJavaObject();
jo.putString("id", id); //$NON-NLS-1$
jo.putString("url", url); //$NON-NLS-1$
jo.putInt("first", first); //$NON-NLS-1$
jo.putInt("count", count); //$NON-NLS-1$
jo.putBoolean("state", state); //$NON-NLS-1$
if( null != linkId ){
jo.putString("linkId", linkId); //$NON-NLS-1$
if( !DISABLED_FORMAT_TEXT.equals(computedDisabledFormat) ){
jo.putString("linkDisabledFormat", computedDisabledFormat); //$NON-NLS-1$
}
}
JsonGenerator.toJson(JsonJavaFactory.instance,b,jo,true);
b.append(");"); //$NON-NLS-1$
} catch(Exception e) {
throw new FacesExceptionEx(e);
}
return b.toString();
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:68,代码来源:DataIteratorAddRows.java
示例12: createCurrencyConstraintsAsJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String createCurrencyConstraintsAsJson() {
try {
JsonJavaObject jo = new JsonJavaObject();
double min = getMin();
if(!Double.isNaN(min)) {
jo.put("min", min); // $NON-NLS-1$
}
double max = getMax();
if(!Double.isNaN(max)) {
jo.put("max", max); // $NON-NLS-1$
}
String curr = getCurrency();
if( null != curr ){
jo.putString("currency", curr); // $NON-NLS-1$
}
String fra = getFractional();
if( null != fra ){
// SPR#JKAE9LEB6L was writing "false" instead of false (incorrectly quoted).
// Acceptable values are either "enable", "disable", "auto", "true", or "false"
// and the currency constraints allows "optional" or "[true, false]"
// and historically we allow any other string value to also be added.
if( "true".equals(fra) || "enable".equals(fra) ){ //$NON-NLS-1$ //$NON-NLS-2$
jo.putBoolean("fractional", true); // $NON-NLS-1$
}else if( "false".equals(fra) || "disable".equals(fra) ){//$NON-NLS-1$ //$NON-NLS-2$
jo.putBoolean("fractional", false); // $NON-NLS-1$
}else if( "auto".equals(fra) ){ //$NON-NLS-1$
// don't render any output
}else if("optional".equals(fra) || "[true, false]".equals(fra) //$NON-NLS-1$ //$NON-NLS-2$
|| "[true,false]".equals(fra) ){ //$NON-NLS-1$
// constraints: { fractional:[true, false] }
JsonJavaArray arr = new JsonJavaArray();
arr.putBoolean(0, true);
arr.putBoolean(1, false);
jo.putArray("fractional", arr); //$NON-NLS-1$
}
else{
// else treat it like a string.
jo.putString("fractional", fra); // $NON-NLS-1$
}
}
// TODO convert Java locale code to Dojo locale code - see ViewRootRendererEx2.convertJavaLocaleToDojoLocale(String, boolean)
Locale loc = getLocale();
if( null != loc ){
jo.putString("locale", loc); // $NON-NLS-1$
}
String pat = getPattern();
if( null != pat ){
jo.putString("pattern", pat); // $NON-NLS-1$
}
int places = getPlaces();
if(places>=0) {
jo.putInt("places", places); // $NON-NLS-1$
}
boolean severe = isStrict();
if( false != severe ){
jo.putBoolean("strict", severe); // $NON-NLS-1$
}
String sym = getSymbol();
if( null != sym ){
jo.putString("symbol", sym); // $NON-NLS-1$
}
String ty = getType();
if( null != ty ){
jo.putString("type", ty); // $NON-NLS-1$
}
return jo.isEmpty() ? null : JsonGenerator.toJson(JsonJavaFactory.instance,jo,true);
} catch(Exception e) {
throw new FacesExceptionEx(e);
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:71,代码来源:NumberConstraints.java
示例13: createDateConstraintsAsJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String createDateConstraintsAsJson() {
try {
JsonJavaObject jo = new JsonJavaObject();
String clickInc = getClickableIncrement();
if( null != clickInc ){
jo.putString("clickableIncrement", clickInc); // $NON-NLS-1$
}
String dp = getDatePattern();
if( null != dp ){
jo.putString("datePattern", dp); // $NON-NLS-1$
}
String len = getFormatLength();
if( null != len ){
jo.putString("formatLength", len); // $NON-NLS-1$
}
// TODO convert Java locale code to Dojo locale code - see ViewRootRendererEx2.convertJavaLocaleToDojoLocale(String, boolean)
Locale loc = getLocale();
if( null != loc ){
jo.putString("locale", loc); // $NON-NLS-1$
}
String sel = getSelector();
if( null != sel ){
jo.putString("selector", sel); // $NON-NLS-1$
}
boolean severe = isStrict();
if( false != severe ){
jo.putBoolean("strict", severe); // $NON-NLS-1$
}
String visInc = getVisibleIncrement();
if( null != visInc ){
jo.putString("visibleIncrement", visInc); // $NON-NLS-1$
}
String visRange = getVisibleRange();
if( null != visRange ){
jo.putString("visibleRange", visRange); // $NON-NLS-1$
}
return jo.isEmpty() ? null : JsonGenerator.toJson(JsonJavaFactory.instance,jo,true);
} catch(Exception e) {
throw new FacesExceptionEx(e);
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:42,代码来源:DateTimeConstraints.java
示例14: createTimeConstraintsAsJson
import com.ibm.commons.util.io.json.JsonGenerator; //导入依赖的package包/类
public String createTimeConstraintsAsJson() {
try {
JsonJavaObject jo = new JsonJavaObject();
String a = getAm();
if( null != a ){
jo.putString("am", a); // $NON-NLS-1$
}
String p = getPm();
if( null != p ){
jo.putString("pm", p); // $NON-NLS-1$
}
String clickInc = getClickableIncrement();
if( null != clickInc ){
jo.putString("clickableIncrement", clickInc); // $NON-NLS-1$
}
String tp = getTimePattern();
if( null != tp ){
jo.putString("timePattern", tp); // $NON-NLS-1$
}
String len = getFormatLength();
if( null != len ){
jo.putString("formatLength", len); // $NON-NLS-1$
}
// TODO convert Java locale code to Dojo locale code - see ViewRootRendererEx2.convertJavaLocaleToDojoLocale(String, boolean)
Locale loc = getLocale();
if( null != loc ){
jo.putString("locale", loc); // $NON-NLS-1$
}
String sel = getSelector();
if( null != sel ){
jo.putString("selector", sel); // $NON-NLS-1$
}
boolean severe = isStrict();
if( false != severe ){
jo.putBoolean("strict", severe); // $NON-NLS-1$
}
String visInc = getVisibleIncrement();
if( null != visInc ){
jo.putString("visibleIncrement", visInc); // $NON-NLS-1$
}
String visRange = getVisibleRange();
if( null != visRange ){
jo.putString("visibleRange", visRange); // $NON-NLS-1$
}
return jo.isEmpty() ? null : JsonGenerator.toJson(JsonJavaFactory.instance,jo,true);
} catch(Exception e) {
throw new FacesExceptionEx(e);
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:50,代码来源:DateTimeConstraints.java
注:本文中的com.ibm.commons.util.io.json.JsonGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论