Example usage for com.google.gwt.regexp.shared RegExp split

List of usage examples for com.google.gwt.regexp.shared RegExp split

Introduction

In this page you can find the example usage for com.google.gwt.regexp.shared RegExp split.

Prototype

public final SplitResult split(String input) 

Source Link

Usage

From source file:cc.kune.common.client.utils.ClientFormattedString.java

License:GNU Affero Public License

/**
 * String format based in/*ww w  .j a v  a  2 s  . co m*/
 * http://stackoverflow.com/questions/3126232/string-formatter-in-gwt
 * 
 * @param format
 *          the format
 * @param args
 *          the args
 * @return the string
 */
@Override
public String format(final String format, final Object... args) {
    final RegExp regex = RegExp.compile("%[a-z]");
    final SplitResult split = regex.split(format);
    final StringBuffer msg = new StringBuffer();
    for (int pos = 0; pos < split.length() - 1; pos += 1) {
        msg.append(split.get(pos));
        msg.append(args[pos].toString());
    }
    msg.append(split.get(split.length() - 1));
    GWT.log("FORMATTER: " + msg.toString());
    return msg.toString();
}

From source file:com.cristal.storm.prototype.client.mvp.view.MainPageView.java

License:Apache License

/**
 * The function adds an MCE to the MCE Collection. Tags are tokenized: we
 * assume a tag is succession of alphanum chars, a dash or an underscore
 * //  w w  w .  j a va  2  s.  co m
 * @param uriText
 * @param tagsText
 */
@Override
public void addToMCECollection(String uriText, String tagsText) {
    RegExp regExp = RegExp.compile("([A-Za-z0-9_\\-]+)");
    SplitResult split = regExp.split(tagsText.toLowerCase());
    Set<String> tags = new TreeSet<String>();
    for (int i = 0; i < split.length(); i++) {
        if (!split.get(i).isEmpty()) {
            tags.add(split.get(i));
        }
    }

    MCE mce = new MCE(uriText, tags);
    int mceIndex = ((Vector<MCE>) mceListVisible).indexOf(mce);

    // On verifie si le MCE (identifie par son URI) est deja present
    if (mceIndex >= 0) {
        MCE existingMCE = mceListVisible.get(mceIndex);
        if (!existingMCE.getTags().equals(mce.getTags())) {
            existingMCE.setTags(tags);
        }
    } else {
        mceListVisible.add(mce);
    }
    mceCollectionDraggable.setRowData(mceListVisible);
    mceSelectionModel.setSelected(mce, true);
}

From source file:com.dotweblabs.timeago.client.TimeAgo.java

License:Open Source License

