Example usage for org.apache.commons.lang StringUtils replaceChars

List of usage examples for org.apache.commons.lang StringUtils replaceChars

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replaceChars.

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:org.syncany.gui.linux.FolderProxy.java

@Override
public String toString() {
    String eFolder = StringUtils.replaceChars(localFile.getAbsolutePath(), "\"", "\\\"");
    return "{\"folder\":\"" + eFolder + "\"}";
}

From source file:org.syncany.gui.linux.NotifyRequest.java

@Override
public String toString() {
    String eSummary = StringUtils.replaceChars(summary, "\"", "\\\"");
    String eBody = StringUtils.replaceChars(body, "\"", "\\\"");
    String eImage = StringUtils.replaceChars(imageFile.getAbsolutePath(), "\"", "\\\"");

    return "{\"request\":\"NotifyRequest\",\"summary\":\"" + eSummary + "\",\"body\":\"" + eBody
            + "\",\"image\":\"" + eImage + "\"}";
}

From source file:org.syncany.gui.linux.ProfileProxy.java

@Override
public String toString() {
    String eName = StringUtils.replaceChars(name, "\"", "\\\"");
    return "{\"name\":\"" + eName + "\",\"folders\":" + folders + "}";
}

From source file:org.syncany.gui.linux.UpdateStatusTextRequest.java

@Override
public String toString() {
    String eStatus = StringUtils.replaceChars(status, "\"", "\\\"");
    return "{\"request\":\"UpdateStatusTextRequest\",\"status\":\"" + eStatus + "\"}";
}

From source file:org.viafirma.nucleo.X509.CertificadoGenericoFactory.java

/**
 * Retorna un certificado generico parseando los datos de un certificado X509
 * @param certificadoX509 /*from   w w  w. j  av  a2 s. com*/
 * @return
 */
