Java Code Examples for com.alibaba.fastjson.JSONObject#getJSONArray()

The following examples show how to use com.alibaba.fastjson.JSONObject#getJSONArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysFillRuleController.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 批量通过 ruleCode 执行自定义填值规则
 *
 * @param ruleData 要执行的填值规则JSON数组:
 *                 示例: { "commonFormData": {}, rules: [ { "ruleCode": "xxx", "formData": null } ] }
 * @return 运行后的结果,返回示例: [{"ruleCode": "order_num_rule", "result": "CN2019111117212984"}]
 *
 */
@PutMapping("/executeRuleByCodeBatch")
public Result executeByRuleCodeBatch(@RequestBody JSONObject ruleData) {
    JSONObject commonFormData = ruleData.getJSONObject("commonFormData");
    JSONArray rules = ruleData.getJSONArray("rules");
    // 遍历 rules ,批量执行规则
    JSONArray results = new JSONArray(rules.size());
    for (int i = 0; i < rules.size(); i++) {
        JSONObject rule = rules.getJSONObject(i);
        String ruleCode = rule.getString("ruleCode");
        JSONObject formData = rule.getJSONObject("formData");
        // 如果没有传递 formData,就用common的
        if (formData == null) {
            formData = commonFormData;
        }
        // 执行填值规则
        Object result = FillRuleUtil.executeRule(ruleCode, formData);
        JSONObject obj = new JSONObject(rules.size());
        obj.put("ruleCode", ruleCode);
        obj.put("result", result);
        results.add(obj);
    }
    return Result.ok(results);
}
 
Example 2
Source File: WXParallax.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
TransformCreator(String type, JSONObject object) {
  transformType = type;
  JSONArray in = object.getJSONArray("in");
  input = parseParamArray(in);
  JSONArray out = object.getJSONArray("out");
  output = parseParamArray(out);

  switch (transformType) {
    case WXAnimationBean.Style.WX_TRANSLATE:
      fromTranslateX = output[0];
      fromTranslateY = output[1];
      break;
    case WXAnimationBean.Style.WX_SCALE:
      fromScaleX = output[0];
      fromScaleY = output[1];
      break;
    case WXAnimationBean.Style.WX_ROTATE:
      fromRotate = output[0];
      break;
    case WX_OPACITY:
      fromOpacity = output[0];
      break;
  }
}
 
Example 3
Source File: MetaschemaImporter.java    From rebuild with GNU General Public License v3.0 6 votes vote down vote up
private String verfiyEntity(JSONObject entity) {
	String entityName = entity.getString("entity");
	if (MetadataHelper.containsEntity(entityName)) {
		return "实体名称重复: " + entityName;
	}
	
	for (Object o : entity.getJSONArray("fields")) {
		JSONObject field = (JSONObject) o;
		if (DisplayType.REFERENCE.name().equalsIgnoreCase(field.getString("displayType"))) {
			String refEntity = field.getString("refEntity");
			if (!entityName.equals(refEntity) && !MetadataHelper.containsEntity(refEntity)) {
				return "缺少必要的引用实体: " + field.getString("fieldLabel") + " (" + refEntity + ")";
			}
		}
	}
	return null;
}
 
Example 4
Source File: Dmas.java    From dbys with GNU General Public License v3.0 6 votes vote down vote up
@Async
public void xzbcdm(String url, String player) {
    String json = HtmlUtils.getHtmlContentNp(url);
    JSONObject jsonObject = JSON.parseObject(json);
    JSONArray comments = jsonObject.getJSONArray("comments");
    int maxc = comments.size();
    for (int j = 0; j < maxc; j++) {
        JSONObject comment = comments.getJSONObject(j);
        Dan d = new Dan();
        d.setReferer("https://v.qq.com");
        d.setIp("::ffff:111.111.111.111");
        d.setType(0);
        d.setTime(comment.getDouble("timepoint"));
        d.setAuthor(comment.getString("opername"));
        d.setPlayer(player);
        d.setText(comment.getString("content"));
        d.setColor(14277107);
        d.setDate(currentTimeMillis());
        mongoTemplate.insert(d);
    }
}
 
