Example usage for java.lang StringBuffer lastIndexOf

List of usage examples for java.lang StringBuffer lastIndexOf

Introduction

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

Prototype

@Override
public int lastIndexOf(String str) 

Source Link

Usage

From source file:org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * Find out the element located to the right of the passed separator.
 * /*from w  w  w .  j  a v  a 2 s. c o m*/
 * @param content the string to parse. This parameter will be modified by the method to remove the parsed content.
 * @param separator the separator string to locate the element
 * @return the parsed element or null if the separator string wasn't found
 */
protected String parseElementAfterString(StringBuffer content, String separator) {
    String element = null;

    // Find the first non escaped separator (starting from the end of the content buffer).
    int index = content.lastIndexOf(separator);
    while (index != -1) {
        // Check if the element is found and it's not escaped.
        if (!shouldEscape(content, index)) {
            element = content.substring(index + separator.length()).trim();
            content.delete(index, content.length());
            break;
        }

        if (index > 0) {
            index = content.lastIndexOf(separator, index - 1);
        } else {
            break;
        }
    }

    return element;
}

From source file:org.objectstyle.wolips.ruleeditor.model.RightHandSide.java

private String valueForObject(Object object) {
    if (object == null) {
        return null;
    }//  w w  w  . j av a  2  s .c  o  m

    if (object instanceof Collection) {
        Collection<Object> arrayOfValues = (Collection<Object>) object;

        if (arrayOfValues.size() == 0) {
            return "()";
        }

        StringBuffer buffer = new StringBuffer();

        buffer.append("( ");

        for (Object value : arrayOfValues) {
            buffer.append(valueForObject(value));
            buffer.append(", ");
        }

        buffer.deleteCharAt(buffer.lastIndexOf(", "));
        buffer.append(")");

        return buffer.toString();
    }

    if (object instanceof Map) {
        Map<Comparable, ?> mapOfValues = (Map<Comparable, ?>) object;

        StringBuffer buffer = new StringBuffer();

        buffer.append("{ ");

        ArrayList<Comparable> list = new ArrayList<Comparable>();

        list.addAll(mapOfValues.keySet());

        Collections.sort(list);

        for (Object key : list) {
            buffer.append("\"");
            buffer.append(key);
            buffer.append("\" = ");
            buffer.append(valueForObject(mapOfValues.get(key)));
            buffer.append("; ");
        }

        buffer.append("}");

        return buffer.toString();
    }

    return "\"" + object.toString() + "\"";
}

From source file:org.wso2.carbon.appmgt.sample.deployer.http.HttpHandler.java

/**
 * This method is used to do a http post request
 *
 * @param url         request url/*  w w w . ja v  a  2 s . c  o m*/
 * @param payload     Content of the post request
 * @param sessionId   sessionId for authentication
 * @param contentType content type of the post request
 * @return response
 * @throws java.io.IOException - Throws this when failed to fulfill a http post request
 */
public String doPostHttp(String url, String payload, String sessionId, String contentType) throws IOException {
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    //add reuqest header
    con.setRequestMethod("POST");
    //con.setRequestProperty("User-Agent", USER_AGENT);
    if (!sessionId.equals("") && !sessionId.equals("none")) {
        con.setRequestProperty("Cookie", "JSESSIONID=" + sessionId);
    }
    con.setRequestProperty("Content-Type", contentType);
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(payload);
    wr.flush();
    wr.close();
    int responseCode = con.getResponseCode();
    if (responseCode == 200) {
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        if (sessionId.equals("")) {
            String session_id = response.substring((response.lastIndexOf(":") + 3),
                    (response.lastIndexOf("}") - 2));
            return session_id;
        } else if (sessionId.equals("appmSamlSsoTokenId")) {
            return con.getHeaderField("Set-Cookie").split(";")[0].split("=")[1];
        } else if (sessionId.equals("header")) {
            return con.getHeaderField("Set-Cookie").split("=")[1].split(";")[0];
        } else {
            return response.toString();
        }
    }
    return null;
}

From source file:org.wso2.carbon.appmgt.sample.deployer.http.HttpHandler.java

/**
 * This method is used to do a https post request
 *
 * @param url         request url// ww  w .jav a 2s.c o m
 * @param payload     Content of the post request
 * @param sessionId   sessionId for authentication
 * @param contentType content type of the post request
 * @return response
 * @throws java.io.IOException - Throws this when failed to fulfill a https post request
 */