public CertificadoGenerico generar(X509Certificate certificadoX509) {
    CertificadoGenerico certificado = new CertificadoGenerico();

    // recuperamos el conjunto de oids
    Map<String, String> propiedadesOid = X509Handler.getCurrentInstance().readPropertiesOid(certificadoX509);

    String subject = certificadoX509.getSubjectDN().toString();

    // parseo el subject
    //StringTokenizer tokenizer=new StringTokenizer(subject,",\"");
    //String [] tokens=subject.split(",");
    //for (int i = 0; i < tokens.length; i++) {
    //   String parIdValor = tokens[i].trim();
    //   String id= parIdValor.split("=")[0];
    //   String valor= parIdValor.split("=")[1];
    //   propiedadesOid.put(id,valor);
    //}
    loadPropiedadesOid(subject, propiedadesOid);

    // guardo todas las propiedades(pintables)
    Set<String> keys = propiedadesOid.keySet();
    for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
        String key = iter.next();
        String valor = propiedadesOid.get(key);
        // FIX: Problema con el encondig utf-8 en openid.
        String newValue = StringUtils.replaceChars(valor, "??", "aeiounuAEIOU");
        if (!StringUtils.isAsciiPrintable(newValue)) {
            // omitimos el campo 
            iter.remove();
        } else {
            // remplazamos el valor
            propiedadesOid.put(key, newValue);
        }
    }
    certificado.setPropiedades(propiedadesOid);

    // identifico el nombre de la CA propietaria del certificado
    certificado.setCa(certificadoX509.getIssuerDN().getName());

    certificado.setNombre(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.1"));
    certificado.setApellido1(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.2"));
    certificado.setApellido2(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.3"));
    certificado.setNumberUserId(certificado.getPropiedades().get("1.3.6.1.4.1.5734.1.4"));
    certificado.setCn(propiedadesOid.get("CN"));

    // si no hemos recuperado el nombre en la extensin lo intento recuperar del GIVENNAME.
    if (StringUtils.isEmpty(certificado.getNombre())) {
        certificado.setNombre(propiedadesOid.get("GIVENNAME"));
    }

    // si no hemos recuperado el nombre APELLIDO.
    if (StringUtils.isEmpty(certificado.getApellido1())) {
        certificado.setApellido1(propiedadesOid.get("SURNAME"));
    }

    // si no tenemos apelligos, los intentamos recuperar del CN ( cado del edni)
    // CN="Apelido1 apellido2, nombre (AUTENTICACIN)",
    if (StringUtils.isEmpty(certificado.getApellido1())) {
        // TODO, no se recupera correctamente el CN, pero el resultado es el correcto.
        // Debera de ser StringUtils.substringAfterLast(propiedadesOid.get("CN").replaceAll("\"", ""),",")
        // pero nos vale con propiedadesOid.get("CN")
        certificado.setApellido1(propiedadesOid.get("CN"));
    }

    // si no hemos recuperado el nombre NIF.
    if (StringUtils.isEmpty(certificado.getNumberUserId())) {
        certificado.setNumberUserId(propiedadesOid.get("SERIALNUMBER"));
    }

    // si no hemos recuperado el nombre email.
    if (StringUtils.isEmpty(certificado.getEmail())) {
        certificado.setEmail(certificado.getPropiedades().get(OID_EMAIL));
    }

    // si sige siendo null lo recupero del oid
    if (StringUtils.isEmpty(certificado.getEmail())) {
        certificado.setEmail(propiedadesOid.get("EMAILADDRESS"));
    }

    // si no hemos recuperado el pais
    if (StringUtils.isEmpty(certificado.getPais())) {
        certificado.setPais(certificado.getPropiedades().get("C"));
    }

    // filtrado para que ningun campo sea null
    if (certificado.getApellido1() == null) {
        certificado.setApellido1("");
    }

    if (certificado.getApellido2() == null) {
        certificado.setApellido2("");
    }

    if (certificado.getCa() == null) {
        certificado.setCa("");
    }
    if (certificado.getEmail() == null) {
        certificado.setEmail("");
    }
    if (certificado.getNombre() == null) {
        certificado.setNombre("");
    }
    if (certificado.getPais() == null) {
        certificado.setPais("");
    }

    if (certificado.getNumberUserId() == null) {
        certificado.setNumberUserId("");
    }

    // recupero el cargo. 
    String cargo = propiedadesOid.get("T");
    if (cargo != null) {
        certificado.setCargo(cargo);
    }
    // recupero el nombre de la organizacin.
    String organizacion = propiedadesOid.get("O");
    if (organizacion != null) {
        certificado.setOrganizacion(organizacion);
    }

    // Detectamos si el certificado est caducado
    Date hoy = new Date();
    if (certificadoX509.getNotAfter().before(hoy)) {
        // el certificado est caducado.
        certificado.setCaducado(true);
    }

    // recuperar el tpo de certificado
    loadTipoCertificado(certificado, propiedadesOid, certificado.getCa());

    return certificado;
}

From source file:raptor.alias.GrantSpoofAlias.java

@Override
public RaptorAliasResult apply(final ChatConsoleController controller, String command) {
    if (StringUtils.startsWith(command, "grantspoof")) {
        RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true);
        tok.nextToken();/*from   w  w  w  .ja va 2s .  c om*/
        final String param = tok.nextToken();

        if (param == null) {
            return new RaptorAliasResult(null, "Invalid syntax: " + command + " \n" + getUsage());
        } else if (param.equalsIgnoreCase("remove") || param.equalsIgnoreCase("kill")) {
            for (String user : usersWithControl) {
                controller.getConnector().sendMessage("tell " + user + " I have removed your spoof access.");
            }
            usersWithControl.clear();
            return new RaptorAliasResult(null, "All spoof access has been removed.");
        } else {
            usersWithControl.add(param);
            controller.getConnector().invokeOnNextRegexMatch(param + " tells you\\: .*", new MessageCallback() {
                public boolean matchReceived(final ChatEvent event) {
                    if (event.getType() != ChatType.TELL || controller.isDisposed()) {
                        return false;
                    }
                    boolean hasAccess = false;
                    for (String user : usersWithControl) {
                        if (user.equalsIgnoreCase(event.getSource())) {
                            hasAccess = true;
                            break;
                        }
                    }
                    if (hasAccess) {
                        String message = event.getMessage();
                        RaptorStringTokenizer messageTok = new RaptorStringTokenizer(message, " ", true);
                        messageTok.nextToken();
                        messageTok.nextToken();
                        messageTok.nextToken();

                        message = messageTok.getWhatsLeft().trim();
                        if (!message.startsWith("/") && !message.startsWith("\\")) {
                            final String finalMessage = StringUtils.replaceChars(message, "\\\n", "");
                            Raptor.getInstance().getDisplay()
                                    .asyncExec(new RaptorRunnable(controller.getConnector()) {
                                        @Override
                                        public void execute() {
                                            controller.onAppendChatEventToInputText(new ChatEvent(null,
                                                    ChatType.INTERNAL,
                                                    event.getSource() + " is spoofing: '" + finalMessage
                                                            + "'. To kill his/her access type 'grantspoof remove'."));
                                        }
                                    });
                            controller.getConnector().sendMessage(finalMessage, true);
                        }
                        return true;
                    } else {
                        return false;
                    }
                }
            });

            return new RaptorAliasResult("tell " + param
                    + " You now have spoof access to my account. Every tell you send me will be executed "
                    + "as a command. If you send me a tell that starts with / or \\ it will not be exuected as a command.",
                    "All tells sent to you from " + param
                            + " will now be executed as commands. You can stop this at any time by "
                            + "typing 'grantspoof remove'. If the user sends you a tell that starts "
                            + "with / or \\ the command will not be executed.");
        }

    }
    return null;
}

From source file:raptor.chat.Bugger.java

public int getRatingAsInt() {
    int result = 0;
    try {/*  w  ww  .j  a v a 2 s  .  c o m*/
        result = Integer.parseInt(StringUtils.replaceChars(rating, "EP", ""));
    } catch (NumberFormatException nfe) {
    }
    return result;
}

From source file:raptor.chat.ChatEventUtils.java

protected static String deserializeField(String field) {
    String result = StringUtils.defaultString(field);
    result = StringUtils.replaceChars(result, NEW_LINE_REPLACEMENT, '\n');
    return result;
}

From source file:raptor.chat.ChatEventUtils.java

protected static String serializeField(String field) {
    String result = StringUtils.defaultString(field);
    result = StringUtils.replaceChars(result, '\n', NEW_LINE_REPLACEMENT);
    return result;
}

From source file:raptor.chat.Seek.java

public int getRatingAsInt() {
    int result = 0;
    try {/*from w  ww.ja va2  s.  c  o  m*/
        result = Integer.parseInt(StringUtils.replaceChars(rating, "PE", ""));
    } catch (NumberFormatException nfe) {
    }
    return result;
}