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:hudson.plugins.sonar.client.SQProjectResolver.java

static String extractServerUrl(String url) {
    return StringUtils.substringBefore(url, "/dashboard");
}

From source file:info.magnolia.init.DefaultMagnoliaInitPaths.java

/**
 * Figures out the local host name, makes sure it's lowercase, and use its unqualified name if the {@value #MAGNOLIA_UNQUALIFIED_SERVER_NAME} init parameter is set to true.
 *///  w w w  .  j  a  va 2  s. c o m
protected String determineServerName(ServletContext context) {
    final boolean unqualifiedServerName = BooleanUtils
            .toBoolean(context.getInitParameter(MAGNOLIA_UNQUALIFIED_SERVER_NAME));
    final String retroCompatMethodCall = magnoliaServletContextListener.initServername(unqualifiedServerName);
    if (retroCompatMethodCall != null) {
        DeprecationUtil.isDeprecated(
                "You should update your code and override determineServerName(ServletContext) instead of initServername(String)");
        return retroCompatMethodCall;
    }

    try {
        String serverName = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName());

        if (unqualifiedServerName && StringUtils.contains(serverName, ".")) {
            serverName = StringUtils.substringBefore(serverName, ".");
        }
        return serverName;
    } catch (UnknownHostException e) {
        log.error(e.getMessage());
        return null;
    }
}

From source file:hydrograph.ui.expression.editor.pages.AddExternalJarPage.java

public boolean createPropertyFileForSavingData() {
    IProject iProject = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject();
    IFolder iFolder = iProject.getFolder(PathConstant.PROJECT_RESOURCES_FOLDER);
    Properties properties = new Properties();
    FileOutputStream file = null;
    boolean isFileCreated = false;
    try {//from  w  w w  . ja v  a2s  .c  o  m
        if (!iFolder.exists()) {
            iFolder.create(true, true, new NullProgressMonitor());
        }
        for (String items : categoriesDialogTargetComposite.getTargetList().getItems()) {
            String jarFileName = StringUtils.trim(StringUtils.substringAfter(items, Constants.DASH));
            String packageName = StringUtils.trim(StringUtils.substringBefore(items, Constants.DASH));
            properties.setProperty(packageName, jarFileName);
        }

        file = new FileOutputStream(iFolder.getLocation().toString() + File.separator
                + PathConstant.EXPRESSION_EDITOR_EXTERNAL_JARS_PROPERTIES_FILES);
        properties.store(file, "");
        ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE,
                new NullProgressMonitor());
        isFileCreated = true;
    } catch (IOException | CoreException exception) {
        LOGGER.error("Exception occurred while saving jar file path at projects setting folder", exception);
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (IOException e) {
                LOGGER.warn("IOException occurred while closing output-stream of file", e);
            }
    }
    return isFileCreated;
}

From source file:com.amalto.core.server.MetadataRepositoryAdminImpl.java

public Set<Expression> getIndexedExpressions(String dataModelName) {
    if (XSystemObjects.DM_UPDATEREPORT.getName().equals(dataModelName)) { // Indexed expressions for UpdateReport
        MetadataRepository repository = get(dataModelName);
        // Index Concept field (used in JournalStatistics for the top N types)
        ComplexTypeMetadata updateType = repository.getComplexType("Update"); //$NON-NLS-1$
        return Collections
                .singleton(from(updateType).where(isNull(updateType.getField("Concept"))).getExpression()); //$NON-NLS-1$
    }/*from w  ww .j a  va  2 s.com*/
    synchronized (metadataRepository) {
        ViewPOJO view = null;
        try {
            MetadataRepository repository = get(dataModelName);
            View viewCtrlLocal = Util.getViewCtrlLocal();
            Set<Expression> indexedExpressions = new HashSet<Expression>();
            for (Object viewAsObject : viewCtrlLocal.getAllViews(".*")) { //$NON-NLS-1$
                UserQueryBuilder qb = null;
                view = (ViewPOJO) viewAsObject;
                ArrayList<String> searchableElements = view.getSearchableBusinessElements().getList();
                for (String searchableElement : searchableElements) {
                    String typeName = StringUtils.substringBefore(searchableElement, "/"); //$NON-NLS-1$
                    ComplexTypeMetadata userType = repository.getComplexType(typeName);
                    if (userType != null) {
                        if (qb == null) {
                            qb = from(userType);
                        } else {
                            qb.and(userType);
                        }
                        String fieldName = StringUtils.substringAfter(searchableElement, "/"); //$NON-NLS-1$
                        if (userType.hasField(fieldName)) {
                            qb.where(UserQueryBuilder.isEmpty(userType.getField(fieldName)));
                        }
                    } else {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("View '" + view.getPK().getUniqueId()
                                    + "' does not apply to data model '" + dataModelName + "'.");
                        }
                        break; // View does not apply to model
                    }
                }
                if (qb != null) {
                    for (IWhereItem condition : view.getWhereConditions().getList()) {
                        qb.where(UserQueryHelper.buildCondition(qb, condition, repository));
                    }
                    indexedExpressions.add(qb.getExpression());
                }
            }
            return indexedExpressions;
        } catch (Exception e) {
            if (view != null) {
                throw new RuntimeException("Can not use view '" + view.getPK().getUniqueId()
                        + "' with data model '" + dataModelName + "': " + e.getMessage(), e);
            } else {
                throw new RuntimeException("Could not get indexed fields.", e);
            }
        }
    }
}

From source file:com.ctc.storefront.security.evaluator.impl.RequireHardLoginEvaluator.java

