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

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

Introduction

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

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:org.craftercms.cstudio.alfresco.service.impl.CStudioNodeServiceImpl.java

@Override
public NodeRef createNewFile(String fullPath, InputStream content, Map<QName, Serializable> nodeProperties) {
    int idx = StringUtils.lastIndexOf(fullPath, '/');
    String parentPath = StringUtils.substring(fullPath, 0, idx - 1);
    String fileName = StringUtils.substring(fullPath, idx + 1);
    if (!nodeProperties.containsKey(ContentModel.PROP_NAME)) {
        nodeProperties.put(ContentModel.PROP_NAME, fileName);
    }/*from   ww  w.j  a v  a  2  s  .co m*/
    return createNewFile(parentPath, fileName, content, nodeProperties);
}

From source file:org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesStringUtils.java

/**
 * @param containerID//from  ww w  . j a va 2s  .  com
 * @return label based on 'ContainerID' (first 12 chars of ID)
 */
public static String getLabelFromContainerID(final String containerID) {
    return StringUtils.substring(containerID, 0, 12);
}

From source file:org.eclipse.che.plugin.openshift.client.OpenShiftConnector.java

/**
 * @param containerID// w  ww.  jav a  2s  .c om
 * @return label based on 'ContainerID' (first 12 chars of ID)
 */
private String getLabelFromContainerID(final String containerID) {
    return StringUtils.substring(containerID, 0, 12);
}

