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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:com.google.gdt.eclipse.designer.core.model.widgets.CoordinatesTest.java

/**
 * For string like <code>"left 10px, top 20 px"</code> returns
 * //from w w  w .  jav a2s. co m
 * <pre>
  *       border-left 10px;
  *       border-top 20px;
  * </pre>
 */
private static String getSidesStyle(String stylesString, String styleName) {
    String styles = "";
    String[] stylesParts = StringUtils.split(stylesString, ',');
    for (String stylePart : stylesParts) {
        stylePart = stylePart.trim();
        styles += "\t";
        if (stylePart.startsWith("top") || stylePart.startsWith("right") || stylePart.startsWith("bottom")
                || stylePart.startsWith("left")) {
            String side = StringUtils.substringBefore(stylePart, " ");
            String withoutSide = StringUtils.substringAfter(stylePart, " ");
            styles += styleName + "-" + side + ": " + withoutSide;
        } else {
            styles += styleName + ": " + stylePart;
        }
        styles += ";\n";
    }
    styles = StringUtils.chomp(styles, "\n");
    return styles;
}

From source file:hydrograph.ui.graph.execution.tracking.utils.TrackingDisplayUtils.java

/**
 * This function will be return process ID which running on defined port.
 * /*from w  w  w.ja  va2 s . c om*/
 * @return the service port pid
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public String getServicePortPID(Properties properties) throws IOException {
    int portNumber = Integer.parseInt(properties.getProperty(EXECUTION_TRACKING_PORT));
    if (OSValidator.isWindows()) {
        ProcessBuilder builder = new ProcessBuilder(
                new String[] { "cmd", "/c", "netstat -a -o -n |findstr :" + portNumber });
        Process process = builder.start();
        InputStream inputStream = process.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String str = bufferedReader.readLine();
        str = StringUtils.substringAfter(str, "LISTENING");
        str = StringUtils.trim(str);
        return str;
    }
    return "";
}

From source file:hydrograph.ui.expression.editor.composites.CategoriesDialogTargetComposite.java

public void loadPackagesFromPropertyFileSettingFolder() {
    Properties properties = new Properties();
    IFolder folder = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()
            .getFolder(PathConstant.PROJECT_RESOURCES_FOLDER);
    IFile file = folder.getFile(PathConstant.EXPRESSION_EDITOR_EXTERNAL_JARS_PROPERTIES_FILES);
    try {/* w w  w . j a v a2 s . c om*/
        LOGGER.debug("Loading property file");
        targetList.removeAll();
        if (file.getLocation().toFile().exists()) {
            FileInputStream inStream = new FileInputStream(file.getLocation().toString());
            properties.load(inStream);
            for (Object key : properties.keySet()) {
                String jarFileName = StringUtils.trim(StringUtils.substringAfter((String) key, Constants.DASH));
                if (BuildExpressionEditorDataSturcture.INSTANCE.getIPackageFragment(jarFileName) != null) {
                    targetList.add((String) key + SWT.SPACE + Constants.DASH + SWT.SPACE
                            + properties.getProperty((String) key));
                }
            }
        }
    } catch (IOException | RuntimeException exception) {
        LOGGER.error("Exception occurred while loading jar files from projects setting folder", exception);
    }

}

From source file:de.faustedition.maven.OddSchemaDeployMojo.java

/**
 * <p>/*www .ja va  2  s.c om*/
 * Get the <code>ProxyInfo</code> of the proxy associated with the
 * <code>host</code> and the <code>protocol</code> of the given
 * <code>repository</code>.
 * </p>
 * <p>
 * Extract from <a href=
 * "http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> J2SE
 * Doc : Networking Properties - nonProxyHosts</a> : "The value can be a
 * list of hosts, each separated by a |, and in addition a wildcard
 * character (*) can be used for matching"
 * </p>
 * <p>
 * Defensively support for comma (",") and semi colon (";") in addition
 * to pipe ("|") as separator.
 * </p>
 * 
 * @param repository
 *                the Repository to extract the ProxyInfo from.
 * @param wagonManager
 *                the WagonManager used to connect to the Repository.
 * @return a ProxyInfo object instantiated or <code>null</code> if no
 *         matching proxy is found
 */
