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:mitm.common.security.keystore.KeyStoreLoader.java

private void determineKeyStoreTypeFromFile(File file) throws KeyStoreException {
    String extension = StringUtils
            .defaultString(StringUtils.lowerCase(FilenameUtils.getExtension(file.getName())));

    keyStoreType = extensionMap.get(extension);

    if (keyStoreType == null) {
        throw new KeyStoreException("Unable to determine key store type for extension " + extension);
    }//from  w w w. j  a  va 2 s.  co m
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.LoginDialog.java

private void showPage(Exchange exc, int page, Object... params) throws Exception {
    String target = StringUtils.defaultString(URLParamUtil.getParams(uriFactory, exc).get("target"));

    exc.getDestinations().set(0, "/index.html");
    wsi.handleRequest(exc);/* w w  w .j  av  a  2 s .c o m*/

    Engine engine = new Engine();
    engine.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(String arg0, Token arg1, Map<String, Object> arg2) throws ParseException {
            log.error(arg0);
        }

        @Override
        public void error(String arg0, Token arg1) throws ParseException {
            log.error(arg0);
        }
    });
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("action", StringEscapeUtils.escapeXml(path));
    model.put("target", StringEscapeUtils.escapeXml(target));
    if (page == 1)
        model.put("token", true);
    for (int i = 0; i < params.length; i += 2)
        model.put((String) params[i], params[i + 1]);

    exc.getResponse().setBodyContent(
            engine.transform(exc.getResponse().getBody().toString(), model).getBytes(Constants.UTF_8_CHARSET));
}

From source file:com.tesora.dve.common.PEStringUtils.java

public static String normalizePrefix(String prefix) {
    String newPrefix = StringUtils.defaultString(prefix);
    if (newPrefix.length() > 0 && !StringUtils.endsWith(newPrefix, ".")) {
        newPrefix = newPrefix + ".";
    }//from   w w w .j a va  2 s .  c  o  m
    return newPrefix;
}

From source file:com.netsteadfast.greenstep.vo.SysExprJobVO.java

public String getRunDatetime() {
    return StringUtils.defaultString(this.runDayOfWeek)
            + ((!StringUtils.isBlank(this.runDayOfWeek) && !StringUtils.isBlank(this.runHour)) ? "/" : "")
            + StringUtils.defaultString(this.runHour)
            + ((!StringUtils.isBlank(this.runHour) && !StringUtils.isBlank(this.runMinute)) ? "/" : "")
            + StringUtils.defaultString(this.runMinute);
}

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

