Example usage for org.apache.wicket.util.string Strings join

List of usage examples for org.apache.wicket.util.string Strings join

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings join.

Prototype

public static String join(final String separator, final String... fragments) 

Source Link

Document

Joins string fragments using the specified separator

Usage

From source file:fiftyfive.wicket.css.CssClassModifier.java

License:Apache License

/**
 * Parse any existing classes declared in the markup for this component and then delegate
 * to {@link #modifyClasses modifyClasses()}. Set resulting set of classes on the component
 * tag to render its {@code class} attribute with the desired values.
 *//* w ww .  ja  va2s  . c om*/
@Override
public void onComponentTag(Component component, ComponentTag tag) {
    if (tag.getType() != TagType.CLOSE) {
        Set<String> values = new LinkedHashSet<String>();
        String existing = tag.getAttribute("class");
        if (existing != null) {
            values.addAll(Arrays.asList(existing.split("\\s+")));
        }
        modifyClasses(component, values);
        tag.put("class", Strings.join(" ", values.toArray(new String[0])));
    }
}

From source file:net.databinder.components.TagField.java

License:Open Source License

/** @param textarea true to generate a text area */
public TagField(String id, IModel model, boolean textarea) {
    super(id, model);
    IModel<String> tagModel = new IModel<String>() {
        public void detach() {
        }//from  w  ww .j  a  v a 2 s . c o  m

        @SuppressWarnings("unchecked")
        public String getObject() {
            Collection<String> tags = (Collection<String>) TagField.this.getDefaultModelObject();
            if (tags == null)
                return null;
            return Strings.join(", ", tags.toArray(new String[tags.size()]));
        }

        public void setObject(String object) {
            if (object == null)
                TagField.this.setDefaultModelObject(new HashSet<String>());
            else {
                String value = object.toLowerCase();
                String[] tagstrs = value.split(" *, *,* *"); // also consumes empty ' ,  ,' tags
                TagField.this.setDefaultModelObject(new HashSet<String>(Arrays.asList(tagstrs)));
            }
        }
    };
    add(new TextField<String>("field", tagModel).setVisible(!textarea));
    add(new TextArea<String>("area", tagModel).setVisible(textarea));
}

From source file:net.dontdrinkandroot.wicket.component.basic.AbstractList.java

License:Apache License

protected final void checkComponentTag(final ComponentTag tag, String... names) {

    for (String name : names) {
        if (tag.getName().equals(name)) {
            return;
        }// w  w w .  j a  v a  2 s  . co m
    }

    String joinedNames = Strings.join(",", names);
    String msg = String.format("Component [%s] (path = [%s]) must be applied to a tag of type [%s], not: %s",
            this.getId(), this.getPath(), joinedNames, tag.toUserDebugString());

    this.findMarkupStream().throwMarkupException(msg);
}

From source file:net.ftlines.wicket.fullcalendar.CalendarResponse.java

License:Apache License

private CalendarResponse execute(String... args) {
    String js = String.format("$('#%s').fullCalendarExt(" + Strings.join(",", args) + ");",
            calendar.getMarkupId());//from   www. ja v  a2 s .c o m
    target.appendJavaScript(js);
    return this;
}

From source file:org.apache.asterix.experiment.builder.AbstractLSMBaseExperimentBuilder.java

License:Apache License

