List of usage examples for org.apache.commons.lang StringUtils replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
From source file:feedsplugin.FeedsSettingsTab.java
public JPanel createSettingsPanel() { final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder( FormFactory.RELATED_GAP_COLSPEC.encode() + ", fill:default:grow"); final CellConstraints cc = new CellConstraints(); mListModel = new DefaultListModel(); for (String feed : mSettings.getFeeds()) { mListModel.addElement(feed);/*from www .j av a2 s .c o m*/ } mFeeds = new JList(mListModel); mFeeds.setSelectedIndex(0); mFeeds.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mFeeds.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { listSelectionChanged(); } }); panelBuilder.addGrowingRow(); panelBuilder.add(new JScrollPane(mFeeds), cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); mAdd = new JButton(mLocalizer.msg("add", "Add feed")); mAdd.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { String genre = JOptionPane.showInputDialog(mLocalizer.msg("addMessage", "Add feed URL"), ""); if (genre != null) { genre = genre.trim(); if (genre.length() > 0) { mListModel.addElement(genre); } } } }); mRemove = new JButton(mLocalizer.msg("remove", "Remove feed")); mRemove.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final int index = mFeeds.getSelectedIndex(); if (index >= 0) { mListModel.remove(index); } } }); panelBuilder.addRow(); ButtonBarBuilder2 buttonBar = new ButtonBarBuilder2(); buttonBar.addButton(new JButton[] { mAdd, mRemove }); panelBuilder.add(buttonBar.getPanel(), cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); mFeeds.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { mRemove.setEnabled(mFeeds.getSelectedIndex() >= 0); } }); panelBuilder.addParagraph(mLocalizer.msg("moreFeeds", "Get more feeds")); panelBuilder.addRow(); JEditorPane help = UiUtilities.createHtmlHelpTextArea(mLocalizer.msg("help", "You can find more news feeds on the <a href=\"{0}\">plugin help page</a>. If you know more interesting feeds, feel free to add them on that page.", StringUtils.replace(PluginInfo.getHelpUrl(FeedsPlugin.getInstance().getId()), "&", "&"))); panelBuilder.add(help, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); // force update of enabled states listSelectionChanged(); return panelBuilder.getPanel(); }
From source file:com.opengamma.id.UniqueId.java
/** * Parses a {@code UniqueId} from a formatted scheme and value. * <p>/*ww w .j av a 2 s.co m*/ * This parses the identifier from the form produced by {@code toString()} * which is {@code <SCHEME>~<VALUE>~<VERSION>}. * * @param str the unique identifier to parse, not null * @return the unique identifier, not null * @throws IllegalArgumentException if the identifier cannot be parsed */ @FromString public static UniqueId parse(String str) { ArgumentChecker.notEmpty(str, "str"); if (str.contains("~") == false) { str = StringUtils.replace(str, "::", "~"); // leniently parse old data } String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, "~"); switch (split.length) { case 2: return UniqueId.of(split[0], split[1], null); case 3: return UniqueId.of(split[0], split[1], split[2]); } throw new IllegalArgumentException("Invalid identifier format: " + str); }
From source file:com.collegesource.interfaces.student.BannerStudentFinder.java
private void createStuMasterAndStuDemoRecord(StuMaster stuMaster) { logger.debug("Attempting to save StuMaster and StuDemo Record for student."); String insertStuMasterQuery = "Insert into Stu_Master(Instidq, Instid, Stuno) values ('" + stuMaster.getInstidq() + "','" + stuMaster.getInstid() + "','" + stuMaster.getStuno() + "')"; try {//ww w .j a va 2 s . c o m //StuMaster Insert logger.debug("StuMasterQuery[" + insertStuMasterQuery + "]"); int stuMasterResult = jdbcTemplate.update(insertStuMasterQuery); logger.debug("Inserted [" + stuMasterResult + "] Records"); //Get IntSeqNo from StuMaster (Sequence PK) String intSeqNoQuery = "Select int_seq_no from Stu_Master where instidq = '" + stuMaster.getInstidq() + "' and instid = '" + stuMaster.getInstid() + "' and stuno = '" + stuMaster.getStuno() + "'"; logger.debug("IntSeqNoQuery[" + intSeqNoQuery + "]"); List<Map<String, Object>> results = jdbcTemplate.queryForList(intSeqNoQuery); logger.debug("Results[" + results + "], Getting First Result"); //Set IntSeqNo to StuMaster Object stuMaster.setIntSeqNo(((BigDecimal) results.get(0).get("int_seq_no")).intValue()); //StuDemo Insert String insertStuDemoQuery = "Insert into Stu_Demo (Stu_Mast_no, Source_Id, Stuname) values ('" + stuMaster.getIntSeqNo() + "','" + stuMaster.getInstid() + "','" + StringUtils.replace(stuMaster.getStuDemos().get(0).getStuname(), "'", "''") + "')"; int stuDemoResult = jdbcTemplate.update(insertStuDemoQuery); logger.debug("Inserted [" + stuDemoResult + "] Records"); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.thistech.spotlink.engine.AbstractPlacementDecisionEngine.java
/** * Build an HttpPost with the// w ww . j a v a2 s. co m * @param body The body * @return The HttpPost */ protected HttpPost buildHttpPost(Object body) { HttpPost post = new HttpPost(getEndpoint()); post.setHeader("Content-type", "application/xml"); post.setHeader("accept", "application/xml"); try { if (!(body instanceof String)) { body = XmlUtil.marshalToString(this.getJaxbContext(), body); } // freewheel requests need namespace removed body = StringUtils.replace((String) body, "fwns:", ""); log.info(String.format("request body: %s", body)); StringEntity bodyEntity = new StringEntity((String) body); bodyEntity.setContentType("text/xml"); post.setEntity(bodyEntity); return post; } catch (Exception e) { throw new SpotLinkException(e); } }
From source file:com.shmsoft.dmass.main.ActionStaging.java
private boolean downloadUri(String[] dirs) throws Exception { boolean anyDownload = false; File downloadDirFile = new File(ParameterProcessing.DOWNLOAD_DIR); if (downloadDirFile.exists()) { Util.deleteDirectory(downloadDirFile); }/*from w ww .j av a 2 s . c o m*/ new File(ParameterProcessing.DOWNLOAD_DIR).mkdirs(); List<DownloadItem> downloadItems = new ArrayList<>(); for (String dir : dirs) { URI uri = null; String path; String savePath; try { uri = new URI(dir); path = uri.getPath(); path = StringUtils.replace(path, "/", ""); savePath = ParameterProcessing.DOWNLOAD_DIR + "/" + path; DownloadItem di = new DownloadItem(); di.uri = uri; di.file = dir; di.savePath = savePath; downloadItems.add(di); } catch (URISyntaxException e) { History.appendToHistory("Incorrect URI syntax, skipping that: " + uri); continue; } } setDownloadState(downloadItems.size()); for (DownloadItem di : downloadItems) { try { if (interrupted) { return anyDownload; } setProcessingFile(di.uri.toString()); URL url = new URL(di.file); URLConnection con = url.openConnection(); BufferedInputStream in = new BufferedInputStream(con.getInputStream()); FileOutputStream out = new FileOutputStream(di.savePath); History.appendToHistory("Download from " + di.uri + " to " + di.savePath); int i; byte[] bytesIn = new byte[1024]; while ((i = in.read(bytesIn)) >= 0) { out.write(bytesIn, 0, i); } out.close(); in.close(); anyDownload = true; File downloadedFile = new File(di.savePath); totalSize += downloadedFile.length(); progress(1); } catch (Exception e) { System.out.println(e.getMessage()); } } return anyDownload; }
From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java
/** * @param str/*from w w w. j a v a2s .com*/ * @return */ public static String convertToAcsii(final String str) { String s = str; for (int ii = 0; ii < chars.length; ii++) { s = StringUtils.replace(s, chars[ii], ascii[ii]); } return s; }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getCmdLineFriendlyUrl(final String url) { return StringUtils.replace(url, " ", "%20"); }
From source file:gov.nih.nci.cabig.caaers.web.admin.AgentImporter.java
/** * This method accepts a String which should be like * "723227","(161-180)ESO-1 Peptide" //from w ww .j a va2 s . c o m * It splits the string into 2 tokens and creates a Agent object. * If the number of token are less than 2 the record/line is rejected. * @param agentString * @param lineNumber * @return */ protected DomainObjectImportOutcome<Agent> processAgent(String agentString, int lineNumber) { DomainObjectImportOutcome<Agent> agentImportOutcome = null; Agent agent = null; StringTokenizer st = null; String nscNumber; String agentName; if (StringUtils.isNotEmpty(agentString)) { logger.debug("Orginial line from file -- >>> " + agentString); agentString = agentString.trim(); //Replace ", with "| //This is done to set a delimiter other than , agentString = StringUtils.replace(agentString, "\",", "\"|"); logger.debug("Modified line -- >>> " + agentString); //Generate tokens from input String. st = new StringTokenizer(agentString, "|"); //If there are 2 tokens as expected, process the record. Create a Agent object. if (st.hasMoreTokens() && st.countTokens() == 2) { agentImportOutcome = new DomainObjectImportOutcome<Agent>(); agent = new Agent(); nscNumber = StringUtils.removeStart(st.nextToken(), "\"").trim(); nscNumber = StringUtils.removeEnd(nscNumber, "\""); agentName = StringUtils.removeStart(st.nextToken(), "\"").trim(); agentName = StringUtils.removeEnd(agentName, "\""); agent.setNscNumber(nscNumber); agent.setName(agentName); agentImportOutcome.setImportedDomainObject(agent); agentImportOutcome.setSavable(Boolean.TRUE); } else { logger.debug("Error in record -- >>> " + agentString); agentImportOutcome = new DomainObjectImportOutcome<Agent>(); StringBuilder msgBuilder = new StringBuilder("Invalid agent record found at line ::: "); msgBuilder.append(lineNumber); agentImportOutcome.addErrorMessage(msgBuilder.toString(), Severity.ERROR); } } return agentImportOutcome; }
From source file:net.java.dev.openim.tools.XStreamStore.java
private Map loadMap() { Map map = null;/*from ww w . j a v a 2 s . com*/ if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); String xmlData = IOUtils.toString(fis); fis.close(); if (substituteFrom != null && substituteTo != null) { xmlData = StringUtils.replace(xmlData, substituteTo, substituteFrom); } map = (Map) xstream.fromXML(xmlData); } catch (Exception e) { getLogger().error(e.getMessage(), e); } } else { getLogger().info("No " + file + " => starting with void store"); map = new HashMap(); } return map; }
From source file:com.prowidesoftware.swift.io.parser.XMLParserTest.java
@Test public void testCRLF_replace() { String text = "aaa\nbbb"; text = StringUtils.replace(text, "\n", FINWriterVisitor.SWIFT_EOL); assertEquals("aaa\r\nbbb", text); }