Example 5
Source File: FrontCommunityServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
private void freshCommunityAttr(JSONArray community) {
    for (int _communityIndex = 0; _communityIndex < community.size(); _communityIndex++) {
        JSONObject _community = community.getJSONObject(_communityIndex);
        if (!_community.containsKey("attrs")) {
            continue;
        }
        JSONArray _attrs = _community.getJSONArray("attrs");
        for (int _cAttrIndex = 0; _cAttrIndex < _attrs.size(); _cAttrIndex++) {
            if (AttrCdConstant.SPEC_CD_COMMUNITY_TEL.equals(_attrs.getJSONObject(_cAttrIndex).getString("specCd"))) {
                _community.put("tel", _attrs.getJSONObject(_cAttrIndex).getString("value"));
            }
        }

    }

}
 
Example 6
Source File: JSONPayloadFormatter.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
@Override
public List<Message> format(ByteBuf payload) {
    if (payload == null) {
        return null;
    }
    String txt = payload.toString(StandardCharsets.UTF_8);
    JSONObject jsonObject = JSON.parseObject(txt);

    Object timestamp = jsonObject.get(JSON_KEY_TIMESTAMP);
    if (timestamp != null) {
        return Lists.newArrayList(JSON.parseObject(txt, Message.class));
    }

    String device = jsonObject.getString(JSON_KEY_DEVICE);
    JSONArray timestamps = jsonObject.getJSONArray(JSON_KEY_TIMESTAMPS);
    JSONArray measurements = jsonObject.getJSONArray(JSON_KEY_MEASUREMENTS);
    JSONArray values = jsonObject.getJSONArray(JSON_KEY_VALUES);

    List<Message> ret = new ArrayList<>();
    for (int i = 0; i < timestamps.size(); i++) {
        Long ts = timestamps.getLong(i);

        Message message = new Message();
        message.setDevice(device);
        message.setTimestamp(ts);
        message.setMeasurements(measurements.toJavaList(String.class));
        message.setValues(((JSONArray)values.get(i)).toJavaList(String.class));
        ret.add(message);
    }
    return ret;
}
 
Example 7
Source File: Config.java    From DBforBIX with GNU General Public License v3.0 5 votes vote down vote up
/**
 * modify zabbix entity to java Map
 * @param zEntity - zabbix entity
 * @return - converted to Map entity
 */
private Map<String, List<String>> zJSONObject2Map(JSONObject zEntity) {
	Map<String,List<String> > m=new HashMap<String,List<String> >();
	JSONArray data=zEntity.getJSONArray("data");
	JSONArray fields=zEntity.getJSONArray("fields");
	for(int i=0;i<fields.size();++i){
		m.put(fields.getString(i),new ArrayList<String>());
		for(int j=0;j<data.size();++j){
			m.get(fields.getString(i)).add(j, data.getJSONArray(j).getString(i));
		}
	}
	return m;
}
 
Example 8
Source File: Res.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * 返回列表数据, 反之返回空.
 * 
 * @return
 */
public JSONArray getDataJSONArray()
{
	if (data != null)
	{
		JSONObject jsonObject = JSONObject.parseObject(data);
		return jsonObject.getJSONArray("list");
	}

	return null;
}
 
Example 9
Source File: CustomConfig.java    From Vert.X-generator with MIT License 5 votes vote down vote up
/**
 * 初始化
 */
public CustomConfig(JSONObject object) {
	super();
	this.overrideFile = object.getBoolean("overrideFile");
	JSONArray array = object.getJSONArray("tableItem");
	if (array != null) {
		array.forEach(v -> {
			tableItem.add(new TableAttributeKeyValueTemplate((JSONObject) v));
		});
	}
}
 
Example 10
Source File: AllSortJsonPipeline.java    From gecco with MIT License 5 votes vote down vote up
@Override
public void process(JSONObject allSort) {
	HttpRequest currRequest = HttpGetRequest.fromJson(allSort.getJSONObject("request"));
	JSONArray categorys = allSort.getJSONArray("mobile");
	process(currRequest, categorys);
	/*List<Category> domestics = allSort.getDomestic();
	process(allSort, domestics);
	List<Category> bodys = allSort.getBaby();
	process(allSort, bodys);*/
}
 
