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.atlassian.jira.plugins.dvcs.webwork.ConfigureDvcsOrganizations.java
public String getSourceOrDefault() { return StringUtils.defaultIfEmpty(source, DEFAULT_SOURCE); }
From source file:it.skymedia.idolTunnel.IdolOEMConnection.java
/** * Constructor: initialization of non-static properties, * then testing comnection and some service actions to an HP IDOL Server *///from w ww. ja va 2 s. com public IdolOEMConnection() { final String host = StringUtils.defaultIfEmpty(properties.getProperty("host"), "localhost"); final int aciPort = NumberUtils.toInt(properties.getProperty("aciPort"), 9000); //final int indexPort = NumberUtils.toInt(properties.getProperty("indexPort"), 9001); try { AciServerDetails sd = new AciServerDetails(host, aciPort); if (Boolean.parseBoolean((String) properties.get("isOEMLicensed"))) { encryptionKey = (String) properties.get("encryptionKey"); sd.setEncryptionCodec(new BteaEncryptionCodec(encryptionKey)); } // Construct the AciService to use... aciService = new AciServiceImpl(new AciHttpClientImpl(new DefaultHttpClient()), sd); /* TEST ACI CONNECTION */ System.out.println("You have successfully communicated to an " + getversion()); /* try action=GetLicenseInfo */ System.out.println("\n\t*** License Info ***\n" + getlicenseinfo("json")); // try action=GetStatus... System.out.println("\n\t*** GetStatus of the server ***\n" + getstatus()); /* try action=GetRequestsLog */ System.out.println("\n\t*** GRL ***\n" + grl(50L)); } catch (Exception e) { log.severe(e.getLocalizedMessage() + "\n"); e.printStackTrace(); } }
From source file:com.adaptris.core.services.mime.FlattenMimeParts.java
private String generateIfNoContentId(BodyPart p) throws Exception { String result = null;/*from ww w. ja v a2 s . c o m*/ try { String[] s = Args.notNull(p.getHeader(HEADER_CONTENT_ID), HEADER_CONTENT_ID); result = s[0]; } catch (IllegalArgumentException e) { } return StringUtils.defaultIfEmpty(result, GUID.getUUID()); }
From source file:de.thischwa.pmcms.view.context.object.GalleryLinkTool.java
/** * Set link to the desired {@link Image}. *///from w ww . j a v a2s . c o m public GalleryLinkTool getImage(final Image imageToLink) { if (imageToLink == null) setLink("NO_IMAGE_FOUND"); else if (isExportView) { Level currentLevel = pojoHelper.getLevel(); Level levelLinkTo = imageToLink.getParent().getParent(); String path = PathTool.getURLRelativePathToLevel(currentLevel, levelLinkTo) .concat(StringUtils.defaultIfEmpty(PathTool.getExportBaseFilename(imageToLink, pm.getSiteProperty("pmcms.site.export.file.extension")), "IMAGE_NOT_EXISTS")); path = PathTool.encodePath(path); setLink(path); } else setImageForPreview(imageToLink); return this; }
From source file:com.adobe.acs.commons.http.injectors.AbstractHtmlRequestInjector.java
@SuppressWarnings("squid:S1149") protected final void registerAsSlingFilter(ComponentContext ctx, int ranking, String pattern) { Dictionary<String, String> filterProps = new Hashtable<String, String>(); filterProps.put("service.ranking", String.valueOf(ranking)); filterProps.put("sling.filter.scope", "REQUEST"); filterProps.put("sling.filter.pattern", StringUtils.defaultIfEmpty(pattern, ".*")); filterRegistration = ctx.getBundleContext().registerService(Filter.class.getName(), this, filterProps); }
From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java
private void initGUI() { try {// ww w. j a v a2 s . c om { } BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("source", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { replaceArea = new JTextArea(); jScrollPane1.setViewportView(replaceArea); replaceArea.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JPopupMenuUtil.newInstance(replaceArea).applyEvent(evt) .addJMenuItem("load from file", true, new ActionListener() { Thread newThread; public void actionPerformed(ActionEvent arg0) { if (newThread != null && newThread.getState() != Thread.State.TERMINATED) { JCommonUtil._jOptionPane_showMessageDialog_error( "file is loading!"); return; } final File file = JCommonUtil._jFileChooser_selectFileOnly(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error( "file is not correct!"); return; } String defaultCharset = Charset.defaultCharset().displayName(); String chst = (String) JCommonUtil._jOptionPane_showInputDialog( "input your charset!", defaultCharset); final Charset charset2 = Charset.forName( StringUtils.defaultIfEmpty(chst, defaultCharset)); newThread = new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { public void run() { try { loadFromFileSb = new StringBuilder(); BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(file), charset2)); for (String line = null; (line = reader .readLine()) != null;) { loadFromFileSb.append(line + "\n"); } reader.close(); replaceArea .setText(loadFromFileSb.toString()); JCommonUtil ._jOptionPane_showMessageDialog_info( "load completed!"); } catch (Exception e) { JCommonUtil.handleException(e); } } }, "" + System.currentTimeMillis()); newThread.setDaemon(true); newThread.start(); } }).show(); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("param", null, jPanel2, null); { exeucte = new JButton(); jPanel2.add(exeucte, BorderLayout.SOUTH); exeucte.setText("exeucte"); exeucte.setPreferredSize(new java.awt.Dimension(491, 125)); exeucte.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.CENTER); { repFromText = new JTextField(); } { repToText = new JTextField(); } jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup() .addContainerGap(25, 25) .addGroup(jPanel3Layout.createParallelGroup() .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repFromText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repToText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(repFromText, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(repToText, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { prop.put(repFromText.getText(), repToText.getText()); reloadTemplateList(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(491, 283)); { DefaultTableModel resultAreaModel = JTableUtil.createModel(true, "match", "count"); resultArea = new JTable(); jScrollPane2.setViewportView(resultArea); JTableUtil.defaultSetting(resultArea); resultArea.setModel(resultAreaModel); } } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jTabbedPane1.addTab("template", null, jPanel5, null); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); { templateList = new JList(); jScrollPane3.setViewportView(templateList); reloadTemplateList(); } templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } Entry<Object, Object> entry = (Entry<Object, Object>) JListUtil .getLeadSelectionObject(templateList); repFromText.setText((String) entry.getKey()); repToText.setText((String) entry.getValue()); } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); } } { jPanel6 = new JPanel(); FlowLayout jPanel6Layout = new FlowLayout(); jPanel6.setLayout(jPanel6Layout); jTabbedPane1.addTab("result1", null, jPanel6, null); { resultBtn1 = new JButton(); jPanel6.add(resultBtn1); resultBtn1.setText("to String[]"); resultBtn1.setPreferredSize(new java.awt.Dimension(105, 32)); resultBtn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTableUtil tableUtil = JTableUtil.newInstance(resultArea); int[] rowPoss = tableUtil.getSelectedRows(); DefaultTableModel model = tableUtil.getModel(); List<Object> valueList = new ArrayList<Object>(); for (int ii = 0; ii < rowPoss.length; ii++) { valueList.add(model.getValueAt(rowPoss[ii], 0)); } String reult = valueList.toString().replaceAll("[\\s]", "") .replaceAll("[\\,]", "\",\"").replaceAll("[\\[\\]]", "\""); ClipboardUtil.getInstance().setContents(reult); } }); } { resultBtn2 = new JButton(); jPanel6.add(resultBtn2); resultBtn2.setText("TODO"); resultBtn2.setPreferredSize(new java.awt.Dimension(105, 32)); resultBtn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("resultBtn1.actionPerformed, event=" + evt); // TODO add your code for // resultBtn1.actionPerformed JCommonUtil._jOptionPane_showMessageDialog_info("TODO"); } }); } } } this.setSize(512, 350); JCommonUtil.setFont(repToText, repFromText, replaceArea, templateList); { panel = new JPanel(); jTabbedPane1.addTab("eBao", null, panel, null); panel.setLayout(new BorderLayout(0, 0)); { scrollPane = new JScrollPane(); panel.add(scrollPane, BorderLayout.CENTER); { ebaoTable = new JTable(); scrollPane.setViewportView(ebaoTable); // TODO DefaultTableModel ebaoModel = JTableUtil.createModel(true, "match", "label"); JTableUtil.defaultSetting(ebaoTable); ebaoTable.setModel(ebaoModel); } } { exactEbaoSearchChk = new JCheckBox(""); panel.add(exactEbaoSearchChk, BorderLayout.NORTH); } } JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (StringUtils.isNotBlank(repFromText.getText())) { prop.put(repFromText.getText(), repToText.getText()); } try { prop.store(new FileOutputStream(propFile), "regexText"); } catch (Exception e) { JCommonUtil.handleException("properties store error!", e); } setVisible(false); dispose(); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:it.ciroppina.idol.generic.tunnel.IdolOEMTunnel.java
/** * Constructor: initialization of non-static properties, * then testing comnection and some service actions to an HP IDOL Server *///from ww w . j a v a2 s . c o m public IdolOEMTunnel() { final String host = StringUtils.defaultIfEmpty(properties.getProperty("host"), "localhost"); final int aciPort = NumberUtils.toInt(properties.getProperty("aciPort"), 9000); //final int indexPort = NumberUtils.toInt(properties.getProperty("indexPort"), 9001); try { AciServerDetails sd = new AciServerDetails(host, aciPort); if (Boolean.parseBoolean((String) properties.get("isOEMLicensed"))) { encryptionKey = (String) properties.get("encryptionKey"); sd.setEncryptionCodec(new BteaEncryptionCodec(encryptionKey)); } // Construct the AciService to use... aciService = new AciServiceImpl(new AciHttpClientImpl(new DefaultHttpClient()), sd); /* TEST ACI CONNECTION */ System.out.println("You have successfully communicated to an " + getversion()); /* try action=GetLicenseInfo */ System.out.println("\n\t*** License Info ***\n" + getlicenseinfo("json")); // try action=GetStatus... //System.out.println("\n\t*** GetStatus of the server ***\n" + getstatus()); /* try action=GetRequestsLog */ //System.out.println("\n\t*** GRL ***\n" + grl(50L) ); } catch (Exception e) { log.severe(e.getLocalizedMessage() + "\n"); e.printStackTrace(); } }
From source file:kirchnerei.glatteis.page.CommonPage.java
private String getMenuMessage(String name, String property, String defaultValue) { String key = String.format("action.%s.%s", name, property); try {//from w w w . j av a 2s .c o m return getMessage(key); } catch (Exception e) { LogUtils.trace(log, "messages key '%s' is missing", key); return StringUtils.defaultIfEmpty(defaultValue, key); } }
From source file:com.gst.portfolio.client.domain.ClientNonPerson.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(9); if (command.isChangeInStringParameterNamed(ClientApiConstants.incorpNumberParamName, this.incorpNumber)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.incorpNumberParamName); actualChanges.put(ClientApiConstants.incorpNumberParamName, newValue); this.incorpNumber = StringUtils.defaultIfEmpty(newValue, null); }/* w ww. j av a 2 s. c o m*/ if (command.isChangeInStringParameterNamed(ClientApiConstants.remarksParamName, this.remarks)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.remarksParamName); actualChanges.put(ClientApiConstants.remarksParamName, newValue); this.remarks = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.incorpValidityTillParamName, getIncorpValidityTillLocalDate())) { final String valueAsInput = command .stringValueOfParameterNamed(ClientApiConstants.incorpValidityTillParamName); actualChanges.put(ClientApiConstants.incorpValidityTillParamName, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(ClientApiConstants.incorpValidityTillParamName); this.incorpValidityTill = newValue.toDate(); } if (command.isChangeInLongParameterNamed(ClientApiConstants.constitutionIdParamName, constitutionId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.constitutionIdParamName); actualChanges.put(ClientApiConstants.constitutionIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.mainBusinessLineIdParamName, mainBusinessLineId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.mainBusinessLineIdParamName); actualChanges.put(ClientApiConstants.mainBusinessLineIdParamName, newValue); } //validate(); return actualChanges; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.AttributeWorkbook.java
/** * Imports the data out of the specified Excel file input stream. If data * could not be imported, an {@code empty} list will be returned. * /*from ww w . jav a 2s . com*/ * @param is the Excel file input stream * @return the list of imported object related permission data objects */ public AttributeData doImport(InputStream is) { AttributeData result = new AttributeData(); loadWorkbookFromInputStream(is); initSheetImporters(); initAttributeTypeHeadlines(); if (!readInConfigSheet()) { getProcessingLog().error("Could not read in configuration sheet. Aborting."); return result; } calculateAllFormulas(); for (int i = 0; i < getWb().getNumberOfSheets(); i++) { Sheet sheet = getWb().getSheetAt(i); String sheetName = sheet.getSheetName(); getProcessingLog().info("Current Sheet: " + StringUtils.defaultIfEmpty(sheetName, "null")); if (DEFAULT_SHEET_KEY.equals(sheetName)) { continue; } if (!SHEET_IMPORTER.containsKey(sheetName)) { getProcessingLog().error("No import is available for this sheet."); continue; } importSheet(sheet, result); } return result; }