Example usage for java.util Objects toString

List of usage examples for java.util Objects toString

Introduction

In this page you can find the example usage for java.util Objects toString.

Prototype

public static String toString(Object o, String nullDefault) 

Source Link

Document

Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

Usage

From source file:org.apache.struts2.config.entities.ConstantConfig.java

public Map<String, String> getAllAsStringsMap() {
    Map<String, String> map = new HashMap<>();

    map.put(StrutsConstants.STRUTS_DEVMODE, Objects.toString(devMode, null));
    map.put(StrutsConstants.STRUTS_I18N_RELOAD, Objects.toString(i18nReload, null));
    map.put(StrutsConstants.STRUTS_I18N_ENCODING, i18nEncoding);
    map.put(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, Objects.toString(configurationXmlReload, null));
    map.put(StrutsConstants.STRUTS_ACTION_EXTENSION, StringUtils.join(actionExtension, ','));
    map.put(StrutsConstants.STRUTS_ACTION_EXCLUDE_PATTERN, StringUtils.join(actionExcludePattern, ','));
    map.put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, Objects.toString(tagAltSyntax, null));
    map.put(StrutsConstants.STRUTS_URL_HTTP_PORT, Objects.toString(urlHttpPort, null));
    map.put(StrutsConstants.STRUTS_URL_HTTPS_PORT, Objects.toString(urlHttpsPort, null));
    map.put(StrutsConstants.STRUTS_URL_INCLUDEPARAMS, urlIncludeParams);
    map.put(StrutsConstants.STRUTS_URL_RENDERER, beanConfToString(urlRenderer));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY, beanConfToString(objectFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, beanConfToString(objectFactoryActionFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_RESULTFACTORY, beanConfToString(objectFactoryResultFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_CONVERTERFACTORY,
            beanConfToString(objectFactoryConverterFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_INTERCEPTORFACTORY,
            beanConfToString(objectFactoryInterceptorFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_VALIDATORFACTORY,
            beanConfToString(objectFactoryValidatorFactory));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_UNKNOWNHANDLERFACTORY,
            beanConfToString(objectFactoryUnknownHandlerFactory));
    map.put(StrutsConstants.STRUTS_OBJECTTYPEDETERMINER, beanConfToString(objectTypeDeterminer));
    map.put(StrutsConstants.STRUTS_LOCALE, locale == null ? null : locale.getLanguage());
    map.put(StrutsConstants.STRUTS_DISPATCHER_PARAMETERSWORKAROUND,
            Objects.toString(dispatcherParametersWorkaround, null));
    map.put(StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, beanConfToString(freemarkerManagerClassname));
    map.put(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY,
            freemarkerTemplatesCacheUpdateDelay);
    map.put(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE,
            Objects.toString(freemarkerBeanwrapperCache, null));
    map.put(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE,
            Objects.toString(freemarkerMruMaxStrongSize, null));
    map.put(StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, beanConfToString(velocityManagerClassname));
    map.put(StrutsConstants.STRUTS_VELOCITY_CONFIGFILE, velocityConfigfile);
    map.put(StrutsConstants.STRUTS_VELOCITY_TOOLBOXLOCATION, velocityToolboxlocation);
    map.put(StrutsConstants.STRUTS_VELOCITY_CONTEXTS, StringUtils.join(velocityContexts, ','));
    map.put(StrutsConstants.STRUTS_UI_TEMPLATEDIR, uiTemplateDir);
    map.put(StrutsConstants.STRUTS_UI_THEME, uiTheme);
    map.put(StrutsConstants.STRUTS_UI_THEME_EXPANSION_TOKEN, uiThemeExpansionToken);
    map.put(StrutsConstants.STRUTS_MULTIPART_MAXSIZE, Objects.toString(multipartMaxSize, null));
    map.put(StrutsConstants.STRUTS_MULTIPART_SAVEDIR, multipartSaveDir);
    map.put(StrutsConstants.STRUTS_MULTIPART_BUFFERSIZE, Objects.toString(multipartBufferSize, null));
    map.put(StrutsConstants.STRUTS_MULTIPART_PARSER, beanConfToString(multipartParser));
    map.put(StrutsConstants.STRUTS_MULTIPART_ENABLED, Objects.toString(multipartEnabled, null));
    map.put(StrutsConstants.STRUTS_MULTIPART_VALIDATION_REGEX,
            Objects.toString(multipartValidationRegex, null));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE, objectFactorySpringAutoWire);
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT,
            Objects.toString(objectFactorySpringAutoWireAlwaysRespect, null));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE,
            Objects.toString(objectFactorySpringUseClassCache, null));
    map.put(StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT,
            Objects.toString(objectFactorySpringEnableAopSupport, null));
    map.put(StrutsConstants.STRUTS_XSLT_NOCACHE, Objects.toString(xsltNocache, null));
    map.put(StrutsConstants.STRUTS_CUSTOM_PROPERTIES, StringUtils.join(customProperties, ','));
    map.put(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES, StringUtils.join(customI18nResources, ','));
    map.put(StrutsConstants.STRUTS_MAPPER_CLASS, beanConfToString(mapperClass));
    map.put(StrutsConstants.PREFIX_BASED_MAPPER_CONFIGURATION, StringUtils.join(mapperPrefixMapping, ','));
    map.put(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT, Objects.toString(serveStatic, null));
    map.put(StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE, Objects.toString(serveStaticBrowserCache, null));
    map.put(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION,
            Objects.toString(enableDynamicMethodInvocation, null));
    map.put(StrutsConstants.STRUTS_ENABLE_SLASHES_IN_ACTION_NAMES,
            Objects.toString(enableSlashesInActionNames, null));
    map.put(StrutsConstants.STRUTS_MAPPER_COMPOSITE, StringUtils.join(mapperComposite, ','));
    map.put(StrutsConstants.STRUTS_ACTIONPROXYFACTORY, beanConfToString(actionProxyFactory));
    map.put(StrutsConstants.STRUTS_FREEMARKER_WRAPPER_ALT_MAP, Objects.toString(freemarkerWrapperAltMap, null));
    map.put(StrutsConstants.STRUTS_XWORKCONVERTER, beanConfToString(xworkConverter));
    map.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE,
            Objects.toString(mapperAlwaysSelectFullNamespace, null));
    map.put(StrutsConstants.STRUTS_XWORKTEXTPROVIDER, beanConfToString(xworkTextProvider));
    map.put(StrutsConstants.STRUTS_LOCALE_PROVIDER, beanConfToString(localeProvider));
    map.put(StrutsConstants.STRUTS_LOCALE_PROVIDER_FACTORY, beanConfToString(localeProviderFactory));
    map.put(StrutsConstants.STRUTS_ID_PARAMETER_NAME, mapperIdParameterName);
    map.put(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS,
            Objects.toString(ognlAllowStaticMethodAccess, null));
    map.put(StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, beanConfToString(actionValidatorManager));
    map.put(StrutsConstants.STRUTS_VALUESTACKFACTORY, beanConfToString(valueStackFactory));
    map.put(StrutsConstants.STRUTS_REFLECTIONPROVIDER, beanConfToString(reflectionProvider));
    map.put(StrutsConstants.STRUTS_REFLECTIONCONTEXTFACTORY, beanConfToString(reflectionContextFactory));
    map.put(StrutsConstants.STRUTS_PATTERNMATCHER, beanConfToString(patternMatcher));
    map.put(StrutsConstants.STRUTS_STATIC_CONTENT_LOADER, beanConfToString(staticContentLoader));
    map.put(StrutsConstants.STRUTS_UNKNOWN_HANDLER_MANAGER, beanConfToString(unknownHandlerManager));
    map.put(StrutsConstants.STRUTS_EL_THROW_EXCEPTION, Objects.toString(elThrowExceptionOnFailure, null));
    map.put(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, Objects.toString(ognlLogMissingProperties, null));
    map.put(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE,
            Objects.toString(ognlEnableExpressionCache, null));
    map.put(StrutsConstants.STRUTS_ENABLE_OGNL_EVAL_EXPRESSION,
            Objects.toString(ognlEnableOGNLEvalExpression, null));
    map.put(StrutsConstants.STRUTS_DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP,
            Objects.toString(disableRequestAttributeValueStackLookup, null));
    map.put(StrutsConstants.STRUTS_URL_HELPER, beanConfToString(viewUrlHelper));
    map.put(StrutsConstants.STRUTS_CONVERTER_COLLECTION, beanConfToString(converterCollection));
    map.put(StrutsConstants.STRUTS_CONVERTER_ARRAY, beanConfToString(converterArray));
    map.put(StrutsConstants.STRUTS_CONVERTER_DATE, beanConfToString(converterDate));
    map.put(StrutsConstants.STRUTS_CONVERTER_NUMBER, beanConfToString(converterNumber));
    map.put(StrutsConstants.STRUTS_CONVERTER_STRING, beanConfToString(converterString));
    map.put(StrutsConstants.STRUTS_HANDLE_EXCEPTION, Objects.toString(handleException, null));
    map.put(StrutsConstants.STRUTS_CONVERTER_PROPERTIES_PROCESSOR,
            beanConfToString(converterPropertiesProcessor));
    map.put(StrutsConstants.STRUTS_CONVERTER_FILE_PROCESSOR, beanConfToString(converterFileProcessor));
    map.put(StrutsConstants.STRUTS_CONVERTER_ANNOTATION_PROCESSOR,
            beanConfToString(converterAnnotationProcessor));
    map.put(StrutsConstants.STRUTS_CONVERTER_CREATOR, beanConfToString(converterCreator));
    map.put(StrutsConstants.STRUTS_CONVERTER_HOLDER, beanConfToString(ConverterHolder));
    map.put(StrutsConstants.STRUTS_EXPRESSION_PARSER, beanConfToString(expressionParser));
    map.put(StrutsConstants.STRUTS_ALLOWED_ACTION_NAMES, Objects.toString(allowedActionNames, null));
    map.put(StrutsConstants.STRUTS_DEFAULT_ACTION_NAME, defaultActionName);
    map.put(StrutsConstants.STRUTS_ALLOWED_METHOD_NAMES, Objects.toString(allowedMethodNames, null));
    map.put(StrutsConstants.STRUTS_DEFAULT_METHOD_NAME, defaultMethodName);
    map.put(StrutsConstants.STRUTS_MAPPER_ACTION_PREFIX_ENABLED,
            Objects.toString(mapperActionPrefixEnabled, null));
    map.put(StrutsConstants.STRUTS_MAPPER_ACTION_PREFIX_CROSSNAMESPACES,
            Objects.toString(mapperActionPrefixCrossNamespaces, null));
    map.put(StrutsConstants.DEFAULT_TEMPLATE_TYPE_CONFIG_KEY, uiTemplateSuffix);
    map.put(StrutsConstants.STRUTS_DISPATCHER_ERROR_HANDLER, beanConfToString(dispatcherErrorHandler));
    map.put(StrutsConstants.STRUTS_EXCLUDED_CLASSES, classesToString(excludedClasses));
    map.put(StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS,
            StringUtils.join(excludedPackageNamePatterns, ','));
    map.put(StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES, StringUtils.join(excludedPackageNames, ','));
    map.put(StrutsConstants.STRUTS_EXCLUDED_PATTERNS_CHECKER, beanConfToString(excludedPatternsChecker));
    map.put(StrutsConstants.STRUTS_ACCEPTED_PATTERNS_CHECKER, beanConfToString(acceptedPatternsChecker));
    map.put(StrutsConstants.STRUTS_OVERRIDE_EXCLUDED_PATTERNS, StringUtils.join(overrideExcludedPatterns, ','));
    map.put(StrutsConstants.STRUTS_OVERRIDE_ACCEPTED_PATTERNS, StringUtils.join(overrideAcceptedPatterns, ','));
    map.put(StrutsConstants.STRUTS_ADDITIONAL_EXCLUDED_PATTERNS,
            StringUtils.join(additionalExcludedPatterns, ','));
    map.put(StrutsConstants.STRUTS_ADDITIONAL_ACCEPTED_PATTERNS,
            StringUtils.join(additionalAcceptedPatterns, ','));
    map.put(StrutsConstants.STRUTS_CONTENT_TYPE_MATCHER, beanConfToString(contentTypeMatcher));
    map.put(StrutsConstants.STRUTS_SMI_METHOD_REGEX, strictMethodInvocationMethodRegex);
    map.put(StrutsConstants.STRUTS_TEXT_PROVIDER_FACTORY, beanConfToString(textProviderFactory));
    map.put(StrutsConstants.STRUTS_LOCALIZED_TEXT_PROVIDER, beanConfToString(localizedTextProvider));
    map.put(StrutsConstants.STRUTS_DISALLOW_PROXY_MEMBER_ACCESS,
            Objects.toString(disallowProxyMemberAccess, null));
    map.put(StrutsConstants.STRUTS_OGNL_AUTO_GROWTH_COLLECTION_LIMIT,
            Objects.toString(ognlAutoGrowthCollectionLimit, null));

    return map;/*from ww w.j a  v  a2s  .  com*/
}