@Override
protected void doBuild(Experiment e) throws Exception {
    SequentialActionList execs = new SequentialActionList();

    String clusterConfigPath = localExperimentRoot.resolve(LSMExperimentConstants.CONFIG_DIR)
            .resolve(clusterConfigFileName).toString();
    String asterixConfigPath = localExperimentRoot.resolve(LSMExperimentConstants.CONFIG_DIR)
            .resolve(LSMExperimentConstants.ASTERIX_CONFIGURATION_DIR).resolve(asterixConfigFileName)
            .toString();/*from   w  w w  . j  ava2 s .  com*/

    File clusterConfigFile = new File(clusterConfigPath);
    JAXBContext ctx = JAXBContext.newInstance(Cluster.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();
    final Cluster cluster = (Cluster) unmarshaller.unmarshal(clusterConfigFile);

    //create instance
    execs.add(new StopAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME));
    execs.add(new DeleteAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME));
    execs.add(new SleepAction(3000));
    execs.add(new CreateAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME, clusterConfigPath,
            asterixConfigPath));

    Map<String, List<String>> dgenProducers = readDatagenPairs(
            localExperimentRoot.resolve(LSMExperimentConstants.DGEN_DIR).resolve(dgenProducerFileName),
            localExperimentRoot.resolve(LSMExperimentConstants.DGEN_DIR).resolve(dgenConsumerFileName));
    final Set<String> ncHosts = new HashSet<>();
    for (List<String> ncHostList : dgenProducers.values()) {
        for (String ncHost : ncHostList) {
            ncHosts.add(ncHost.split(":")[0]);
        }
    }

    execs.add(new SleepAction(2000));
    //run ddl statements
    // TODO: implement retry handler
    execs.add(new RunAQLFileAction(httpClient, restHost, restPort,
            localExperimentRoot.resolve(LSMExperimentConstants.AQL_DIR).resolve(LSMExperimentConstants.BASE_DIR)
                    .resolve(LSMExperimentConstants.BASE_TYPES)));

    if (statFile != null) {
        ParallelActionSet ioCountActions = new ParallelActionSet();
        for (String ncHost : ncHosts) {
            ioCountActions.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {

                @Override
                protected String getCommand() {
                    String cmd = "screen -d -m sh -c \"iostat 1 > " + statFile + "\"";
                    return cmd;
                }
            });
        }
        execs.add(ioCountActions);
    }

    OutputStream os = null;
    if (resultsFile != null) {
        os = new FileOutputStream(resultsFile, true);
    } else {
        os = System.out;
    }
    final PrintStream ps = new PrintStream(os);

    SequentialActionList getDataSizeAction = new SequentialActionList();
    String[] storageRoots = cluster.getIodevices().split(",");
    for (String ncHost : ncHosts) {
        for (final String sRoot : storageRoots) {
            //                duAction.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {
            //                    @Override
            //                    protected String getCommand() {
            //                        return "ls -Rl " + sRoot;
            //                    }
            //                });
            getDataSizeAction.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {
                @Override
                protected String getCommand() {
                    return "du -cksh " + sRoot;
                }
            });

        }
    }

    //        PipedOutputStream pos = new PipedOutputStream();
    //        PipedInputStream pis = new PipedInputStream(pos);
    //        DataOutputStream dos = new DataOutputStream(pos);
    //        dos.writeLong(0);
    for (int runNum = 0; runNum < queryRunsNum; runNum++) {
        final int finalRunNum = runNum + 1;
        execs.add(new IAction() {

            @Override
            public void perform() {
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info("Executing run #" + finalRunNum + " ...");
                }
            }
        });

        doBuildDDL(execs);
        Map<String, List<String>> portNCHostMap = new TreeMap<>();
        for (List<String> ncHostList : dgenProducers.values()) {
            for (String ncHost : ncHostList) {
                String port = ncHost.split(":")[1];
                List<String> hostList = portNCHostMap.get(port);
                if (hostList == null) {
                    hostList = new ArrayList<>();
                }
                hostList.add(ncHost);
                portNCHostMap.put(port, hostList);
            }
        }
        ParallelActionSet runParallelActions = new ParallelActionSet();
        Iterator<Map.Entry<String, List<String>>> mapIt = portNCHostMap.entrySet().iterator();
        for (int i = 0; i < ingestFeedsNumber; i++) {
            runParallelActions.add(new RunAQLFileAction(httpClient, restHost, restPort,
                    assemblingIngest(
                            localExperimentRoot.resolve(LSMExperimentConstants.AQL_DIR)
                                    .resolve(LSMExperimentConstants.BASE_DIR)
                                    .resolve(LSMExperimentConstants.BASE_INGEST),
                            Strings.join(",", mapIt.next().getValue()), i + 1)));
        }

        SequentialActionList runActions = new SequentialActionList();

        runActions.add(new SleepAction(2000));
        // start record generator
        doBuildDataGen(runActions, dgenProducers);
        for (int i = 0; i < ingestFeedsNumber; i++) {
            runActions.add(new RunAQLFileAction(httpClient, restHost, restPort,
                    assemblingIngestCleanup(localExperimentRoot.resolve(LSMExperimentConstants.AQL_DIR)
                            .resolve(LSMExperimentConstants.BASE_DIR)
                            .resolve(LSMExperimentConstants.INGEST_CLEANUP), i + 1)));
        }
        runParallelActions.add(runActions);
        execs.add(runParallelActions);

        runActions = new SequentialActionList();
        runActions.add(new SleepAction(5000));
        if (countFileName != null) {
            runActions.add(new RunAQLFileAction(httpClient, restHost, restPort,
                    localExperimentRoot.resolve(LSMExperimentConstants.AQL_DIR).resolve(countFileName), ps));
            runActions.add(new IAction() {
                @Override
                public void perform() {
                    ps.print(",");
                }
            });
        }
        runActions.add(new SleepAction(2000));
        runActions.add(getDataSizeAction);

        runActions.add(new SleepAction(2000));
        runActions.add(new RunAQLFileAction(httpClient, restHost, restPort,
                localExperimentRoot.resolve(LSMExperimentConstants.AQL_DIR)
                        .resolve(LSMExperimentConstants.BASE_DIR).resolve("base_cleanup.aql")));
        runActions.add(new SleepAction(2000));

        execs.add(runActions);
    }
    execs.add(new IAction() {

        @Override
        public void perform() {
            ps.println();
        }
    });

    if (statFile != null) {
        ParallelActionSet ioCountKillActions = new ParallelActionSet();
        for (String ncHost : ncHosts) {
            ioCountKillActions.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {

                @Override
                protected String getCommand() {
                    String cmd = "screen -list | grep Detached | awk '{print $1}' | xargs -I % screen -X -S % quit";
                    return cmd;
                }
            });
        }
        execs.add(ioCountKillActions);
    }

    doPost(execs);

    execs.add(new StopAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME));
    ParallelActionSet killCmds = new ParallelActionSet();
    for (String ncHost : ncHosts) {
        killCmds.add(new RemoteAsterixDriverKill(ncHost, username, sshKeyLocation));
    }
    killCmds.add(new RemoteAsterixDriverKill(restHost, username, sshKeyLocation));
    execs.add(killCmds);
    if (statFile != null) {
        ParallelActionSet collectIOActions = new ParallelActionSet();
        for (String ncHost : ncHosts) {
            collectIOActions.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {

                @Override
                protected String getCommand() {
                    String cmd = "cp " + statFile + " " + cluster.getLogDir();
                    return cmd;
                }
            });
        }
        execs.add(collectIOActions);

    }

    //collect logs form the instance
    execs.add(new LogAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME, localExperimentRoot
            .resolve(LSMExperimentConstants.LOG_DIR + "-" + logDirSuffix).resolve(getName()).toString()));

    //collect profile information
    //        if (ExperimentProfiler.PROFILE_MODE) {
    //            if (!SpatialIndexProfiler.PROFILE_HOME_DIR.contentEquals(cluster.getLogDir())) {
    //                ParallelActionSet collectProfileInfo = new ParallelActionSet();
    //                for (String ncHost : ncHosts) {
    //                    collectProfileInfo.add(new AbstractRemoteExecutableAction(ncHost, username, sshKeyLocation) {
    //                        @Override
    //                        protected String getCommand() {
    //                            String cmd = "mv " + SpatialIndexProfiler.PROFILE_HOME_DIR + "*.txt " + cluster.getLogDir();
    //                            return cmd;
    //                        }
    //                    });
    //                }
    //                execs.add(collectProfileInfo);
    //            }
    //        }

    //        execs.add(new LogAsterixManagixAction(managixHomePath, ASTERIX_INSTANCE_NAME, localExperimentRoot
    //                .resolve(LSMExperimentConstants.LOG_DIR + "-" + logDirSuffix).resolve(getName()).toString()));

    if (getName().contains("SpatialIndexExperiment2") || getName().contains("SpatialIndexExperiment5")) {

        //get query result file
        SequentialActionList getQueryResultFileActions = new SequentialActionList();
        final String queryResultFilePath = openStreetMapFilePath.substring(0,
                openStreetMapFilePath.lastIndexOf(File.separator)) + File.separator + "QueryGenResult-*.txt";
        for (final String qgenHost : dgenProducers.keySet())

        {
            getQueryResultFileActions
                    .add(new AbstractRemoteExecutableAction(restHost, username, sshKeyLocation) {

                        @Override
                        protected String getCommand() {
                            String cmd = "scp " + username + "@" + qgenHost + ":" + queryResultFilePath + " "
                                    + localExperimentRoot
                                            .resolve(LSMExperimentConstants.LOG_DIR + "-" + logDirSuffix)
                                            .resolve(getName()).toString();
                            return cmd;
                        }
                    });
        }
        execs.add(getQueryResultFileActions);

    }

    e.addBody(execs);
}

