List of usage examples for org.apache.commons.lang StringUtils replaceOnce
public static String replaceOnce(String text, String searchString, String replacement)
Replaces a String with another String inside a larger String, once.
From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.ObjectModifyAction.java
@Override public void run(IStructuredSelection selection, UserDBDAO userDB, DB_ACTION actionType) { if (actionType == PublicTadpoleDefine.DB_ACTION.TABLES) { CreateTableAction cta = new CreateTableAction(); // sqlite db? ?? creation ?. if (DBDefine.getDBDefine(userDB) == DBDefine.SQLite_DEFAULT) { TableDAO tc = (TableDAO) selection.getFirstElement(); if (tc == null) cta.run(userDB, actionType); else//ww w . j a va 2 s. co m cta.run(userDB, tc.getComment(), actionType); } else { cta.run(userDB, actionType); } } else if (actionType == PublicTadpoleDefine.DB_ACTION.VIEWS) { CreateViewAction cva = new CreateViewAction(); cva.run(userDB, actionType); } else if (actionType == PublicTadpoleDefine.DB_ACTION.INDEXES) { CreateIndexAction cia = new CreateIndexAction(); cia.run(userDB, actionType); } else if (actionType == PublicTadpoleDefine.DB_ACTION.PROCEDURES) { try { DDLScriptManager scriptManager = new DDLScriptManager(userDB, actionType); String strScript = scriptManager.getScript(selection.getFirstElement()); strScript = StringUtils.replaceOnce(strScript, "CREATE", "ALTER"); if (strScript.indexOf("ALTER") == -1) { strScript = StringUtils.replaceOnce(strScript, "create", "alter"); } FindEditorAndWriteQueryUtil.run(userDB, strScript, true, actionType); } catch (Exception e) { logger.error("Alter ddl script", e); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError(null, "Error", //$NON-NLS-1$ selection.getFirstElement() + " Load scipt error", errStatus); } } else if (actionType == PublicTadpoleDefine.DB_ACTION.FUNCTIONS) { CreateFunctionAction cia = new CreateFunctionAction(); cia.run(userDB, actionType); } else if (actionType == PublicTadpoleDefine.DB_ACTION.TRIGGERS) { CreateTriggerAction cia = new CreateTriggerAction(); cia.run(userDB, actionType); } else if (actionType == PublicTadpoleDefine.DB_ACTION.JAVASCRIPT) { CreateJavaScriptAction csa = new CreateJavaScriptAction(); csa.run(userDB, actionType); } }
From source file:net.sf.firemox.action.UserAction.java
@Override public String toHtmlString(Ability ability, ContextEventListener context) { if (actionName != null) { if (actionName.charAt(0) == '%') { return ""; }//from w w w.java2 s. co m if (actionName.charAt(0) == '@') { final String picture = ActionFactory.PICTURES.get(actionName); if (picture != null) { return toHtmlString(ability, picture); } } if (actionName.indexOf("%n") != -1) { return LanguageManagerMDB.getString(actionName.replaceAll("%n", "1")); } return StringUtils.replaceOnce(LanguageManagerMDB.getString(actionName), "{this}", ability.getCard().toString()); } // we return only the string representation return toString(ability); }
From source file:com.hangum.tadpole.rdb.core.editors.main.execute.sub.ExecuteOtherSQL.java
/** * select ?? /*w w w. j a va 2 s . co m*/ * * @param reqQuery * @exception */ public static void runSQLOther(final RequestQuery reqQuery, final UserDBDAO userDB, final String userType, final String userEmail) throws SQLException, Exception { // is tajo if (DBDefine.TAJO_DEFAULT == userDB.getDBDefine()) { new TajoConnectionManager().executeUpdate(userDB, reqQuery.getSql()); } else { // commit rollback ? . if (TransactionManger.calledCommitOrRollback(reqQuery.getSql(), userEmail, userDB)) return; java.sql.Connection javaConn = null; Statement statement = null; try { if (reqQuery.isAutoCommit()) { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); javaConn = client.getDataSource().getConnection(); } else { javaConn = TadpoleSQLTransactionManager.getInstance(userEmail, userDB); } statement = javaConn.createStatement(); // TODO mysql? https://github.com/hangum/TadpoleForDBTools/issues/3 ? create table ? ?? '(' ?? ? ?? . if (userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT || userDB.getDBDefine() == DBDefine.MARIADB_DEFAULT) { final String checkSQL = reqQuery.getSql().trim().toUpperCase(); if (StringUtils.startsWithIgnoreCase(checkSQL, "CREATE TABLE")) { //$NON-NLS-1$ reqQuery.setSql(StringUtils.replaceOnce(reqQuery.getSql(), "(", " (")); //$NON-NLS-1$ //$NON-NLS-2$ } } // hive executeUpdate() ? . 13.08.19-hangum if (userDB.getDBDefine() == DBDefine.HIVE_DEFAULT || userDB.getDBDefine() == DBDefine.HIVE2_DEFAULT || userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) { statement.execute(reqQuery.getSql()); } else { statement.executeUpdate(reqQuery.getSql()); } } finally { try { statement.close(); } catch (Exception e) { } if (reqQuery.isAutoCommit()) { try { javaConn.close(); } catch (Exception e) { } } } } // end which db }
From source file:eionet.cr.web.util.columns.SearchResultColumn.java
/** * Builds a factsheet HTML link (relative to the webapp root) for the given URI. * Returns full// w w w .j a v a2s . com * * <pre> * <a href="..." title="...">...</a> * </pre> * * tag. * URL encodings and XML escapings also preformed. * * @param uri The given URI. * @param isAnonymous True if the given URI is an anonymous resource. * @param label The link's displayed label. * @param showTitle If true then the given URI will be put into title="...", otherwise no title attribute rendered. * @return As indicated above. */ String buildFactsheetLink(String uri, boolean isAnonymous, String label, boolean showTitle) { String factsheetUrlBinding = FactsheetActionBean.class.getAnnotation(UrlBinding.class).value(); int i = factsheetUrlBinding.lastIndexOf("/"); String uriParam = uri; if (isAnonymous) { if (uriParam.startsWith(VirtuosoBaseDAO.N3_BNODE_PREFIX)) { uriParam = StringUtils.replaceOnce(uriParam, VirtuosoBaseDAO.N3_BNODE_PREFIX, VirtuosoBaseDAO.VIRTUOSO_BNODE_PREFIX); } else if (!uriParam.startsWith(VirtuosoBaseDAO.VIRTUOSO_BNODE_PREFIX)) { uriParam = VirtuosoBaseDAO.VIRTUOSO_BNODE_PREFIX + uriParam; } } StringBuffer href = new StringBuffer(i >= 0 ? factsheetUrlBinding.substring(i + 1) : factsheetUrlBinding) .append("?"); href.append("uri=").append(Util.urlEncode(uriParam)); StringBuilder result = new StringBuilder("<a href=\"").append(href).append("\""); result.append(showTitle ? "title=\"" + StringEscapeUtils.escapeXml(uri) + "\">" : ">"); result.append(StringEscapeUtils.escapeXml(label)).append("</a>"); return result.toString(); }
From source file:com.t163.http.client.T163HttpClient.java
/** * getBody/*from w w w. ja va2s . c om*/ * @param object * @return * @throws IllegalArgumentException * @throws IllegalAccessException */ private String getBody(Object object) throws IllegalArgumentException, IllegalAccessException { StringBuffer body = new StringBuffer(); Field[] fields = object.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); if (field.get(object) != null) { body.append("&").append(field.getName()).append("=").append(field.get(object)); } } return StringUtils.replaceOnce(body.toString(), "&", "?"); }
From source file:com.alibaba.intl.bcds.goldroom.remote.DoubanBookInfoFetcher.java
/** * @param isbn/*from w ww . j a v a2 s. c om*/ * @param imageUrl * @return */ private String saveImage(String isbn, String imageUrl) { String largeImageUrl = StringUtils.replaceOnce(imageUrl, "s", "l"); HttpMethod method = new GetMethod(largeImageUrl); HttpClient client = new HttpClient(); try { // ??????api????douban????~~~ client.executeMethod(method); if (method.getStatusCode() != 200) { method = new GetMethod(imageUrl); client.executeMethod(method); } byte[] imgBody = method.getResponseBody(); return imageUtil.save(isbn, getImageSuffix(imageUrl), imgBody); } catch (Exception e) { logger.warn("error occurred while save image from url :" + imageUrl + " for isbn " + isbn, e); } return null; }
From source file:mitm.application.djigzo.james.mailets.StripUnsupportedFormats.java
private void initAttachmentMatchers() { Iterator<?> it = getInitParameterNames(); while (it.hasNext()) { Object o = it.next();//from w w w . java2 s . c om if (!(o instanceof String)) { continue; } String name = (String) o; if (StringUtils.startsWithIgnoreCase(name, Parameter.CONTENT_WILDCARD.getName())) { String contentWildcard = getInitParameter(name); if (StringUtils.isBlank(contentWildcard)) { continue; } name = StringUtils.replaceOnce(name, Parameter.CONTENT_WILDCARD.getName(), Parameter.FILENAME_WILDCARD.getName()); String filenameWildcard = getInitParameter(name); if (StringUtils.isBlank(filenameWildcard)) { filenameWildcard = "*"; } String[] wildcards = StringUtils.split(filenameWildcard, ','); for (String wildcard : wildcards) { attachmentMatchers.add( new UnsupportedFormatStripper.MatchingPair(contentWildcard.trim(), wildcard.trim())); } } } }
From source file:com.neatresults.mgnltweaks.ui.field.FieldTypeSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {//from w w w.j a va2 s .c o m if (registry.getClass().getDeclaredFields().length == 0) { // 5.4 Collection<FieldTypeDefinition> defs = (Collection<FieldTypeDefinition>) registry.getClass() .getMethod("getAllDefinitions").invoke(registry, null); for (FieldTypeDefinition fieldDef : defs) { if (fieldDef == null || fieldDef.getDefinitionClass() == null || fieldDef.getDefinitionClass().getName() == null) { System.out.println("field def is not valid: " + fieldDef); continue; } SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); String label = fieldDef.getDefinitionClass().getName(); if (label.startsWith("com.neatresults.mgnltweaks")) { label = StringUtils.replace(label, "com.neatresults.mgnltweaks.ui.field.", " NeatTweaks "); label = StringUtils.removeEnd(label, "FieldFactory$Definition"); } if (label.startsWith("info.magnolia")) { label = StringUtils.replace(label, "info.magnolia.ui.form.field.definition.", " Default "); label = StringUtils.removeStart(label, "info.magnolia.module."); label = StringUtils.removeStart(label, "info.magnolia."); } field.setLabel(label); field.setName(definition.getName()); field.setValue(fieldDef.getDefinitionClass().getName()); fields.add(field); } } else { // 5.3 Field registryField = registry.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, FieldTypeDefinitionProvider> providers = (RegistryMap<String, FieldTypeDefinitionProvider>) registryField .get(registry); for (String id : providers.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); Class<? extends FieldDefinition> fieldDef = registry.get(id).getDefinitionClass(); // directly defined label String label = id + " (" + StringUtils.replaceOnce(fieldDef.getName(), "info.magnolia.module.", "i.m.m.") + ")"; field.setLabel(label); field.setName(definition.getName()); field.setValue(fieldDef.getName()); fields.add(field); } } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException | InvocationTargetException | NoSuchMethodException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName(definition.getName()); field.setLabel("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:com.funambol.server.SyncMLCanonizer.java
private String devInfHandler(String msg) { msg = StringUtils.replaceOnce(msg, "<UTC></UTC>", "<UTC/>"); msg = StringUtils.replaceOnce(msg, "<SupportLargeObjs></SupportLargeObjs>", "<SupportLargeObjs/>"); msg = StringUtils.replaceOnce(msg, "<SupportNumberOfChanges></SupportNumberOfChanges>", "<SupportNumberOfChanges/>"); msg = StringUtils.replaceOnce(msg, "<MoreData></MoreData>", "<MoreData/>"); return msg;/*from w w w . ja va2 s.c o m*/ }
From source file:com.s3d.webapps.util.time.DurationFormatUtils.java
/** * <p>Formats an elapsed time into a plurialization correct string.</p> * //from w w w . j ava 2 s .co m * <p>This method formats durations using the days and lower fields of the * format pattern. Months and larger are not used.</p> * * @param durationMillis the elapsed time to report in milliseconds * @param suppressLeadingZeroElements suppresses leading 0 elements * @param suppressTrailingZeroElements suppresses trailing 0 elements * @return the formatted text in days/hours/minutes/seconds */ public static String formatDurationWords(long durationMillis, boolean suppressLeadingZeroElements, boolean suppressTrailingZeroElements) { // This method is generally replacable by the format method, but // there are a series of tweaks and special cases that require // trickery to replicate. String duration = formatDuration(durationMillis, "d' days 'H' hours 'm' minutes 's' seconds'"); if (suppressLeadingZeroElements) { // this is a temporary marker on the front. Like ^ in regexp. duration = " " + duration; String tmp = StringUtils.replaceOnce(duration, " 0 days", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", ""); duration = tmp; if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 seconds", ""); } } } if (duration.length() != 0) { // strip the space off again duration = duration.substring(1); } } if (suppressTrailingZeroElements) { String tmp = StringUtils.replaceOnce(duration, " 0 seconds", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", ""); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", ""); if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 days", ""); } } } } // handle plurals duration = " " + duration; duration = StringUtils.replaceOnce(duration, " 1 seconds", " 1 second"); duration = StringUtils.replaceOnce(duration, " 1 minutes", " 1 minute"); duration = StringUtils.replaceOnce(duration, " 1 hours", " 1 hour"); duration = StringUtils.replaceOnce(duration, " 1 days", " 1 day"); return duration.trim(); }