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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:org.ebayopensource.turmeric.eclipse.config.core.SOADomainAccessor.java

private static void init(String buildSystemID, String organization)
        throws SOAConfigAreaCorruptedException, IOException {
    final Properties props = SOAGlobalConfigAccessor.getOrganizationConfigurations(buildSystemID, organization);
    if (props != null) {
        final String key = getKey(buildSystemID, organization);
        final String domainNames = StringUtils.trim(props.getProperty(PROP_KEY_DOMAINS));
        final String isDomainRequired = StringUtils.trim(props.getProperty(PROP_KEY_DOMAIN_REQUIRED));
        IS_DOMAIN_REQUIRED.put(key, Boolean.valueOf(isDomainRequired));
        Map<String, List<String>> data = DOMAINS.get(key);
        if (data == null) {
            data = new LinkedHashMap<String, List<String>>(2);
        }//from   w w  w  .  ja  v  a2s.  c o m
        if (data.containsKey(buildSystemID) == false) {
            for (String val : StringUtils.split(domainNames, ",")) {
                String domain = StringUtils.substringBefore(val, "=").trim();
                String classifiers = StringUtils.substringAfter(val, "=").trim();
                List<String> classifierList = data.get(domain);
                if (classifierList == null)
                    classifierList = new ArrayList<String>(5);
                for (String classifier : StringUtils.split(classifiers, ":")) {
                    final String clas = classifier.trim();
                    if (classifierList.contains(clas) == false)
                        classifierList.add(clas);
                }

                data.put(domain, classifierList);
            }
        }
        DOMAINS.put(key, data);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.config.core.SOADomainAccessor.java

/**
 * Parses the string to domain map./* w w  w  .  j a  v  a2s  .c  o m*/
 *
 * @param value the value
 * @return the map
 */
public static Map<String, List<String>> parseStringToDomainMap(String value) {
    final Map<String, List<String>> data = new LinkedHashMap<String, List<String>>();
    for (String val : StringUtils.split(value, ",")) {
        String domain = StringUtils.substringBefore(val, "=").trim();
        String classifiers = StringUtils.substringAfter(val, "=").trim();
        List<String> classifierList = data.get(domain);
        if (classifierList == null)
            classifierList = new ArrayList<String>(5);
        for (String classifier : StringUtils.split(classifiers, ":")) {
            final String clas = classifier.trim();
            if (classifierList.contains(clas) == false)
                classifierList.add(clas);
        }

        data.put(domain, classifierList);
    }
    return data;
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAServiceUtil.java

/**
 * Get the major version of the given service version.
 * @param version/*ww  w .j a va  2s .c o  m*/
 * @return
 */
public static String getServiceMajorVersion(String version) {
    if (StringUtils.isBlank(version))
        return "1";
    return StringUtils.substringBefore(version, ".");
}

From source file:org.ebayopensource.turmeric.eclipse.services.ui.wizards.pages.ConsumeNewServiceWizardPage.java

/**
 * {@inheritDoc}//from  w  ww .  ja  va  2s. c o  m
 */
@Override
public void createControl(Composite parent) {
    try {
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
        composite.setLayout(new GridLayout(4, false));

        if (project != null) {
            final IFile propsFile = SOAConsumerUtil.getConsumerPropertiesFile(project);
            //the client name is default to be the project name
            String clientName = TurmericServiceUtils.isSOAImplProject(project) ? "" : this.project.getName();
            String consumerId = "";
            if (propsFile.exists() == true) {
                final Properties props = SOAConsumerUtil.loadConsumerProperties(project);
                clientName = StringUtils
                        .trim(props.getProperty(SOAProjectConstants.PROPS_KEY_CLIENT_NAME, clientName));
                consumerId = StringUtils.trim(props.getProperty(SOAProjectConstants.PROPS_KEY_CONSUMER_ID, ""));
                scppVersion = StringUtils
                        .trim(props.getProperty(SOAProjectConstants.PROPS_KEY_SCPP_VERSION, ""));
                isZeroConfig = Boolean.valueOf(StringUtils.trim(props
                        .getProperty(SOAProjectConstants.PROPS_SUPPORT_ZERO_CONFIG, Boolean.FALSE.toString())));
                if (isZeroConfig) {
                    setDescription(SIMPLE_TITLE);
                } else {
                    setDescription(ADV_TITLE);
                }
            } else {
                logger.warning("The underlying projects do not have service_consumer_project.properties file->",
                        project.getName());
            }

            final Text clientNameText = createClientNameText(composite, clientName);
            if (TurmericServiceUtils.isSOAImplProject(project)
                    && TurmericServiceUtils.isSOAConsumerProject(project) == false
                    && StringUtils.isEmpty(clientName)) {
                clientNameText.setText(
                        StringUtils.substringBefore(project.getName(), SOAProjectConstants.IMPL_PROJECT_SUFFIX)
                                + SOAProjectConstants.CLIENT_PROJECT_SUFFIX);
            } else {
                clientNameText.setText(clientName);
            }
            createConsumerIDText(composite, consumerId);
            createServiceList(composite);
        }
        setControl(composite);
        dialogChanged();
    } catch (Exception e) {
        SOALogger.getLogger().error(e);
        UIUtil.showErrorDialog(e);
    }
    UIUtil.getHelpSystem().setHelp(parent, getHelpContextID());
}

From source file:org.ebayopensource.turmeric.eclipse.services.ui.wizards.pages.ConsumeServiceFromExistingWSDLWizardPage.java

/**
 * Instantiates a new consume service from existing wsdl wizard page.
 *
 * @param selection the selection//  w  w  w . j  a v  a 2  s . c o m
 * @throws Exception the exception
 */
public ConsumeServiceFromExistingWSDLWizardPage(final IStructuredSelection selection) throws Exception {
    super("ConsumeServiceFromWSDLWizardPage", "Consume Service From Existing WSDL Wizard", ADV_MODE_TITLE);
    IProject project = (IProject) selection.getFirstElement();
    soaPrj = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem().getAssetRegistry()
            .getSOAProject(project);
    String consumerNatureId = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem()
            .getProjectNatureId(SupportedProjectType.CONSUMER);
    if ((soaPrj instanceof SOAImplProject == true) && (project.hasNature(consumerNatureId) == false)) {
        // if this project is just a impl project
        SOAImplMetadata metadata = ((SOAImplProject) soaPrj).getMetadata();
        consumerIDStr = "";
        clientNameStr = StringUtils.substringBefore(project.getName(), SOAProjectConstants.IMPL_PROJECT_SUFFIX)
                + SOAProjectConstants.CLIENT_PROJECT_SUFFIX;
        environments.add(SOAProjectConstants.DEFAULT_CLIENT_CONFIG_ENVIRONMENT);
        clientPropEditable = true;
        serviceLayerStr = metadata.getIntfMetadata().getServiceLayer();
    } else if ((soaPrj instanceof SOAConsumerProject) && (project.hasNature(consumerNatureId) == true)) {
        SOAConsumerMetadata metadata = ((SOAConsumerProject) soaPrj).getMetadata();
        consumerIDStr = metadata.getConsumerId();
        clientNameStr = metadata.getClientName();
        try {
            environments = SOAConsumerUtil.getClientEnvironmentList(soaPrj.getProject(), null);
        } catch (CoreException e) {
            logger.error("Unable to load environments.", e);
            UIUtil.showErrorDialog("Unable to load environments.", e);
        }
        clientPropEditable = false;
    }
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPCopyUtil.java

private static void updatePrefixes(Element element, Map<String, String> prefixMap) {
    NamedNodeMap namedNodeMap = element.getAttributes();
    for (int i = 0; i < namedNodeMap.getLength(); i++) {
        String attrValue = namedNodeMap.item(i).getNodeValue();
        String attrName = namedNodeMap.item(i).getNodeName();
        for (String str : prefixMap.keySet()) {
            if (StringUtils.isNotEmpty(attrValue) && attrValue.trim().startsWith(str + ":")) {
                String trimmedAttrValue = attrValue.trim();
                String newAttrValue = trimmedAttrValue;
                if (trimmedAttrValue.startsWith(str + ":xs:")) {
                    newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, str + ":xs:", "xs:");
                } else if (StringUtils.countMatches(trimmedAttrValue, ":") == 2) {
                    //already contains a prefix
                    trimmedAttrValue = StringUtils.substringAfter(trimmedAttrValue, ":");
                    String oldPrefix = StringUtils.substringBefore(trimmedAttrValue, ":");
                    newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, oldPrefix + ":",
                            prefixMap.get(oldPrefix) + ":");
                } else {
                    newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, str + ":",
                            prefixMap.get(str) + ":");
                }/*from w  ww  .j  a  v a 2s .  c o m*/
                element.getAttributeNode(attrName).setValue(newAttrValue);
            }
        }
    }
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element)
            updatePrefixes((Element) child, prefixMap);
    }
}

