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, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is null, the value of defaultStr.

Usage

From source file:com.flexive.faces.components.tree.dojo.DojoTreeNode.java

/**
 * Write all tree nodes, including optional child nodes, to the
 * given tree writer.//from  ww  w . j  a  va2s.  c  o m
 *
 * @param writer the tree node writer
 * @throws IOException if the tree could not be written to the output writer
 */
public void writeTreeNodes(TreeNodeWriter writer) throws IOException {
    if (!isRendered()) {
        return;
    }
    List<DojoTreeNode> childNodes = getNodeChildren();
    final String linkUrl = StringUtils.isNotBlank(getLink()) ? getLink().startsWith("javascript:") ? getLink()
            : FxJsfUtils.getRequest().getContextPath() + getLink() : null;
    if (childNodes.size() == 0) {
        writer.writeNode(new Node(getId(), getTitle(),
                StringUtils.defaultString(getTitleClass(), Node.TITLE_CLASS_LEAF), getIcon(), linkUrl));
    } else {
        writer.startNode(new Node(getId(), getTitle(),
                StringUtils.defaultString(titleClass, Node.TITLE_CLASS_NODE), getIcon(), linkUrl));
        writer.startChildren();
        for (DojoTreeNode child : childNodes) {
            child.writeTreeNodes(writer);
        }
        writer.closeChildren();
        writer.closeNode();
    }
}

From source file:com.bstek.dorado.config.text.DispatchableTextParser.java

/**
 * ?????//from  w w w. j a v a 2 s  . com
 * @param constraint ??
 *            ??????WILDCARD??
 */
protected TextParser findAttributeParser(String constraint) {
    constraint = StringUtils.defaultString(constraint, WILDCARD);
    TextParser parser = attributeParsers.get(constraint);
    if (parser == null && !WILDCARD.equals(constraint)) {
        parser = attributeParsers.get(WILDCARD);
    }
    return parser;
}

From source file:info.magnolia.cms.taglibs.util.Breadcrumb.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 *///from   ww  w  .j a va2  s  .  com
public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    Content actpage = Resource.getCurrentActivePage(request);
    int endLevel = 0;

    try {
        endLevel = actpage.getLevel();

        if (this.excludeCurrent) {
            endLevel--;
        }

        JspWriter out = pageContext.getOut();
        for (int i = this.startLevel; i <= endLevel; i++) {
            if (i != this.startLevel) {
                out.print(StringUtils.defaultString(this.delimiter, " > ")); //$NON-NLS-1$
            }
            if (this.link) {
                out.print("<a href=\""); //$NON-NLS-1$
                out.print(request.getContextPath());
                out.print(actpage.getAncestor(i).getHandle() + "." + Server.getDefaultExtension());
                out.print("\">"); //$NON-NLS-1$
            }
            out.print(actpage.getAncestor(i).getTitle());
            if (this.link) {
                out.print("</a>"); //$NON-NLS-1$
            }
        }
    } catch (RepositoryException e) {
        log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
    } catch (IOException e) {
        throw new NestableRuntimeException(e);
    }

    return super.doStartTag();
}

From source file:com.bstek.dorado.config.xml.DispatchableXmlParser.java

/**
 * ?????//from ww w .j  av a2  s.  c om
 * 
 * @param constraint
 *            ?? ??????WILDCARD??
 */
protected XmlParser findPropertyParser(String constraint) {
    constraint = StringUtils.defaultString(constraint, WILDCARD);
    XmlParser parser = propertyParsers.get(constraint);
    if (parser == null && !WILDCARD.equals(constraint)) {
        parser = propertyParsers.get(WILDCARD);
    }
    return parser;
}

From source file:com.bstek.dorado.web.resolver.ErrorPageResolver.java

private void doExcecute(HttpServletRequest request, HttpServletResponse response)
        throws Exception, IOException {
    response.setContentType(HttpConstants.CONTENT_TYPE_HTML);
    response.setCharacterEncoding(Constants.DEFAULT_CHARSET);

    Context velocityContext = new VelocityContext();
    Exception e = (Exception) request.getAttribute(EXCEPTION_ATTRIBUTE);
    if (e != null) {
        logger.error(e, e);/*from  ww w  .  jav  a  2 s.co m*/

        if (e instanceof PageNotFoundException) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        } else if (e instanceof PageAccessDeniedException) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }

        Throwable throwable = e;
        while (throwable.getCause() != null) {
            throwable = throwable.getCause();
        }

        String message = null;
        if (throwable != null) {
            message = throwable.getMessage();
        }
        message = StringUtils.defaultString(message, throwable.getClass().getName());

        velocityContext.put("message", message);
        velocityContext.put(EXCEPTION_ATTRIBUTE, throwable);
    } else {
        velocityContext.put("message", "Can not gain exception information!");
    }
    velocityContext.put("esc", stringEscapeHelper);

    Template template = getVelocityEngine().getTemplate("com/bstek/dorado/web/resolver/ErrorPage.html");

    PrintWriter writer = getWriter(request, response);
    try {
        template.merge(velocityContext, writer);
    } finally {
        writer.flush();
        writer.close();
    }
}

From source file:info.magnolia.cms.taglibs.NewBar.java