From source file:com.formkiq.core.form.service.FormValidatorServiceImpl.java

/**
 * Validate Field formatter.// w  w  w  . j  ava  2  s . co m
 * @param form {@link FormJSON}
 * @param field {@link FormJSONField}
 * @param value {@link String}
 * @param errors {@link Map}
 */
private void validateFieldCustomFormatter(final FormJSON form, final FormJSONField field, final String value,
        final Map<String, String> errors) {

    String formatter = Objects.toString(field.getFormatter(), "");
    if ("Custom".equals(formatter)) {

        String placeholder = Objects.toString(field.getPlaceholder(), "");

        if (value.length() > 0 && value.length() != placeholder.length()) {
            errors.put(String.valueOf(field.getId()), "Field required");
        }
    }
}

From source file:org.jenkinsci.plugins.drupal.beans.DrushInvocation.java

/**
 * Get a map of projects installed on Drupal, keyed by machine name.
 *//*from   www . j a v a 2s. c om*/
public Map<String, DrupalExtension> getProjects(boolean modulesOnly, boolean enabledOnly) {
    ArgumentListBuilder args = getArgumentListBuilder();
    args.add("pm-list").add("--pipe").add("--format=json");
    if (modulesOnly) {
        args.add("--type=module");
    }
    if (enabledOnly) {
        args.add("--status=enabled");
    }

    OutputStream json = new ByteArrayOutputStream();
    try {
        execute(args, new StreamTaskListener(json));
    } catch (IOException e1) {
        listener.getLogger().println(e1);
        return MapUtils.EMPTY_MAP;
    } catch (InterruptedException e2) {
        listener.getLogger().println(e2);
        return MapUtils.EMPTY_MAP;
    }

    Map<String, DrupalExtension> projects = new HashMap<String, DrupalExtension>();
    JSONObject entries = (JSONObject) JSONValue.parse(json.toString());
    if (entries == null) {
        listener.getLogger().println("[DRUPAL] Could not list available projects");
        return MapUtils.EMPTY_MAP;
    }
    for (Object name : entries.keySet()) {
        JSONObject entry = (JSONObject) entries.get(name);
        DrupalExtension project = new DrupalExtension(Objects.toString(name, ""),
                Objects.toString(entry.get("type"), ""), Objects.toString(entry.get("status"), ""),
                Objects.toString(entry.get("version"), ""));
        projects.put(name.toString(), project);
    }

    return projects;
}