public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|");
    for (int i = 0; i < nonProxyHosts.length; i++) {
        String nonProxyHost = nonProxyHosts[i];
        if (StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or
            // middle of the nonProxyHost
            String nonProxyHostPrefix = StringUtils.substringBefore(nonProxyHost, "*");
            String nonProxyHostSuffix = StringUtils.substringAfter(nonProxyHost, "*");
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix)
                    && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}

From source file:com.dushyant.flume.sink.aws.sqs.SQSSink.java

/**
 * The method for resolving the configured property value.
 * <p>/*w w  w .  j a  v  a 2 s  .c  om*/
 * For example, the configuration allows properties to be specified in the {@code env.propertyName} format. This
 * method resolves that configuration property value using the environment variable named {@code propertyName}. In
 * other cases, the method returns the given property as is.
 *
 * @param property The configured property value to be resolved
 *
 * @return The resolved property value
 */
protected String resolve(String property) {
    String resolved = property;
    if (StringUtils.isNotBlank(property) && property.startsWith("env.")) {
        String envVariableName = StringUtils.substringAfter(property, "env.");
        resolved = System.getenv(envVariableName);
    }
    return resolved;
}

From source file:eu.europeana.uim.plugin.solr.service.SolrWorkflowPlugin.java

@Override
public boolean process(MetaDataRecord<I> mdr, ExecutionContext<MetaDataRecord<I>, I> context)
        throws IngestionPluginFailedException, CorruptedDatasetException {
    mdr.deleteValues(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD);

    String overrideChecks = context.getProperties().getProperty(OVERRIDECHECKS);
    boolean check = false;
    if (StringUtils.isNotEmpty(overrideChecks)) {
        check = Boolean.parseBoolean(overrideChecks);
    }//from ww  w  .  jav  a  2 s .  c om
    if (StringUtils.isNotEmpty(context.getProperties().getProperty(CLEARCACHE))) {
        if (Boolean.parseBoolean(context.getProperties().getProperty(CLEARCACHE))) {
            OsgiExtractor.clearCache();
            VocMemCache.clearCache(solrWorkflowService);
        }
    }
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);
    try {

        Date updateDate = sdf.parse((mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).size() > 0)
                ? mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).get(0)
                : new Date(0).toString());
        Date ingestionDate = new Date(context.getValue(date));

        if (updateDate.after(ingestionDate) || updateDate.toString().equals(ingestionDate.toString())
                || check) {
            if (mdr.getValues(EuropeanaModelRegistry.STATUS).size() == 0
                    || !mdr.getValues(EuropeanaModelRegistry.STATUS).get(0).equals(Status.DELETED)) {
                try {

                    String value = mdr.getValues(EuropeanaModelRegistry.EDMRECORD).get(0);
                    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
                    IMarshallingContext marshallingContext = bfact.createMarshallingContext();
                    marshallingContext.setIndent(2);
                    RDF rdf = (RDF) uctx.unmarshalDocument(new StringReader(value));
                    RDF rdfCopy = clone(rdf);
                    if (rdf.getAgentList() != null) {
                        for (AgentType agent : rdf.getAgentList()) {
                            dereferenceAgent(rdfCopy, agent);
                        }
                    }
                    if (rdf.getConceptList() != null) {
                        for (Concept concept : rdf.getConceptList()) {
                            dereferenceConcept(rdfCopy, concept);
                        }
                    }

                    if (rdf.getPlaceList() != null) {
                        for (PlaceType place : rdf.getPlaceList()) {
                            dereferencePlace(rdfCopy, place);
                        }
                    }

                    for (ProxyType proxy : rdf.getProxyList()) {
                        if (proxy.getEuropeanaProxy() == null
                                || !proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                            if (StringUtils
                                    .isNotEmpty(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                if (Boolean
                                        .parseBoolean(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                    for (Choice choice : proxy.getChoiceList()) {
                                        if (choice.ifSubject()) {
                                            if (StringUtils.startsWith(choice.getSubject().getString(), "sh")
                                                    && StringUtils.isNumeric(StringUtils.substringAfter(
                                                            choice.getSubject().getString(), "sh"))) {
                                                Subject sbj = choice.getSubject();
                                                String subject = "http://data.europeana.eu/concept/loc/"
                                                        + sbj.getString();
                                                ResourceOrLiteralType.Resource rs = new ResourceOrLiteralType.Resource();
                                                rs.setResource(subject);
                                                Subject sbjNrm = new Subject();
                                                sbjNrm.setResource(rs);
                                                sbjNrm.setLang(new ResourceOrLiteralType.Lang());
                                                sbjNrm.setString("");
                                                choice.setSubject(sbjNrm);
                                            }
                                        }
                                    }
                                }
                            }
                            dereferenceProxy(rdfCopy, proxy);
                        }
                    }

                    if (rdf.getTimeSpanList() != null) {
                        for (TimeSpanType timespan : rdf.getTimeSpanList()) {
                            dereferenceTimespan(rdfCopy, timespan);
                        }
                    }
                    if (rdf.getWebResourceList() != null) {
                        for (WebResourceType webresource : rdf.getWebResourceList()) {
                            dereferenceWebResource(rdfCopy, webresource);
                        }
                    }

                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    RDF rdfFinal = cleanRDF(rdfCopy);

                    ProxyType europeanaProxy = new ProxyType();
                    EuropeanaProxy prx = new EuropeanaProxy();
                    prx.setEuropeanaProxy(true);
                    europeanaProxy.setEuropeanaProxy(prx);
                    List<String> years = new ArrayList<String>();
                    for (ProxyType proxy : rdfFinal.getProxyList()) {
                        years.addAll(new EuropeanaDateUtils().createEuropeanaYears(proxy));
                        europeanaProxy.setType(proxy.getType());
                    }
                    List<Year> yearList = new ArrayList<Year>();
                    for (String year : years) {
                        Year yearObj = new Year();
                        Lang lang = new Lang();
                        lang.setLang("def");
                        yearObj.setLang(lang);
                        yearObj.setString(year);
                        yearList.add(yearObj);
                    }
                    europeanaProxy.setYearList(yearList);
                    for (ProxyType proxy : rdfFinal.getProxyList()) {
                        if (proxy != null && proxy.getEuropeanaProxy() != null
                                && proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                            rdfFinal.getProxyList().remove(proxy);
                        }
                    }
                    rdfFinal.getProxyList().add(europeanaProxy);

                    marshallingContext.marshalDocument(rdfFinal, "UTF-8", null, out);
                    String der = out.toString("UTF-8");

                    mdr.addValue(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD, der);
                    return true;

                } catch (JiBXException e) {
                    e.printStackTrace();
                    context.getLoggingEngine().logFailed(Level.SEVERE, this, e,
                            "JiBX unmarshalling has failed with the following error: " + e.getMessage());

                } catch (MalformedURLException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IOException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (SecurityException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    if (logEngine != null) {
                        logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                    }
                    log.log(Level.SEVERE, "Error: " + e.getMessage());

                    e.printStackTrace();
                }

            }
        }
    } catch (Exception e) {
        if (logEngine != null) {
            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
        }
        e.printStackTrace();
    }
    return false;
}

From source file:com.lll.util.ServletUtils.java

/**
 * ?contentTypeheaders./*w  ww.ja va  2  s.  c  om*/
 */
private static void initResponseHeader(HttpServletResponse response, final String contentType,
        final String... headers) {
    //?headers?
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "??header");
        }
    }

    //headers?
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        ServletUtils.setNoCacheHeader(response);
    }

}