Example 11
Source File: RDBAnalyzeResultService.java    From RCT with Apache License 2.0 5 votes vote down vote up
public JSONArray getTopKeyFromResultByKey(String result, Long startNum) {
	if(null == result || "".equals(result.trim())) {
		return null;
	}
	JSONObject resultJsonObj = JSONObject.parseObject(result);
	JSONObject startNumData = JSONObject.parseObject(resultJsonObj.getString(IAnalyzeDataConverse.TOP_KEY_ANALYZE));
	JSONArray jsonArray = startNumData.getJSONArray(String.valueOf(startNum));
	return jsonArray;
}
 
Example 12
Source File: ExcelWriterImpl.java    From tephra with MIT License 5 votes vote down vote up
@Override
public boolean write(JSONObject object, OutputStream outputStream) {
    try (Workbook workbook = new XSSFWorkbook()) {
        JSONArray sheets = object.getJSONArray("sheets");
        for (int sheetIndex = 0, sheetSize = sheets.size(); sheetIndex < sheetSize; sheetIndex++) {
            JSONObject sheetJson = sheets.getJSONObject(sheetIndex);
            Sheet sheet = workbook.createSheet(sheetJson.containsKey("name") ? sheetJson.getString("name") : ("sheet " + sheetIndex));
            int firstRow = sheetJson.containsKey("first") ? sheetJson.getIntValue("first") : 0;
            JSONArray rows = sheetJson.getJSONArray("rows");
            for (int rowIndex = 0, rowSize = rows.size(); rowIndex < rowSize; rowIndex++) {
                JSONObject rowJson = rows.getJSONObject(rowIndex);
                int firstCol = rowJson.containsKey("first") ? rowJson.getIntValue("first") : 0;
                Row row = sheet.createRow(firstRow + rowIndex);
                JSONArray cells = rowJson.getJSONArray("cells");
                for (int cellIndex = 0, cellSize = cells.size(); cellIndex < cellSize; cellIndex++) {
                    JSONObject cellJson = cells.getJSONObject(cellIndex);
                    Cell cell = row.createCell(firstCol + cellIndex);
                    cell.setCellValue(cellJson.getString("value"));
                }
            }
        }
        workbook.write(outputStream);
        outputStream.close();

        return true;
    } catch (Throwable throwable) {
        logger.warn(throwable, "输出Excel时发生异常!");

        return false;
    }
}
 
Example 13
Source File: GrafanaDashBoardService.java    From DBus with Apache License 2.0 4 votes vote down vote up
/**
 * 批量删除grafana dashboard template table regex
 *
 * @param topoTableMap
 */