private void initGUI() {
    try {//from w  ww.j a v  a  2  s  . co  m
        FlowLayout thisLayout = new FlowLayout();
        getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jLabel1 = new JLabel();
            getContentPane().add(jLabel1);
            jLabel1.setText("FileP100.xls");
            jLabel1.setPreferredSize(new java.awt.Dimension(68, 15));
        }
        {
            fileP100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(fileP100Text, false);
            getContentPane().add(fileP100Text);
            fileP100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            label2 = new JLabel();
            getContentPane().add(label2);
            getContentPane().add(label2);
            label2.setText("RCDFP100.xls");
            label2.setPreferredSize(new java.awt.Dimension(84, 15));
        }
        {
            rcdfp100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(rcdfp100Text, false);
            getContentPane().add(rcdfp100Text);
            rcdfp100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            executeBtn = new JButton();
            getContentPane().add(executeBtn);
            executeBtn.setText("\u7522\u751f\u532f\u51fa\u6a94");
            executeBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    if (StringUtils.isBlank(rcdfp100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }
                    File rcdfp100File = new File(StringUtils.defaultString(rcdfp100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }

                    if (StringUtils.isBlank(fileP100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }
                    File fileP100File = new File(StringUtils.defaultString(fileP100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }

                    try {
                        TestForJermy test = new TestForJermy();
                        test.execute(fileP100File, rcdfp100File,
                                PropertiesUtil.getJarCurrentPath(JermyP100UI.class));
                        File outputFile = test.getOutputCvs();
                        JCommonUtil._jOptionPane_showMessageDialog_info(
                                ":\n" + outputFile.getAbsolutePath());
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
        }
        pack();
        this.setSize(457, 146);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:de.thischwa.pmcms.gui.dialog.pojo.DialogFieldsSiteComp.java

private void initialize() {
    GridData gridDataLabel = new GridData();
    gridDataLabel.horizontalAlignment = GridData.END;
    gridDataLabel.verticalAlignment = GridData.CENTER;
    GridData gridDataText = new GridData();
    gridDataText.heightHint = -1;/*from ww  w  .  j a  v a2 s  .  co m*/
    gridDataText.widthHint = 150;
    GridLayout gridLayoutMy = new GridLayout();
    gridLayoutMy.numColumns = 2;
    gridLayoutMy.marginWidth = 25;
    gridLayoutMy.verticalSpacing = 5;
    gridLayoutMy.horizontalSpacing = 20;
    gridLayoutMy.marginHeight = 25;
    gridLayoutMy.makeColumnsEqualWidth = false;
    GridData gridDataMy = new GridData();
    gridDataMy.grabExcessHorizontalSpace = true;
    gridDataMy.verticalAlignment = GridData.CENTER;
    gridDataMy.horizontalSpan = 1;
    gridDataMy.horizontalAlignment = GridData.FILL;
    this.setLayoutData(gridDataMy);
    this.setLayout(gridLayoutMy);
    Label label1 = new Label(this, SWT.RIGHT);
    label1.setText("*  ".concat(LabelHolder.get("dialog.pojo.site.fields.url"))); //$NON-NLS-1$
    label1.setLayoutData(gridDataLabel);
    textUrl = new Text(this, SWT.BORDER);
    textUrl.setTextLimit(256);
    textUrl.setLayoutData(gridDataText);
    textUrl.setText(StringUtils.defaultString(site.getUrl()));
    Label label2 = new Label(this, SWT.RIGHT);
    label2.setText(LabelHolder.get("dialog.pojo.site.fields.title")); //$NON-NLS-1$
    label2.setLayoutData(gridDataLabel);
    textTitle = new Text(this, SWT.BORDER);
    textTitle.setTextLimit(256);
    textTitle.setLayoutData(gridDataText);
    textTitle.setText(StringUtils.defaultString(site.getTitle()));

    label = new Label(this, SWT.NONE);
    label.setText(LabelHolder.get("dialog.pojo.site.fields.ftp.host")); //$NON-NLS-1$
    label.setLayoutData(gridDataLabel);
    textHost = new Text(this, SWT.BORDER);
    textHost.setTextLimit(256);
    textHost.setLayoutData(gridDataText);
    textHost.setText(StringUtils.defaultString(site.getTransferHost()));
    label = new Label(this, SWT.NONE);
    label.setText(LabelHolder.get("dialog.pojo.site.fields.ftp.user")); //$NON-NLS-1$
    label.setLayoutData(gridDataLabel);
    textLoginUser = new Text(this, SWT.BORDER);
    textLoginUser.setTextLimit(256);
    textLoginUser.setLayoutData(gridDataText);
    textLoginUser.setText(StringUtils.defaultString(site.getTransferLoginUser()));
    label = new Label(this, SWT.NONE);
    label.setText(LabelHolder.get("dialog.pojo.site.fields.ftp.password")); //$NON-NLS-1$
    label.setLayoutData(gridDataLabel);
    textLoginPassword = new Text(this, SWT.BORDER);
    textLoginPassword.setTextLimit(256);
    textLoginPassword.setLayoutData(gridDataText);
    String plainPwd = cryptor.decrypt(site.getTransferLoginPassword());
    textLoginPassword.setText(StringUtils.defaultString(plainPwd));

    label = new Label(this, SWT.NONE);
    label.setText(LabelHolder.get("dialog.pojo.site.fields.ftp.startdir")); //$NON-NLS-1$
    label.setLayoutData(gridDataLabel);
    textStartDirectory = new Text(this, SWT.BORDER);
    textStartDirectory.setTextLimit(256);
    textStartDirectory.setLayoutData(gridDataText);
    textStartDirectory.setText(StringUtils.defaultString(site.getTransferStartDirectory()));
}

From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsCommand.java

/**
 * {@inheritDoc}//w  ww.  ja v a  2  s. c  o  m
 */
@Override
protected int run() throws Exception {
    store.checkPermission(CredentialsProvider.VIEW);
    List<Domain> domains = store.getDomains();
    for (Domain domain : domains) {
        List<Credentials> credentials = store.getCredentials(domain);
        Map<String, String> nameById = new LinkedHashMap<String, String>(credentials.size());
        int maxIdLen = "# of Credentials".length(), maxNameLen = 0;
        int index = 0;
        for (Credentials c : credentials) {
            String id;
            if (c instanceof IdCredentials) {
                id = ((IdCredentials) c).getId();
            } else {
                while (nameById.containsKey("index-" + index)) {
                    index++;
                }
                id = "index-" + index;
                index++;
            }
            String name = CredentialsNameProvider.name(c);
            nameById.put(id, name);
            maxIdLen = Math.max(maxIdLen, id.length());
            maxNameLen = Math.max(maxNameLen, name.length());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Domain", maxIdLen) + " "
                + (domain.isGlobal() ? "(global)" : domain.getName()));
        stdout.println(StringUtils.rightPad("Description", maxIdLen) + " "
                + StringUtils.defaultString(domain.getDescription()));
        stdout.println(StringUtils.rightPad("# of Credentials", maxIdLen) + " " + credentials.size());
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Id", maxIdLen) + " Name");
        stdout.println(StringUtils.repeat("=", maxIdLen) + " " + StringUtils.repeat("=", maxNameLen));
        for (Map.Entry<String, String> entry : nameById.entrySet()) {
            stdout.println(StringUtils.rightPad(entry.getKey(), maxIdLen) + " " + entry.getValue());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println();
    }
    return 0;
}

From source file:jp.co.nemuzuka.service.impl.UploadFileServiceImpl.java

@Override
public String put(FileItem fileItem, String comment, String ticketKeyToString, String projectKeyString) {

    BlobKey blobKey = null;// ww  w .  j a  v  a2s .co  m
    try {
        FileService fileService = FileServiceFactory.getFileService();
        AppEngineFile blobFile = fileService.createNewBlobFile(fileItem.getContentType());
        FileWriteChannel writeChannel = fileService.openWriteChannel(blobFile, true);
        writeChannel.write(ByteBuffer.wrap(fileItem.getData()));
        writeChannel.closeFinally();
        blobKey = fileService.getBlobKey(blobFile);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    //?
    UploadFileModel model = new UploadFileModel();
    BlobInfoFactory factory = new BlobInfoFactory();
    model.setBlobKey(blobKey.getKeyString());
    BlobInfo blobInfo = factory.loadBlobInfo(blobKey);
    BeanUtil.copy(blobInfo, model, new CopyOptions().exclude("blobKey"));
    model.setParentKey(Datastore.stringToKey(ticketKeyToString));
    model.setProjectKey(Datastore.stringToKey(projectKeyString));
    model.setFilename(fileItem.getShortFileName());
    model.setComment(new Text(StringUtils.defaultString(comment)));

    //
    Datastore.put(model);
    return Datastore.keyToString(model.getKey());
}

From source file:jp.co.nemuzuka.service.impl.CommentServiceImpl.java

@Override
public void put(Key refsKey, String comment, String email) {

    CommentModel model = new CommentModel();
    model.setComment(new Text(StringUtils.defaultString(comment)));
    Key memberKey = memberService.getKey(email);
    if (memberKey == null) {
        return;/*  w  ww.java2  s .  c o m*/
    }
    model.setCreateMemberKey(memberKey);
    model.setRefsKey(refsKey);
    commentDao.put(model);
}

From source file:de.snertlab.xdccBee.settings.Settings.java

private Document buildSettingXml() {
    Document doc = new Document();
    Element nodeRoot = new Element("ROOT"); //$NON-NLS-1$
    doc.setRootElement(nodeRoot);/*from www  .ja va  2s.c  o m*/

    Element nodeBot = XmlTool.addChildNode(nodeRoot, "BOT"); //$NON-NLS-1$
    nodeBot.setAttribute("botName", StringUtils.defaultString(botName)); //$NON-NLS-1$
    nodeBot.setAttribute("botVersion", StringUtils.defaultString(botVersion)); //$NON-NLS-1$
    nodeBot.setAttribute("standardNickname", StringUtils.defaultString(standardNickname)); //$NON-NLS-1$
    nodeBot.setAttribute("downloadFolder", StringUtils.defaultString(downloadFolder)); //$NON-NLS-1$
    nodeBot.setAttribute("mainWindowPositionX", StringUtils.defaultString(mainWindowPositionX)); //$NON-NLS-1$
    nodeBot.setAttribute("mainWindowPositionY", StringUtils.defaultString(mainWindowPositionY)); //$NON-NLS-1$
    nodeBot.setAttribute("mainWindowSizeX", StringUtils.defaultString(mainWindowSizeX)); //$NON-NLS-1$
    nodeBot.setAttribute("mainWindowSizeY", StringUtils.defaultString(mainWindowSizeY)); //$NON-NLS-1$

    return doc;
}