Example usage for java.util ResourceBundle getObject

List of usage examples for java.util ResourceBundle getObject

Introduction

In this page you can find the example usage for java.util ResourceBundle getObject.

Prototype

public final Object getObject(String key) 

Source Link

Document

Gets an object for the given key from this resource bundle or one of its parents.

Usage

From source file:com.foo.manager.commonManager.thread.HttpHandleThread.java

private String handleXml_sn_receipt(String jsonString) throws CommonException {

    // String jsonReturnString = "";
    SimpleDateFormat sf = CommonUtil.getDateFormatter(CommonDefine.COMMON_FORMAT_1);

    System.out.println("---------------------------?FPAPI_SN_RECEIPT-------------------------------");
    // /*  w w  w . ja v a2  s . c  om*/
    JSONObject jsonObject = JSONObject.fromObject(jsonString);

    JSONObject orderInfo = (JSONObject) jsonObject.get("orderInfo");
    JSONObject senderInfo = (JSONObject) orderInfo.get("senderInfo");

    JSONArray orderItemList = (JSONArray) orderInfo.get("orderItemList");
    // JSONArray customerInfo = (JSONArray) jsonObject.get("customerInfo");
    // JSONArray barCodeInfo = (JSONArray) jsonObject.get("barCodeInfo");
    // ??
    ResourceBundle bundle = CommonUtil.getMessageMappingResource("CEB_SN");

    JSONObject result = new JSONObject();
    //ORDER_CODEt_sn_order.ORDER_CODE??????
    List orderDataList = commonManagerMapper.selectTableListByCol("T_SN_ORDER", "ORDER_CODE",
            orderInfo.get("orderCode"), null, null);
    if (orderDataList.size() > 0) {
        result.put("success", "true");
        result.put("errorCode", "");
        result.put("errorMsg", "");
        result.put("orderCode", orderInfo.get("orderCode"));
        return result.toString();
    }

    JSONArray resultArray = new JSONArray();

    // T_SN_RECEIPT
    Map primary = new HashMap();
    primary.put("primaryId", null);

    Map data = new HashMap();
    for (Object key : orderInfo.keySet()) {
        if (bundle.containsKey("SN_RECEIPT_" + key.toString().toUpperCase())) {

            if (orderInfo.get(key) == null || orderInfo.get(key).toString().isEmpty()) {
                data.put(bundle.getObject("SN_RECEIPT_" + key.toString().toUpperCase()), null);
            } else {
                data.put(bundle.getObject("SN_RECEIPT_" + key.toString().toUpperCase()), orderInfo.get(key));
            }

        }
    }
    for (Object key : senderInfo.keySet()) {
        if (bundle.containsKey("SN_RECEIPT_" + key.toString().toUpperCase())) {

            if (senderInfo.get(key) == null || senderInfo.get(key).toString().isEmpty()) {
                data.put(bundle.getObject("SN_RECEIPT_" + key.toString().toUpperCase()), null);
            } else {
                data.put(bundle.getObject("SN_RECEIPT_" + key.toString().toUpperCase()), senderInfo.get(key));
            }

        }
    }
    data.put("SENDER_CODE", orderInfo.get("ownerUserId"));
    data.put("RECEIPT_STATUS", "0");
    data.put("CREAT_DATE", sf.format(new Date()));
    data.put("CREAT_TIME", new Date());
    commonManagerMapper.insertTableByNVList("T_SN_RECEIPT", new ArrayList<String>(data.keySet()),
            new ArrayList<Object>(data.values()), primary);

    //????
    List<Map> orderItemListForCJ = new ArrayList<Map>();

    for (Iterator it = orderItemList.iterator(); it.hasNext();) {

        JSONObject item = (JSONObject) it.next();
        Map primary_sub = new HashMap();
        primary_sub.put("primaryId", null);

        Map dataSub = new HashMap();

        Map dataSubForCJ = new HashMap();

        for (Object key : item.keySet()) {
            if (bundle.containsKey("SN_RECEIPT_DETAIL_" + key.toString().toUpperCase())) {

                if (item.get(key) == null || item.get(key).toString().isEmpty()) {
                    dataSub.put(bundle.getObject("SN_RECEIPT_DETAIL_" + key.toString().toUpperCase()), null);
                } else {
                    dataSub.put(bundle.getObject("SN_RECEIPT_DETAIL_" + key.toString().toUpperCase()),
                            item.get(key));
                }
            }
        }

        // ?
        dataSub.put("RECEIPT_ID", primary.get("primaryId"));
        // data.put("CREAT_DATE", sf.format(new Date()));
        dataSub.put("CREAT_TIME", new Date());
        commonManagerMapper.insertTableByNVList("T_SN_RECEIPT_DETAIL", new ArrayList<String>(dataSub.keySet()),
                new ArrayList<Object>(dataSub.values()), primary_sub);

        //?????
        dataSubForCJ.put("ORDER_ITEM_ID", dataSub.get("ORDER_ITEM_ID"));
        dataSubForCJ.put("SKU", dataSub.get("SKU"));
        dataSubForCJ.put("ITEM_NAME", dataSub.get("ITEM_NAME"));
        dataSubForCJ.put("EXPECT_QTY", dataSub.get("EXPECT_QTY"));
        dataSubForCJ.put("PRODUCE_CODE", dataSub.get("PRODUCE_CODE"));
        orderItemListForCJ.add(dataSubForCJ);

    }
    //????
    Map order = new HashMap();
    order.put("OWNER", data.get("OWNER"));
    order.put("ORDER_CODE", data.get("ORDER_CODE"));
    order.put("ORDER_TYPE", data.get("ORDER_TYPE"));
    order.put("EXPECT_START_TIME", data.get("EXPECT_START_TIME"));
    order.put("EXPECT_END_TIME", data.get("EXPECT_END_TIME"));
    order.put("TMS_ORDER_CODE", data.get("TMS_ORDER_CODE"));
    order.put("SENDER_ADDRESS", data.get("SENDER_ADDRESS"));
    order.put("SENDER_CODE", data.get("SENDER_CODE"));
    order.put("SENDER_NAME", data.get("SENDER_NAME"));
    order.put("SENDER_MOBILE", data.get("SENDER_MOBILE"));
    order.put("SENDER_PHONE", data.get("SENDER_PHONE"));
    order.put("CUST", CommonUtil.getSystemConfigProperty("CJ_cust"));

    String xmlStringData = XmlUtil.generalCommonXml_CJ("DATA", order, orderItemListForCJ);

    String requestXmlData = XmlUtil.generalSoapXml_CJ(xmlStringData, "sendInStockOrder");

    System.out.println(requestXmlData);
    //??????
    String response = HttpUtil.sendHttpCMD_CJ(requestXmlData,
            CommonUtil.getSystemConfigProperty("CJ_sendInStockOrder_requestUrl").toString());

    //??
    //      String returnXmlData = XmlUtil
    //            .getResponseFromXmlString_CJ(response);

    String returnXmlData = XmlUtil.getTotalMidValue(StringEscapeUtils.unescapeXml(response), "<ns:return>",
            "</ns:return>");

    //
    //      String returnXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DATA><ORDER><ORDER_CODE>3434222e333</ORDER_CODE><CD>OK</CD><INFO><![CDATA[]]></INFO><ITEMS><ITEM><ORDER_ITEM_ID>420000002xxxxxx</ORDER_ITEM_ID><SKU>P0000KMM</SKU><ACTUAL_QTY>1</ACTUAL_QTY><ACTUAL_QTY_DEFECT>5590</ACTUAL_QTY_DEFECT></ITEM><ITEM><ORDER_ITEM_ID>1234567891</ORDER_ITEM_ID><SKU>P0001KMM</SKU><ACTUAL_QTY>1</ACTUAL_QTY><ACTUAL_QTY_DEFECT>5591</ACTUAL_QTY_DEFECT></ITEM></ITEMS></ORDER></DATA>";
    //
    //      String returnXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DATA><ORDER><ORDER_CODE>W107xxxxxx</ORDER_CODE><CD>102</CD><INFO>??</INFO></ORDER></DATA>";

    //?
    //
    Map orderResult = XmlUtil.parseXmlFPAPI_SingleNodes(returnXmlData, "//DATA/ORDER/child::*");

    //
    if (orderResult.containsKey("CD") && "OK".equals(orderResult.get("CD").toString())) {
        //??
        result.put("success", "true");
        result.put("errorCode", "");
        result.put("errorMsg", "");
    } else {
        //
        //????B0007,?
        result.put("success", "false");
        result.put("errorCode", "B0007");
        result.put("errorMsg", orderResult.get("INFO"));
    }
    result.put("orderCode", orderResult.get("ORDER_CODE"));

    return result.toString();
}

