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:net.groupbuy.controller.admin.StatisticsController.java

/**
 * /*ww w .ja  v  a 2s.co m*/
 */
@RequestMapping(value = "/setting", method = RequestMethod.POST)
public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled,
        RedirectAttributes redirectAttributes) {
    Setting setting = SettingUtils.get();
    if (isEnabled) {
        if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) {
            try {
                String createAccountUrl = "http://intf.cnzz.com/user/companion/groupbuy.php?domain="
                        + setting.getSiteUrl() + "&key="
                        + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H");
                URLConnection urlConnection = new URL(createAccountUrl).openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.contains("@")) {
                        break;
                    }
                }
                if (line != null) {
                    setting.setCnzzSiteId(StringUtils.substringBefore(line, "@"));
                    setting.setCnzzPassword(StringUtils.substringAfter(line, "@"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    setting.setIsCnzzEnabled(isEnabled);
    SettingUtils.set(setting);
    cacheService.clear();
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:setting.jhtml";
}

From source file:com.dp2345.controller.admin.StatisticsController.java

/**
 * //from w  ww  .j a v a 2  s  .  com
 */
@RequestMapping(value = "/setting", method = RequestMethod.POST)
public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled,
        RedirectAttributes redirectAttributes) {
    Setting setting = SettingUtils.get();
    if (isEnabled) {
        if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) {
            try {
                String createAccountUrl = "http://intf.cnzz.com/user/companion/dp2345.php?domain="
                        + setting.getSiteUrl() + "&key="
                        + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H");
                URLConnection urlConnection = new URL(createAccountUrl).openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.contains("@")) {
                        break;
                    }
                }
                if (line != null) {
                    setting.setCnzzSiteId(StringUtils.substringBefore(line, "@"));
                    setting.setCnzzPassword(StringUtils.substringAfter(line, "@"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    setting.setIsCnzzEnabled(isEnabled);
    SettingUtils.set(setting);
    cacheService.clear();
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:setting.jhtml";
}

From source file:cn.com.p2p.framework.util.Struts2Utils.java

/**
 * ./*from w  ww  .  ja  va2  s  .c  om*/
 * 
 * eg. <br/>
 * render("text/plain", "hello", "encoding:GBK"); <br/>
 * render("text/plain", "hello", "no-cache:false"); <br/>
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 * 
 * @param headers
 *            ??header??"encoding:""no-cache:",UTF-8true.
 */
public static void render(final String contentType, final String content, final String... headers) {
    try {
        // ?headers?
        String encoding = ENCODING_DEFAULT;
        boolean noCache = NOCACHE_DEFAULT;
        for (String header : headers) {
            String headerName = StringUtils.substringBefore(header, ":");
            String headerValue = StringUtils.substringAfter(header, ":");

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

        HttpServletResponse response = ServletActionContext.getResponse();

        // headers?
        String fullContentType = contentType + ";charset=" + encoding;
        response.setContentType(fullContentType);
        if (noCache) {
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
        }

        response.getWriter().write(content);
        response.getWriter().flush();

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:com.widen.valet.importer.ImportBulkZones.java

private void processZoneFile(File f) throws IOException {
    if (!f.getName().endsWith(".dns")) {
        log.warn("Skipping file {}", f.getAbsolutePath());
        return;//from   ww  w . j a v a2 s  .  c  o m
    }

    String zoneName = StringUtils.substringBefore(f.getName(), "dns");

    Zone zone = findZone(zoneName);

    if (zone != null) {
        log.info("zone {} = {}", zoneName, zone);
    } else {
        log.info("creating new zone for {}", zoneName);

        ZoneChangeStatus changeStatus = driver.createZone(zoneName, "Create zone " + zoneName);

        driver.waitForSync(changeStatus);

        zone = driver.zoneDetails(changeStatus.zoneId);
    }

    new ImportZone(zoneProperties(f.getAbsolutePath(), zone.zoneId)).run();
}

From source file:jp.primecloud.auto.ui.util.CommonUtils.java

public static Icons getImageIcon(ImageDto imageDto) {
    String iconName = StringUtils.substringBefore(imageDto.getImage().getImageName(), "_");
    Icons rtIcon = Icons.NONE;//w w w.  j  a va 2  s  . co  m
    if (PCCConstant.IMAGE_NAME_APPLICATION.equals(iconName)) {
        rtIcon = Icons.PAAS;
    } else if (PCCConstant.IMAGE_NAME_PRJSERVER.equals(iconName)) {
        rtIcon = Icons.PRJSERVER;
    } else if (PCCConstant.IMAGE_NAME_WINDOWS.equals(iconName)) {
        rtIcon = Icons.WINDOWS_APP;
    } else if ("cloudstack".equals(iconName)) {
        rtIcon = Icons.CLOUD_STACK;
    } else {
        rtIcon = Icons.fromName(iconName);
    }
    return rtIcon;
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

private Attr createAttribute(Node parentNode, Document domDocument) {
    // Ensure xsi prefix is declared
    if (attributeName.indexOf(':') > 0) {
        String attributePrefix = StringUtils.substringBefore(attributeName, ":"); //$NON-NLS-1$
        String namespaceURI = domDocument.lookupNamespaceURI(attributePrefix);
        if (namespaceURI == null) {
            if ("xsi".equals(attributePrefix)) { //$NON-NLS-1$
                domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
                        "xmlns:xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); //$NON-NLS-1$
            } else if ("tmdm".equals(attributePrefix)) { //$NON-NLS-1$
                domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
                        "xmlns:tmdm", SkipAttributeDocumentBuilder.TALEND_NAMESPACE); //$NON-NLS-1$
            } else {
                throw new IllegalArgumentException("Unrecognized attribute prefix: '" + attributePrefix + "'."); //$NON-NLS-1$ //$NON-NLS-2$
            }//from w  w w .  j  a  v  a2  s  .com
        }
    }
    QName qName = getQName(domDocument);
    Attr newAttribute = domDocument.createAttributeNS(qName.getNamespaceURI(), qName.getLocalPart());
    String prefix = qName.getPrefix();
    newAttribute.setPrefix(prefix);
    parentNode.getAttributes().setNamedItemNS(newAttribute);
    return newAttribute;
}

From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java

/**
 * Split components of a line with an optional starting string and a component separator
 * and returns the first token found or <code>null</code> if the string without starting substring
 * is empty or <code>null</code>.<br />
 * This method does not validate the starting string presence, it just strips it if present.
 *
 * @param line/*  w  w w .  jav a  2 s.  com*/
 * @param starting
 * @param separator
 * @return the first token found or <code>null</code>
 */
public static String getTokenFirst(String line, final String starting, final String separator) {
    String result = null;
    if (StringUtils.isNotBlank(line)) {
        String lineNoPrefix = removePrefix(line, starting);

        result = StringUtils.substringBefore(lineNoPrefix, separator);
        if (StringUtils.isBlank(result)) {
            return null;
        }
    }
    return result;
}

From source file:com.hangum.tadpole.engine.query.dao.mysql.SessionListDAO.java

public String getSID() {
    if (StringUtils.contains(getId(), ",")) {
        return StringUtils.substringBefore(getId(), ",");
    } else {//from  w w w.ja  v  a2  s .  co m
        return getId();
    }
}

From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionNamespaceContextHelpers.java

/**
 * This method returns all prefixes that are in an xpath expression
 * // ww w  . java 2s. c om
 * @param xpath
 * @return
 */
public static Set<String> returnPrefixes(String xpath) {
    //Return all the strings by splitting on the regular expression that will find '/' and '//'
    //TODO: improve this regular expression, it will return empty strings in some use cases.
    String[] xpathValue = xpath.split("/|//");

    //Use a hashset for prefixes so we don't repeat namespaces
    Set<String> prefixes = new HashSet<String>();

    for (int i = 0; i < xpathValue.length; i++) {

        //Check to see if string is empty, regular expression will return empty strings in some cases
        if (StringUtils.isNotEmpty(xpathValue[i])) {
            String prefixAndElement = xpathValue[i];

            //If we have an '@', we need to get that prefix as well
            if (prefixAndElement.contains("@")) {
                String[] prefixesFromAttributes = StringUtils.substringsBetween(prefixAndElement, "@", ":");

                for (int j = 0; j < prefixesFromAttributes.length; j++) {
                    prefixes.add(prefixesFromAttributes[j]);
                }

            } else {
                //If there are no attributes, just get the namespace prefix which will appear before the ':'
                String prefix = StringUtils.substringBefore(prefixAndElement, ":");
                prefixes.add(prefix);
            }
        }
    }

    return prefixes;

}

From source file:de.griffel.confluence.plugins.plantuml.preprocess.ShortcutLinkUrlRenderer.java

private String getShortcutValue(final String pageTitle) {
    return StringUtils.substringBefore(pageTitle, ConfluenceLink.SHORTCUT_LINK_SEPARATOR);
}