From source file:eu.itesla_project.online.tools.RunWcaOnStateTool.java

@Override
public void run(CommandLine line) throws Exception {
    String workflowId = line.getOptionValue("workflow");
    Integer stateId = Integer.valueOf(line.getOptionValue("state"));
    System.out.println("loading state " + stateId + " of workflow " + workflowId + " from the online db ...");
    OnlineConfig config = OnlineConfig.load();
    OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create();
    // load the network
    Network network = onlinedb.getState(workflowId, stateId);
    if (network != null) {
        OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflowId);
        String offlineWorkflowId = parameters.getOfflineWorkflowId();
        if (line.hasOption("offline-workflow"))
            offlineWorkflowId = line.getOptionValue("offline-workflow");
        Interval histoInterval = parameters.getHistoInterval();
        if (line.hasOption("history-interval"))
            histoInterval = Interval.parse(line.getOptionValue("history-interval"));
        double purityThreshold = parameters.getRulesPurityThreshold();
        if (line.hasOption("purity-threshold"))
            purityThreshold = Double.parseDouble(line.getOptionValue("purity-threshold"));
        Set<SecurityIndexType> securityIndexTypes = parameters.getSecurityIndexes();
        if (line.hasOption("security-index-types")) {
            securityIndexTypes = Arrays.stream(line.getOptionValue("security-index-types").split(","))
                    .map(SecurityIndexType::valueOf).collect(Collectors.toSet());
        }//from w  ww  .j av  a 2s. com
        boolean stopWcaOnViolations = DEFAULT_STOP_WCA_ON_VIOLATIONS;
        if (line.hasOption("stop-on-violations")) {
            stopWcaOnViolations = Boolean.parseBoolean(line.getOptionValue("stop-on-violations"));
        }
        ComputationManager computationManager = new LocalComputationManager();
        network.getStateManager().allowStateMultiThreadAccess(true);
        WCAParameters wcaParameters = new WCAParameters(histoInterval, offlineWorkflowId, securityIndexTypes,
                purityThreshold, stopWcaOnViolations);
        ContingenciesAndActionsDatabaseClient contingenciesDb = config.getContingencyDbClientFactoryClass()
                .newInstance().create();
        LoadFlowFactory loadFlowFactory = config.getLoadFlowFactoryClass().newInstance();
        try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create();
                RulesDbClient rulesDbClient = config.getRulesDbClientFactoryClass().newInstance()
                        .create("rulesdb")) {
            UncertaintiesAnalyserFactory uncertaintiesAnalyserFactory = config
                    .getUncertaintiesAnalyserFactoryClass().newInstance();
            WCA wca = config.getWcaFactoryClass().newInstance().create(network, computationManager,
                    histoDbClient, rulesDbClient, uncertaintiesAnalyserFactory, contingenciesDb,
                    loadFlowFactory);
            WCAResult result = wca.run(wcaParameters);
            Table table = new Table(7, BorderStyle.CLASSIC_WIDE);
            table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Cluster 1", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Cluster 2", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Cluster 3", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Cluster 4", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Undefined", new CellStyle(CellStyle.HorizontalAlign.center));
            table.addCell("Cause", new CellStyle(CellStyle.HorizontalAlign.center));
            for (WCACluster cluster : result.getClusters()) {
                table.addCell(cluster.getContingency().getId());
                int[] clusterIndexes = new int[] { 1, 2, 3, 4, -1 };
                for (int k = 0; k < clusterIndexes.length; k++) {
                    if (clusterIndexes[k] == cluster.getNum().toIntValue()) {
                        table.addCell("X", new CellStyle(CellStyle.HorizontalAlign.center));
                    } else {
                        table.addCell("-", new CellStyle(CellStyle.HorizontalAlign.center));
                    }
                }
                table.addCell(Objects.toString(cluster.getCauses(), ""),
                        new CellStyle(CellStyle.HorizontalAlign.center));
            }
            System.out.println(table.render());
        }
    }
}