From source file:com.foo.manager.commonManager.thread.HttpHandleThread.java

private String handleXml_Inventory(String xmlString) {

    String xmlReturnString = "";

    System.out.println("---------------------------?FPAPI_INVENTORY-------------------------------");

    List<String> inventoryOrderDataXML = XmlUtil.getNodesXmlData(xmlString, "//inputList/inventoryOrder");

    List<Map> resultList = new ArrayList<Map>();

    // ?????// ww w . ja va 2  s.  co  m
    List<Map> dataList = new ArrayList<Map>();

    // ?<businessType>C061?

    // <inventoryDetailItems><goodsNumber>t_new_import_receipt?ACTUAL_QTY
    // 1.inventoryDetailHead.logisticsOrderId = RECEIPT_NO
    // 2.inventoryDetailItems.goodsCode = SKU

    // ?t_new_import_books
    // <goodsCode>?SKU
    // <goodsDescription>?DESCRIPTION
    // <goodsNumber>?QTY
    // ADD_REDUCE_FLAG1
    // <logisticsOrderId>?ORDER_NO
    // CREAT_DATE?YYYYMMDD
    // ?
    String checkBusinessTypeC061 = CommonUtil.getSystemConfigProperty("checkInventoryBusinessType_C061");
    String checkBusinessTypeC005 = CommonUtil.getSystemConfigProperty("checkInventoryBusinessType_C005");

    // ??
    ResourceBundle bundle = CommonUtil.getMessageMappingResource("CEB_SN");

    SimpleDateFormat sf = CommonUtil.getDateFormatter(CommonDefine.COMMON_FORMAT_1);

    for (String xmlData : inventoryOrderDataXML) {

        Map head = null;

        Map singleResult = new HashMap();
        singleResult.put("isSuccess", "true");
        try {
            // businessType
            head = XmlUtil.parseXmlFPAPI_SingleNodes(xmlData, "//inventoryDetailHead/child::*");

            singleResult.put("messageId", head.get("messageId"));

            String businessType = null;
            String logisticsOrderId = head.get("logisticsOrderId") != null
                    ? head.get("logisticsOrderId").toString()
                    : "";

            if (head != null && head.containsKey("businessType") && head.get("businessType") != null) {
                businessType = (String) head.get("businessType");
            }

            // --C061
            if (checkBusinessTypeC061.equals(businessType)) {
                List<Map> items = XmlUtil.parseXmlFPAPI_MulitpleNodes(xmlData, "//inventoryDetailItems");

                List<String> colNames = new ArrayList<String>();
                List<Object> colValues = new ArrayList<Object>();

                for (Map item : items) {
                    Map data = new HashMap();
                    // ?
                    for (Object key : item.keySet()) {
                        if (bundle.containsKey("inventory_" + key.toString())) {
                            data.put(bundle.getObject("inventory_" + key.toString()), item.get(key));
                        }
                    }
                    // t_new_import_receipt.ACTUAL_QTY, ?SKURECEIPT_NO
                    String sku = data.get("SKU").toString();

                    colNames.clear();
                    colValues.clear();
                    colNames.add("RECEIPT_NO");
                    colNames.add("SKU");
                    colValues.add(logisticsOrderId);
                    colValues.add(sku);

                    List<Map<String, Object>> rows = commonManagerMapper
                            .selectTableListByNVList("t_new_import_receipt", colNames, colValues, null, null);

                    if (rows.size() > 0) {
                        for (Map row : rows) {
                            colNames.clear();
                            colValues.clear();
                            colNames.add("ACTUAL_QTY");
                            colValues.add(data.get("QTY"));
                            // ?
                            commonManagerMapper.updateTableByNVList("t_new_import_receipt", "RECEIPT_ID",
                                    row.get("RECEIPT_ID"), colNames, colValues);
                        }
                        // ?
                        data.put("ORDER_NO", logisticsOrderId);
                        data.put("ADD_REDUCE_FLAG", "1");
                        data.put("CREAT_DATE", sf.format(new Date()));
                        data.put("CREAT_TIME", new Date());
                        Map primary = new HashMap();
                        primary.put("primaryId", null);
                        commonManagerMapper.insertTableByNVList("t_new_import_books",
                                new ArrayList<String>(data.keySet()), new ArrayList<Object>(data.values()),
                                primary);
                    } else {
                        singleResult.put("isSuccess", "false");
                    }
                }
                // ???--SN
                Map data = new HashMap();

                String dateFormatString = CommonUtil.getDateFormatter(CommonDefine.COMMON_FORMAT)
                        .format(new Date());

                data.put("messageId", getMessageId());
                data.put("logisticsOrderId", logisticsOrderId);
                data.put("logisticsExpressId", "");
                data.put("statusCode", "1120");
                data.put("logisticsStation", "tianjin");
                data.put("finishedDate", dateFormatString.split(" ")[0]);
                data.put("finishedTime", dateFormatString.split(" ")[1]);
                data.put("operator", "sinotrans");
                data.put("telNumber", "");
                data.put("shipmentCode", "");
                data.put("weight", "");
                data.put("weightUnit", "");
                data.put("note", "");
                data.put("consignee", "");
                data.put("airwayBillNo", "");
                data.put("flightNo", "");
                data.put("flightDate", "");
                data.put("keyValueAdd", "");
                data.put("thirdPartyCompany", "");

                dataList.add(data);

            } else if (checkBusinessTypeC005.equals(businessType)) {
                String statusCode = head.get("statusCode") != null ? head.get("statusCode").toString() : "";
                if ("1060".equals(statusCode)) {
                    // ??
                } else if ("1131".equals(statusCode)) {
                    // ?
                    // t_new_import_inventory_detail?
                    List<String> colNames = new ArrayList<String>();
                    List<Object> colValues = new ArrayList<Object>();
                    colNames.add("ORDER_NO");
                    colValues.add(logisticsOrderId);

                    List<Map<String, Object>> rows = commonManagerMapper.selectTableListByCol(
                            "t_new_import_inventory_detail", "LOS_NO", logisticsOrderId, null, null);

                    if (rows != null && rows.size() > 0) {
                        // ?????
                        /*
                         * <InventoryCancel> <orderNo></orderNo>
                         * <ebpCode></ebpCode> </InventoryCancel>
                         */
                        for (Map<String, Object> row : rows) {
                            Map InventoryCancelData = new HashMap();

                            InventoryCancelData.put("orderNo", row.get("ORDER_NO"));
                            InventoryCancelData.put("ebpCode", "3201966A69");
                            InventoryCancelData.put("note", "??");
                            String xmlStringData = XmlUtil.generalCommonXml("InventoryCancel",
                                    InventoryCancelData);

                            //  ??????
                            Map reponse = postToTJ(xmlStringData,
                                    CommonUtil.getSystemConfigProperty("TJ_business_type_cancel"));
                        }
                        singleResult.put("isSuccess", "true");

                    } else {
                        singleResult.put("isSuccess", "false");
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            singleResult.put("isSuccess", "false");
        }

        resultList.add(singleResult);
    }

    // ???
    if (dataList.size() > 0) {
        Map requestParam = new HashMap();
        requestParam.put("logistic_provider_id",
                CommonUtil.getSystemConfigProperty("SN_inputStatusList_logistic_provider_id"));
        requestParam.put("msg_type", CommonUtil.getSystemConfigProperty("SN_inputStatusList_msg_type"));
        requestParam.put("url", CommonUtil.getSystemConfigProperty("SN_inputStatusList_requestUrl"));
        String content = XmlUtil.generalReceiptXml_LoadRec_FP(
                CommonUtil.getSystemConfigProperty("inputStatusListRoot"),
                CommonUtil.getSystemConfigProperty("inputStatusListFirstElement"), dataList);
        //         System.out.println(content);
        // ??
        send2SN(requestParam, content);
    }

    // ?
    List<LinkedMap> dataListReturn = new ArrayList<LinkedMap>();

    for (int i = 0; i < resultList.size(); i++) {
        LinkedMap resultData = new LinkedMap();
        resultData.put("messageId", resultList.get(i).get("messageId"));
        resultData.put("success", resultList.get(i).get("isSuccess"));
        resultData.put("errorCode", "");
        resultData.put("errorMsg", "");
        dataListReturn.add(resultData);
    }
    String root = CommonUtil.getSystemConfigProperty("inventoryReceiptRoot");
    String firstElement = CommonUtil.getSystemConfigProperty("inventoryFirstElement");

    xmlReturnString = XmlUtil.generalReceiptXml_FP(root, firstElement, dataListReturn);

    return xmlReturnString;
}

From source file:net.sourceforge.pmd.util.database.DBType.java

/**
 * Convert <code>resourceBundle</code> to usable {@link Properties}.
 *
 * @param resourceBundle//from w  w w. j  ava 2 s.  c o m
 *            ResourceBundle
 * @return Properties
 */
public static Properties getResourceBundleAsProperties(ResourceBundle resourceBundle) {
    Properties properties = new Properties();
    for (String key : resourceBundle.keySet()) {
        properties.put(key, resourceBundle.getObject(key));
    }

    return properties;
}

From source file:org.alfresco.web.app.ResourceBundleWrapper.java

/**
 * @see java.util.ResourceBundle#handleGetObject(java.lang.String)
 *///from  w w  w .j a v a 2 s  .c o  m
protected Object handleGetObject(String key) {
    Object result = null;

    for (ResourceBundle delegate : getDelegates()) {
        try {
            // Try and lookup the key from the resource bundle 
            result = delegate.getObject(key);
            if (result != null) {
                break;
            }
        } catch (MissingResourceException mre) {
            // ignore as this means the key was not present  
        }
    }

    // if the key was not found return a default string 
    if (result == null) {
        if (logger.isWarnEnabled() == true) {
            logger.warn("Failed to find I18N message key: " + key + " for locale: " + locale.toString());
        }

        result = "$$" + key + "$$";
    }

    return result;
}

From source file:org.hx.rainbow.common.util.PropertiesUtil.java

/**
 * ?.properties?Map/*  w  w w.  j  a  v  a2s  .c  o m*/
 * @param propertiesFile
 * @return
 */
public Map<String, Object> read(String propertiesFile) {

    @SuppressWarnings("unchecked")
    Map<String, Object> maps = (Map<String, Object>) map.get(propertiesFile);
    if (maps == null) {
        maps = new HashMap<String, Object>();
        ResourceBundle rb = ResourceBundle.getBundle(propertiesFile);
        Enumeration<String> enu = rb.getKeys();
        while (enu.hasMoreElements()) {
            String obj = enu.nextElement();
            Object objv = rb.getObject(obj);
            maps.put(obj, objv);
        }
        map.put(propertiesFile, maps);
    }
    return maps;
}

From source file:org.jtalks.jcommune.plugin.kaptcha.KaptchaPluginService.java

public String getHtml(HttpServletRequest request, String pluginId, Locale locale) {
    SecurityContextHolder.getContext();//w  w  w. j a  v  a2s.  c o m
    ResourceBundle resourceBundle = ResourceBundle.getBundle("org.jtalks.jcommune.plugin.kaptcha.messages",
            locale);

    VelocityEngine engine = new VelocityEngine(getProperties());
    engine.init();
    Map<String, Object> model = new HashMap<>();
    model.put(CAPTCHA_LABEL, resourceBundle.getObject("label.tip.captcha"));
    model.put(ALT_CAPTCHA, resourceBundle.getObject("alt.captcha.image"));
    model.put(ALT_REFRESH_CAPTCHA, resourceBundle.getObject("alt.captcha.update"));
    model.put(CAPTCHA_PLUGIN_ID, pluginId);
    model.put(FORM_ELEMENT_ID, getFormElementId(pluginId));
    model.put(BASE_URL, getDeploymentRootUrl(request));
    model.put(DATE, new DateTool());
    return VelocityEngineUtils.mergeTemplateIntoString(engine,
            "org/jtalks/jcommune/plugin/kaptcha/template/captcha.vm", "UTF-8", model);
}

From source file:org.kineticsystem.commons.util.Localizer.java

/** 
 * Helper method used to retrieve and return an object from a resource
 * bundle using the given searching key. It is used to avoid the problem of
 * fragile classes.//w w  w .j  a va2s.  c  o  m
 * @param resourceName The resource name.
 * @param key The resource key.
 * @return The localized object.
 */
private static Object doLocalize(String resourceName, String key) {
    Object localized = null;
    ResourceBundle resource = null;
    try {
        resource = ResourceBundle.getBundle(resourceName, locale);
    } catch (MissingResourceException ex) {
        logger.error(ex);
    }
    try {
        localized = resource.getObject(key);
    } catch (MissingResourceException ex) {
        logger.error(ex);
    }
    return localized;
}

From source file:org.paxml.bean.BundleTag.java

private Properties toProperties(ResourceBundle bundle) {
    Properties props = new Properties();
    Enumeration<String> en = bundle.getKeys();
    while (en.hasMoreElements()) {
        String key = en.nextElement();
        props.put(key, bundle.getObject(key));
    }// ww  w. j a  v  a2s. co  m
    return props;
}

From source file:org.pentaho.reporting.engine.classic.core.filter.ResourceFileFilter.java

/**
 * Returns the current value for the data source. The method will return null, if no datasource or no resource bundle
 * is defined or if the datasource's value is null.
 * <p/>/* w w  w . j a  v  a  2  s . c  om*/
 * The value read from the dataSource is looked up in the given resourcebundle using the
 * <code>ResourceBundle.getObject()</code> method. If the lookup fails, null is returned.
 *
 * @param runtime
 *          the expression runtime that is used to evaluate formulas and expressions when computing the value of this
 *          filter.
 * @param element
 * @return the value or null, if the value could not be looked up.
 */
public Object getValue(final ExpressionRuntime runtime, final ReportElement element) {
    if (dataSource == null) {
        return null;
    }
    if (runtime == null) {
        return null;
    }
    final Object value = dataSource.getValue(runtime, element);
    if (value == null) {
        return null;
    }
    final String svalue = String.valueOf(value);

    try {
        final String resourceId;
        if (resourceIdentifier != null) {
            resourceId = resourceIdentifier;
        } else {
            resourceId = runtime.getConfiguration()
                    .getConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY);
        }

        if (resourceId == null) {
            return null;
        }

        final ResourceBundleFactory resourceBundleFactory = runtime.getResourceBundleFactory();
        final ResourceBundle bundle = resourceBundleFactory.getResourceBundle(resourceId);
        if (bundle != null) {
            return bundle.getObject(svalue);
        }
    } catch (Exception e) {
        // on errors return null.
        ResourceFileFilter.logger.warn("Failed to retrive the value for key " + svalue);
    }
    return null;
}

From source file:org.sakaiproject.util.ResourceLoader.java

protected Map<String, Object> getBundleAsMap(ResourceBundle bundle) {
    Map<String, Object> bundleMap = new HashMap<String, Object>();

    for (Enumeration e = bundle.getKeys(); e.hasMoreElements();) {
        Object key = e.nextElement();
        bundleMap.put((String) key, bundle.getObject((String) key));
    }//from   w  w w . ja  v  a2s  .  c o  m

    return bundleMap;
}