Example usage for java.lang StringBuffer length

List of usage examples for java.lang StringBuffer length

Introduction

In this page you can find the example usage for java.lang StringBuffer length.

Prototype

@Override
    public synchronized int length() 

Source Link

Usage

From source file:com.fantasia.snakerflow.engine.SnakerHelper.java

private static String getProperty(NodeModel node) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("props:{");
    try {/*from  www  .  j  a v  a2 s .  c o m*/
        PropertyDescriptor[] beanProperties = PropertyUtils.getPropertyDescriptors(node);
        for (PropertyDescriptor propertyDescriptor : beanProperties) {
            if (propertyDescriptor.getReadMethod() == null || propertyDescriptor.getWriteMethod() == null)
                continue;
            String name = propertyDescriptor.getName();
            String value = "";
            if (propertyDescriptor.getPropertyType() == String.class) {
                value = (String) BeanUtils.getProperty(node, name);
            } else {
                continue;
            }
            if (value == null || value.equals(""))
                continue;
            buffer.append(name);
            buffer.append(":{value:'");
            buffer.append(convert(value));
            buffer.append("'},");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    buffer.deleteCharAt(buffer.length() - 1);
    buffer.append("}}");
    return buffer.toString();
}

From source file:de.nrw.hbz.regal.sync.MyConfiguration.java

/**
 * //from  w  ww. java  2  s . c  om
 * generates the configuration in terms of arguments and options
 * 
 * @param args
 *            Command line arguments
 * @param options
 *            Command line options
 * @throws ParseException
 *             When the configuration cannot be parsed
 */
MyConfiguration(String[] args, Options options) {
    try {
        CommandLineParser parser = new BasicParser();
        CommandLine commandLine = parser.parse(options, args);
        for (Option option : commandLine.getOptions()) {
            String key = option.getLongOpt();
            // System.out.println(key);
            if (key.compareTo("set") == 0) {
                String[] vals = option.getValues();
                if (vals == null || vals.length == 0) {
                    this.addProperty(key, "N/A");
                } else {
                    StringBuffer val = new StringBuffer();
                    for (int i = 0; i < vals.length; i++) {
                        val.append(vals[i]);
                        val.append(",");
                    }
                    val.delete(val.length(), val.length());
                    this.addProperty(key, val.toString());
                }
            } else {
                String val = option.getValue();
                if (val == null) {
                    this.addProperty(key, "N/A");
                } else {

                    this.addProperty(key, val);
                }
            }
        }
    } catch (ParseException e) {
        throw new ConfigurationParseException(e);
    }
}

From source file:eionet.transfer.controller.FileOpsController.java

/**
 * Upload file for transfer./*  w  w w.  j  av a  2s  .  c  o  m*/
 */
@RequestMapping(value = "/fileupload", method = RequestMethod.POST)
public String importFile(@RequestParam("file") MultipartFile myFile, @RequestParam("fileTTL") int fileTTL,
        final RedirectAttributes redirectAttributes, final HttpServletRequest request) throws IOException {

    if (myFile == null || myFile.getOriginalFilename() == null) {
        redirectAttributes.addFlashAttribute("message", "Select a file to upload");
        return "redirect:fileupload";
    }
    if (fileTTL > 90) {
        redirectAttributes.addFlashAttribute("message", "Invalid expiration date");
        return "redirect:fileupload";
    }
    String uuidName = storeFile(myFile, fileTTL);
    redirectAttributes.addFlashAttribute("uuid", uuidName);
    StringBuffer requestUrl = request.getRequestURL();
    redirectAttributes.addFlashAttribute("url",
            requestUrl.substring(0, requestUrl.length() - "/fileupload".length()));
    return "redirect:fileupload";
    //return "redirect:uploadSuccess";
}

From source file:org.openvpms.tools.archetype.loader.DerivedNodeUpdater.java

/**
 * Updates derived fields for all objects with the specified archetype
 * short names./*from  w w  w  .  jav a 2s .  c o  m*/
 *
 * @param shortNames the archetype short names. May contain wildcards.
 * @return the no. of updated objects
 * @throws ArchetypeServiceException for any archetype service error
 */
public int update(String[] shortNames) {
    if (log.isInfoEnabled()) {
        StringBuffer buff = new StringBuffer();
        for (String shortName : shortNames) {
            if (buff.length() != 0) {
                buff.append(", ");
            }
            buff.append(shortName);
        }
        log.info("Updating: " + buff);
    }
    int saved = 0;
    ArchetypeQuery query = new ArchetypeQuery(shortNames, false, false);
    Iterator<IMObject> iter = new IMObjectQueryIterator<IMObject>(service, query);
    List<IMObject> batch = new ArrayList<IMObject>();
    while (iter.hasNext()) {
        IMObject object = iter.next();
        service.deriveValues(object);
        batch.add(object);
        if (batch.size() >= batchSize) {
            saved += saveBatch(batch);
        }
    }
    if (!batch.isEmpty()) {
        saved += saveBatch(batch);
    }
    if (log.isInfoEnabled()) {
        log.info("Updated " + saved + " objects");
    }
    return saved;
}

From source file:com.abstratt.mdd.core.util.MDDUtil.java

public static String computeSignatureName(List<Parameter> signature) {
    StringBuffer name = new StringBuffer("{(");
    final List<Parameter> inputParameters = FeatureUtils.filterParameters(signature,
            ParameterDirectionKind.IN_LITERAL);
    for (Parameter parameter : inputParameters) {
        if (parameter.getName() != null) {
            name.append(parameter.getName());
            name.append(" ");
        }/* w w  w.  j a v a 2 s.c  o  m*/
        name.append(": ");
        final Type parameterType = parameter.getType();
        final String parameterTypeName = parameterType == null ? "any" : parameterType.getQualifiedName();
        name.append(parameterTypeName);
        addMultiplicity(name, parameter);
        name.append(", ");
    }
    if (!inputParameters.isEmpty())
        name.delete(name.length() - ", ".length(), name.length());
    name.append(")");
    List<Parameter> returnParameter = FeatureUtils.filterParameters(signature,
            ParameterDirectionKind.RETURN_LITERAL);
    if (!returnParameter.isEmpty()) {
        name.append(" : ");
        final Type returnType = returnParameter.get(0).getType();
        final String returnTypeName = returnType == null ? "any" : returnType.getQualifiedName();
        name.append(returnTypeName);
    }
    name.append('}');
    return name.toString();
}

From source file:com.aw.core.db.support.WhereBuilder.java

public List getFilter(StringBuffer hql, List params) {
    execute();//from   www .j a  v a  2s .  c  o  m
    StringBuffer sqlWithArgs = getSqlWithArgs();
    if (sqlWithArgs.length() > 0) {
        boolean containsWhere = containsWhere(hql);
        hql.append(containsWhere ? " and " : " where ");
        hql.append(sqlWithArgs);
        params.addAll(getParametersList());
    }
    return params;
}

From source file:jp.mathes.databaseWiki.dav.TableResource.java

@Override
@SuppressWarnings("unchecked")
public Resource createNew(String newName, InputStream inputStream, Long length, String contentType)
        throws IOException, ConflictException, NotAuthorizedException, BadRequestException {
    try {//from  www .  j a v  a2 s .  c om
        Document doc = DbwConfiguration.getInstance().getBackend().getDocument(this.user, this.password,
                this.dbName, this.name, name, true);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line = reader.readLine();
        while (line != null) {
            if (StringUtils.isEmpty(line) || StringUtils.isWhitespace(line)) {
                // everything after this line is field content
                StringBuffer content = new StringBuffer();
                while ((line = reader.readLine()) != null) {
                    if (content.length() > 0) {
                        content.append("\n");
                    }
                    content.append(line);
                }
                if (doc.getAllFields().containsKey("content")) {
                    doc.getAllFields().get("content").setValue(content.toString());
                } else {
                    DbwConfiguration.getInstance().davLog("Parse error, could not set field 'content'.");
                    throw new BadRequestException(this, "Parse error, could not set field 'content'.");
                }
            } else if (line.startsWith("\t")) {
                // if the line starts with a tab it has to be the continuation of
                // another line (which is handled in the else path) or is a mistake
                DbwConfiguration.getInstance()
                        .davLog("Line starts with tab although it is not a continuation.");
                throw new BadRequestException(this, "Line starts with tab although it is not a continuation.");
            } else {
                // this is a regular field, potentially with continuation
                String[] split = StringUtils.split(line, ":", 2);
                String fieldName = split[0].trim();
                StringBuffer fieldValue = new StringBuffer(split[1].trim());
                String nextLine = reader.readLine();
                while (nextLine != null && nextLine.startsWith("\t")) {
                    fieldValue.append("\n").append(StringUtils.substring(nextLine, 1));
                }
                line = nextLine;
                if (doc.getAllFields().containsKey(fieldName)) {
                    doc.getAllFields().get(fieldName).setValue(fieldValue.toString());
                } else {
                    DbwConfiguration.getInstance()
                            .davLog(String.format("Parse error, could not set field '%s'.", fieldName));
                    throw new BadRequestException(this,
                            String.format("Parse error, could not set field '%s'.", fieldName));
                }
            }
        }
        DbwConfiguration.getInstance().getBackend().saveDocument(this.user, this.password, this.dbName,
                this.name, name, doc);
    } catch (DocumentNotFoundException e) {
        DbwConfiguration.getInstance().davLog("Impossible DocumentNotFoundException in createNew()", e);
        throw new BadRequestException(this, "This cannot happen with allowEmpty=true (getDocument).");
    } catch (BackendException e) {
        DbwConfiguration.getInstance().davLog("BackendException in createNew()", e);
        throw new BadRequestException(this, e.getMessage());
    }
    return null;
}

From source file:com.sqewd.open.dal.api.persistence.AbstractEntity.java

/**
 * Get a string value representing the key columns.
 * /*from   ww w . j  a  v  a  2  s .c  o  m*/
 * @return
 * @throws Exception
 */
@JsonIgnore
public String getEntityKey() throws Exception {
    StringBuffer buff = new StringBuffer();
    StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(getClass());

    for (StructAttributeReflect attr : enref.Attributes) {
        if (attr.IsKeyColumn) {
            if (buff.length() > 0)
                buff.append(_KEY_SEPARATOR_);
            Object value = PropertyUtils.getSimpleProperty(this, attr.Field.getName());
            if (value instanceof AbstractEntity) {
                buff.append(((AbstractEntity) value).getEntityKey());
            } else {
                buff.append(value);
            }
        }
    }
    if (buff.length() == 0)
        return null;
    return buff.toString();
}

From source file:com.comcast.dawg.test.base.IndexPageUITestBase.java

/**
 * Does the tagging operation specified by sending a REST request.
 *
 * @param   operation  To specify add or remove opration to be done.
 * @param   tagName    Tag name to be removed.
 * @param   stbIds     List of stb IDs tag together.
 *
 * @return  Response of tag removal.//from   w  w w. j av a  2  s .c o m
 *
 * @throws  IOException  If any connection failures.
 */
private HttpResponse taggingOperation(String operation, String tagName, String... stbIds) throws IOException {

    if (null == stbIds) {
        throw new IllegalArgumentException(
                "No STB ids passed for tagging. Tag creation is not allowed with out any STB id passed.");
    }

    StringBuffer stbList = new StringBuffer();

    for (String stbId : stbIds) {

        if (stbList.length() > 0) {
            stbList.append(',');
        }

        stbList.append('"').append(stbId).append('"');
    }

    logger.info(String.format("About to %s tag (%s) with stb list [%s].", operation, tagName, stbList));

    HttpEntity entity = new StringEntity("{\"id\": [" + stbList + "],\"tag\":[\"" + tagName + "\"]}");
    HttpPost method = new HttpPost(TestConstants.TAG_UPDATE_REST_URI + operation);
    method.addHeader("Content-Type", "application/json");
    method.setEntity(entity);

    HttpClient httpClient = new DefaultHttpClient();

    return httpClient.execute(method);
}

From source file:org.bitsofinfo.util.address.usps.ais.convert.MySqlLoadDataConverter.java

@Override
public String convert(String rawRecord) throws Exception {
    Class<? extends USPSRecord> clazz = uspsUtils.getClassForRawRecord(rawRecord);

    // get the list of all Fields known in this class annotated by USPSDataFileField
    List<Field> dataFileFields = uspsUtils.getFieldsByAnnotation(clazz, USPSDataFileField.class);

    StringBuffer sb = new StringBuffer("@S@");

    for (Field f : dataFileFields) {
        Object[] parts = USPSDataFileFieldHelper.extractValue(rawRecord, f);
        String rawValue = parts[0].toString();
        sb.append(rawValue.trim() + "|");
    }/*from w w  w  .j  a  v a  2 s. c o  m*/

    return sb.toString().substring(0, sb.length() - 1);

}