List of usage examples for org.springframework.util StringUtils replace
public static String replace(String inString, String oldPattern, @Nullable String newPattern)
From source file:net.sf.sze.util.VariableUtility.java
/** * Ersetzt in dem Text vorkommene Variablen: * <ul>/* www. ja va 2 s .c o m*/ * <li> NAME - ersetzt den Rufamen, </li> * <li> Vorname - setzt den Vornamen, </li> * <li> Nachname - den Nachnamen. </li> * </ul> * @param text der urspngliche Text * @param schueler das Schler-Objekt * @return den Text mit den Variablen. */ public static String insertVariables(String text, Schueler schueler) { String result = text; if (!schueler.getRufnameOrVorname().equals(schueler.getVorname())) { result = StringUtils.replace(result, schueler.getVorname(), "@Vorname@"); } result = StringUtils.replace(result, schueler.getName(), "@Nachname@"); result = StringUtils.replace(result, schueler.getRufnameOrVorname(), "@NAME@"); return result; }
From source file:ui.web2.web.servlet.view.tiles2.DynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used./*from ww w. j av a 2s . co m*/ * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (container.isValidDefinition(beanName, request, response)) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:com.parakhcomputer.web.servlet.view.tiles2.DynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used./*from ww w .j a v a 2 s. co m*/ * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (container.isValidDefinition(beanName, request, response)) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:org.springbyexample.web.servlet.view.tiles2.MyDynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used.//from ww w .jav a 2 s .c om * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template Boolean isValidDefinition = true; try { isValidDefinition = container.isValidDefinition(beanName, request, response); } catch (NullPointerException e) { } if (derivedDefinitionName != null) { return derivedDefinitionName; } else if (isValidDefinition) { derivedDefinitionName = beanName; return beanName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:edu.msstate.nsparc.spring.view.DynamicTilesViewProcessor.java
/** * Processes values to get tiles template definition name. First * a Tiles definition matching the url is checked, then a * url specific template is checked, and then just the * default root definition is used.//from w ww. ja va 2 s. c om * * @throws TilesException If no valid Tiles definition is found. */ protected String processTilesDefinitionName(String beanName, TilesContainer container, HttpServletRequest request, HttpServletResponse response) throws TilesException { // check for request parameter override. if (request.getParameter("template") != null && container.isValidDefinition(request.getParameter("template"), request, response)) { return request.getParameter("template"); } else if (derivedDefinitionName != null) { // if definition already derived use it, otherwise // check if url (bean name) is a template definition, then // check for main template return derivedDefinitionName; } else if (container.isValidDefinition(beanName, request, response)) { derivedDefinitionName = beanName; return beanName; } else if (container.isValidDefinition("." + beanName.replace("/", "."), request, response)) { derivedDefinitionName = "." + beanName.replace("/", "."); return derivedDefinitionName; } else { String result = null; StringBuilder sb = new StringBuilder(); int lastIndex = beanName.lastIndexOf("/"); boolean rootDefinition = false; // if delim, tiles def will start with it if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } // if no '/', then at context root if (lastIndex == -1) { rootDefinition = true; } else { String path = (beanName != null ? beanName.substring(0, lastIndex) : ""); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { path = StringUtils.replace(path, "/", tilesDefinitionDelimiter); } sb.append(path); if (StringUtils.hasLength(tilesDefinitionDelimiter)) { sb.append(tilesDefinitionDelimiter); } } sb.append(tilesDefinitionName); if (container.isValidDefinition(sb.toString(), request, response)) { result = sb.toString(); } else if (!rootDefinition) { String root = null; if (StringUtils.hasLength(tilesDefinitionDelimiter)) { root = tilesDefinitionDelimiter; } root += tilesDefinitionName; if (container.isValidDefinition(root, request, response)) { result = root; } else { throw new TilesException( "No defintion of found for " + "'" + root + "'" + " or '" + sb.toString() + "'"); } } derivedDefinitionName = result; return result; } }
From source file:com.springinpractice.ch11.web.sitemap.Sitemap.java
/** * @param path//from w w w. ja v a 2s.c om * @return */ @Deprecated private String wrap(String path) { return "'" + StringUtils.replace(path, "'", "''") + "'"; }
From source file:org.bitsofinfo.util.address.usps.ais.loader.hadoop.HadoopDataLoader.java
@Override public void load(LoaderJob theJob) throws Exception { // big error/*from w w w.jav a 2 s . c o m*/ if (!(theJob instanceof HadoopLoaderJob)) { throw new Exception("Cannot pass non-HadoopLoaderJob instance to HadoopDataLoader! Get your job" + " via the createJob() factory method on a HadoopDataLoader instance"); } HadoopLoaderJob loaderJob = (HadoopLoaderJob) theJob; // create our internal job tracker which will actually run the job in hadoop LoaderJobTracker jobTracker = new LoaderJobTracker(loaderJob, hadoopConfResource, hdfsJobOutputRootDir); // get the file system, so we can push the source files into HDFS Configuration conf = new Configuration(); conf.addResource(hadoopConfResource.getURL()); FileSystem hdfs = FileSystem.get(conf); // for each source data file, lets get it into HDFS for (FileHandle sourceData : loaderJob.getSourceData()) { String sourceURI = sourceData.getUri().toString(); // we currently only support local files if (sourceURI.indexOf(URIScheme.FILE.name()) != -1) { throw new Exception( "HadoopDataLoader currently only supports source data URIs that are from the local file system (file:.//)"); } // get the product type of this source file, we need this to determine the record length USPSProductType uspsProdType = (USPSProductType) sourceData .getProperty(FILE_HANDLE_PROP_USPS_PRODUCT_TYPE); if (uspsProdType == null) { throw new Exception( "Source data FileHandles passed to HadoopDataLoader must have the FILE_HANDLE_PROP_USPS_PRODUCT_TYPE property set."); } // ok, lets make sure to copy the local file into the HDFS filesystem // the target path in HDFS is /[hdfsSourceDataRootDir]/loader_job-[id]/[local source URI with file:// stripped] Path sourceFileLocalPath = new Path(new File(sourceData.getUri()).getAbsolutePath()); String localPathStripped = sourceData.getUri().toString(); localPathStripped = StringUtils.replace(localPathStripped, URIScheme.FILE.getName() + ":/", ""); Path sourceFileTargetHDFSPath = new Path(this.hdfsSourceDataRootDir + "/loader_job-" + loaderJob.getIdentifier() + "/" + localPathStripped); // copy..if not already there if (!hdfs.exists(sourceFileTargetHDFSPath)) { hdfs.copyFromLocalFile(false, true, sourceFileLocalPath, sourceFileTargetHDFSPath); } // add the source file in HDFS to the job tracker, keyed by the USPSProductType jobTracker.addSourceDataFile(uspsProdType, sourceFileTargetHDFSPath); } // have the jobTracker fire off the job jobTracker.startHadoopJob(); // add to running jobs this.runningJobs.put(loaderJob.getIdentifier(), jobTracker); // make sure to wake it synchronized (this) { notify(); } }
From source file:org.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java
@Override public String getHadoopMapperAppContextXMLFilename() { String pack = StringUtils.replace(USPSDataFileMapper.class.getPackage().getName(), ".", "/"); return pack + "/USPSDataFileMapper2JPA-context.xml"; }
From source file:fr.openwide.talendalfresco.alfresco.importer.ContentImporterComponentBase.java
/** * Bind the specified value to the passed configuration values if it is a place holder * //from w w w . j a v a 2 s.co m * @param value the value to bind * @param binding the configuration properties to bind to * @return the bound value */ protected String bindPlaceHolder(String value, ImporterBinding binding) { if (binding != null) { int iStartBinding = value.indexOf(START_BINDING_MARKER); while (iStartBinding != -1) { int iEndBinding = value.indexOf(END_BINDING_MARKER, iStartBinding + START_BINDING_MARKER.length()); if (iEndBinding == -1) { throw new ImporterException( "Cannot find end marker " + END_BINDING_MARKER + " within value " + value); } String key = value.substring(iStartBinding + START_BINDING_MARKER.length(), iEndBinding); String keyValue = binding.getValue(key); if (keyValue == null) { logger.warn("No binding value for placeholder (will default to empty string): " + value); } value = StringUtils.replace(value, START_BINDING_MARKER + key + END_BINDING_MARKER, keyValue == null ? "" : keyValue); iStartBinding = value.indexOf(START_BINDING_MARKER); } } return value; }
From source file:org.bitsofinfo.util.address.usps.ais.store.hbase.HBaseStore.java
@Override public String getHadoopMapperAppContextXMLFilename() { String pack = StringUtils.replace(USPSDataFileMapper.class.getPackage().getName(), ".", "/"); return pack + "/USPSDataFileMapper2HBase-context.xml"; }