List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:org.apache.ftpserver.usermanager.LdapUserManager.java
/** * Get the distinguished name (DN) for this user name. */// ww w.ja v a 2 s.co m private String getDN(String userName) throws NamingException { StringBuffer valBuf = new StringBuffer(userName); for (int i = 0; i < valBuf.length(); i++) { char ch = valBuf.charAt(i); if (ch == '\\' || ch == ',' || ch == '+' || ch == '\"' || ch == '<' || ch == '>' || ch == ';') { valBuf.insert(i, '\\'); i++; } } return CN + '=' + valBuf.toString() + ',' + m_userBaseDn; }
From source file:org.obiba.onyx.spring.AnnotatedBeanFinderFactoryBean.java
/** * @param classPath//w ww. ja v a 2s. c om * @return */ private Set<String> listAllPossibleQualifiedClassNames(String classPath) { Set<String> qualifiedClassNames = new HashSet<String>(); // Format the path first. String path = pathToQualifiedClassName(classPath); // Split the QName by the dot (i.e. '.') character. String[] pathParts = path.split("\\."); // Add the path parts one by one from the end of the array to the // beginning. StringBuffer qName = new StringBuffer(); for (int i = pathParts.length - 1; i >= 0; i--) { qName.insert(0, pathParts[i]); qualifiedClassNames.add(qName.toString()); qName.insert(0, "."); } return qualifiedClassNames; }
From source file:com.ables.pix.utility.PictureOps.java
public UploadStatus storePicture(PictureUpload upload) { if ((upload.getAlbumId() == null) || upload.getUpload() == null || repositoryRoot == null) { throw new IllegalArgumentException( "A picture cannot be stored if the album ID or file is not provided."); }//from www . j av a 2 s .com StringBuffer target = new StringBuffer(); target.append("album"); target.append(File.separator); target.append(upload.getAlbumId()); target.append(File.separator); // Set the relative file location here. String path = target.toString(); target.insert(0, this.repositoryRoot); // Create album folder if it doesn't exist. File dir = new File(target.toString()); if (!dir.exists()) { dir.mkdir(); } String fileName = upload.getUpload().getOriginalFilename(); if (fileName == null || "".equals(fileName)) { fileName = upload.getUpload().getName(); } target.append(fileName); // Check if the picture exists. File targetFile = new File(target.toString()); if (targetFile.exists()) { if (log.isInfoEnabled()) { log.info(targetFile + " already exists"); } return UploadStatus.EXISTS; } // Mark for automatic deletion on JVM shutdown. if (deleteOnShutDown) { targetFile.deleteOnExit(); // Check if this is a valid image. try { if (ImageIO.read(upload.getUpload().getInputStream()) == null) { return UploadStatus.INVALID; } } catch (IOException io) { io.printStackTrace(); return UploadStatus.FAILED; } } // Get a reference to the picture object to populate with data coming // from the file. Picture picture = upload.getPicture(); if (picture == null) { picture = new Picture(); upload.setPicture(picture); } picture.setFileName(fileName); picture.setPath(path); picture.setSize(upload.getUpload().getSize()); return UploadStatus.SUCCESS; }
From source file:com.npower.dm.processor.RegistryItem.java
/** * Return real path of this item./*from w w w. j a va 2 s. co m*/ * Eg: * ./a/b * ./ * ./a * ./a/b/c * * @return */ public String getPath() { RegistryItem parent = this.getParent(); if (parent == null) { return this.getName(); } StringBuffer result = new StringBuffer(); result.append(this.getName()); if (parent != null) { result.insert(0, '/'); result.insert(0, parent.getPath()); } return result.toString(); }
From source file:org.chiba.xml.xforms.xpath.ExtensionFunctionsHelper.java
/** * Returns a date parsed from a date/dateTime string formatted accorings to * ISO 8601 rules.//from ww w . jav a 2 s . c om * * @param date the formatted date/dateTime string. * @return the parsed date. * @throws ParseException if the date/dateTime string could not be parsed. */ public static Date parseISODate(String date) throws ParseException { String pattern; StringBuffer buffer = new StringBuffer(date); switch (buffer.length()) { case 4: // Year: yyyy (eg 1997) pattern = "yyyy"; break; case 7: // Year and month: yyyy-MM (eg 1997-07) pattern = "yyyy-MM"; break; case 10: // Complete date: yyyy-MM-dd (eg 1997-07-16) pattern = "yyyy-MM-dd"; break; default: // Complete date plus hours and minutes: yyyy-MM-ddTHH:mmTZD (eg 1997-07-16T19:20+01:00) // Complete date plus hours, minutes and seconds: yyyy-MM-ddTHH:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) // Complete date plus hours, minutes, seconds and a decimal fraction of a second: yyyy-MM-ddTHH:mm:ss.STZD (eg 1997-07-16T19:20:30.45+01:00) pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; if (buffer.length() == 16) { // add seconds buffer.append(":00"); } if (buffer.length() > 16 && buffer.charAt(16) != ':') { // insert seconds buffer.insert(16, ":00"); } if (buffer.length() == 19) { // add milliseconds buffer.append(".000"); } if (buffer.length() > 19 && buffer.charAt(19) != '.') { // insert milliseconds buffer.insert(19, ".000"); } if (buffer.length() == 23) { // append timzeone buffer.append("+0000"); } if (buffer.length() == 24 && buffer.charAt(23) == 'Z') { // replace 'Z' with '+0000' buffer.replace(23, 24, "+0000"); } if (buffer.length() == 29 && buffer.charAt(26) == ':') { // delete '.' from 'HH:mm' buffer.deleteCharAt(26); } } // always set time zone on formatter SimpleDateFormat format = new SimpleDateFormat(pattern); final String dateFromBuffer = buffer.toString(); if (dateFromBuffer.length() > 10) { format.setTimeZone(TimeZone.getTimeZone("GMT" + dateFromBuffer.substring(23))); } if (!format.format(format.parse(dateFromBuffer)).equals(dateFromBuffer)) { throw new ParseException("Not a valid ISO date", 0); } format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.parse(buffer.toString()); }
From source file:CreditCardValidator.java
/** * Returns a 64 length String with the first flag on the right and the * 64th flag on the left. A 1 indicates the flag is on, a 0 means it's * off.//from w w w . j a v a 2 s. c o m * * @return string representation of this object. */ public String toString() { StringBuffer bin = new StringBuffer(Long.toBinaryString(this.flags)); for (int i = 64 - bin.length(); i > 0; i--) { bin.insert(0, "0"); } return bin.toString(); }
From source file:org.jlibrary.client.export.freemarker.FreemarkerExporter.java
/** * Returns a relative location URL based in the passed category. Each item * in the returned location URL has a link to that item. * /* w w w . ja v a 2s. c o m*/ * @param node Node * * @return String Relative location URL */ public String getLocationURL(Category category) { StringBuffer path = new StringBuffer("<A href=\"./index.html\">" + category.getName() + "</A>"); String href = "./"; while (category.getParent() != null) { category = category.getParent(); path.insert(0, "<A href=\" " + href + "/index.html\">" + category.getName() + "</A>/"); href = href + "../"; } path.insert(0, "/"); return path.toString(); }
From source file:org.ajax4jsf.webapp.WebXml.java
/** * Convert {@link org.ajax4jsf.resource.InternetResource } key to real URL * for handle by chameleon filter, depend of mapping in WEB.XML . For prefix * or * mapping, prepend servlet prefix and default Resource prefix to key. * For suffix mapping, prepend with resource prefix and append default faces * suffix to URL ( before request param ). After conversion, call * {@link javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext, java.lang.String)} * and/*from w w w . j av a2 s . c o m*/ * {@link javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)} * . * * @param context * @param Url * @return */ public String getFacesResourceURL(FacesContext context, String Url, boolean isGlobal) { StringBuffer buf = new StringBuffer(); buf.append(isGlobal ? getGlobalResourcePrefix() : getSessionResourcePrefix()).append(Url); // Insert suffix mapping if (isPrefixMapping()) { buf.insert(0, getFacesFilterPrefix()); } else { int index; if ((index = buf.indexOf("?")) >= 0) { buf.insert(index, getFacesFilterSuffix()); } else { buf.append(getFacesFilterSuffix()); } } String resourceURL = context.getApplication().getViewHandler().getResourceURL(context, buf.toString()); return resourceURL; }
From source file:com.linuxbox.enkive.message.MultiPartHeaderImpl.java
public String printMultiPartHeader() throws IOException { String msg = getOriginalHeaders() + getLineEnding() + getPreamble() + getLineEnding(); List<ContentHeader> partHeaders = getPartHeaders(); StringBuffer boundary = new StringBuffer(getBoundary() + getLineEnding()); for (int i = 0; i < partHeaders.size(); i++) { msg += "--" + boundary.toString(); if (partHeaders.get(i).isMultipart()) msg += ((MultiPartHeader) partHeaders.get(i)).printMultiPartHeader() + getLineEnding(); else//from w w w .j ava2 s . co m msg += ((SinglePartHeader) partHeaders.get(i)).printSinglePartHeader(); } msg += "--" + boundary.insert(boundary.toString().trim().length(), "--" + getLineEnding()); msg += getEpilogue() + getLineEnding(); return msg; }
From source file:org.apache.hadoop.fs.webdav.FSDavResource.java
public String getHref() { StringBuffer buffer = new StringBuffer(); Path p = this.path; while (p != null && !("".equals(p.getName()))) { buffer.insert(0, p.getName()); buffer.insert(0, "/"); p = p.getParent();// w w w . j a v a 2s. c om } if (0 == buffer.length()) { buffer.insert(0, "/"); } LOG.info("HREF: " + buffer.toString()); return buffer.toString(); }