public String doPostHttps(String url, String payload, String sessionId, String contentType) throws IOException {
    URL obj = new URL(url);

    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
    //add reuqest header
    con.setRequestMethod("POST");
    if (!sessionId.equals("")) {
        con.setRequestProperty("Cookie", "JSESSIONID=" + sessionId);
    }
    if (!contentType.equals("")) {
        con.setRequestProperty("Content-Type", contentType);
    }
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(payload);
    wr.flush();
    wr.close();
    int responseCode = con.getResponseCode();
    if (responseCode == 200) {
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        if (sessionId.equals("")) {
            String session_id = response.substring((response.lastIndexOf(":") + 3),
                    (response.lastIndexOf("}") - 2));
            return session_id;
        } else if (sessionId.equals("header")) {
            return con.getHeaderField("Set-Cookie");
        }

        return response.toString();
    }
    return null;
}

From source file:org.openhealthtools.openxds.webapp.action.ViewAction.java

public String execute() throws Exception {
    contextpath = getRequest().getContextPath();
    StringBuffer reqURL = getRequest().getRequestURL();
    int index = 0;
    if (reqURL != null)
        index = reqURL.lastIndexOf("/");

    if (index != -1) {
        registryUrl = reqURL.substring(0, index + 1) + "services/DocumentRegistry";
    }//from w  w  w  .j a va 2  s  .  c  o  m
    return SUCCESS;
}

From source file:org.wso2.carbon.appmgt.sampledeployer.http.HttpHandler.java

public String doPostHttp(String backEnd, String payload, String your_session_id, String contentType)
        throws IOException {
    URL obj = new URL(backEnd);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("User-Agent", USER_AGENT);
    if (!your_session_id.equals("") && !your_session_id.equals("none")) {
        con.setRequestProperty("Cookie", "JSESSIONID=" + your_session_id);
    }/*from www .  j  a  v a2 s  .c o m*/
    con.setRequestProperty("Content-Type", contentType);
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(payload);
    wr.flush();
    wr.close();
    int responseCode = con.getResponseCode();
    if (responseCode == 200) {
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        if (your_session_id.equals("")) {
            String session_id = response.substring((response.lastIndexOf(":") + 3),
                    (response.lastIndexOf("}") - 2));
            return session_id;
        } else if (your_session_id.equals("appmSamlSsoTokenId")) {
            return con.getHeaderField("Set-Cookie").split(";")[0].split("=")[1];
        } else if (your_session_id.equals("header")) {
            return con.getHeaderField("Set-Cookie").split("=")[1].split(";")[0];
        } else {
            return response.toString();
        }
    }
    return null;
}

From source file:org.wso2.carbon.appmgt.sampledeployer.http.HttpHandler.java

public String doPostHttps(String backEnd, String payload, String your_session_id, String contentType)
        throws IOException {
    URL obj = new URL(backEnd);

    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("User-Agent", USER_AGENT);
    if (!your_session_id.equals("")) {
        con.setRequestProperty("Cookie", "JSESSIONID=" + your_session_id);
    }/* w  w w. j  ava 2  s.c o m*/
    if (!contentType.equals("")) {
        con.setRequestProperty("Content-Type", contentType);
    }
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(payload);
    wr.flush();
    wr.close();
    int responseCode = con.getResponseCode();
    if (responseCode == 200) {
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        if (your_session_id.equals("")) {
            String session_id = response.substring((response.lastIndexOf(":") + 3),
                    (response.lastIndexOf("}") - 2));
            return session_id;
        } else if (your_session_id.equals("header")) {
            return con.getHeaderField("Set-Cookie");
        }

        return response.toString();
    }
    return null;
}

From source file:org.apache.hadoop.hbase.backup.impl.TableBackupClient.java

/**
 * Get backup request meta data dir as string.
 * @param backupInfo backup info// w  ww . j  a  v  a2  s.  c  om
 * @return meta data dir
 */
private String obtainBackupMetaDataStr(BackupInfo backupInfo) {
    StringBuffer sb = new StringBuffer();
    sb.append("type=" + backupInfo.getType() + ",tablelist=");
    for (TableName table : backupInfo.getTables()) {
        sb.append(table + ";");
    }
    if (sb.lastIndexOf(";") > 0) {
        sb.delete(sb.lastIndexOf(";"), sb.lastIndexOf(";") + 1);
    }
    sb.append(",targetRootDir=" + backupInfo.getBackupRootDir());

    return sb.toString();
}

From source file:org.directwebremoting.drapgen.generate.gi.GiType.java

/**
 * @param directory Base directory in which to write the Java files
 * @throws java.io.IOException If writing fails
 *//*from  w  w w.ja  v  a  2  s  .c  om*/
