List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str)
Returns either the passed in String, or if the String is null , an empty String ("").
StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"
From source file:com.netsteadfast.greenstep.bsc.model.HistoryItemScoreNoticeHandler.java
public HistoryItemScoreNoticeHandler vision(String visionId, String ruleExpression) { if (StringUtils.isBlank(visionId) || this.visions.get(visionId) != null) { return this; }//from w ww . j a v a2s .c o m this.visions.put(visionId, StringUtils.defaultString(ruleExpression).trim()); return this; }
From source file:com.mirth.connect.donkey.server.queue.DestinationQueue.java
private Integer getBucket(ConnectorMessage connectorMessage) { Integer bucket = connectorMessage.getQueueBucket(); // Get the bucket if we haven't already, or if value replacement needs to be done if (bucket == null || regenerateTemplate) { String groupByVariable = groupBy; /*/*from w w w . jav a 2 s .c om*/ * If we're not regenerating connector properties, then we need to get the group by * variable from the actual persisted sent content, because it could be different than * what is being used in the currently deployed revision. */ if (!regenerateTemplate) { try { ConnectorProperties sentProperties = connectorMessage.getSentProperties(); if (sentProperties == null) { sentProperties = serializer.deserialize(connectorMessage.getSent().getContent(), ConnectorProperties.class); connectorMessage.setSentProperties(sentProperties); } groupByVariable = StringUtils .defaultString(((DestinationConnectorPropertiesInterface) sentProperties) .getDestinationConnectorProperties().getThreadAssignmentVariable()); } catch (SerializerException e) { } } String groupByValue = String.valueOf(messageMaps.get(groupByVariable, connectorMessage)); // Attempt to get the bucket from the initial assignment map first bucket = initialThreadAssignmentMap.get(groupByValue); if (bucket == null) { /* * If the initial assignment map isn't yet full, assign the next available queue * bucket directly to the assignment value. Otherwise, calculate the bucket using * the hash function. */ if (initialThreadAssignmentMap.size() < queueBuckets) { synchronized (initialThreadAssignmentMap) { int size = initialThreadAssignmentMap.size(); if (size < queueBuckets) { bucket = size; initialThreadAssignmentMap.put(groupByValue, bucket); } } } if (bucket == null) { // Calculate the 32-bit hash, then reduce it to one of the buckets bucket = Math.abs(hashFunction.hashUnencodedChars(groupByValue).asInt() % queueBuckets); } } connectorMessage.setQueueBucket(bucket); } return bucket; }
From source file:com.netsteadfast.greenstep.bsc.model.HistoryItemScoreNoticeHandler.java
public HistoryItemScoreNoticeHandler perspective(String perspectiveId, String ruleExpression) { if (StringUtils.isBlank(perspectiveId) || this.perspectives.get(perspectiveId) != null) { return this; }//from w w w.jav a 2 s.c o m this.perspectives.put(perspectiveId, StringUtils.defaultString(ruleExpression).trim()); return this; }
From source file:gtu._work.ui.ObnfExceptionLogDownloadUI.java
private void makeReportBtnPerformed() { try {// w w w . ja v a 2 s . c o m final String messageIdAreaText = StringUtils.defaultString(messageIdArea.getText()); String destDirStr = exportTextField.getText(); if (StringUtils.isBlank(destDirStr)) { JCommonUtil._jOptionPane_showMessageDialog_error(""); return; } final File destDir = new File(destDirStr); if (!destDir.exists()) { JCommonUtil._jOptionPane_showMessageDialog_error("?"); return; } final ObnfRepairDBBatch batch = new ObnfRepairDBBatch(); if (StringUtils.isNotBlank(domainJarText.getText())) { File domainJarFile = new File(domainJarText.getText()); if (domainJarFile.exists() && domainJarFile.isFile() && domainJarFile.getName().endsWith(".jar")) { batch.setDomainJar(domainJarFile); } } batch.setOut(new PrintStream(new PrintStreamAdapter("big5") { @Override public void println(String message) { logArea.append(message + "\n"); } })); new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { @Override public void run() { try { if (destDir.isFile()) { batch.executeDecrypt(destDir); } else { batch.execute(messageIdAreaText, destDir); } JCommonUtil._jOptionPane_showMessageDialog_info("?, log"); } catch (Throwable ex) { JCommonUtil.handleException(ex); } } }, "xxxxxxxxxxxx").start(); } catch (Throwable ex) { JCommonUtil.handleException(ex); } }
From source file:net.andydvorak.intellij.lessc.fs.LessFile.java
/** * Copies the contents of the temp file to its corresponding CSS file(s) in every output directory specified in the profile. * @throws IOException/*from ww w . j a v a 2 s .c om*/ */ private void updateCssFiles(@NotNull final File cssTempFile, @NotNull final LessProfile lessProfile) throws IOException { if (cssTempFile.length() == 0) { FileUtil.delete(cssTempFile); return; } final File lessProfileDir = lessProfile.getLessDir(); final String relativeLessPath = StringUtils.defaultString(FileUtil.getRelativePath(lessProfileDir, this)); final String relativeCssPath = relativeLessPath.replaceFirst("\\.less$", ".css"); final String cssTempFileContent = FileUtil.loadFile(cssTempFile); int numUpdated = 0; for (CssDirectory cssDirectory : lessProfile.getCssDirectories()) { final File cssDestFile = new File(cssDirectory.getPath(), relativeCssPath); // CSS file hasn't changed, so don't bother updating if (cssDestFile.exists() && FileUtil.loadFile(cssDestFile).equals(cssTempFileContent)) continue; numUpdated++; FileUtil.createIfDoesntExist(cssDestFile); FileUtil.copy(cssTempFile, cssDestFile); refreshCssFile(cssDirectory, cssDestFile); } FileUtil.delete(cssTempFile); cssChanged.set(numUpdated > 0); }
From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java
private void createDateRange(PdfPTable table, VisionVO vision, Context context, int maxRows) throws Exception { String frequency = (String) context.get("frequency"); String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim(); String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim(); String startDate = StringUtils.defaultString((String) context.get("startDate")).trim(); String endDate = StringUtils.defaultString((String) context.get("endDate")).trim(); String date1 = startDate;/*from www . j a va 2 s .c om*/ String date2 = endDate; if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) { date1 = startYearDate + "/01/01"; date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12); } Map<String, Object> headContentMap = new HashMap<String, Object>(); this.fillHeadContent(context, headContentMap); String content = "Frequency: " + BscMeasureDataFrequency.getFrequencyMap(false).get(frequency) + " Date range: " + date1 + " ~ " + date2 + "\n" + StringUtils.defaultString((String) headContentMap.get("headContent")); PdfPCell cell = null; cell = new PdfPCell(); cell.addElement(new Phrase(content, this.getFont(BscReportPropertyUtils.getFontColor(), false))); this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor()); cell.setColspan(maxRows); table.addCell(cell); for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { cell = new PdfPCell(); cell.addElement(new Phrase(kpi.getName(), this.getFont(kpi.getFontColor(), false))); this.setCellBackgroundColor(cell, kpi.getBgColor()); cell.setColspan(4); cell.setRowspan(2); table.addCell(cell); for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) { cell = new PdfPCell(); cell.addElement( new Phrase(dateScore.getDate(), this.getFont(dateScore.getFontColor(), false))); this.setCellBackgroundColor(cell, dateScore.getBgColor()); table.addCell(cell); } for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) { Image image = Image .getInstance(BscReportSupportUtils.getByteIcon(kpi, dateScore.getScore())); image.setWidthPercentage(20f); cell = new PdfPCell(); cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateScore.getScore()), this.getFont(dateScore.getFontColor(), false))); cell.addElement(image); this.setCellBackgroundColor(cell, dateScore.getBgColor()); table.addCell(cell); } } } } }
From source file:gtu._work.ui.RegexReplacer.java
private void initGUI() { try {//from w ww . j av a 2s . c o m BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { try { if (configHandler != null && jTabbedPane1.getSelectedIndex() == TabIndex.TEMPLATE.ordinal()) { System.out.println("-------ChangeEvent[" + jTabbedPane1.getSelectedIndex() + "]"); configHandler.reloadTemplateList(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); 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); } } } { 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.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); jPanel2.add(JCommonUtil.createScrollComponent(jPanel3), BorderLayout.CENTER); jPanel3.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, RowSpec.decode("default:grow"), })); { lblNewLabel = new JLabel("key"); jPanel3.add(lblNewLabel, "2, 2, right, default"); } { configKeyText = new JTextField(); jPanel3.add(configKeyText, "4, 2, fill, default"); configKeyText.setColumns(10); } { lblNewLabel_1 = new JLabel("from"); jPanel3.add(lblNewLabel_1, "2, 4, right, default"); } { repFromText = new JTextArea(); repFromText.setRows(3); jPanel3.add(JCommonUtil.createScrollComponent(repFromText), "4, 4, fill, default"); repFromText.setColumns(10); } { lblNewLabel_2 = new JLabel("to"); jPanel3.add(lblNewLabel_2, "2, 6, right, default"); } { repToText = new JTextArea(); repToText.setRows(3); // repToText.setPreferredSize(new Dimension(0, 50)); jPanel3.add(JCommonUtil.createScrollComponent(repToText), "4, 6, fill, default"); } } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { configHandler.put(configKeyText.getText(), repFromText.getText(), repToText.getText(), tradeOffArea.getText()); configHandler.reloadTemplateList(); } }); } } { 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); } templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } PropConfigHandler.Config config = (PropConfigHandler.Config) JListUtil .getLeadSelectionObject(templateList); configKeyText.setText(config.configKeyText); repFromText.setText(config.fromVal); repToText.setText(config.toVal); tradeOffArea.setText(config.tradeOff); templateList.setToolTipText(config.fromVal + " <----> " + config.toVal); if (JMouseEventUtil.buttonLeftClick(2, evt)) { String replaceText = StringUtils.defaultString(replaceArea.getText()); replaceText = replacer(config.fromVal, config.toVal, replaceText); resultArea.setText(replaceText); jTabbedPane1.setSelectedIndex(TabIndex.RESULT.ordinal()); // pasteTextToClipboard(); } } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); // ? JListUtil.newInstance(templateList).setItemColorTextProcess(new ItemColorTextHandler() { public Pair<String, Color> setColorAndText(Object value) { PropConfigHandler.Config config = (PropConfigHandler.Config) value; if (config.tradeOffScore != 0) { return Pair.of(null, Color.GREEN); } return null; } }); // ? } { scheduleExecute = new JButton(); jPanel5.add(scheduleExecute, BorderLayout.SOUTH); scheduleExecute.setText("schedule execute"); scheduleExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scheduleExecuteActionPerformed(evt); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); { resultArea = new JTextArea(); jScrollPane2.setViewportView(resultArea); } } } } { configHandler = new PropConfigHandler(prop, propFile, templateList, replaceArea); JCommonUtil.setFont(repToText, repFromText, replaceArea, templateList); { tradeOffArea = new JTextArea(); tradeOffArea.setRows(3); // tradeOffArea.setPreferredSize(new Dimension(0, 50)); tradeOffArea.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (JMouseEventUtil.buttonLeftClick(2, e)) { String tradeOff = StringUtils.trimToEmpty(tradeOffArea.getText()); JSONObject json = null; if (StringUtils.isBlank(tradeOff)) { json = new JSONObject(); json.put(CONTAIN_ARRY_KEY, new JSONArray()); json.put(NOT_CONTAIN_ARRY_KEY, new JSONArray()); tradeOff = json.toString(); } else { json = JSONObject.fromObject(tradeOff); } // String selectItem = (String) JCommonUtil._JOptionPane_showInputDialog( "?!", "?", new Object[] { "NA", "equal", "not_equal", "ftl" }, "NA"); if ("NA".equals(selectItem)) { return; } String string = StringUtils.trimToEmpty( JCommonUtil._jOptionPane_showInputDialog(":")); string = StringUtils.trimToEmpty(string); if (StringUtils.isBlank(string)) { tradeOffArea.setText(json.toString()); return; } String arryKey = ""; String boolKey = ""; String strKey = ""; String intKey = ""; if (selectItem.equals("equal")) { arryKey = CONTAIN_ARRY_KEY; } else if (selectItem.equals("not_equal")) { arryKey = NOT_CONTAIN_ARRY_KEY; } else if (selectItem.equals("ftl")) { strKey = FREEMARKER_KEY; } else { throw new RuntimeException(" : " + selectItem); } if (StringUtils.isNotBlank(arryKey)) { if (!json.containsKey(arryKey)) { json.put(arryKey, new JSONArray()); } JSONArray arry = (JSONArray) json.get(arryKey); boolean findOk = false; for (int ii = 0; ii < arry.size(); ii++) { if (StringUtils.equalsIgnoreCase(arry.getString(ii), string)) { findOk = true; break; } } if (!findOk) { arry.add(string); } } else if (StringUtils.isNotBlank(strKey)) { json.put(strKey, string); } else if (StringUtils.isNotBlank(intKey)) { json.put(intKey, Integer.parseInt(string)); } else if (StringUtils.isNotBlank(boolKey)) { json.put(boolKey, Boolean.valueOf(string)); } tradeOffArea.setText(json.toString()); JCommonUtil._jOptionPane_showMessageDialog_info("?!"); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); { panel = new JPanel(); jPanel3.add(panel, "4, 8, fill, fill"); { multiLineCheckBox = new JCheckBox(""); panel.add(multiLineCheckBox); } { autoPasteToClipboardCheckbox = new JCheckBox(""); panel.add(autoPasteToClipboardCheckbox); } } { lblNewLabel_3 = new JLabel("? "); jPanel3.add(lblNewLabel_3, "2, 10"); } jPanel3.add(JCommonUtil.createScrollComponent(tradeOffArea), "4, 10, fill, fill"); } configHandler.reloadTemplateList(); } this.setSize(512, 350); JCommonUtil.setJFrameCenter(this); JCommonUtil.defaultToolTipDelay(); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { 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:com.netsteadfast.greenstep.bsc.model.HistoryItemScoreNoticeHandler.java
public HistoryItemScoreNoticeHandler objective(String objectiveId, String ruleExpression) { if (StringUtils.isBlank(objectiveId) || this.objectives.get(objectiveId) != null) { return this; }//www. j a v a 2s.c o m this.objectives.put(objectiveId, StringUtils.defaultString(ruleExpression).trim()); return this; }
From source file:com.netsteadfast.greenstep.util.MenuSupportUtils.java
/** * ??(?)//from w w w. j a va 2s . c o m * * @param basePath * @return * @throws ServiceException * @throws Exception */ public static MenuResultObj getMenuData(String basePath, String jsessionId, String localeCode) throws ServiceException, Exception { if (LocaleLanguageUtils.getMap().get(localeCode) == null) { localeCode = LocaleLanguageUtils.getDefault(); } Map<String, String> orderParams = new HashMap<String, String>(); orderParams.put("name", "asc"); List<TbSys> sysList = sysService.findListByParams(null, null, orderParams); if (sysList == null || sysList.size() < 1) { // ? TB_SYS throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS)); } MenuResultObj resultObj = new MenuResultObj(); StringBuilder jsSb = new StringBuilder(); StringBuilder htmlSb = new StringBuilder(); StringBuilder dlgSb = new StringBuilder(); jsSb.append("var ").append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append(" = new Object(); ") .append("\n"); jsSb.append("function ").append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_FN).append(" { ") .append("\n"); jsSb.append(" var name = ").append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("[progId];") .append("\n"); jsSb.append(" if (name == null) { ").append("\n"); jsSb.append(" return progId; ").append("\n"); jsSb.append(" } ").append("\n"); jsSb.append(" return name; ").append("\n"); jsSb.append("} ").append("\n"); for (TbSys sys : sysList) { Map<String, String> menuData = getMenuData(basePath, sys, jsessionId, localeCode); jsSb.append(StringUtils.defaultString(menuData.get(MENU_ITEM_JAVASCRIPT))); htmlSb.append(StringUtils.defaultString(menuData.get(MENU_ITEM_HTML))); dlgSb.append(StringUtils.defaultString(menuData.get(MENU_ITEM_DIALOG))); } resultObj.setJavascriptData(jsSb.toString()); resultObj.setHtmlData(htmlSb.toString()); resultObj.setDialogHtmlData(dlgSb.toString()); return resultObj; }
From source file:com.netsteadfast.greenstep.bsc.model.HistoryItemScoreNoticeHandler.java
public HistoryItemScoreNoticeHandler kpi(String kpiId, String ruleExpression) { if (StringUtils.isBlank(kpiId) || this.kpis.get(kpiId) != null) { return this; }/*from ww w . j a v a2 s . c om*/ this.kpis.put(kpiId, StringUtils.defaultString(ruleExpression).trim()); return this; }