public static String format(final String format, final Object arg) {
    final RegExp regex = RegExp.compile("{(.*?)}");
    final SplitResult split = regex.split(format);
    final StringBuffer msg = new StringBuffer();
    //      for (int pos = 0; pos < split.length() - 1; ++pos) {
    //         msg.append(split.get(pos));
    //         msg.append(String.valueOf(arg));
    //      }// www .j  av a2  s.  c  o m
    msg.append(split.get(0));
    msg.append(String.valueOf(arg).split("\\.")[0]);
    msg.append(split.get(split.length() - 1));
    return msg.toString();
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.draw.LogoExample.java

License:sencha.com license

private List<PathCommand> getCommandsFromString(String path) {
    String pathCommands = "AaCcHhLlMmQqSsTtVvZz";
    RegExp commandRegExp = RegExp.compile("(?=[" + pathCommands + "])");
    RegExp valueRegExp = RegExp.compile("(?=-)|[,\\s]");

    List<PathCommand> commands = new ArrayList<PathCommand>();
    SplitResult split = commandRegExp.split(path);
    for (int i = 0; i < split.length(); i++) {
        String rawCommand = split.get(i);
        SplitResult splitValues = valueRegExp.split(rawCommand.substring(1));
        char type = rawCommand.charAt(0);
        boolean relative = Character.isLowerCase(type);
        type = Character.toLowerCase(type);
        if (type == 'c') {
            commands.add(new CurveTo(Double.valueOf(splitValues.get(0)), Double.valueOf(splitValues.get(1)),
                    Double.valueOf(splitValues.get(2)), Double.valueOf(splitValues.get(3)),
                    Double.valueOf(splitValues.get(4)), Double.valueOf(splitValues.get(5)), relative));
        } else if (type == 'l') {
            commands.add(new LineTo(Double.valueOf(splitValues.get(0)), Double.valueOf(splitValues.get(1)),
                    relative));//  ww  w  .jav  a2 s.  c o m
        } else if (type == 'm') {
            commands.add(new MoveTo(Double.valueOf(splitValues.get(0)), Double.valueOf(splitValues.get(1)),
                    relative));
        } else if (type == 'z') {
            commands.add(new ClosePath(relative));
        } else if (type == 'a') {
            commands.add(new EllipticalArc(Double.valueOf(splitValues.get(0)),
                    Double.valueOf(splitValues.get(1)), Double.valueOf(splitValues.get(2)),
                    Integer.valueOf(splitValues.get(3)), Integer.valueOf(splitValues.get(4)),
                    Double.valueOf(splitValues.get(5)), Double.valueOf(splitValues.get(6)), relative));
        } else if (type == 'h') {
            commands.add(new LineToHorizontal(Double.valueOf(splitValues.get(0)), relative));
        } else if (type == 'v') {
            commands.add(new LineToVertical(Double.valueOf(splitValues.get(0)), relative));
        } else if (type == 'q') {
            commands.add(
                    new CurveToQuadratic(Double.valueOf(splitValues.get(0)), Double.valueOf(splitValues.get(1)),
                            Double.valueOf(splitValues.get(2)), Double.valueOf(splitValues.get(3)), relative));
        } else if (type == 's') {
            commands.add(
                    new CurveToSmooth(Double.valueOf(splitValues.get(0)), Double.valueOf(splitValues.get(1)),
                            Double.valueOf(splitValues.get(2)), Double.valueOf(splitValues.get(3)), relative));
        } else if (type == 't') {
            commands.add(new CurveToQuadraticSmooth(Double.valueOf(splitValues.get(0)),
                    Double.valueOf(splitValues.get(1)), relative));
        }
    }
    return commands;
}

From source file:com.pastekit.umbrella.gwt.client.strings.StringHelper.java

License:Open Source License

public static String format(final String format, final Object... args) {
    final RegExp regex = RegExp.compile("%[a-z]");
    final SplitResult split = regex.split(format);
    final StringBuffer msg = new StringBuffer();
    for (int pos = 0; pos < split.length() - 1; ++pos) {
        msg.append(split.get(pos));//from   ww w.  j  a  v  a  2  s  . co  m
        msg.append(args[pos].toString());
    }
    msg.append(split.get(split.length() - 1));
    return msg.toString();
}

From source file:cz.cas.lib.proarc.webapp.client.ClientUtils.java

License:Open Source License

/**
 * Simplified version of {@link String#format(java.lang.String, java.lang.Object[]) String.format}
 * For now it supports only {@code %s} format specifier.
 *///from w ww.  ja va  2s  . co  m
public static String format(String format, Object... args) {
    RegExp re = RegExp.compile("%s");
    SplitResult split = re.split(format);
    StringBuilder sb = new StringBuilder();
    sb.append(split.get(0));
    for (int i = 1; i < split.length(); i++) {
        sb.append(args[i - 1]);
        sb.append(split.get(i));
    }
    return sb.toString();
}

From source file:cz.fi.muni.xkremser.editor.client.util.ClientUtils.java

License:Open Source License

/**
 * String.format is not accessible on the gwt client-side
 * //w ww  .  j  a  v  a2  s  .c o  m
 * @param format
 * @param args
 * @return formatted string
 */
public static String format(final String format, final char escapeCharacter, final Object... args) {
    final RegExp regex = RegExp.compile("%" + escapeCharacter);
    final SplitResult split = regex.split(format);
    final StringBuffer msg = new StringBuffer();
    for (int pos = 0; pos < split.length() - 1; pos += 1) {
        msg.append(split.get(pos));
        msg.append(args[pos].toString());
    }
    msg.append(split.get(split.length() - 1));
    return msg.toString();
}

From source file:edu.ucla.loni.client.ServerLibraryManager.java

License:Open Source License

/**
 *  Sets the workarea with file operations and a form to edit
 *///from  w w  w  .ja  v a2s . c  o m
private void viewFile(final Pipefile pipe) {
    clearWorkarea();

    lastPipefileId = pipe.fileId;
    backToLastPipefile.hide();

    // File Operations
    fileOperationsActions(new Pipefile[] { pipe });

    // Title
    Label editFileTitle = new Label("Edit File");
    editFileTitle.setHeight(40);
    editFileTitle.setStyleName("workarea-title");
    workarea.addMember(editFileTitle);

    // Edit File
    final DynamicForm form = new DynamicForm();
    form.setCanEdit(true);
    form.setPadding(10);
    form.setStyleName("edit-form");

    int width = 400;

    TextItem name = new TextItem();
    name.setTitle("Name");
    name.setName("name");
    name.setWidth(width);

    TextItem packageName = new TextItem();
    packageName.setTitle("Package");
    packageName.setName("package");
    packageName.setWidth(width);

    StaticTextItem type = new StaticTextItem();
    type.setTitle("Type");
    type.setName("type");

    TextAreaItem description = new TextAreaItem();
    description.setTitle("Description");
    description.setName("description");
    description.setWidth(width);

    TextItem tags = new TextItem();
    tags.setTitle("Tags");
    tags.setName("tags");
    tags.setWidth(width);
    tags.setHint("Comma separated list");

    SelectItem formatType = new SelectItem();
    formatType.setTitle("Value Format Type");
    formatType.setType("comboBox");
    formatType.setName("formatType");
    final String str = "String", dir = "Directory", file = "File", num = "Number";
    formatType.setValueMap(str, dir, file, num);

    TextAreaItem values = new TextAreaItem();
    values.setTitle("Values");
    values.setName("values");
    values.setWidth(width);
    values.setHint("Newline separated list<br/>");

    final TextItem valuesPrefix = new TextItem();
    valuesPrefix.setTitle("Values Prefix");
    valuesPrefix.setName("valuesPrefix");
    valuesPrefix.setWidth(width);

    TextItem location = new TextItem();
    location.setTitle("Location");
    location.setName("location");
    location.setWidth(width);

    TextItem locationPrefix = new TextItem();
    locationPrefix.setTitle("Location Prefix");
    locationPrefix.setName("locationPrefix");
    locationPrefix.setWidth(width);

    TextItem uri = new TextItem();
    uri.setTitle("URI");
    uri.setName("uri");
    uri.setWidth(width);

    final TextAreaItem access = new TextAreaItem();
    access.setTitle("Access");
    access.setName("access");
    access.setWidth(width);
    access.setHeight(50);
    access.setHint(groupHint);

    final StaticTextItem accessInfo = new StaticTextItem();
    accessInfo.setTitle("Access Groups Expanded");

    formatType.addChangedHandler(new ChangedHandler() {
        public void onChanged(ChangedEvent event) {
            if (form.getValueAsString("formatType").equals(num)) {
                valuesPrefix.disable();
            } else
                valuesPrefix.enable();
        }
    });

    access.addChangedHandler(new ChangedHandler() {
        public void onChanged(ChangedEvent event) {
            expandGroups("", access.getValueAsString(), accessInfo);
        }
    });

    form.setFields(name, packageName, type, description, tags, locationPrefix, location, uri, valuesPrefix,
            values, formatType, access, accessInfo);

    // Set the value of the fields
    form.setValue("name", pipe.name);
    form.setValue("package", pipe.packageName);
    if (pipe.type.equals("Modules"))
        form.setValue("type", "Module");
    else if (pipe.type.equals("Groups"))
        form.setValue("type", "Group");
    else
        form.setValue("type", pipe.type);
    form.setValue("description", pipe.description);
    form.setValue("tags", pipe.tags);
    form.setValue("access", pipe.access);
    expandGroups("", access.getValueAsString(), accessInfo);

    if (pipe.type.equals("Data")) {
        String valString = "";
        pipe.valuesPrefix = "";

        RegExp split = RegExp.compile("\n", "m");
        SplitResult vals = split.split(pipe.values);
        RegExp re = RegExp.compile("((.*/)*)(.*)");

        for (int j = 0; j < vals.length(); j++) {
            MatchResult m = re.exec(vals.get(j));
            if (m != null && m.getGroup(0) != null && m.getGroup(0).length() > 0) {
                //check if group is null before assigning
                if (m.getGroup(3) != null)
                    valString += m.getGroup(3) + "\n";
                if (j == 0) {
                    if (m.getGroup(2) != null)
                        pipe.valuesPrefix = m.getGroup(2);
                } else {

                    if (m.getGroup(2) == null || !pipe.valuesPrefix.equals(m.getGroup(2))) {
                        pipe.valuesPrefix = "";
                    }
                }
            }
            if (pipe.valuesPrefix.equals(""))
                valString = pipe.values;
        }
        form.setValue("formatType", pipe.formatType);
        if (pipe.formatType.equals(file) || pipe.formatType.equals(dir) || pipe.formatType.equals(str))
            form.setValue("valuesPrefix", pipe.valuesPrefix);
        else
            valuesPrefix.disable();
        form.setValue("values", valString);
    } else {
        form.hideItem("values");
        form.hideItem("valuesPrefix");
        form.hideItem("formatType");
    }

    if (pipe.type.equals("Modules")) {
        String loc = "";
        pipe.locationPrefix = "";

        RegExp re = RegExp.compile("(.*://.*/)(.*)");
        MatchResult m = re.exec(pipe.location);

        if (m != null) {
            pipe.locationPrefix = m.getGroup(1);
            loc = m.getGroup(2);
        } else {
            pipe.locationPrefix = "";
            loc = "";
        }

        form.setValue("locationPrefix", pipe.locationPrefix);
        form.setValue("location", loc);
    } else {
        form.hideItem("locationPrefix");
        form.hideItem("location");
    }

    if (pipe.type.equals("Modules") || pipe.type.equals("Groups")) {
        form.setValue("uri", pipe.uri);
    } else {
        form.hideItem("uri");
    }

    // Update Button
    Button update = new Button("Update");
    update.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String newName = form.getValueAsString("name");
            pipe.nameUpdated = (!pipe.name.equals(newName));

            String newPackageName = form.getValueAsString("package");
            pipe.packageUpdated = (!pipe.packageName.equals(newPackageName));

            pipe.name = newName;
            pipe.packageName = newPackageName;
            // pipe.type is not editable
            pipe.description = form.getValueAsString("description");
            pipe.tags = form.getValueAsString("tags");
            pipe.access = form.getValueAsString("access");

            if (pipe.type.equals("Data")) {
                String valString = "";
                if (form.getValueAsString("formatType").equals(num)) {
                    valString = form.getValueAsString("values");
                } else { //append prefix
                    pipe.valuesPrefix = form.getValueAsString("valuesPrefix");
                    if (pipe.valuesPrefix == null)
                        pipe.valuesPrefix = "";
                    RegExp split = RegExp.compile("\n", "m");
                    SplitResult vals = split.split(form.getValueAsString("values"));

                    for (int j = 0; j < vals.length(); j++) {
                        if (vals.get(j).length() == 0)
                            continue;
                        valString += pipe.valuesPrefix + vals.get(j) + "\n";
                    }
                }
                pipe.values = valString;
                pipe.formatType = form.getValueAsString("formatType");
            }

            if (pipe.type.equals("Modules")) {
                pipe.locationPrefix = form.getValueAsString("locationPrefix");
                pipe.location = pipe.locationPrefix + form.getValueAsString("location");
            }

            if (pipe.type.equals("Modules") || pipe.type.equals("Groups")) {
                pipe.uri = form.getValueAsString("uri");
            }

            updateFile(pipe);
        }
    });

    Button cancel = new Button("Cancel");
    cancel.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            basicInstructions();
        }
    });

    HLayout buttonRow = new HLayout(10);
    buttonRow.addMember(update);
    buttonRow.addMember(cancel);

    workarea.addMember(form);
    workarea.addMember(buttonRow);
}