From source file:org.cast.cwm.data.validator.FileTypeValidator.java

License:Open Source License

@Override
protected Map<String, Object> variablesMap(IValidatable<FileUpload> validatable) {
    final Map<String, Object> map = super.variablesMap(validatable);
    map.put("type", validatable.getValue().getContentType());
    String types = "'" + Strings.join("', '", mimeTypes.toArray(new String[0])) + "'";
    map.put("allowed", types);
    return map;// w  w  w . ja v a  2  s. c  o m
}

From source file:org.cast.cwm.data.validator.MultipleFileTypeValidator.java

License:Open Source License

@Override
protected Map<String, Object> variablesMap(IValidatable<Collection<FileUpload>> validatable) {
    final Map<String, Object> map = super.variablesMap(validatable);
    String types = "'" + Strings.join("', '", mimeTypes.toArray(new String[0])) + "'";
    map.put("allowed", types);
    return map;/*  w  w w  .j  a v  a 2  s  . c o m*/
}

From source file:org.cast.cwm.data.validator.UrlTypeValidator.java

License:Open Source License

@Override
protected Map<String, Object> variablesMap(IValidatable<String> validatable) {
    final Map<String, Object> map = super.variablesMap(validatable);

    String type;/*from   w ww  .  j a va  2 s .co  m*/
    try {
        URL url = new URL(validatable.getValue());

        // Ensure a connection can be made
        URLConnection c = url.openConnection();
        c.connect();

        type = c.getContentType();
        if (type == null)
            type = "unknown";

    } catch (Exception ex) {
        type = "unknown";
    }

    map.put("type", type);
    String types = "'" + Strings.join("', '", mimeTypes.toArray(new String[0])) + "'";
    map.put("allowed", types);
    return map;
}