From source file:org.eclipse.leshan.server.demo.servlet.ClientServlet.java

private LwM2mNode extractLwM2mNode(String target, HttpServletRequest req) throws IOException {
    String contentType = StringUtils.substringBefore(req.getContentType(), ";");
    if ("application/json".equals(contentType)) {
        String content = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding());
        LwM2mNode node;/*from  w ww  .  j ava2 s .  co m*/
        try {
            node = gson.fromJson(content, LwM2mNode.class);
        } catch (JsonSyntaxException e) {
            throw new InvalidRequestException("unable to parse json to tlv:" + e.getMessage(), e);
        }
        return node;
    } else if ("text/plain".equals(contentType)) {
        String content = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding());
        int rscId = Integer.valueOf(target.substring(target.lastIndexOf("/") + 1));
        return LwM2mSingleResource.newStringResource(rscId, content);
    }
    throw new InvalidRequestException("content type " + req.getContentType() + " not supported");
}

From source file:org.eclipse.mylyn.gerrit.tests.support.GerritProject.java

public String getGitUsername(AuthenticationCredentials credentials) {
    String shortUsername = StringUtils.substringBefore(credentials.getUserName(), "@"); //$NON-NLS-1$
    return shortUsername;
}

From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java

/**
 * Parses a HH:MM string and returns the minutes.
 *//*  w w  w.j  ava  2s  .co m*/
private static int getMinutesFromTime(String configTime) {
    String time = StringUtils.trimToNull(configTime);
    if (time != null) {
        try {
            if (!HHMM_PATTERN.matcher(time).matches()) {
                throw new NumberFormatException();
            } else {
                int hour = Integer.parseInt(StringUtils.substringBefore(time, ":"));
                int minutes = Integer.parseInt(StringUtils.substringAfter(time, ":"));
                return (hour * 60) + minutes;
            }
        } catch (Exception ex) {
            LOGGER.warn(
                    "Can not parse astro channel configuration '{}' to hour and minutes, use pattern hh:mm, ignoring!",
                    time);
        }
    }
    return 0;
}

From source file:org.eclipse.smarthome.binding.digitalstrom.internal.lib.serverconnection.impl.HttpTransportImpl.java

private boolean checkNeededSessionToken(String request) {
    String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/");
    return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
}