From source file:org.eclipse.gyrex.admin.ui.http.internal.EditApplicationDialog.java

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    final GridData gd = (GridData) composite.getLayoutData();
    gd.minimumHeight = convertVerticalDLUsToPixels(200);
    gd.minimumWidth = convertHorizontalDLUsToPixels(400);

    idField.setLabelText("Id");
    contextPathField.setLabelText("Context");
    providerField.setLabelText("Provider");

    final IDialogFieldListener validateListener = new IDialogFieldListener() {
        @Override/*w ww  .j  av a  2  s .c o  m*/
        public void dialogFieldChanged(final DialogField field) {
            validate();
        }
    };

    idField.setDialogFieldListener(validateListener);
    contextPathField.setDialogFieldListener(validateListener);
    providerField.setDialogFieldListener(validateListener);

    providerItemToIdMap.clear();
    final TreeSet<String> providerItems = new TreeSet<String>();
    final Collection<ApplicationProviderRegistration> providers = HttpActivator.getInstance()
            .getProviderRegistry().getRegisteredProviders().values();
    for (final ApplicationProviderRegistration registration : providers) {
        final String label = HttpUiAdapter.getLabel(registration);
        providerItemToIdMap.put(label, registration.getProviderId());
        providerItems.add(label);
    }
    providerField.setItems(providerItems.toArray(new String[providerItems.size()]));

    contextPathField.setContentProposalProcessor(new IContentProposalProvider() {
        /** serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public IContentProposal[] getProposals(final String contents, final int position) {
            final List<IContentProposal> resultList = new ArrayList<IContentProposal>();

            final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position));

            final Collection<ContextDefinition> contexts = ContextActivator.getInstance()
                    .getContextRegistryImpl().getDefinedContexts();
            for (final ContextDefinition contextDefinition : contexts) {
                if ((null == patternString)
                        || StringUtils.contains(contextDefinition.getPath().toString(), patternString)) {
                    resultList.add(new ContentProposal(contextDefinition.getPath().toString(),
                            contextDefinition.toString()));
                }
            }

            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    });

    propertiesField.setLabelText("Properties");
    mountsField.setLabelText("Mounts");

    final Text warning = new Text(composite, SWT.WRAP | SWT.READ_ONLY);
    warning.setText(
            "Warning: this dialog is ugly. Please help us improve the UI. Any mockups and/or patches are very much appreciated!");
    warning.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    LayoutUtil.doDefaultLayout(composite, new DialogField[] { new Separator(), idField, providerField,
            contextPathField, new Separator(), propertiesField, mountsField }, false);
    LayoutUtil.setHorizontalGrabbing(idField.getTextControl(null));
    LayoutUtil.setHorizontalGrabbing(providerField.getComboControl(null));
    LayoutUtil.setHorizontalGrabbing(contextPathField.getTextControl(null));
    LayoutUtil.setHorizontalGrabbing(propertiesField.getListControl(null));
    LayoutUtil.setHorizontalGrabbing(mountsField.getListControl(null));

    if (null != applicationRegistration) {
        idField.setText(applicationRegistration.getApplicationId());
        idField.setEnabled(false);
        contextPathField.setText(applicationRegistration.getContext().getContextPath().toString());
        contextPathField.setEnabled(false);
        for (final Entry<String, String> e : providerItemToIdMap.entrySet()) {
            if (e.getValue().equals(applicationRegistration.getProviderId())) {
                providerField.selectItem(e.getKey());
            }
        }
        providerField.setEnabled(false);

        applicationProperties.putAll(applicationRegistration.getInitProperties());
        mountsField.setElements(applicationManager.getMounts(applicationRegistration.getApplicationId()));
    }

    refreshProperties();

    final GridLayout masterLayout = (GridLayout) composite.getLayout();
    masterLayout.marginWidth = 5;
    masterLayout.marginHeight = 5;

    LayoutUtil.setHorizontalSpan(warning, masterLayout.numColumns);

    return composite;
}

From source file:org.eclipse.gyrex.admin.ui.http.jetty.internal.AddChannelDialog.java

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    final GridData gd = (GridData) composite.getLayoutData();
    gd.minimumHeight = convertVerticalDLUsToPixels(200);
    gd.minimumWidth = convertHorizontalDLUsToPixels(400);
    gd.widthHint = convertHorizontalDLUsToPixels(400);

    idField.setLabelText("Id");
    portField.setLabelText("Port");
    secureField.setLabelText("SSL");
    certificateIdField.setLabelText("Certificate");
    secureChannelIdField.setLabelText("Secure Connector");
    nodeFilterField.setLabelText("Node Filter");

    final IDialogFieldListener validateListener = new IDialogFieldListener() {
        @Override//from w  ww. j  a va2 s .c  o m
        public void dialogFieldChanged(final DialogField field) {
            validate();
        }
    };

    idField.setDialogFieldListener(validateListener);
    portField.setDialogFieldListener(validateListener);
    secureField.setDialogFieldListener(validateListener);
    certificateIdField.setDialogFieldListener(validateListener);
    secureChannelIdField.setDialogFieldListener(validateListener);
    nodeFilterField.setDialogFieldListener(validateListener);

    certificateIdField.setContentProposalProcessor(new IContentProposalProvider() {
        /** serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public IContentProposal[] getProposals(final String contents, final int position) {
            final List<IContentProposal> resultList = new ArrayList<IContentProposal>();

            final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position));

            final Collection<ICertificate> certificates = jettyManager.getCertificates();
            for (final ICertificate certificate : certificates) {
                if ((null == patternString) || StringUtils.contains(certificate.getId(), patternString)) {
                    resultList.add(new ContentProposal(certificate.getId(), certificate.getInfo()));
                }
            }

            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    });

    secureChannelIdField.setContentProposalProcessor(new IContentProposalProvider() {
        /** serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public IContentProposal[] getProposals(final String contents, final int position) {
            final List<IContentProposal> resultList = new ArrayList<IContentProposal>();

            final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position));

            final Collection<ChannelDescriptor> channels = jettyManager.getChannels();
            for (final ChannelDescriptor channel : channels) {
                if (channel.isSecure()
                        && ((null == patternString) || StringUtils.contains(channel.getId(), patternString))) {
                    resultList.add(new ContentProposal(channel.getId(),
                            String.format("%s (%s)", channel.getId(), channel.toString())));
                }
            }

            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    });

    secureField.setAttachedDialogFields(certificateIdField);

    final Infobox infobox = new Infobox(composite);
    infobox.setLayoutData(AdminUiUtil.createHorzFillData());
    infobox.addHeading("Create a new connector!");
    infobox.addParagraph(
            "Please fill in id and port to create a connector!\nIf the connector should support encryption, please choose the certificate to be used. You need some more documentation on the usage of the fields SecureConnector and nodefilter.");

    LayoutUtil.doDefaultLayout(composite,
            new DialogField[] { new Separator(), idField, portField, new Separator(), secureField,
                    certificateIdField, new Separator(), secureChannelIdField, new Separator(),
                    nodeFilterField },
            false);
    LayoutUtil.setHorizontalGrabbing(idField.getTextControl(null));

    final GridLayout masterLayout = (GridLayout) composite.getLayout();
    masterLayout.marginWidth = 5;
    masterLayout.marginHeight = 5;

    LayoutUtil.setHorizontalSpan(infobox, masterLayout.numColumns);

    return composite;
}

From source file:org.eclipse.gyrex.admin.ui.jobs.internal.ContextPathProposals.java

@Override
public IContentProposal[] getProposals(final String contents, final int position) {
    final List<IContentProposal> resultList = new ArrayList<IContentProposal>();

    final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position));

    final Collection<ContextDefinition> contexts = JobsUiActivator.getInstance()
            .getService(IRuntimeContextDefinitionManager.class).getDefinedContexts();
    for (final ContextDefinition contextDefinition : contexts) {
        if ((null == patternString)
                || StringUtils.contains(contextDefinition.getPath().toString(), patternString)) {
            resultList.add(/*from  w w  w.j av  a 2s .com*/
                    new ContentProposal(contextDefinition.getPath().toString(), contextDefinition.toString()));
        }
    }

    return resultList.toArray(new IContentProposal[resultList.size()]);
}

From source file:org.eclipse.gyrex.admin.ui.jobs.internal.TimeZoneProposals.java