From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java

/**
 * ??/*from  ww  w .  j av  a 2 s . c o  m*/
 * 
 * @param params
 * @return
 */
@POST
@Path("/preOrder")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> preOrder(String params) {
    Map<String, Object> req = new HashMap<>();
    JSONObject obj = JSONObject.parseObject(params);

    //????
    String businessNo = "9056";

    String uno = obj.getString("uno");
    String prod_no = Objects.toString(obj.getString("packageNo"), "0");
    Float orderPrice = obj.getFloat("price");
    int price = (int) (orderPrice * 100);
    String pay_way = obj.getString("pay_way");
    String service_time = obj.getString("service_time");
    int use_date = obj.getIntValue("use_date");
    String service_end_time = obj.getString("service_end_time");
    String remark = obj.getString("remark");
    String orderNo = obj.getString("orderNo");

    PackageProduct packageProduct = packageProductBean.findByPackageNo(prod_no);

    if (packageProduct != null) {
        MemberOrder order = null;
        Long id = 0L;
        //??
        if (orderNo != null) {
            order = memberOrderBean.findByOrderNo(orderNo);
            if (order != null) {
                if ("3".equals(pay_way) || "4".equals(pay_way)) {
                    String str = new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
                    order.setPayNo(str + "-" + businessNo + "-" + OrderNoUtil.getOrderNo("OR"));
                } else {
                    order.setPayNo(OrderNoUtil.getOrderNo("OR"));
                }
                order.setPayWay(pay_way);
                memberOrderBean.updateOrder(order);
                id = order.getId();
            }
        } else {
            order = new MemberOrder();
            order.setMemberNumber(uno);
            order.setOrderTime(new Date());
            order.setPackageNo(prod_no);
            order.setPackageName(packageProduct.getSubject());
            order.setPackageType(packageProduct.getType());
            order.setPackageDesc(packageProduct.getDesc());
            if ("3".equals(pay_way) || "4".equals(pay_way)) {
                String str = new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
                order.setOrderNo(str + "-" + businessNo + "-" + OrderNoUtil.getOrderNo("OR"));
            } else {
                order.setOrderNo(OrderNoUtil.getOrderNo("OR"));
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            try {
                order.setServiceTime(sdf.parse(service_time));
            } catch (ParseException e1) {
                e1.printStackTrace();
                order.setServiceTime(new Date());
            }

            try {
                if (service_end_time != null) {
                    order.setServiceEndTime(sdf.parse(service_end_time));
                }
            } catch (ParseException e1) {
                e1.printStackTrace();
                order.setServiceTime(new Date(System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000));
            }

            order.setSurplusCallDuration(packageProduct.getSurplusCallDuration() * use_date);
            order.setUseDate(use_date);
            order.setUseState(OrderUseStatus.PERPARE);
            order.setState(OrderStatus.CREATED);
            order.setOrderPrice(String.valueOf(orderPrice));
            order.setPayWay(pay_way);
            order.setRemark(remark);
            order.setPayNo(order.getOrderNo());

            id = memberOrderBean.createOrder(order);
        }

        Map<String, Object> chargeMap = new HashMap<String, Object>();
        Charge charge;
        if (id > 0) {
            //??app
            chargeMap.put("amount", price);
            chargeMap.put("currency", "cny");
            chargeMap.put("subject", order.getPackageName());
            chargeMap.put("body", "Your Body");
            chargeMap.put("order_no", order.getPayNo());

            switch (pay_way) {
            case "0":
                req.put("order_no", order.getPayNo());
                req.put("amount", price);
                req.put("pay_way", order.getPayWay());
                req.put("credential", "");
                req.put("error_code", "000000");
                req.put("error_msg", "");
                break;
            case "1":
                chargeMap.put("channel", "alipay");
                chargeMap.put("client_ip", "127.0.0.1");
                try {
                    charge = paymentBean.charge(chargeMap);
                    //                     order.setCredential(JSONObject.toJSONString(charge)
                    //                           .toString());
                    //                     orderBean.updateOrder(order);
                    req.put("charge", JSONObject.toJSONString(charge).toString());
                    req.put("order_no", order.getPayNo());
                    req.put("amount", price);
                    req.put("pay_way", order.getPayWay());
                    //                     req.put("credential", order.getCredential());
                    req.put("error_code", "000000");
                    req.put("error_msg", "");
                } catch (Exception e) {
                    log.info(e.getMessage());
                    order.setState(OrderStatus.CANCELLED);
                    memberOrderBean.updateOrder(order);
                    req.put("result", "fail");
                    req.put("error_code", "5001");
                    req.put("error_msg", "");
                }
                break;
            case "2":
                chargeMap.put("channel", "wx");
                chargeMap.put("client_ip", "127.0.0.1");
                chargeMap.put("order_no", order.getPayNo());
                //Integer am = order.getAmount().multiply(new BigDecimal(100)).;
                chargeMap.put("amount", price);
                try {
                    charge = paymentBean.charge(chargeMap);
                    //                     order.setCredential(JSONObject.toJSONString(charge)
                    //                           .toString());
                    //                     orderBean.updateOrder(order);
                    req.put("charge", JSONObject.toJSONString(charge).toString());
                    req.put("charge_id", charge.getId());
                    req.put("order_no", order.getPayNo());
                    req.put("amount", order.getOrderPrice());
                    req.put("pay_way", order.getPayWay());
                    //                     req.put("credential", order.getCredential());
                    req.put("error_code", "000000");
                    req.put("error_msg", "");
                } catch (Exception e) {
                    order.setState(OrderStatus.CANCELLED);
                    memberOrderBean.updateOrder(order);
                    log.info(e.getMessage());
                    req.put("result", "fail");
                    req.put("error_code", "5001");
                    req.put("error_msg", "");
                }
                break;
            case "3":
                req.put("order_no", order.getPayNo());
                req.put("amount", order.getOrderPrice());
                req.put("pay_way", order.getPayWay());
                req.put("business_no", businessNo);
                req.put("key", "test");
                //                  req.put("credential", "");
                req.put("error_code", "000000");
                req.put("error_msg", "");
                break;
            case "4":
                req.put("order_no", order.getPayNo());
                req.put("amount", order.getOrderPrice());
                req.put("pay_way", order.getPayWay());
                req.put("businessNo", businessNo);
                req.put("key", "test");
                //                  req.put("credential", "");
                req.put("error_code", "000000");
                req.put("error_msg", "");
                break;
            }
        } else {
            req.put("result", "fail");
            req.put("error_code", "5005");
            req.put("error_msg", "??");
        }

    } else {
        req.put("result", "fail");
        req.put("error_code", "5005");
        req.put("error_msg", "??");
    }
    return req;
}

From source file:com.norconex.importer.ImporterConfig.java

@Override
public void saveToXML(Writer out) throws IOException {
    try {//  w  w  w  . ja  v  a  2  s  .  c o m
        EnhancedXMLStreamWriter writer = new EnhancedXMLStreamWriter(out);
        writer.writeStartElement("importer");
        writer.writeElementString("tempDir", getTempDir().toString());
        writer.writeElementString("parseErrorsSaveDir", Objects.toString(getParseErrorsSaveDir(), null));
        writer.writeElementInteger("maxFileCacheSize", getMaxFileCacheSize());
        writer.writeElementInteger("maxFilePoolCacheSize", getMaxFilePoolCacheSize());
        writer.flush();

        writeHandlers(out, "preParseHandlers", getPreParseHandlers());
        writeObject(out, "documentParserFactory", getParserFactory());
        writeHandlers(out, "postParseHandlers", getPostParseHandlers());
        writeResponseProcessors(out, "responseProcessors", getResponseProcessors());

        writer.writeEndElement();
    } catch (XMLStreamException e) {
        throw new IOException("Could not save importer config.", e);
    }
}

From source file:org.openhab.io.dropbox.internal.DropboxService.java

@SuppressWarnings("rawtypes")
@Override/*from   w  ww .  j a  v  a2s . co m*/
public void updated(Dictionary config) throws ConfigurationException {
    if (config == null) {
        logger.debug("Updated() was called with a null config!");
        return;
    }

    DropboxSynchronizer synchronizer = getDropboxSynchronizer();

    String appKeyString = Objects.toString(config.get("appkey"), null);
    if (isNotBlank(appKeyString)) {
        appKey = appKeyString;
    }

    String appSecretString = Objects.toString(config.get("appsecret"), null);
    if (isNotBlank(appSecretString)) {
        appSecret = appSecretString;
    }

    String pat = Objects.toString(config.get("personalAccessToken"), null);
    if (isNotBlank(pat)) {
        personalAccessToken = pat;
    }

    if (logger.isDebugEnabled()) {
        StringBuffer message = new StringBuffer();
        message.append("Authentication parameters to be used:\r\n");
        if (isNotBlank(personalAccessToken)) {
            message.append("     Personal access token = " + personalAccessToken + "\r\n");
        } else {
            message.append("     appkey = " + appKey + "\r\n");
            message.append("  appsecret = " + appSecret + "\r\n");
        }
        logger.debug(message.toString());
    }

    if (isBlank(personalAccessToken) && (isBlank(appKey) || isBlank(appSecret))) {
        throw new ConfigurationException("dropbox:authentication",
                "The Dropbox authentication parameters are incorrect!  "
                        + "The parameter 'personalAccesstoken' must be set, or both of"
                        + " the parameters 'appkey' and 'appsecret' must be set. Please"
                        + " check your configuration.");
    } else if (isNotBlank(appKey) && isNotBlank(appSecret)) {
        appInfo = new DbxAppInfo(appKey, appSecret);
    }

    String fakeModeString = Objects.toString(config.get("fakemode"), null);
    if (isNotBlank(fakeModeString)) {
        synchronizer.setFakeMode(BooleanUtils.toBoolean(fakeModeString));
    }

    String contentDirString = Objects.toString(config.get("contentdir"), null);
    synchronizer.setContentDir(contentDirString);

    String uploadIntervalString = Objects.toString(config.get("uploadInterval"), null);
    if (isNotBlank(uploadIntervalString)) {
        uploadInterval = uploadIntervalString;
    }

    String downloadIntervalString = Objects.toString(config.get("downloadInterval"), null);
    if (isNotBlank(downloadIntervalString)) {
        downloadInterval = downloadIntervalString;
    }

    String syncModeString = Objects.toString(config.get("syncmode"), null);
    if (isNotBlank(syncModeString)) {
        try {
            syncMode = DropboxSyncMode.valueOf(syncModeString.toUpperCase());
        } catch (IllegalArgumentException iae) {
            throw new ConfigurationException("dropbox:syncmode", "Unknown SyncMode '" + syncModeString
                    + "'. Valid SyncModes are 'DROPBOX_TO_LOCAL', 'LOCAL_TO_DROPBOX' and 'BIDIRECTIONAL'.");
        }
    }

    String uploadFilterString = Objects.toString(config.get("uploadfilter"), null);
    if (isNotBlank(uploadFilterString)) {
        String[] newFilterElements = uploadFilterString.split(",");
        synchronizer.setUploadFilterElements(Arrays.asList(newFilterElements));
    }

    String downloadFilterString = Objects.toString(config.get("downloadfilter"), null);
    if (isNotBlank(downloadFilterString)) {
        String[] newFilterElements = downloadFilterString.split(",");
        synchronizer.setDownloadFilterElements(Arrays.asList(newFilterElements));
    }

    // we got this far, so we define this synchronizer as properly configured ...
    isProperlyConfigured = true;
    logger.debug("Dropbox I/O is properly configured. Activating synchronizer.");
    activateSynchronizer();
}

From source file:org.kitodo.config.ConfigProject.java

/**
 * Determine a list of configuration parameters.
 *
 * @return Parameter als List/*from   ww w.  j av  a2 s  . c o m*/
 */
public List<String> getParamList(String parameter) {
    try {
        List<Object> configs = this.config.getList(this.projectTitle + parameter);
        return configs.stream().map(object -> Objects.toString(object, null)).collect(Collectors.toList());
    } catch (RuntimeException e) {
        logger.error(e.getMessage(), e);
        return new ArrayList<>();
    }
}

From source file:com.github.helenusdriver.driver.impl.TypeClassInfoImpl.java

/**
 * {@inheritDoc}// ww w .  j av  a 2 s .co  m
 *
 * @author paouelle
 *
 * @see com.github.helenusdriver.driver.impl.ClassInfoImpl#getObject(com.datastax.driver.core.Row, java.util.Map)
 */
@Override
public T getObject(Row row, Map<String, Object> suffixes) {
    if (row == null) {
        return null;
    }
    // extract the type so we know which object we are creating
    for (final ColumnDefinitions.Definition coldef : row.getColumnDefinitions()) {
        // find the table for this column
        final TableInfoImpl<T> table = (TableInfoImpl<T>) getTable(coldef.getTable());

        if (table != null) {
            // find the field in the table for this column
            final FieldInfoImpl<T> field = table.getColumn(coldef.getName());

            if ((field != null) && field.isTypeKey()) { // get the POJO type
                return getObject(row, Objects.toString(field.decodeValue(row), null), suffixes);
            }
        }
    }
    throw new ObjectConversionException(clazz, row, "missing POJO type column");
}

From source file:com.hubspot.jinjava.interpret.JinjavaInterpreter.java

/**
 * Resolve a variable into a string value. If given a string literal (e.g. 'foo' or "foo"), this method returns the literal unquoted. If the variable is undefined in the context, this method returns the given variable string.
 *
 * @param variable//from  w ww  . ja va 2s  .com
 *          name of variable in context
 * @param lineNumber
 *          current line number, for error reporting
 * @return resolved value for variable
 */
public String resolveString(String variable, int lineNumber) {
    return Objects.toString(resolveObject(variable, lineNumber), "");
}