List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:com.comcast.locker.gateway.xgateway.service.ValidateLicenseController.java
@VisibleForTesting String getClient(ValidateLicenseRequest request) { String provider = request.getSubjectInfo().getProvider(); String model = request.getSubjectInfo().getDeviceModel(); String clientKey;// ww w . ja v a 2s.c o m if (model == null && provider == null) { //if both empty, keep it short and sweet clientKey = UNKNOWN_CLIENT_PART; } else { clientKey = StringUtils.defaultIfEmpty(provider, UNKNOWN_CLIENT_PART) + ':' + StringUtils.defaultIfEmpty(model, UNKNOWN_CLIENT_PART); } String client = CLIENT_OVERRIDES.get(clientKey); if (client == null) { LOG.warn("Received unexpected client fields " + clientKey); return clientKey; } return client; }
From source file:gtu.zcognos.SimpleUI.java
private void initGUI() { try {/* ww w .j ava2 s . com*/ final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this); { GroupLayout thisLayout = new GroupLayout((JComponent) getContentPane()); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); { projectId = new JTextField(); } { packageId = new JTextField(); } { jLabel1 = new JLabel(); jLabel1.setText("PROJECT_ID"); } { jLabel2 = new JLabel(); jLabel2.setText("PACKAGE_ID"); } { jLabel3 = new JLabel(); jLabel3.setText("DATATABLE"); } { jScrollPane1 = new JScrollPane(); { dataTable = new JTextArea(); jScrollPane1.setViewportView(dataTable); } } { create = new JButton(); create.setText("create"); create.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("create.actionPerformed", evt); } }); } thisLayout.setVerticalGroup(thisLayout.createSequentialGroup().addContainerGap(16, 16) .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(projectId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING, thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(packageId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup() .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE) .addComponent(create, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE) .addContainerGap()); thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup().addContainerGap(31, 31).addGroup( thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING, thisLayout .createSequentialGroup() .addGroup(thisLayout.createParallelGroup() .addComponent(jLabel2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(thisLayout.createParallelGroup() .addComponent(packageId, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE) .addComponent(projectId, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(create, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE)) .addGroup(thisLayout.createSequentialGroup() .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 417, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap(17, 17)); } this.setSize(473, 356); swingUtil.addAction("create.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { String project = projectId.getText(); String dataTab = dataTable.getText(); Validate.notEmpty(project); Validate.notEmpty(dataTab); String pkgId = StringUtils.defaultIfEmpty(packageId.getText(), project); List<String> dataTableList = new ArrayList<String>(); StringTokenizer tok = new StringTokenizer(dataTab); for (int ii = 0; tok.hasMoreElements(); ii++) { String column = (String) tok.nextElement(); System.out.format("%d -- %s\n", ii, column); if (StringUtils.isBlank(column)) { continue; } dataTableList.add(column.trim()); } File destDir = new File(CREATE_DEST + "\\" + project); destDir.mkdirs(); Map<String, Object> map = new HashMap<String, Object>(); map.put("PROJECT_ID", project); map.put("PACKAGE_ID", pkgId); map.put("DATATABLE", dataTableList); ConfigCopy.getInstance().applyBaseDir(new File(CREATE_DEST)).applyProjectId(project).execute(); Simple.getInstance()// .applyDestDir(destDir.getAbsolutePath())// .applyParameter(map)// .execute(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog(pkgId + " create completed!!\r\n dir : " // + destDir.getAbsolutePath(), pkgId); Desktop.getDesktop().open(destDir); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.iteratec.iteraplan.model.BusinessMapping.java
private String processNameString(String processName) { final String defaultName = StringUtils.defaultIfEmpty(processName, "null"); return defaultName.replaceAll("\\W", ""); }
From source file:hudson.plugins.testlink.util.TestLinkHelper.java
/** * Creates a Map (name, value) of environment variables for a TestLink Test Case. * // w w w .j av a 2 s .co m * @param testProject TestLink Test Project. * @param testPlan TestLink Test Plan. * @param build TestLink Build. * @return Map (name, value) of environment variables. */ public static Map<String, String> createTestLinkEnvironmentVariables(int numberOfTests, TestProject testProject, TestPlan testPlan, Build build) { Map<String, String> testLinkEnvVar = new HashMap<String, String>(); testLinkEnvVar.put(TESTLINK_BUILD_NAME_ENVVAR, StringUtils.defaultIfEmpty(build.getName(), "")); testLinkEnvVar.put(TESTLINK_TESTPLAN_NAME_ENVVAR, StringUtils.defaultIfEmpty(testPlan.getName(), "")); testLinkEnvVar.put(TESTLINK_TESTPROJECT_NAME_ENVVAR, StringUtils.defaultIfEmpty(testProject.getName(), "")); testLinkEnvVar.put(TESTLINK_TESTCASE_PREFIX + "TOTAL", Integer.toString(numberOfTests)); return testLinkEnvVar; }
From source file:com.cloudbees.jenkins.support.SupportPlugin.java
public static void setLogLevel(String level) { setLogLevel(Level.parse(StringUtils.defaultIfEmpty(level, "INFO"))); }
From source file:com.eviware.soapui.support.components.SimpleForm.java
private void setToolTip(JComponent component, String tooltip) { component.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null)); }
From source file:de.iteratec.iteraplan.businesslogic.common.URLBuilder.java
public static String getEntityURL(ObjectExpression instance, RStructuredTypeExpression type, String serverURL) { TypeOfBuildingBlock tobb = null;/*from w w w .j av a 2s . c o m*/ try { tobb = getTOBBForStructuredType(type); } catch (IteraplanTechnicalException e) { return ""; //no link for unknown type } StringBuilder url = new StringBuilder(BUFFER_SIZE); // iteraplan properties are checked for server address override url.append(StringUtils.defaultIfEmpty(APPLICATION_ADDRESS_FROM_PROPERTIES, serverURL)); LOGGER.info("The application address from the properties is: " + APPLICATION_ADDRESS_FROM_PROPERTIES); LOGGER.info("URL created from the application address: " + url.toString()); String typeName = Dialog.dialogNameForClass(tobb.getAssociatedClass()).toLowerCase(Locale.ENGLISH); url.append(FLOW_MAPPING); url.append(typeName); url.append(FORWARD_SLASH); RPropertyExpression idProperty = type.findPropertyByPersistentName(ElasticMiConstants.PERSISTENT_NAME_ID); url.append(idProperty.apply(instance).getOne().asInteger()); return url.toString(); }
From source file:gtu._work.etc.HotnoteMakerUI.java
private void initGUI() { try {//from www.j a v a 2s. c o m ToolTipManager.sharedInstance().setInitialDelay(0); 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("hott notes - checklist", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(612, 348)); { checkListArea = new JTextArea(); jScrollPane1.setViewportView(checkListArea); checkListArea.addMouseListener(new MouseAdapter() { String randomColor() { StringBuilder sb = new StringBuilder().append("#"); for (int ii = 0; ii < 6; ii++) { sb.append(RandomUtil.randomChar('a', 'b', 'c', 'd', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')); } return sb.toString(); } void saveXml(Document document, File file) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-16"); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(file), format); writer.write(document); } catch (IOException e) { JCommonUtil.handleException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { JCommonUtil.handleException(e); } } } } public void mouseClicked(MouseEvent evt) { if (!JMouseEventUtil.buttonLeftClick(2, evt)) { return; } if (StringUtils.isEmpty(checkListArea.getText())) { JCommonUtil ._jOptionPane_showMessageDialog_error("checklist area is empty!"); return; } File file = JCommonUtil._jFileChooser_selectFileOnly_saveFile(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error("file is not correct!"); return; } //XXX StringTokenizer tok = new StringTokenizer(checkListArea.getText(), "\t\n\r\f"); List<String> list = new ArrayList<String>(); String tmp = null; for (; tok.hasMoreElements();) { tmp = ((String) tok.nextElement()).trim(); System.out.println(tmp); list.add(tmp); } //XXX Document document = DocumentHelper.createDocument(); Element rootHot = document.addElement("hottnote"); rootHot.addAttribute("creationtime", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("lastmodified", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("type", "checklist"); //appearence Element appearenceE = rootHot.addElement("appearence"); appearenceE.addAttribute("alpha", "204"); Element fontE = appearenceE.addElement("font"); fontE.addAttribute("face", "Default"); fontE.addAttribute("size", "0"); Element styleE = appearenceE.addElement("style"); styleE.addElement("bg2color").addAttribute("color", randomColor()); styleE.addElement("bgcolor").addAttribute("color", randomColor()); styleE.addElement("textcolor").addAttribute("color", randomColor()); styleE.addElement("titlecolor").addAttribute("color", randomColor()); //behavior rootHot.addElement("behavior"); //content Element contentE = rootHot.addElement("content"); Element checklistE = contentE.addElement("checklist"); for (String val : list) { checklistE.addElement("item").addCDATA(val); } //desktop Element desktopE = rootHot.addElement("desktop"); desktopE.addElement("position").addAttribute("x", RandomUtil.numberStr(3)) .addAttribute("y", RandomUtil.numberStr(3)); desktopE.addElement("size").addAttribute("height", "200").addAttribute("width", "200"); //title Element titleE = rootHot.addElement("title"); titleE.addCDATA(StringUtils.defaultIfEmpty(checkListTitle.getText(), DateFormatUtils.format(System.currentTimeMillis(), "dd/MM/yyyy"))); if (!file.getName().toLowerCase().endsWith(".hottnote")) { file = new File(file.getParentFile(), file.getName() + ".hottnote"); } saveXml(document, file); JCommonUtil._jOptionPane_showMessageDialog_info("completed!\n" + file); } }); } } { checkListTitle = new JTextField(); checkListTitle.setToolTipText("title"); jPanel1.add(checkListTitle, BorderLayout.NORTH); } } } pack(); this.setSize(633, 415); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler.java
@POST @Path("/data/datasets/{name}/admin/upgrade") public void upgrade(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) { Id.Namespace namespace = Id.Namespace.from(namespaceId); try {/*from w w w. j ava 2 s .c o m*/ DatasetAdmin datasetAdmin = getDatasetAdmin(Id.DatasetInstance.from(namespace, instanceName)); datasetAdmin.upgrade(); responder.sendJson(HttpResponseStatus.OK, new DatasetAdminOpResponse(null, null)); } catch (HandlerException e) { LOG.debug("Got handler exception", e); responder.sendString(e.getFailureStatus(), StringUtils.defaultIfEmpty(e.getMessage(), "")); } catch (Exception e) { LOG.error(getAdminOpErrorMessage("upgrade", instanceName), e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, getAdminOpErrorMessage("upgrade", instanceName)); } }
From source file:com.adobe.acs.commons.replication.status.impl.JcrPackageReplicationStatusEventHandler.java
@Override public final JobResult process(final Job job) { final String[] paths = (String[]) job.getProperty(PROPERTY_PATHS); final String replicatedBy = StringUtils.defaultIfEmpty(this.replicatedByOverride, (String) job.getProperty(PROPERTY_REPLICATED_BY)); log.debug("Processing Replication Status Update for JCR Package: {}", paths); ResourceResolver resourceResolver = null; try {// w ww . ja va2s. co m resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO); final List<JcrPackage> jcrPackages = this.getJcrPackages(resourceResolver, paths); if (CollectionUtils.isEmpty(jcrPackages)) { log.warn("JCR Package is unavailable for Replication Status Update at: {}", paths); return JobResult.OK; } for (final JcrPackage jcrPackage : jcrPackages) { try { setReplicationStatus(jcrPackage, replicatedBy, resourceResolver); } finally { // Close each package when we are done. jcrPackage.close(); } } } catch (LoginException e) { logJobError(job, "Could not obtain a resource resolver for applying replication status updates", e); return JobResult.FAILED; } catch (RepositoryException e) { logJobError(job, "Could not update replication metadata", e); return JobResult.FAILED; } finally { if (resourceResolver != null) { resourceResolver.close(); } } return JobResult.OK; }