@Override
public IContentProposal[] getProposals(final String contents, final int position) {
    final List<IContentProposal> resultList = new ArrayList<IContentProposal>();

    final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position));

    final String[] availableIDs = TimeZone.getAvailableIDs();
    Arrays.sort(availableIDs);/* w  w w  .  j av a2 s  .c om*/
    for (final String id : availableIDs) {
        final TimeZone timeZone = TimeZone.getTimeZone(id);
        if ((null == patternString) || StringUtils.contains(StringUtils.lowerCase(timeZone.getID()),
                StringUtils.lowerCase(patternString))) {
            resultList.add(
                    new ContentProposal(timeZone.getID(), id + " - " + timeZone.getDisplayName(Locale.US)));
        }
    }

    return resultList.toArray(new IContentProposal[resultList.size()]);
}

From source file:org.eclipse.gyrex.cloud.tests.internal.zookeeper.preferences.ZooKeeperPreferencesEnsambleTests.java

private String randomPath() {
    IPath path = Path.EMPTY;//from  w  w w .java 2  s .c o m
    final int segments = RandomUtils.nextInt(16);
    for (int i = 0; i < segments; i++) {
        path = path.append(StringUtils.substring(DigestUtils.shaHex(UUID.randomUUID().toString()), 0, 6));
    }
    return path.toString();
}

From source file:org.eclipse.jubula.client.alm.mylyn.ui.dialogs.InspectALMAttributesDialog.java

/**
 * creates the options column which has a mapping between valid values and its meaning
 * @param tableViewer the tableviewer/*from w ww .j a  v a2  s  . c om*/
 */
@SuppressWarnings("unchecked")
private void createOptionsColumn(TableViewer tableViewer) {
    TableViewerColumn options = new TableViewerColumn(tableViewer, SWT.NONE);
    options.getColumn().setWidth(300);
    options.getColumn().setText(Messages.InspecotrTableOptions);
    options.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            KeyValue<TaskAttribute> p = (KeyValue<TaskAttribute>) element;
            String text = p.getValue().getOptions().toString();
            text = StringUtils.substring(text, 1, text.length() - 1);
            return text;
        }
    });
    new ColumnViewerSorter(tableViewer, options) {
        protected int doCompare(Viewer viewer, Object e1, Object e2) {
            return getCommonsComparator().compare(
                    ((KeyValue<TaskAttribute>) e1).getValue().getOptions().toString(),
                    ((KeyValue<TaskAttribute>) e2).getValue().getOptions().toString());
        }
    };
    ColumnViewerToolTipSupport.enableFor(tableViewer);
}

From source file:org.eclipse.jubula.client.ui.rcp.handlers.SaveImageAsHandler.java

/**
 * {@inheritDoc}/*  w ww.  j  a v  a 2s .  c  o m*/
 */
protected Object executeImpl(ExecutionEvent event) {
    IStructuredSelection structuredSelection = getSelection();
    Object selectedObject = structuredSelection.getFirstElement();
    if (selectedObject instanceof TestResultNode) {
        TestResultNode result = (TestResultNode) selectedObject;

        // necessary to get test suite name
        TestResultNode parent = result;
        while (parent.getParent() != null) {
            parent = parent.getParent();
        }

        // get the date of test from time stamp
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
        String date = format.format(result.getTimeStamp());

        FileDialog saveDialog = new FileDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                SWT.SAVE);
        String fileName = "ErrorInTest_" + parent.getName() + "_" //$NON-NLS-1$ //$NON-NLS-2$
                + result.getNode().getName();
        // eliminate whitespaces and characters which are illegal in a file name
        fileName = fileName.replaceAll("[\\s\\?\\\\/:|<>\\*\"]", ""); //$NON-NLS-1$ //$NON-NLS-2$

        String fileEnding = "_" + date + ".png"; //$NON-NLS-1$ //$NON-NLS-2$
        fileName = StringUtils.substring(fileName, 0,
                MAX_FILE_NAME_LENGTH - fileEnding.length() - saveDialog.getFilterPath().length());
        fileName = fileName + fileEnding;
        saveDialog.setFileName(fileName);
        saveDialog.setFilterExtensions(new String[] { "*.png" }); //$NON-NLS-1$
        saveDialog.setOverwrite(true);
        String path = saveDialog.open();

        if (path != null) {
            if (result.getScreenshot() != null) {
                try {
                    File file = new File(path);
                    OutputStream out = new FileOutputStream(file);
                    out.write(result.getScreenshot());
                    out.flush();
                    out.close();
                } catch (FileNotFoundException e) {
                    ErrorHandlingUtil.createMessageDialog(MessageIDs.E_FILE_NO_PERMISSION);
                } catch (IOException e) {
                    ErrorHandlingUtil.createMessageDialog(MessageIDs.E_IO_EXCEPTION);
                }
            }
        }
    }
    return null;
}