From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java

private String prepareCountSql(String orgHql) {
    String fromHql = orgHql;//from w w w. j  ava 2  s  .com
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}

From source file:net.itransformers.toplogyviewer.gui.neo4j.Neo4jLoader.java

public void getVertexes(String NetworkId) throws ParseException {
    String query = "start network=node(" + NetworkId
            + ") match network-->device where device.objectType='Node' return device.name, device.DeviceType,device.DeviceModel,device.ManagementIPAddress,device.YCoordinate,device.XCoordinate,device.siteID,device.ipv6Forwarding,device.BGPLocalASInfo,device.DeviceState";
    String params = "";
    String output = executeCypherQuery(query, params);
    JSONObject json = (JSONObject) new JSONParser().parse(output);
    JSONArray data = (JSONArray) json.get("data");
    JSONArray columns = (JSONArray) json.get("columns");
    Iterator dataIter = data.iterator();

    while (dataIter.hasNext()) {
        JSONArray temp = (JSONArray) dataIter.next();
        Iterator tempIter = temp.iterator();
        Iterator columnsIter = columns.iterator();
        String nodeName = null;/*from   w  w w .  j a  v a 2s  .c  o m*/
        HashMap<String, GraphMLMetadata<String>> nodePropertiesMap = new HashMap<String, GraphMLMetadata<String>>();
        HashMap<String, GraphMLMetadata<String>> graphMLPropertiesMap = new HashMap<String, GraphMLMetadata<String>>();

        while (tempIter.hasNext() & columnsIter.hasNext()) {

            String keyNodeProperty = tempIter.next().toString();
            String columnsValue = StringUtils
                    .replace(StringUtils.substringAfter(columnsIter.next().toString(), "device."), "%20", " ");
            if (columnsValue.equals("name")) {

                nodeName = keyNodeProperty;

            } else {
                if (keyNodeProperty == null) {
                    keyNodeProperty = "";
                } else if (keyNodeProperty.equals("emptyValue")) {
                    keyNodeProperty = "";
                }
                HashMap<String, String> transformerValue = new HashMap<String, String>();
                transformerValue.put(nodeName, keyNodeProperty);
                MapSettableTransformer<String, String> transfrmer = new MapSettableTransformer<String, String>(
                        transformerValue);

                GraphMLMetadata<String> t = new GraphMLMetadata<String>(null, null, transfrmer);
                nodePropertiesMap.put(columnsValue, t);
            }

        }
        if (nodeName != null) {
            entireGraph.addVertex(nodeName);
            vertexMetadatas.put(nodeName, nodePropertiesMap);
            graphMetadatas.put(nodeName, graphMLPropertiesMap);
        }
    }

}