protected boolean checkForAnonymousCheckout() {
    if (Boolean.TRUE.equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT))) {
        if (getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID) == null) {
            getSessionService().setAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID,
                    StringUtils.substringBefore(getCartService().getSessionCart().getUser().getUid(), "|"));
        }/*  w  ww.  j  av a  2  s. co  m*/
        return true;
    }

    return false;
}

From source file:com.opengamma.component.ComponentConfigLoader.java

private void parseReplacement(String line, ConcurrentMap<String, String> properties) {
    String key = StringUtils.substringBefore(line, "=").trim();
    String value = StringUtils.substringAfter(line, "=").trim();
    // do not overwrite properties that were passed in
    properties.putIfAbsent(key, value);// w  w  w .j  a va2 s  .com
}

From source file:eionet.rod.scheduled.AbstractScheduledJob.java

/**
 * Parses job params value from props file and adds to job data map.
 *
 * @param clazz   class which is used for building the job
 * @param jobs    list of jobs/*  ww w .  j ava2  s.c om*/
 * @param jobData full String for several jobs in format key1=valueA;key2=valueB|key1=valueC;key2=valueD|...|key1=valueN
 */
private void parseJobData(Class clazz, List<JobDetail> jobs, String jobData) {
    StringTokenizer differentJobs = new StringTokenizer(jobData, "|");
    while (differentJobs.hasMoreTokens()) {
        String jobParams = differentJobs.nextToken();
        JobDetail jobDetails = newJob(clazz)
                .withIdentity(clazz.getSimpleName() + ":" + jobParams, clazz.getName()).build();
        StringTokenizer args = new StringTokenizer(jobParams, ";");
        while (args.hasMoreTokens()) {
            String arg = args.nextToken();
            String key = StringUtils.substringBefore(arg, "=");
            String value = StringUtils.substringAfter(arg, "=");
            jobDetails.getJobDataMap().put(key, value);
        }
        jobs.add(jobDetails);
    }

}

From source file:eu.annocultor.analyzers.SolrPropertyHitsAnalyzer.java

static String extractQuery(String line) {
    line = StringUtils.substringAfter(line, ", query=");
    String query = StringUtils.substringBefore(line, ", ");
    if (StringUtils.length(query) < 3) {
        // try referal
        query = StringUtils.substringAfter(line, ", referer=");
        query = StringUtils.substringAfter(query, "&q=");
        if (!StringUtils.isBlank(query)) {
            query = StringUtils.substringBefore(query, "&");
            query = StringUtils.replace(query, "+", " ");
            if (isLongEnoughToCount(query)) {
                return query;
            } else {
                return "";
            }// w ww  .  ja v a2  s. c  o m
        }
    }
    return query;
}

From source file:edu.mayo.cts2.framework.core.xml.DelegatingMarshaller.java

/**
 * Instantiates a new delgating marshaller.
 *
 * @throws Exception the exception// w  ww. ja  va 2 s.co  m
 */
public DelegatingMarshaller(boolean validate, ModelXmlPropertiesHandler modelXmlPropertiesHandler) {
    super();
    this.modelXmlPropertiesHandler = modelXmlPropertiesHandler;
    this.castorBuilderProperties = this.modelXmlPropertiesHandler.getCastorBuilderProperties();
    this.namespaceLocationProperties = this.modelXmlPropertiesHandler.getNamespaceLocationProperties();
    this.namespaceMappingProperties = this.modelXmlPropertiesHandler.getNamespaceMappingProperties();

    this.populateNamespaceMaps(this.namespaceMappingProperties, this.namespaceLocationProperties);

    String proxyInterfaces = this.createMapFromProperties(this.modelXmlPropertiesHandler.getCastorProperties())
            .get(PROXY_INTERFACES_PROP);

    this.marshallSuperClasses = new HashSet<String>(Arrays.asList(StringUtils.split(proxyInterfaces, ',')));

    String nsMappings = (String) this.castorBuilderProperties.get(NS_PROP);

    String[] nsAndPackage = StringUtils.split(nsMappings, ",");

    List<String> allPackages = new ArrayList<String>();

    Map<String, String> namespacePackageMapping = new HashMap<String, String>();

    for (String entry : nsAndPackage) {
        String ns = StringUtils.substringBefore(entry, "=");
        String pkg = StringUtils.substringAfter(entry, "=");

        packageToMarshallerMap.put(pkg, createNewMarshaller(ns, validate));
        allPackages.add(pkg);

        namespacePackageMapping.put(ns, pkg);
    }

    this.defaultMarshaller = new PatchedCastorMarshaller();
    this.defaultMarshaller.setNamespaceMappings(this.namespaceMap);
    this.defaultMarshaller.setTargetPackages(Iterables.toArray(allPackages, String.class));
    this.defaultMarshaller.setNamespaceToPackageMapping(namespacePackageMapping);
    this.defaultMarshaller.setValidating(validate);

    try {
        this.defaultMarshaller.afterPropertiesSet();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.bible.service.common.CommonUtils.java

public static String limitTextLength(String text, int maxLength, boolean singleLine) {
    if (text != null) {
        int origLength = text.length();

        if (singleLine) {
            // get first line but limit length in case there are no line breaks
            text = StringUtils.substringBefore(text, "\n");
        }//from w ww  . j  ava2 s  .co  m

        if (text.length() > maxLength) {
            // break on a space rather than mid-word
            int cutPoint = text.indexOf(" ", maxLength);
            if (cutPoint >= maxLength) {
                text = text.substring(0, cutPoint + 1);
            }
        }

        if (text.length() != origLength) {
            text += ELLIPSIS;
        }
    }
    return text;
}