public void deleteDashboardTemplate(Map<String, List<Map<String, Object>>> topoTableMap) throws
        Exception {
    init();
    for (Map.Entry<String, List<Map<String, Object>>> entry : topoTableMap.entrySet()) {
        String projectName = entry.getKey();
        List<Map<String, Object>> topoTables = entry.getValue();
        try {
            String url = host + api + projectName;
            List<Object> ret = HttpClientUtils.send(url, "GET", "", token);
            if ((int) ret.get(0) == 200) {
                String strJson = (String) ret.get(1);
                JSONObject json = JSONObject.parseObject(strJson);
                JSONObject dashboard = json.getJSONObject("dashboard");
                JSONObject templating = dashboard.getJSONObject("templating");
                JSONArray list = templating.getJSONArray("list");
                if (list != null && list.size() > 0) {

                    boolean isFind = false;
                    for (int i = 0; i < list.size(); i++) {
                        JSONObject item = list.getJSONObject(i);
                        if (StringUtils.equalsIgnoreCase(item.getString("name"), "table")) {
                            String regex = item.getString("regex");
                            String[] split = regex.split("\\|");
                            for (Map<String, Object> topoTable : topoTables) {
                                String wkTable = StringUtils.join(new String[]{(String) topoTable.get("ds_name"),
                                        (String) topoTable.get("schema_name"), (String) topoTable.get("table_name")}, ".");
                                for (int j = 0; j < split.length; j++) {
                                    if (StringUtils.equals(split[j], wkTable)) {
                                        split[j] = null;
                                    }
                                }
                            }
                            StringBuilder regexSb = new StringBuilder();
                            for (String str : split) {
                                if (StringUtils.isNotBlank(str) && !StringUtils.equalsIgnoreCase(str, "none")) {
                                    regexSb.append(str);
                                    regexSb.append("|");
                                }
                            }
                            if (StringUtils.endsWith(regexSb.toString(), "|")) {
                                regex = StringUtils.substringBeforeLast(regexSb.toString(), "|");
                            } else {
                                regex = regexSb.toString();
                            }
                            if (StringUtils.isBlank(regex)) {
                                item.put("regex", "none");
                            } else {
                                item.put("regex", regex);
                            }
                            isFind = true;
                        }
                    }
                    if (isFind) {
                        updateDashboardTemplate(json);
                    }
                }
            } else if (((int) ret.get(0) == -1)) {
                logger.error("call url:{} fail", url);
            } else {
                logger.warn("call url:{} response msg:{}", url, ret.get(1));
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
Example 14
Source File: GeneratorBindingComponent.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
/**
 * 生成API 侦听处理类
 *
 * @param data
 */
private void genneratorListListener(JSONObject data) {
    StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/binding/BindingListener.java").getFile());
    String fileContext = sb.toString();

    fileContext = super.replaceBindingTemplateContext(fileContext, data);

    //替换校验部分代码 @@validateTemplateColumns@@
    JSONArray flows = data.getJSONArray("flows");
    StringBuffer validateStr = new StringBuffer();
    StringBuffer variableStr = new StringBuffer();

    StringBuffer ifCode = new StringBuffer();

    StringBuffer methodCode = new StringBuffer();
    for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {

        JSONObject flowObj = flows.getJSONObject(flowIndex);

        String vcName = flowObj.getString("vcName");

        variableStr.append("JSONObject " + vcName + " = getObj(infos, \"" + vcName + "\");\n");

        ifCode.append("" +
                "        if(!hasKey("+vcName+", \"" + flowObj.getString("flowKey") + "\")){\n" +
                "             "+vcName+".put(\"" + flowObj.getString("flowKey") + "\", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_" + flowObj.getString("flowKey") + "));\n" +
                "             "+vcName+".put(\"userId\", context.getRequestCurrentHeaders().get(CommonConstant.HTTP_USER_ID));\n" +
                "             businesses.add(add" + toUpperCaseFirstOne(flowObj.getString("businessName")) + "("+vcName+", context));\n" +
                "        }\n");


        methodCode.append("private JSONObject add"+toUpperCaseFirstOne(flowObj.getString("businessName"))+"(JSONObject paramInJson, DataFlowContext dataFlowContext) {\n" +
                "        JSONObject business = JSONObject.parseObject(\"{\\\"datas\\\":{}}\");\n" +
                "        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant."+flowObj.getString("businessType")+");\n" +
                "        business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);\n" +
                "        business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);\n" +
                "        JSONObject businessObj = new JSONObject();\n" +
                "        businessObj.putAll(paramInJson);\n" +
                "        //计算 应收金额\n" +
                "        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(\""+flowObj.getString("businessName")+"\", businessObj);\n" +
                "        return business;\n" +
                "    }\n");
        if (flowObj.containsKey("existsComponent") && flowObj.getBoolean("existsComponent")) {
            continue;
        }


        JSONObject vcObject = data.getJSONObject("components").getJSONObject(vcName);

        JSONArray columns = vcObject.getJSONArray("columns");

        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
            JSONObject column = columns.getJSONObject(columnIndex);
            if (column.getBoolean("required")) {
                validateStr.append("Assert.hasKeyByFlowData(infos, \"" + flowObj.getString("vcName") + "\", \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
            }
        }
    }

    fileContext = fileContext.replace("@@validateTemplateColumns@@", validateStr.toString());
    fileContext = fileContext.replace("@@doSoService@@", variableStr.toString() + ifCode.toString());
    fileContext = fileContext.replace("@@bindingMethod@@", methodCode.toString());


    String writePath = this.getClass().getResource("/").getPath()
            + "out/api/listener/" + data.getString("templateCode") + "/" + toUpperCaseFirstOne(data.getString("templateCode")) + "Binding"+"Listener.java";
    System.out.printf("writePath: " + writePath);
    writeFile(writePath,
            fileContext);
}
 
Example 15
Source File: AddOwnerRoomBindingSMOImpl.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
@Override
protected void validate(IPageData pd, JSONObject paramIn) {

    //super.validatePageInfo(pd);
    JSONArray infos = paramIn.getJSONArray("data");
    Assert.hasKeyAndValue(paramIn, "communityId", "未包含小区信息");

    if (infos.size() != 3) {
        throw new IllegalArgumentException("数据被篡改");
    }

    Assert.hasKeyByFlowData(infos, "viewFloorInfo", "floorId", "必填,未选择楼栋");
    Assert.hasKeyByFlowData(infos, "sellRoomSelectRoom", "roomId", "必填,未选择房屋");
    Assert.hasKeyByFlowData(infos, "viewOwnerInfo", "ownerId", "必填,未包含业主信息");


    super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.ADD_OWNER_ROOM);

}
 
Example 16
Source File: NavBuilder.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 渲染导航菜單
 *
 * @param item
 * @param activeNav
 * @return
 */
public String renderNavItem(JSONObject item, String activeNav) {
    final boolean isUrlType = "URL".equals(item.getString("type"));
    String navName = item.getString("value");
    String navUrl = item.getString("value");

    boolean isOutUrl = isUrlType && navUrl.startsWith("http");
    if (isUrlType) {
        navName = "nav_url-" + navName.hashCode();
        if (isOutUrl) {
            navUrl = ServerListener.getContextPath() + "/commons/url-safe?url=" + CodecUtils.urlEncode(navUrl);
        } else {
            navUrl = ServerListener.getContextPath() + navUrl;
        }
    } else if (NAV_FEEDS.equals(navName)) {
        navName = "nav_entity-Feeds";
        navUrl = ServerListener.getContextPath() + "/feeds/home";
    } else if (NAV_FILEMRG.equals(navName)) {
        navName = "nav_entity-Attachment";
        navUrl = ServerListener.getContextPath() + "/files/home";
    } else {
        navName = "nav_entity-" + navName;
        navUrl = ServerListener.getContextPath() + "/app/" + navUrl + "/list";
    }

    String navIcon = StringUtils.defaultIfBlank(item.getString("icon"), "texture");
    String navText = item.getString("text");

    JSONArray subNavs = null;
    if (activeNav != null) {
        subNavs = item.getJSONArray("sub");
        if (subNavs == null || subNavs.isEmpty()) {
            subNavs = null;
        }
    }

    StringBuilder navHtml = new StringBuilder()
            .append(String.format("<li class=\"%s\"><a href=\"%s\" target=\"%s\"><i class=\"icon zmdi zmdi-%s\"></i><span>%s</span></a>",
                    navName + (subNavs == null ? StringUtils.EMPTY : " parent"),
                    subNavs == null ? navUrl : "###",
                    isOutUrl ? "_blank" : "_self",
                    navIcon,
                    navText));
    if (subNavs != null) {
        StringBuilder subHtml = new StringBuilder()
                .append("<ul class=\"sub-menu\"><li class=\"title\">")
                .append(navText)
                .append("</li><li class=\"nav-items\"><div class=\"content\"><ul class=\"sub-menu-ul\">");

        for (Object o : subNavs) {
            JSONObject subNav = (JSONObject) o;
            subHtml.append(renderNavItem(subNav, null));
        }
        subHtml.append("</ul></div></li></ul>");
        navHtml.append(subHtml);
    }
    navHtml.append("</li>");

    if (activeNav != null) {
        Document navBody = Jsoup.parseBodyFragment(navHtml.toString());
        for (Element nav : navBody.select("." + activeNav)) {
            nav.addClass("active");
            if (activeNav.startsWith("nav_entity-")) {
                Element navParent = nav.parent();
                if (navParent != null && navParent.hasClass("sub-menu-ul")) {
                    navParent.parent().parent().parent().parent().addClass("open active");
                }
            }
        }
        return navBody.selectFirst("li").outerHtml();
    }
    return navHtml.toString();
}
 
Example 17
Source File: ShowapiExpressQuerier.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<ExpressInfo> query(ExpressCompany company, String num) {

    String appId = JPressOptions.get("express_api_appid");
    String appSecret = JPressOptions.get("express_api_appsecret");

    String param = "{\"com\":\"" + company.getCode() + "\",\"num\":\"" + num + "\"}";
    String sign = HashKit.md5(param + appSecret + appId);
    HashMap params = new HashMap();
    params.put("showapi_appid", appId);
    params.put("com", sign);
    params.put("nu", num);
    params.put("contentType", "bodyString");
    params.put("showapi_sign", signRequest(params, appSecret));


    String result = HttpUtil.httpGet("http://route.showapi.com/64-19", params);
    if (StrUtil.isBlank(result)) {
        return null;
    }

    try {
        JSONObject object = JSONObject.parseObject(result);
        JSONObject body = object.getJSONObject("showapi_res_body");
        if (body != null) {
            JSONArray jsonArray = body.getJSONArray("data");
            if (jsonArray != null && jsonArray.size() > 0) {
                List<ExpressInfo> list = new ArrayList<>();
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject expObject = jsonArray.getJSONObject(i);
                    ExpressInfo ei = new ExpressInfo();
                    ei.setInfo(expObject.getString("context"));
                    ei.setTime(expObject.getString("time"));
                    list.add(ei);
                }
                return list;
            }
        }
    } catch (Exception ex) {
        LOG.error(ex.toString(), ex);
    }

    LOG.error(result);

    return null;
}
 
Example 18
Source File: TextImpl.java    From tephra with MIT License 4 votes vote down vote up
@Override
public void parseShape(WriterContext writerContext, XSLFSimpleShape xslfSimpleShape, JSONObject shape) {
    if (!shape.containsKey("text"))
        return;

    JSONObject text = shape.getJSONObject("text");
    JSONArray paragraphs = text.getJSONArray("paragraphs");
    XSLFTextShape xslfTextShape = (XSLFTextShape) xslfSimpleShape;
    xslfTextShape.clearText();
    parseInsets(xslfTextShape, text);
    xslfTextShape.setTextDirection(text.containsKey("direction") && text.getString("direction").equals("vertical") ?
            TextShape.TextDirection.VERTICAL : TextShape.TextDirection.HORIZONTAL);
    xslfTextShape.setVerticalAlignment(getVerticalAlign(text));
    for (int i = 0, pSize = paragraphs.size(); i < pSize; i++) {
        JSONObject paragraph = paragraphs.getJSONObject(i);
        JSONArray words = paragraph.getJSONArray("words");
        XSLFTextParagraph xslfTextParagraph = xslfTextShape.addNewTextParagraph();
        xslfTextParagraph.setTextAlign(getHorizontalAlign(text, paragraph));
        for (int j = 0, wSize = words.size(); j < wSize; j++) {
            JSONObject word = words.getJSONObject(j);
            XSLFTextRun xslfTextRun = xslfTextParagraph.addNewTextRun();
            xslfTextRun.setFontFamily(getString(text, paragraph, word, "fontFamily"));
            xslfTextRun.setFontSize(officeHelper.pixelToPoint(getFontSize(text, paragraph, word)));
            JSONObject color = getColor(text, paragraph, word);
            if (color != null)
                xslfTextRun.setFontColor(officeHelper.jsonToColor(color));
            if (hasTrue(text, paragraph, word, "bold"))
                xslfTextRun.setBold(true);
            if (hasTrue(text, paragraph, word, "italic"))
                xslfTextRun.setItalic(true);
            if (hasTrue(text, paragraph, word, "underline"))
                xslfTextRun.setUnderlined(true);
            if (hasTrue(text, paragraph, word, "strikethrough"))
                xslfTextRun.setStrikethrough(true);
            if (hasTrue(text, paragraph, word, "subscript"))
                xslfTextRun.setSubscript(true);
            if (hasTrue(text, paragraph, word, "superscript"))
                xslfTextRun.setSuperscript(true);
            if (!hasTrue(text, paragraph, word, "layout"))
                xslfTextRun.setText(word.getString("word"));
        }
    }
}
 
Example 19
Source File: JuheExpressQuerier.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<ExpressInfo> query(ExpressCompany company, String num) {

    String appId = JPressOptions.get("express_api_appid");
    String appSecret = JPressOptions.get("express_api_appsecret");

    Map params = new HashMap();
    params.put("com", codeMap.get(company.getCode()));
    params.put("no", num);
    params.put("key", appId);
    params.put("dtype", "json");

    String result = HttpUtil.httpGet("http://v.juhe.cn/exp/index", params);
    if (StrUtil.isBlank(result)) {
        return null;
    }

    try {
        JSONObject object = JSONObject.parseObject(result);
        Integer errorCode = object.getInteger("error_code");
        if (errorCode != null && errorCode == 0) {
            JSONObject resultObject = object.getJSONObject("result");
            if (resultObject != null) {
                JSONArray jsonArray = resultObject.getJSONArray("list");
                if (jsonArray != null && jsonArray.size() > 0) {
                    List<ExpressInfo> list = new ArrayList<>();
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JSONObject expObject = jsonArray.getJSONObject(i);
                        ExpressInfo ei = new ExpressInfo();
                        ei.setInfo(expObject.getString("remark"));
                        ei.setTime(expObject.getString("datetime"));
                        list.add(ei);
                    }
                    return list;
                }
            }
        }
    } catch (Exception ex) {
        LOG.error(ex.toString(), ex);
    }

    LOG.error(result);
    return null;
}
 
Example 20
Source File: PublicMethedForMutiSign.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * constructor.
 */
public static GrpcAPI.Return accountPermissionUpdateForResponse(String permissionJson,
    byte[] owner, String priKey,
    WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) {
  Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE);
  ECKey temKey = null;
  try {
    BigInteger priK = new BigInteger(priKey, 16);
    temKey = ECKey.fromPrivate(priK);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  ECKey ecKey = temKey;

  Contract.AccountPermissionUpdateContract.Builder builder =
      Contract.AccountPermissionUpdateContract.newBuilder();

  JSONObject permissions = JSONObject.parseObject(permissionJson);
  JSONObject ownersPermission = permissions.getJSONObject("owner_permission");
  JSONObject witnesssPermission = permissions.getJSONObject("witness_permission");
  JSONArray activesPermissions = permissions.getJSONArray("active_permissions");

  if (ownersPermission != null) {
    Permission ownerPermission = json2Permission(ownersPermission);
    builder.setOwner(ownerPermission);
  }
  if (witnesssPermission != null) {
    Permission witnessPermission = json2Permission(witnesssPermission);
    builder.setWitness(witnessPermission);
  }
  if (activesPermissions != null) {
    List<Permission> activePermissionList = new ArrayList<>();
    for (int j = 0; j < activesPermissions.size(); j++) {
      JSONObject permission = activesPermissions.getJSONObject(j);
      activePermissionList.add(json2Permission(permission));
    }
    builder.addAllActives(activePermissionList);
  }
  builder.setOwnerAddress(ByteString.copyFrom(owner));

  Contract.AccountPermissionUpdateContract contract = builder.build();

  TransactionExtention transactionExtention = blockingStubFull
      .accountPermissionUpdate(contract);
  if (transactionExtention == null) {
    return null;
  }
  Return ret = transactionExtention.getResult();
  if (!ret.getResult()) {
    System.out.println("Code = " + ret.getCode());
    System.out.println("Message = " + ret.getMessage().toStringUtf8());
    return ret;
  }
  Transaction transaction = transactionExtention.getTransaction();
  if (transaction == null || transaction.getRawData().getContractCount() == 0) {
    System.out.println("Transaction is empty");
    return ret;
  }
  System.out.println(
      "Receive txid = " + ByteArray.toHexString(transactionExtention.getTxid().toByteArray()));

  transaction = signTransaction(transaction, blockingStubFull, priKeys);
  Return response = broadcastTransaction1(transaction, blockingStubFull);
  return response;
}