List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:calliope.db.CouchConnection.java
/** * Add a revid to a json document// w w w. java2s. c om * @param json the json in question * @param revid the revid of its current incarnation * @return the rebuilt json file */ private String addRevId(String json, String revid) { StringBuilder sb = new StringBuilder(json); int pos = sb.indexOf("{"); if (pos != -1) { sb.insert(pos + 1, "\n\t\"_rev\": \"" + revid + "\","); } return sb.toString(); }
From source file:com.legstar.cob2xsd.XsdDataItem.java
/** * Turn a COBOL name to a unique XSD type name. * <p/>//ww w . java 2 s.c o m * Complex type names customarily start with an uppercase character. * <p/> * The proposed name might be conflicting with another so we disambiguate * xsd type names with one of 2 options: * <ul> * <li>Appending the COBOL source line number (compatible with * legstar-schemagen)</li> * <li>Appending the parent XSD type name</li> * </ul> * * @param cobolDataItem the COBOL data item * @param elementName the element name built from the COBOL name * @param nonUniqueCobolNames a list of non unique COBOL names * @param model the translator options * @param parent used to resolve potential name conflict * @param order order within parent to disambiguate siblings * @return a nice XML type name */ public static String formatTypeName(final String elementName, final CobolDataItem cobolDataItem, final List<String> nonUniqueCobolNames, final Cob2XsdModel model, final XsdDataItem parent, final int order) { StringBuilder sb = new StringBuilder(); sb.append(Character.toUpperCase(elementName.charAt(0))); sb.append(elementName.substring(1)); if (nonUniqueCobolNames.contains(cobolDataItem.getCobolName())) { if (model.nameConflictPrependParentName()) { if (parent != null) { sb.insert(0, parent.getXsdTypeName()); } } else { sb.append(cobolDataItem.getSrceLine()); } } return sb.toString(); }
From source file:net.sourceforge.fenixedu.util.UniqueAcronymCreator.java
private static StringBuilder appendLastChar(int index, StringBuilder acronym) { if (logger.isDebugEnabled()) { logger.info("appendLastChar, called with index " + index + " and " + acronym); }//from w w w. jav a2s. com for (int i = splitsName.length - 1; i > -1; i--) { if (!(isValidAcception(splitsName[i])) && splitsName[i].length() > index) { String toAppend = (splitsName[i].substring(index, index + 1)); toAppend = (toLowerCase) ? toAppend.toLowerCase() : toAppend.toUpperCase(); if (acronym.toString().contains("-")) { int hiffen = acronym.toString().indexOf("-"); if (isValidNumeration(String.valueOf(acronym.charAt(hiffen + 1))) || hasNumber(String.valueOf(acronym.charAt(hiffen + 1)))) { acronym.insert(hiffen, toAppend); if (logger.isDebugEnabled()) { logger.info("appendLastChar, found a '-', appending before hiffen " + toAppend); } } else { acronym.append(toAppend); if (logger.isDebugEnabled()) { logger.info("appendLastChar, found a '-', appending in end " + toAppend); } } } else { if (logger.isDebugEnabled()) { logger.info("appendLastChar, appending " + toAppend); } acronym.append(toAppend); } break; } } return acronym; }
From source file:com.moorestudio.seniorimageprocessing.SeniorSorter.java
private void saveImages(HashMap<String, String> studentInfo, File activeStudentFolder, ArrayList<File> studentImages) throws IOException { // Get the student information String schoolName = studentInfo.get("SCHOOL").replaceAll(" ", "_"); // If the filenames have spaces then an error will be thrown! String year = studentInfo.get("YEAR").replaceAll(" ", ""); String lastName = studentInfo.get("LAST").replaceAll(" ", ""); String firstName = studentInfo.get("FIRST").replaceAll(" ", ""); //Write out the images for (File image : studentImages) { String oldImageName = image.getName(); //Get the image extension String ext = oldImageName.substring(oldImageName.lastIndexOf(".")); //Make the index string StringBuilder indexString = new StringBuilder(valueOf(parent.pollNextImageIndex())); //If image index is less than the desired number of digits, then padd it. while (indexString.length() < parent.getNumImageIndexDigits()) { indexString.insert(0, '0'); }//from ww w.j a va 2s . c om //Make the new file File newFile = new File(activeStudentFolder, schoolName + year + lastName + indexString.toString() + ext); //Copy and rename the old file to the new file copy(image.toPath(), newFile.toPath()); parent.addProgress(((.5 / parent.studentImages.size()) / studentImages.size())); } }
From source file:com.flexive.shared.structure.FxSelectListItem.java
/** * If this item is cascaded, get the label path up to the root element * * @param outputLanguage desired output language * @return label path/*from ww w . j a v a 2s.c om*/ */ public String getLabelBreadcrumbPath(FxLanguage outputLanguage) { if (!hasParentItem()) return getLabel().getBestTranslation(outputLanguage); StringBuilder sb = new StringBuilder(100); FxSelectListItem curr = this; while (curr != null) { if (curr != this) sb.insert(0, getList().getBreadcrumbSeparator()); sb.insert(0, curr.getLabel().getBestTranslation(outputLanguage)); curr = curr.getParentItem(); } return sb.toString(); }
From source file:com.flexive.shared.structure.FxSelectListItem.java
/** * If this item is cascaded, get the label path up to the root element * * @return label path// w w w . j a va2 s .c om */ public String getLabelBreadcrumbPath() { final UserTicket ticket = FxContext.getUserTicket(); if (!hasParentItem()) return getLabel().getBestTranslation(ticket); StringBuilder sb = new StringBuilder(100); FxSelectListItem curr = this; while (curr != null) { if (curr != this) sb.insert(0, getList().getBreadcrumbSeparator()); sb.insert(0, curr.getLabel().getBestTranslation(ticket)); curr = curr.getParentItem(); } return sb.toString(); }
From source file:hudson.plugins.robot.model.RobotTestObject.java
/** * Get path in tree relative to given TestObject * @return// w w w . j a v a 2 s. co m */ public String getRelativeId(RobotTestObject thisObject) { StringBuilder sb = new StringBuilder(urlEncode(getDuplicateSafeName())); RobotTestObject parent = getParent(); if (parent != null && !parent.equals(thisObject)) { String parentId = parent.getRelativeId(thisObject); if (StringUtils.isNotBlank(parentId)) { sb.insert(0, "/"); sb.insert(0, parentId); } } return sb.toString(); }
From source file:com.ewcms.core.site.model.TemplateSource.java
private void constructPath() { StringBuilder builder = new StringBuilder(); for (TemplateSource templatesrc = this; templatesrc != null; templatesrc = templatesrc.parent) { if (StringUtils.isBlank(templatesrc.getName())) { break; }/*from w ww . j a va 2 s . c o m*/ String dir = removeStartAndEndPathSeparator(templatesrc.getName()); builder.insert(0, dir); builder.insert(0, PATH_SEPARATOR); } path = removeStartAndEndPathSeparator(builder.toString()); uniquePath = getSite().getId().toString() + PATH_SEPARATOR + path; }
From source file:net.solarnetwork.web.support.SimpleXmlView.java
private void writeElement(String name, Map<?, ?> props, Writer out, boolean close, ViewResponseAugmentor augmentor) throws IOException { out.write('<'); out.write(name);/* ww w .j a va 2s.com*/ if (augmentor != null) { augmentor.augmentResponse(out); } Map<String, Object> nested = null; if (props != null) { for (Map.Entry<?, ?> me : props.entrySet()) { String key = me.getKey().toString(); Object val = me.getValue(); if (getPropertySerializerRegistrar() != null) { val = getPropertySerializerRegistrar().serializeProperty(name, val.getClass(), props, val); } if (val instanceof Date) { SimpleDateFormat sdf = SDF.get(); // SimpleDateFormat has no way to create xs:dateTime with tz, // so use trick here to insert required colon for non GMT dates Date date = (Date) val; StringBuilder buf = new StringBuilder(sdf.format(date)); if (buf.charAt(buf.length() - 1) != 'Z') { buf.insert(buf.length() - 2, ':'); } val = buf.toString(); } else if (val instanceof Collection) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (val instanceof Map<?, ?>) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (classNamesAllowedForNesting != null && !(val instanceof Enum<?>)) { for (String prefix : classNamesAllowedForNesting) { if (val.getClass().getName().startsWith(prefix)) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; break; } } } if (val != null) { // replace & with & String attVal = val.toString(); Matcher matcher = AMP.matcher(attVal); attVal = matcher.replaceAll("&"); attVal = attVal.replace("\"", """); out.write(' '); out.write(key); out.write("=\""); out.write(attVal); out.write('"'); } } } if (close && nested == null) { out.write('/'); } out.write('>'); if (nested != null) { for (Map.Entry<String, Object> me : nested.entrySet()) { outputObject(me.getValue(), me.getKey(), out, augmentor); } if (close) { closeElement(name, out); } } }