From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java

private String getAuthenticatedUserFromGitRequestUsingOAuthToken(HttpServletRequest req,
        HttpServletResponse rsp) throws IOException {
    final String httpBasicAuth = getHttpBasicAuthenticationHeader(req);
    if (httpBasicAuth == null) {
        return null;
    }/*from www  .  j av a  2  s . c  o  m*/

    if (isInvalidHttpAuthenticationHeader(httpBasicAuth)) {
        rsp.sendError(SC_UNAUTHORIZED);
        return null;
    }

    String oauthToken = StringUtils.substringBefore(httpBasicAuth, ":");
    String oauthKeyword = StringUtils.substringAfter(httpBasicAuth, ":");
    if (Strings.isNullOrEmpty(oauthToken) || Strings.isNullOrEmpty(oauthKeyword)) {
        rsp.sendError(SC_UNAUTHORIZED);
        return null;
    }

    if (!oauthKeyword.equalsIgnoreCase(GITHUB_X_OAUTH_BASIC)) {
        return null;
    }

    boolean loginSuccessful = false;
    String oauthLogin = null;
    try {
        oauthLogin = oauthCache.getLoginByAccessToken(new AccessToken(oauthToken));
        loginSuccessful = !Strings.isNullOrEmpty(oauthLogin);
    } catch (ExecutionException e) {
        log.warn("Login failed for OAuth token " + oauthToken, e);
        loginSuccessful = false;
    }

    if (!loginSuccessful) {
        rsp.sendError(SC_FORBIDDEN);
        return null;
    }

    return oauthLogin;
}