public void writeCode(String directory) throws IOException {
    String javaClassName = xmlClassName.replaceFirst("\\.xml$", ".java");
    File javaFile = new File(directory + javaClassName);
    File javaParentDir = javaFile.getParentFile();

    if (!javaParentDir.isDirectory()) {
        if (!javaParentDir.mkdirs()) {
            throw new IOException("Failed to create directory: " + javaParentDir.getName());
        }
    }

    FileWriter out = null;

    try {
        StringBuffer outerCode = output.getBuffer();
        if (outerCode.toString().trim().length() != 0) {
            int closeCurly = outerCode.lastIndexOf("}");
            if (closeCurly != -1) {
                outerCode.delete(closeCurly, outerCode.length() - 1);
            }

            out = new FileWriter(javaFile);
            out.append(outerCode);

            for (GiType innerSource : innerSources) {
                String innerCode = innerSource.output.toString();
                innerCode = innerCode.replaceAll("import .*;", "");
                innerCode = innerCode.replaceAll("package .*;", "");
                innerCode = innerCode.replaceAll(" " + getShortName() + "." + innerSource.getShortName(),
                        " " + innerSource.getShortName());

                out.append(innerCode);
            }

            if (closeCurly != -1) {
                out.append("}\n");
            }
        }
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:nl.b3p.kaartenbalie.struts.WMSUrlCreatorAction.java

public ActionForward getMapUrl(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (!isTokenValid(request)) {
        prepareMethod(dynaForm, request, EDIT, LIST);
        addAlternateMessage(mapping, request, TOKEN_ERROR_KEY);
        return getAlternateForward(mapping, request);
    }//from  www  . jav  a 2s.c  o m

    ActionErrors errors = dynaForm.validate(mapping, request);
    if (!errors.isEmpty()) {
        super.addMessages(request, errors);
        prepareMethod(dynaForm, request, EDIT, LIST);
        addAlternateMessage(mapping, request, VALIDATION_ERROR_KEY);
        return getAlternateForward(mapping, request);
    }

    //Create the String
    String[] layers = (String[]) dynaForm.get("sortedLayers");
    String projectie = (String) dynaForm.get("selectedProjectie");
    String bbox = (String) dynaForm.get("bbox");
    Integer height = (Integer) dynaForm.get("height");
    Integer width = (Integer) dynaForm.get("width");
    String format = (String) dynaForm.get("selectedFormat");
    String pUrl = (String) dynaForm.get("personalUrl");

    if (layers.length == 0) {
        prepareMethod(dynaForm, request, LIST, LIST);
        addAlternateMessage(mapping, request, NO_LAYERS_SELECTED_ERROR_KEY);
        return getAlternateForward(mapping, request);
    }

    /*
     * Get the URL to start with
     */
    User user = (User) request.getUserPrincipal();
    if (user == null) {
        prepareMethod(dynaForm, request, LIST, LIST);
        addAlternateMessage(mapping, request, UNKNOWN_SES_USER_ERROR_KEY);
        return getAlternateForward(mapping, request);
    }

    StringBuffer layerString = new StringBuffer();
    for (int i = 0; i < layers.length; i++) {
        layerString.append(layers[i]);
        layerString.append(",");
    }
    String layer = layerString.substring(0, layerString.lastIndexOf(","));

    StringBuffer getMapUrl = new StringBuffer(user.getPersonalURL(request));
    getMapUrl.append("?");
    getMapUrl.append(OGCConstants.WMS_SERVICE);
    getMapUrl.append("=");
    getMapUrl.append(OGCConstants.WMS_SERVICE_WMS);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_VERSION);
    getMapUrl.append("=");
    getMapUrl.append(OGCConstants.WMS_VERSION_111);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_REQUEST);
    getMapUrl.append("=");
    getMapUrl.append(OGCConstants.WMS_REQUEST_GetMap);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_LAYERS);
    getMapUrl.append("=");
    getMapUrl.append(layer);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_BBOX);
    getMapUrl.append("=");
    getMapUrl.append(bbox);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_SRS);
    getMapUrl.append("=");
    getMapUrl.append(projectie);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_HEIGHT);
    getMapUrl.append("=");
    getMapUrl.append(height);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_WIDTH);
    getMapUrl.append("=");
    getMapUrl.append(width);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_FORMAT);
    getMapUrl.append("=");
    getMapUrl.append(format);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_BGCOLOR);
    getMapUrl.append("=");
    getMapUrl.append("0xF0F0F0");
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_EXCEPTIONS);
    getMapUrl.append("=");
    getMapUrl.append(OGCConstants.WMS_PARAM_EXCEPTION_INIMAGE);
    getMapUrl.append("&");
    getMapUrl.append(OGCConstants.WMS_PARAM_STYLES);
    getMapUrl.append("=");

    user.setDefaultGetMap(getMapUrl.toString());

    log.debug("Getting entity manager ......");
    EntityManager em = getEntityManager();
    if (user.getId() == null) {
        em.persist(user);
    } else {
        em.merge(user);
    }
    em.flush();

    populateForm(getMapUrl.toString(), dynaForm, request);
    prepareMethod(dynaForm, request, LIST, EDIT);
    addDefaultMessage(mapping, request, ACKNOWLEDGE_MESSAGES);
    return getDefaultForward(mapping, request);
}