From source file:org.geoserver.jdbcconfig.internal.ConfigDatabase.java

License:Open Source License

/**
 * @param info/*w  w w .  j  a  va2  s.com*/
 * @param prop
 * @return
 */
private Info lookUpRelatedObject(final Info info, final Property prop, @Nullable Integer collectionIndex) {

    checkArgument(collectionIndex == 0 || prop.isCollectionProperty());

    final FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    final Integer targetPropertyTypeId = prop.getPropertyType().getTargetPropertyOid();
    checkArgument(targetPropertyTypeId != null);

    final PropertyType targetPropertyType = dbMappings.getPropertyType(targetPropertyTypeId);
    checkState(targetPropertyType != null);

    final Class<?> targetType = dbMappings.getType(targetPropertyType.getObjectTypeOid());
    checkState(targetType != null);

    final String localPropertyName = prop.getPropertyName();
    String[] steps = localPropertyName.split("\\.");
    // Step back through ancestor property references If starting at a.b.c.d, then look at a.b.c, then a.b, then a
    for (int i = steps.length - 1; i >= 0; i--) {
        String backPropName = Strings.join(".", Arrays.copyOfRange(steps, 0, i));
        Object backProp = ff.property(backPropName).evaluate(info);
        if (backProp != null) {
            if (prop.isCollectionProperty() && (backProp instanceof Set || backProp instanceof List)) {
                List<?> list;
                if (backProp instanceof Set) {
                    list = asValueList(backProp);
                    if (list.size() > 0 && list.get(0) != null
                            && targetType.isAssignableFrom(list.get(0).getClass())) {
                        String targetPropertyName = targetPropertyType.getPropertyName();
                        final PropertyName expr = ff.property(targetPropertyName);
                        Collections.sort(list, new Comparator<Object>() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                Object v1 = expr.evaluate(o1);
                                Object v2 = expr.evaluate(o2);
                                String m1 = marshalValue(v1);
                                String m2 = marshalValue(v2);
                                return m1 == null ? (m2 == null ? 0 : -1) : (m2 == null ? 1 : m1.compareTo(m2));
                            }
                        });
                    }
                } else {
                    list = (List<?>) backProp;
                }
                if (collectionIndex <= list.size()) {
                    backProp = list.get(collectionIndex - 1);
                }
            }
            if (targetType.isAssignableFrom(backProp.getClass())) {
                return (Info) backProp;
            }
        }
    }
    // throw new IllegalArgumentException("Found no related object of type "
    // + targetType.getName() + " for property " + localPropertyName + " of " + info);
    return null;
}

From source file:org.hippoecm.frontend.ClassFromKeyStringResourceLoader.java

License:Apache License

@Override
public String loadStringResource(final Component component, final String key, final Locale locale,
        final String style, final String variation) {
    if (key.indexOf(',') > 0) {
        List<String> criteria = new LinkedList<String>();
        for (String subKey : key.split(",")) {
            criteria.add(subKey);/*from   w w  w.  j a  va 2 s .  com*/
        }

        String realKey = key.substring(0, key.indexOf(','));
        ValueMap map = new ValueMap(key.substring(key.indexOf(',') + 1));
        if (map.containsKey("class")) {
            // remove class key from map and criteria
            String clazz = (String) map.remove("class");
            Iterator<String> iter = criteria.iterator();
            while (iter.hasNext()) {
                if (iter.next().startsWith("class=")) {
                    iter.remove();
                    break;
                }
            }

            // iterate while no value is found, dropping the last 
            String value = getStringForClass(Strings.join(",", criteria.toArray(new String[criteria.size()])),
                    locale, style, clazz);
            if (value != null) {
                return value;
            }
        }
        if ("exception".equals(realKey) && map.containsKey("type")) {
            // remove class key from map and criteria
            String clazz = (String) map.remove("type");
            Iterator<String> iter = criteria.iterator();
            while (iter.hasNext()) {
                if (iter.next().startsWith("type=")) {
                    iter.remove();
                    break;
                }
            }

            // Load the properties associated with the path
            String value = getStringForClass(Strings.join(",", criteria.toArray(new String[criteria.size()])),
                    locale, style, clazz);
            if (value != null) {
                return value;
            }
        }
    }
    return null;
}