Example usage for org.apache.commons.lang StringUtils defaultString

List of usage examples for org.apache.commons.lang StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultString.

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:gtu._work.ui.PropertyEditUI.java

private String getChs2Big5(String value) {
    try {//from  w ww  .ja v  a 2  s .com
        value = StringUtils.defaultString(value);
        value = value.replace((char) 65292, ',');
        value = value.replace((char) 65288, '(');
        value = value.replace((char) 65289, ')');
        value = value.replace((char) 65307, ';');
        value = value.replace((char) 65306, ':');
        value = value.replace((char) 8220, '"');
        value = value.replace((char) 8221, '"');
        value = value.replace((char) 12289, ',');
        value = value.replaceAll("", "...");
        try {
            value = JChineseConvertor.getInstance().s2t(value);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return value;
}

From source file:gtu._work.ui.EstoreCodeGenerateUI.java

private void updateBtnActionPerformed(ActionEvent evt) {
    //[jsp] /src/main/webapp/jsp/backend/marketing/littleWebHomepageApplyMaintain/littleWebHomepageApplyMaintainInit.jsp
    //[action] /src/main/java/com/sti/estore/backend/web/action/marketing/littleWebHomepageApplyMaintain/LittleWebHomepageApplyMaintainAction.java
    //[serviceImpl] /src/main/java/com/sti/estore/service/impl/LittleWebHomepageApplyMaintainServiceImpl.java
    //[serviceInterface] /src/main/java/com/sti/estore/service/LittleWebHomepageApplyMaintainService.java

    String className = StringUtils.defaultString(classNameText.getText());
    String packageMiddleName = StringUtils.defaultString(packageMiddleNameText.getText());
    String jspPath = StringUtils.defaultString(jspPathText.getText());
    String actionPath = StringUtils.defaultString(actionPathText.getText());
    String serviceInterface = StringUtils.defaultString(serviceInterfaceText.getText());
    String serviceImpl = StringUtils.defaultString(serviceImplText.getText());

    String lowerCaseClassName = className.substring(0, 1).toLowerCase() + className.substring(1);
    Validate.notBlank(className, "??");
    if (StringUtils.isBlank(packageMiddleName)) {
        packageMiddleName = lowerCaseClassName;
        packageMiddleNameText.setText(packageMiddleName);
    }//from w  ww. j av  a  2s  .  co m

    jspPath = String.format("/src/main/webapp/jsp/backend/marketing/%s/%s.jsp", packageMiddleName,
            lowerCaseClassName);
    actionPath = String.format("/src/main/java/com/sti/estore/backend/web/action/marketing/%s/%sAction.java",
            packageMiddleName, className);
    serviceInterface = String.format("/src/main/java/com/sti/estore/service/%sService.java", className);
    serviceImpl = String.format("/src/main/java/com/sti/estore/service/impl/%sServiceImpl.java", className);

    jspPathText.setText(jspPath);
    actionPathText.setText(actionPath);
    serviceInterfaceText.setText(serviceInterface);
    serviceImplText.setText(serviceImpl);

    jspPath = jspPath.replaceFirst("/src/main/webapp", "");

    //%1$s - ?class
    //%2$s - package
    //%3$s - class
    //%4$s - jsp
    String configMessage = String.format(REPLACE_MESSAGE, lowerCaseClassName, packageMiddleName, className,
            jspPath);
    xmlConfigArea.setText(configMessage);
}

From source file:com.redhat.rhn.manager.kickstart.KickstartScheduleCommand.java

/**
 * Create ExtraOptions string/*from  ww  w. jav a  2s.c o  m*/
 * @return extraOptions that will be appended to the Kickstart.
 */
public String getExtraOptions() {
    StringBuilder retval = new StringBuilder();
    String kOptions = StringUtils.defaultString(kernelOptions);
    /** Some examples:
    dhcp:eth0 , dhcp:eth2, static:10.1.4.75
    static:146.108.30.184, static:auto, static:eth0
     */
    if (!StringUtils.isBlank(networkInterface)) {
        if (!LINK_NETWORK_TYPE.equals(networkInterface)) {
            // Get rid of the dhcp:
            String params = " ksdevice=" + networkInterface;
            if (!kOptions.contains("ksdevice")) {
                retval.append(params);
            }
        }
    } else if (!kOptions.contains("ksdevice")) {
        retval.append("ksdevice=" + ConfigDefaults.get().getDefaultKickstartNetworkInterface());
    }
    retval.append(" ").append(kOptions);
    return retval.toString();
}

From source file:gtu._work.ui.EstoreCodeGenerateUI.java

private void makeFileBtnActionPerformed(ActionEvent evt) throws IOException {
    String className = StringUtils.defaultString(classNameText.getText());
    String packageMiddleName = StringUtils.defaultString(packageMiddleNameText.getText());
    String jspPath = StringUtils.defaultString(jspPathText.getText());
    String actionPath = StringUtils.defaultString(actionPathText.getText());
    String serviceInterface = StringUtils.defaultString(serviceInterfaceText.getText());
    String serviceImpl = StringUtils.defaultString(serviceImplText.getText());

    String lowerCaseClassName = className.substring(0, 1).toLowerCase() + className.substring(1);
    Validate.notBlank(className, "??");
    if (StringUtils.isBlank(packageMiddleName)) {
        packageMiddleName = lowerCaseClassName;
    }//from   ww w.  ja va  2 s. c  om

    String actionPath2 = actionPath.replaceAll("/src/main/java/", "").replaceAll(className + "Action.java", "")
            .replace('/', '.');
    String serviceInterfacePath2 = serviceInterface.replaceAll("/src/main/java/", "")
            .replaceAll(className + "Service.java", "").replace('/', '.');
    String serviceImplPath2 = serviceImpl.replaceAll("/src/main/java/", "")
            .replaceAll(className + "ServiceImpl.java", "").replace('/', '.');
    actionPath2 = actionPath2.substring(0, actionPath2.length() - 1);
    serviceInterfacePath2 = serviceInterfacePath2.substring(0, serviceInterfacePath2.length() - 1);
    serviceImplPath2 = serviceImplPath2.substring(0, serviceImplPath2.length() - 1);

    System.out.println(actionPath2);
    System.out.println(serviceInterfacePath2);
    System.out.println(serviceImplPath2);

    // %1$s - package
    // %2$s - class
    // %3$s - ?class
    String actionMessage = String.format(ACTION_DATA, actionPath2, className, lowerCaseClassName);

    // %1$s - package
    // %2$s - class
    String serviceInterfaceMessage = String.format(SERVICE_INTERFACE, serviceInterfacePath2, className);

    // %1$s - package
    // %2$s - class
    String serviceImplMessage = String.format(SERVICE_IMPL, serviceImplPath2, className);

    File jspFile = new File(FileUtil.DESKTOP_DIR, jspPath);
    File actionFile = new File(FileUtil.DESKTOP_DIR, actionPath);
    File serviceInterfaceFile = new File(FileUtil.DESKTOP_DIR, serviceInterface);
    File serviceImplFile = new File(FileUtil.DESKTOP_DIR, serviceImpl);

    System.out.println(jspFile);
    System.out.println(actionFile);
    System.out.println(serviceInterfaceFile);
    System.out.println(serviceImplFile);

    jspFile.getParentFile().mkdirs();
    actionFile.getParentFile().mkdirs();
    serviceInterfaceFile.getParentFile().mkdirs();
    serviceImplFile.getParentFile().mkdirs();

    FileUtils.write(jspFile, "", "utf8");
    FileUtils.write(actionFile, actionMessage, "utf8");
    FileUtils.write(serviceInterfaceFile, serviceInterfaceMessage, "utf8");
    FileUtils.write(serviceImplFile, serviceImplMessage, "utf8");

    JCommonUtil._jOptionPane_showMessageDialog_info("?!");
}

From source file:com.raddle.tools.MergeMain.java

private void updatePropertyLine(PropertyLine pl) {
    if (pl != null) {
        if (pl.getState() == LineState.deleted) {
            JOptionPane.showMessageDialog(MergeMain.this, pl.getKey() + "?");
        } else {//from  w  ww  .  ja  va 2 s. c o m
            StringBuilder sb = new StringBuilder();
            sb.append(": ");
            if (pl.getComment() != null) {
                sb.append(pl.getComment());
            }
            sb.append('\n');
            sb.append(": " + pl.getKey()).append('\n');
            ;
            sb.append(": " + StringUtils.defaultString(pl.getOriginalValue()));
            String v = JOptionPane.showInputDialog(MergeMain.this, sb.toString(), pl.getValue());
            if (v != null && !v.trim().equals(pl.getValue())) {
                if (pl.getState() != LineState.added && pl.getState() != LineState.deleted) {
                    pl.setState(LineState.updated);
                }
                pl.setValue(v);
                if (pl.getValue().equals(pl.getOriginalValue())) {
                    pl.setState(LineState.original);
                }
                compare();
            }
        }
    }
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * List the child channels that this system can subscribe to.
 * @param loggedInUser The current user//from w ww. j  av a2  s. c o  m
 * @param sid The id of the system in question
 * @return Returns an array of maps representing the channels this server could
 * subscribe too.
 * @throws FaultException A FaultException is thrown if the server corresponding to
 * sid cannot be found.
 *
 * @xmlrpc.doc Returns a list of subscribable child channels.  This only shows channels
 * the system is *not* currently subscribed to.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "serverId")
 * @xmlrpc.returntype
 *      #array()
 *          #struct("child channel")
 *              #prop("int", "id")
 *              #prop("string", "name")
 *              #prop("string", "label")
 *              #prop("string", "summary")
 *              #prop("string", "has_license")
 *              #prop("string", "gpg_key_url")
 *          #struct_end()
 *      #array_end()
 */
public Object[] listSubscribableChildChannels(User loggedInUser, Integer sid) throws FaultException {
    // Get the logged in user and server
    Server server = lookupServer(loggedInUser, sid);
    Channel baseChannel = server.getBaseChannel();
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();

    //make sure channel is not null
    if (baseChannel == null) {
        //return empty array since we can't have any child channels without a base
        return returnList.toArray();
    }

    DataResult<Map<String, Object>> dr = SystemManager.subscribableChannels(server.getId(),
            loggedInUser.getId(), baseChannel.getId());

    //TODO: This should go away once we teach marquee how to deal with nulls in a list.
    //      Luckily, this list shouldn't be too long.
    for (Iterator<Map<String, Object>> itr = dr.iterator(); itr.hasNext();) {
        Map<String, Object> row = itr.next();
        Map<String, Object> channel = new HashMap<String, Object>();

        channel.put("id", row.get("id"));
        channel.put("label", row.get("label"));
        channel.put("name", row.get("name"));
        channel.put("summary", row.get("summary"));
        channel.put("has_license", "");
        channel.put("gpg_key_url", StringUtils.defaultString((String) row.get("gpg_key_url")));

        returnList.add(channel);
    }

    return returnList.toArray();
}

From source file:com.medicaid.mmis.util.DataLoader.java

/**
 * Parses the names and sets it to the owner.
 * @param person the person to set to//www . j  av  a2s.c  o m
 * @param fullname the full name
 */
static void parseFullnameToPersonName(Person person, String fullname) {
    if (StringUtils.isBlank(fullname)) {
        return;
    }
    String[] tokens = fullname.split(" ");
    if (tokens.length == 1) { // we can only set the last name
        person.setLastName(tokens[0]);
    } else if (tokens.length > 1) { // first name, last name
        for (int index = tokens.length - 1; index > -1; index--) {
            if (index == tokens.length - 1) {
                // last word always part of the last name
                person.setLastName(tokens[index]);
            } else if (index == tokens.length - 2 && SURNAME_PREFIX.contains(tokens[index])) {
                person.setLastName(tokens[index] + " " + person.getLastName());
            } else if (index == 0) {
                person.setFirstName(tokens[index]);
            } else {
                person.setMiddleName(
                        (tokens[index] + " " + StringUtils.defaultString(person.getMiddleName())).trim());
            }
        }
    }
}

From source file:gtu._work.ui.SvnLastestCommitInfoUI.java

void reloadSvnTable(String scanText, ScanProcess scanProcess) {
    boolean needFilterScanText = StringUtils.isNotBlank((scanText = StringUtils.defaultString(scanText)));
    DefaultTableModel model = JTableUtil.createModel(true, SvnTableColumn.getColumn());
    for (SvnFile svnFile : svnFileSet) {
        if (!svnFile.file.exists() || !svnFile.file.isFile()) {
            continue;
        }//w  w  w . j a v  a2 s  .com
        if (needFilterScanText) {
            scanProcess.process(scanText, svnFile, model);
        } else {
            this.addRow(svnFile, model);
        }
    }
    svnTable.setModel(model);
    matchCount.setText(String.valueOf(model.getRowCount()));
    if (model.getRowCount() != 0) {
        JTableUtil.newInstance(svnTable).setMaxWidth(SvnTableColumn.getMaxWidth());
    }
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java

/**
 * Private helper method to fillout a map representing a package
 * @param pkgName The name of the package
 * @param pkgVersion The version of the package
 * @param pkgRelease The release of the package
 * @param pkgEpoch The epoch of the package
 * @return Returns a map representing a package
 *///  w w  w. j  a va2s  .  co m
private Map<String, String> fillOutPackage(String pkgName, String pkgVersion, String pkgRelease,
        String pkgEpoch) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("name", StringUtils.defaultString(pkgName));
    map.put("version", StringUtils.defaultString(pkgVersion));
    map.put("release", StringUtils.defaultString(pkgRelease));
    map.put("epoch", StringUtils.defaultString(pkgEpoch));
    return map;
}

From source file:com.manydesigns.portofino.actions.admin.appwizard.ApplicationWizard.java

protected void setupUsers() {
    try {// w  w w .j  av  a 2s  .c  o  m
        TemplateEngine engine = new SimpleTemplateEngine();
        Template secTemplate = engine.createTemplate(ApplicationWizard.class.getResource("Security.groovy"));
        Map<String, String> bindings = new HashMap<String, String>();
        bindings.put("databaseName", connectionProvider.getDatabase().getDatabaseName());
        bindings.put("userTableEntityName", userTable.getActualEntityName());
        bindings.put("userIdProperty", userIdProperty);
        bindings.put("userNameProperty", userNameProperty);
        bindings.put("passwordProperty", userPasswordProperty);
        bindings.put("userEmailProperty", userEmailProperty);
        bindings.put("userTokenProperty", userTokenProperty);

        bindings.put("groupTableEntityName", groupTable != null ? groupTable.getActualEntityName() : "");
        bindings.put("groupIdProperty", StringUtils.defaultString(groupIdProperty));
        bindings.put("groupNameProperty", StringUtils.defaultString(groupNameProperty));

        bindings.put("userGroupTableEntityName",
                userGroupTable != null ? userGroupTable.getActualEntityName() : "");
        bindings.put("groupLinkProperty", StringUtils.defaultString(groupLinkProperty));
        bindings.put("userLinkProperty", StringUtils.defaultString(userLinkProperty));
        bindings.put("adminGroupName", StringUtils.defaultString(adminGroupName));

        bindings.put("encryptionAlgorithm", encryptionAlgorithm);
        File gcp = (File) context.getServletContext().getAttribute(BaseModule.GROOVY_CLASS_PATH);
        FileWriter fw = new FileWriter(new File(gcp, "Security.groovy"));
        secTemplate.make(bindings).writeTo(fw);
        IOUtils.closeQuietly(fw);
    } catch (Exception e) {
        logger.warn("Couldn't configure users", e);
        SessionMessages.addWarningMessage(ElementsThreadLocals.getText("couldnt.set.up.user.management._", e));
    }
}