List of usage examples for org.apache.commons.lang StringUtils defaultString
public static String defaultString(String str)
Returns either the passed in String, or if the String is null
, an empty String ("").
From source file:hudson.plugins.clearcase.history.FieldFilter.java
public boolean accept(String value) { switch (type) { case Equals:/*from w w w. j av a 2 s . c om*/ return StringUtils.equals(value, patternText); case EqualsIgnoreCase: return StringUtils.equalsIgnoreCase(value, patternText); case NotEquals: return !StringUtils.equals(value, patternText); case NotEqualsIgnoreCase: return !StringUtils.equalsIgnoreCase(value, patternText); case StartsWith: return value != null && value.startsWith(patternText); case StartsWithIgnoreCase: return value != null && value.toLowerCase().startsWith(patternText); case EndsWith: return value != null && value.endsWith(patternText); case EndsWithIgnoreCase: return value != null && value.toLowerCase().endsWith(patternText); case Contains: return StringUtils.contains(value, patternText); case ContainsIgnoreCase: return StringUtils.contains(StringUtils.lowerCase(value), patternText); case DoesNotContain: return !StringUtils.contains(value, patternText); case DoesNotContainIgnoreCase: LOGGER.fine(StringUtils.lowerCase(value) + " <>" + patternText); return !StringUtils.contains(StringUtils.lowerCase(value), patternText); case ContainsRegxp: Matcher m = pattern.matcher(StringUtils.defaultString(value)); return m.find(); case DoesNotContainRegxp: Matcher m2 = pattern.matcher(StringUtils.defaultString(value)); return !m2.find(); } return true; }
From source file:info.magnolia.cms.gui.controlx.search.QueryBuilder.java
/** * Make a jcr expression out of the expression * @param expression//from w w w .j a v a 2s .com * @return the expression as string */ private String toJCRExpression(SearchQueryExpression expression) { if (expression instanceof SearchQueryOperator) { // operator is 1:1 usable in jcr return StringUtils.defaultString(((SearchQueryOperator) expression).getOperator()); } else if (expression instanceof StringSearchQueryParameter) { return toStringJCRExpression((StringSearchQueryParameter) expression); } else if (expression instanceof DateSearchQueryParameter) { return getDateJCRExpression((DateSearchQueryParameter) expression); } return StringUtils.EMPTY; }
From source file:info.magnolia.cms.taglibs.EditBar.java
/** * @see javax.servlet.jsp.tagext.Tag#doEndTag() *//*w w w.j a v a2s . c o m*/ public int doEndTag() { if (!adminOnly || Server.isAdmin()) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); if (Server.isAdmin() && Resource.getActivePage(request).isGranted(Permission.SET)) { try { BarEdit bar = new BarEdit((HttpServletRequest) this.pageContext.getRequest()); try { bar.setPath( Resource.getCurrentActivePage((HttpServletRequest) this.pageContext.getRequest()) .getHandle()); } catch (Exception re) { bar.setPath(StringUtils.EMPTY); } if (this.paragraph == null) { Content contentParagraph = Resource .getLocalContentNode((HttpServletRequest) this.pageContext.getRequest()); if (contentParagraph != null) { bar.setParagraph(contentParagraph.getMetaData().getTemplate()); } } else { bar.setParagraph(this.paragraph); } if (this.nodeCollectionName == null) { bar.setNodeCollectionName( StringUtils.defaultString(Resource.getLocalContentNodeCollectionName( (HttpServletRequest) this.pageContext.getRequest()))); } else { bar.setNodeCollectionName(this.nodeCollectionName); } if (this.nodeName == null) { Content localContentNode = Resource .getLocalContentNode((HttpServletRequest) this.pageContext.getRequest()); if (localContentNode != null) { bar.setNodeName(localContentNode.getName()); } } else { bar.setNodeName(this.nodeName); } bar.setDefaultButtons(); if (this.editLabel != null) { if (StringUtils.isEmpty(this.editLabel)) { bar.setButtonEdit(null); } else { bar.getButtonEdit().setLabel(this.editLabel); } } if (this.moveLabel != null) { if (StringUtils.isEmpty(this.moveLabel)) { bar.setButtonMove(null); } else { bar.getButtonMove().setLabel(this.moveLabel); } } if (this.deleteLabel != null) { if (StringUtils.isEmpty(this.deleteLabel)) { bar.setButtonDelete(null); } else { bar.getButtonDelete().setLabel(this.deleteLabel); } } bar.placeDefaultButtons(); bar.drawHtml(pageContext.getOut()); } catch (IOException e) { throw new NestableRuntimeException(e); } } } return EVAL_PAGE; }
From source file:de.snertlab.xdccBee.settings.Settings.java
private void initFields(Document docSettings) { Element nodeBot = docSettings.getRootElement().getChild("BOT"); //$NON-NLS-1$ botName = StringUtils.defaultString(nodeBot.getAttributeValue("botName")); //$NON-NLS-1$ botVersion = StringUtils.defaultString(nodeBot.getAttributeValue("botVersion")); //$NON-NLS-1$ standardNickname = StringUtils.defaultString(nodeBot.getAttributeValue("standardNickname")); //$NON-NLS-1$ downloadFolder = StringUtils.defaultString(nodeBot.getAttributeValue("downloadFolder")); //$NON-NLS-1$ mainWindowPositionX = StringUtils.defaultString(nodeBot.getAttributeValue("mainWindowPositionX")); //$NON-NLS-1$ mainWindowPositionY = StringUtils.defaultString(nodeBot.getAttributeValue("mainWindowPositionY")); //$NON-NLS-1$ mainWindowSizeX = StringUtils.defaultString(nodeBot.getAttributeValue("mainWindowSizeX")); //$NON-NLS-1$ mainWindowSizeY = StringUtils.defaultString(nodeBot.getAttributeValue("mainWindowSizeY")); //$NON-NLS-1$ }
From source file:de.snertlab.xdccBee.settings.ServerSettings.java
private Document buildSettingXml() { Document doc = new Document(); Element nodeRoot = new Element("ROOT"); //$NON-NLS-1$ doc.setRootElement(nodeRoot);/* www.j a v a2 s .c o m*/ Element nodeIrcServer = XmlTool.addChildNode(nodeRoot, "IRC_SERVER"); //$NON-NLS-1$ for (IrcServer ircServer : mapIrcServer.values()) { Element nodeServer = new Element("IRC_SERVER"); //$NON-NLS-1$ nodeServer.setAttribute("id", StringUtils.defaultString(ircServer.getId())); //$NON-NLS-1$ nodeServer.setAttribute("hostname", StringUtils.defaultString(ircServer.getHostname())); //$NON-NLS-1$ nodeServer.setAttribute("nickname", StringUtils.defaultString(ircServer.getNickname())); //$NON-NLS-1$ nodeServer.setAttribute("port", StringUtils.defaultString(ircServer.getPort())); //$NON-NLS-1$ nodeServer.setAttribute("isDebug", ircServer.isDebug() ? "1" : "0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ nodeServer.setAttribute("isAutoconnect", ircServer.isAutoconnect() ? "1" : "0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ for (IrcChannel ircChannel : ircServer.getListChannels()) { Element nodeChannel = new Element("IRC_CHANNEL"); //$NON-NLS-1$ nodeChannel.setAttribute("channelName", StringUtils.defaultString(ircChannel.getChannelName())); //$NON-NLS-1$ nodeChannel.setAttribute("isAutoconnect", ircChannel.isAutoconnect() ? "1" : "0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ nodeServer.addContent(nodeChannel); } nodeIrcServer.addContent(nodeServer); } return doc; }
From source file:com.opengamma.web.position.WebPositionsResource.java
private FlexiBean createSearchResultData(PagingRequest pr, String identifier, String minQuantityStr, String maxQuantityStr, List<String> positionIdStrs, List<String> tradeIdStrs) { minQuantityStr = StringUtils.defaultString(minQuantityStr).replace(",", ""); maxQuantityStr = StringUtils.defaultString(maxQuantityStr).replace(",", ""); FlexiBean out = createRootData();//from ww w.j a v a 2s. co m PositionSearchRequest searchRequest = new PositionSearchRequest(); searchRequest.setPagingRequest(pr); searchRequest.setSecurityIdValue(StringUtils.trimToNull(identifier)); if (NumberUtils.isNumber(minQuantityStr)) { searchRequest.setMinQuantity(NumberUtils.createBigDecimal(minQuantityStr)); } if (NumberUtils.isNumber(maxQuantityStr)) { searchRequest.setMaxQuantity(NumberUtils.createBigDecimal(maxQuantityStr)); } for (String positionIdStr : positionIdStrs) { searchRequest.addPositionObjectId(ObjectId.parse(positionIdStr)); } for (String tradeIdStr : tradeIdStrs) { searchRequest.addPositionObjectId(ObjectId.parse(tradeIdStr)); } out.put("searchRequest", searchRequest); if (data().getUriInfo().getQueryParameters().size() > 0) { PositionSearchResult searchResult = data().getPositionMaster().search(searchRequest); out.put("searchResult", searchResult); out.put("paging", new WebPaging(searchResult.getPaging(), data().getUriInfo())); } return out; }
From source file:gtu._work.etc.SqlReplacerUI.java
private void initGUI() { try {/*w w w .jav a 2s .c o m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 246)); { jTextArea1 = new JTextArea(); jScrollPane1.setViewportView(jTextArea1); jTextArea1.setText(""); } } } { jPanel2 = new JPanel(); FlowLayout jPanel2Layout = new FlowLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { replaceFromText = new JTextField(); jPanel2.add(replaceFromText); replaceFromText.setPreferredSize(new java.awt.Dimension(266, 22)); } { replaceToText = new JTextField(); jPanel2.add(replaceToText); replaceToText.setPreferredSize(new java.awt.Dimension(266, 22)); } { execute = new JButton(); jPanel2.add(execute); execute.setText("execute"); execute.setPreferredSize(new java.awt.Dimension(149, 42)); execute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String text = jTextArea1.getText(); if (StringUtils.isBlank(text)) { JCommonUtil._jOptionPane_showMessageDialog_error("area empty!"); return; } String fromTxt = replaceFromText.getText(); String toTxt = StringUtils.defaultString(replaceToText.getText()); if (StringUtils.isBlank(fromTxt)) { JCommonUtil._jOptionPane_showMessageDialog_error("fromTxt empty!"); return; } StringBuffer sb = new StringBuffer(); Pattern ptn = Pattern.compile("(.){0,1}" + fromTxt + "(.){0,1}", Pattern.CASE_INSENSITIVE); Matcher mth = null; String[] scopeStrs = { ",", " ", "(", ")", "[", "]" }; BufferedReader reader = new BufferedReader(new StringReader(text)); for (String line = null; (line = reader.readLine()) != null;) { mth = ptn.matcher(line); while (mth.find()) { String scope1 = mth.group(1); String scope2 = mth.group(2); boolean ok1 = scope1.length() == 0 || StringUtils.indexOfAny(scope1, scopeStrs) != -1; boolean ok2 = scope2.length() == 0 || StringUtils.indexOfAny(scope2, scopeStrs) != -1; if (ok1 && ok2) { mth.appendReplacement(sb, scope1 + toTxt + scope2); } } mth.appendTail(sb); sb.append("\n"); } reader.close(); jTextArea1.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } } } pack(); setSize(400, 300); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:com.thoughtworks.go.server.controller.beans.PipelineBean.java
public Tasks getTasks() { Tasks tasks = new Tasks(); if ("ant".equals(builder)) { AntTask antTask = new AntTask(); antTask.setTarget(this.target); antTask.setBuildFile(defaultString(StringUtils.isBlank(this.buildfile) ? "build.xml" : this.buildfile)); tasks.add(antTask);// ww w .jav a2s . c om } else if ("nant".equals(builder)) { NantTask nantTask = new NantTask(); nantTask.setTarget(this.target); nantTask.setBuildFile( defaultString(StringUtils.isBlank(this.buildfile) ? "default.build" : this.buildfile)); tasks.add(nantTask); } else if ("rake".equals(builder)) { RakeTask rakeTask = new RakeTask(); rakeTask.setTarget(this.target); rakeTask.setBuildFile(StringUtils.isBlank(this.buildfile) ? null : this.buildfile); tasks.add(rakeTask); } else if ("exec".equals(builder)) { String trimmedCommand = StringUtils.defaultString(this.command).trim(); String trimmedArguments = StringUtils.defaultString(this.arguments).trim(); ExecTask execTask = new ExecTask(trimmedCommand, trimmedArguments, (String) null); tasks.add(execTask); } return tasks; }
From source file:com.redhat.rhn.frontend.xmlrpc.serializer.ServerSerializer.java
/** * {@inheritDoc}/*from w w w . j a v a 2s . c om*/ */ protected void doSerialize(Object value, Writer output, XmlRpcSerializer serializer) throws XmlRpcException, IOException { Server server = (Server) value; SerializerHelper helper = new SerializerHelper(serializer); helper.add("id", server.getId()); helper.add("profile_name", server.getName()); Set networks = server.getNetworks(); if (networks != null && !networks.isEmpty()) { // we only care about the first one Network net = (Network) networks.iterator().next(); helper.add("hostname", net.getHostname()); } else { helper.add("hostname", LocalizationService.getInstance().getMessage("sdc.details.overview.unknown")); } // Find this server's base entitlement: String baseEntitlement = EntitlementManager.UNENTITLED; List<String> addonEntitlements = new LinkedList<String>(); for (Entitlement ent : server.getEntitlements()) { if (ent.isBase()) { baseEntitlement = ent.getLabel(); } else { addonEntitlements.add(ent.getLabel()); } } helper.add("base_entitlement", baseEntitlement); helper.add("addon_entitlements", addonEntitlements); Boolean autoUpdate = Boolean.FALSE; if (server.getAutoUpdate().equals("Y")) { autoUpdate = Boolean.TRUE; } helper.add("auto_update", autoUpdate); helper.add("description", StringUtils.defaultString(server.getDescription())); String address1 = ""; String address2 = ""; String city = ""; String state = ""; String country = ""; String building = ""; String room = ""; String rack = ""; if (server.getLocation() != null) { address1 = StringUtils.defaultString(server.getLocation().getAddress1()); address2 = StringUtils.defaultString(server.getLocation().getAddress2()); city = StringUtils.defaultString(server.getLocation().getCity()); state = StringUtils.defaultString(server.getLocation().getState()); country = StringUtils.defaultString(server.getLocation().getCountry()); building = StringUtils.defaultString(server.getLocation().getBuilding()); room = StringUtils.defaultString(server.getLocation().getRoom()); rack = StringUtils.defaultString(server.getLocation().getRack()); } helper.add("address1", address1); helper.add("address2", address2); helper.add("city", city); helper.add("state", state); helper.add("country", country); helper.add("building", building); helper.add("room", room); helper.add("rack", rack); helper.add("release", server.getRelease()); helper.add("last_boot", server.getLastBootAsDate()); if (server.getPushClient() != null) { helper.add("osa_status", server.getPushClient().getState().getName()); } else { helper.add("osa_status", LocalizationService.getInstance().getMessage("sdc.details.overview.unknown")); } Boolean locked = Boolean.FALSE; if (server.getLock() != null) { locked = Boolean.TRUE; } helper.add("lock_status", locked); if (server.isVirtualGuest()) { if (server.getVirtualInstance().getType() != null) { helper.add("virtualization", server.getVirtualInstance().getType().getName()); } else { helper.add("virtualization", ""); } } helper.writeTo(output); }
From source file:mitm.application.djigzo.mail.repository.MailRepositoryEventListenerImpl.java
private void sendNotification(Notification notification, MailRepositoryItem item, Set<String> recipients, String templateSource) {//from w ww . j a v a 2s.com SimpleHash root = new SimpleHash(); SimpleHash org = new SimpleHash(); org.put("subject", StringUtils.defaultString(item.getSubject())); org.put("id", StringUtils.defaultString(item.getID())); org.put("from", StringUtils.defaultString(item.getFromHeader())); org.put("messageID", StringUtils.defaultString(item.getMessageID())); root.put("org", org); root.put("recipients", recipients); try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bos); Template template = templateBuilder.createTemplate(new StringReader(templateSource)); template.process(root, writer); MimeMessage message = MailUtils.byteArrayToMessage(bos.toByteArray()); message.saveChanges(); MailUtils.validateMessage(message); MailImpl mail = new MailImpl(MailetUtils.createUniqueMailName(), null, MailAddressUtils.toMailAddressList(recipients), message); mail.setState(newMailProcessor); JamesStoreManager storemanager = new JamesStoreManager(serviceManager); try { storemanager.store(mail); } finally { mail.dispose(); } } catch (IOException e) { logger.error("Error creating the notification template.", e); } catch (TemplateException e) { logger.error("The template is not a valid Freemarker template or variables are missing.", e); } catch (MessagingException e) { logger.error("The resulting mime message is not valid.", e); } catch (ServiceException e) { logger.error("Error getting the JamesStoreManager.", e); } }