/**
 * @return String , label for the new bar
 *//*from  w  w  w . j  a  v a2 s.c o  m*/
private String getNewLabel() {
    String defStr = MessagesManager.getMessages().get(DEFAULT_NEW_LABEL);
    return StringUtils.defaultString(this.newLabel, defStr);
}

From source file:hudson.slaves.CommandLauncher.java

@Override
public void launch(SlaveComputer computer, final TaskListener listener) {
    EnvVars _cookie = null;/*from  w w  w  . j a v a 2  s. co  m*/
    Process _proc = null;
    try {
        Slave node = computer.getNode();
        if (node == null) {
            throw new AbortException("Cannot launch commands on deleted nodes");
        }

        listener.getLogger().println(hudson.model.Messages.Slave_Launching(getTimestamp()));
        if (getCommand().trim().length() == 0) {
            listener.getLogger().println(Messages.CommandLauncher_NoLaunchCommand());
            return;
        }
        listener.getLogger().println("$ " + getCommand());

        ProcessBuilder pb = new ProcessBuilder(Util.tokenize(getCommand()));
        final EnvVars cookie = _cookie = EnvVars.createCookie();
        pb.environment().putAll(cookie);
        pb.environment().put("WORKSPACE",
                StringUtils.defaultString(computer.getAbsoluteRemoteFs(), node.getRemoteFS())); //path for local slave log

        {// system defined variables
            String rootUrl = Jenkins.getInstance().getRootUrl();
            if (rootUrl != null) {
                pb.environment().put("HUDSON_URL", rootUrl); // for backward compatibility
                pb.environment().put("JENKINS_URL", rootUrl);
                pb.environment().put("SLAVEJAR_URL", rootUrl + "/jnlpJars/slave.jar");
            }
        }

        if (env != null) {
            pb.environment().putAll(env);
        }

        final Process proc = _proc = pb.start();

        // capture error information from stderr. this will terminate itself
        // when the process is killed.
        new StreamCopyThread("stderr copier for remote agent on " + computer.getDisplayName(),
                proc.getErrorStream(), listener.getLogger()).start();

        computer.setChannel(proc.getInputStream(), proc.getOutputStream(), listener.getLogger(),
                new Channel.Listener() {
                    @Override
                    public void onClosed(Channel channel, IOException cause) {
                        reportProcessTerminated(proc, listener);

                        try {
                            ProcessTree.get().killAll(proc, cookie);
                        } catch (InterruptedException e) {
                            LOGGER.log(Level.INFO, "interrupted", e);
                        }
                    }
                });

        LOGGER.info("slave agent launched for " + computer.getDisplayName());
    } catch (InterruptedException e) {
        e.printStackTrace(listener.error(Messages.ComputerLauncher_abortedLaunch()));
    } catch (RuntimeException e) {
        e.printStackTrace(listener.error(Messages.ComputerLauncher_unexpectedError()));
    } catch (Error e) {
        e.printStackTrace(listener.error(Messages.ComputerLauncher_unexpectedError()));
    } catch (IOException e) {
        Util.displayIOException(e, listener);

        String msg = Util.getWin32ErrorMessage(e);
        if (msg == null) {
            msg = "";
        } else {
            msg = " : " + msg;
        }
        msg = hudson.model.Messages.Slave_UnableToLaunch(computer.getDisplayName(), msg);
        LOGGER.log(Level.SEVERE, msg, e);
        e.printStackTrace(listener.error(msg));

        if (_proc != null) {
            reportProcessTerminated(_proc, listener);
            try {
                ProcessTree.get().killAll(_proc, _cookie);
            } catch (InterruptedException x) {
                x.printStackTrace(listener.error(Messages.ComputerLauncher_abortedLaunch()));
            }
        }
    }
}

From source file:info.magnolia.cms.core.Path.java

/**
 * Returns the decoded URI of the current request, without the context path.
 * @param req request/*w  w  w. j  a  v a 2 s  .co m*/
 * @return request URI without servlet context
 */
private static String getDecodedURI(HttpServletRequest req) {
    String encoding = StringUtils.defaultString(req.getCharacterEncoding(), ENCODING_DEFAULT);
    String decodedURL = null;
    try {
        decodedURL = URLDecoder.decode(req.getRequestURI(), encoding);
    } catch (UnsupportedEncodingException e) {
        decodedURL = req.getRequestURI();
    }
    return StringUtils.substringAfter(decodedURL, req.getContextPath());
}

From source file:com.bstek.dorado.config.text.DispatchableTextParser.java

/**
 * ?????/*from  w  w  w  .j  a v  a2 s.c  om*/
 * @param constraint ????? ?nullWILDCARD??
 * @param parser ??
 */
public void registerSubParser(String constraint, TextParser parser) {
    Assert.notNull(parser, "[parser] is required");
    constraint = StringUtils.defaultString(constraint, WILDCARD);
    subParsers.put(constraint, parser);
}

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

/**
 * Model.//  w w  w  . jav  a 2 s  .co  m
 * @param model Model
 * @param form Form
 */
private void setModel(StatusModel model, StatusForm form) {
    model.setStatusName(new Text(form.statusName));
    model.setCloseStatusName(new Text(StringUtils.defaultString(form.closeStatusName, "")));
}