Example usage for org.apache.commons.lang3 StringUtils remove

List of usage examples for org.apache.commons.lang3 StringUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils remove.

Prototype

public static String remove(final String str, final char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

A null source string will return null .

Usage

From source file:org.starnub.starnubserver.connections.player.session.PlayerSession.java

public PlayerSession(Connection connection, String playerName, UUID playerUUID) {
    if (connection instanceof StarNubProxyConnection) {
        CONNECTION_TYPE = ConnectionType.PROXY_IN_GAME;
    } else if (connection instanceof StarNubConnection) {
        CONNECTION_TYPE = ConnectionType.REMOTE;
    } else {/*from   ww w . ja  v a2s.  c  o  m*/
        CONNECTION_TYPE = null;
    }
    CONNECTION = connection;
    InetAddress playerIP = connection.getClientIP();
    StarNub.getConnections().getINTERNAL_IP_WATCHLIST().removeCache(playerIP);
    this.startTimeUtc = DateTime.now();
    this.sessionIpString = StringUtils.remove(playerIP.toString(), "/");
    this.playerCharacter = PlayerCharacter.getPlayerCharacter(playerName, playerUUID);
    this.gameName = playerCharacter.getName();
    this.nickName = playerCharacter.getName();
    this.cleanNickName = playerCharacter.getCleanName();
    CharacterIP characterIP = new CharacterIP(playerCharacter, playerIP, false);
    characterIP.logCharacterIp();
    this.idleTime = 0L;
    try {
        this.op = StarNub.getConnections().getCONNECTED_PLAYERS().getOPERATORS().collectionContains("uuids");
    } catch (Exception e) {
        this.op = false;
    }
    loadPermissions();
    PlayerSessionLog.getInstance().create(this);
    new StarNubEvent("Player_New_Session", playerCharacter);
}

From source file:org.starnub.starnubserver.resources.connections.handlers.ClientConnectHandler.java

/**
 * Recommended: For connections use with StarNub
 * <p>/*from   w  w w .j  ava2 s. c  o m*/
 * Uses: Handles Client Connection Packets for connection attempts. Step 1 of 2 (ConnectionResponsePacket is Part 2).
 *
 * @param eventData Packet representing the packet being routed
 */
@Override
public void onEvent(Packet eventData) {
    ClientConnectPacket clientConnectPacket = (ClientConnectPacket) eventData;
    ChannelHandlerContext clientCTX = clientConnectPacket.getSENDER_CTX();

    StarNubProxyConnection starnubProxyConnection = (StarNubProxyConnection) StarNub.getConnections()
            .getOPEN_CONNECTIONS().remove(clientCTX);

    String playerName = clientConnectPacket.getPlayerName();
    UUID playerUUID = clientConnectPacket.getPlayerUuid();

    PlayerSession playerSession = new PlayerSession(starnubProxyConnection, playerName, playerUUID);

    String header = "^#f5f5f5;-== " + StarNub.getConfiguration().getNestedValue("starnub_info", "server_name")
            + " ==-\n" + "^#f5f5f5;-= Powered by StarNub.org =- \n\n";
    String footer = "\n\n^#f5f5f5;For information visit: ^#990000;" + StringUtils.remove(
            (String) StarNub.getConfiguration().getNestedValue("starnub_info", "server_url"), "http://");

    RejectionCache rejectionCache = null;

    /* Server Restarting Check */
    rejectionCache = restartingCheck(playerSession, header, footer);
    if (rejectionCache != null) {
        addToRejections(rejectionCache, clientConnectPacket);
        return;
    }

    /* Player Whitelist Check */
    rejectionCache = whitelist(playerSession, header, footer);
    if (rejectionCache != null) {
        addToRejections(rejectionCache, clientConnectPacket);
        return;
    }

    /* Player Ban Check */
    rejectionCache = bannedCheck(playerSession, header, footer);
    if (rejectionCache != null) {
        addToRejections(rejectionCache, clientConnectPacket);
        return;
    }

    /* Already Logged On */
    rejectionCache = alreadyLoggedOn(playerSession, header, footer);
    if (rejectionCache != null) {
        addToRejections(rejectionCache, clientConnectPacket);
        return;
    }

    /* Server Full Check */
    rejectionCache = serverFull(playerSession, header, footer);
    if (rejectionCache != null) {
        addToRejections(rejectionCache, clientConnectPacket);
        return;
    }

    /* Allow Connection */
    addToRejections(new RejectionCache(false, playerSession), clientConnectPacket);
}

From source file:org.structr.javaparser.JavaParserModule.java

private String getMemberName(final String rawName) {
    final String[] parts = StringUtils.split(rawName, " ");
    return StringUtils.strip(StringUtils.remove(parts[parts.length - 1], ";"));
}

From source file:org.structr.web.entity.dom.Content.java

@Override
public void renderContent(final RenderContext renderContext, final int depth) throws FrameworkException {

    try {/*from  www.  j a  va 2 s .  c  o  m*/

        if (isDeleted() || isHidden() || !displayForLocale(renderContext)
                || !displayForConditions(renderContext)) {
            return;
        }

        final String id = getUuid();
        final EditMode edit = renderContext.getEditMode(securityContext.getUser(false));
        final boolean inBody = renderContext.inBody();
        final AsyncBuffer out = renderContext.getBuffer();

        String _contentType = getProperty(contentType);

        // fetch content with variable replacement
        String _content = getPropertyWithVariableReplacement(renderContext, Content.content);

        if (!(EditMode.RAW.equals(edit) || EditMode.WIDGET.equals(edit))
                && (_contentType == null || ("text/plain".equals(_contentType)))) {

            _content = escapeForHtml(_content);

        }

        if (EditMode.CONTENT.equals(edit) && inBody && this.isGranted(Permission.write, securityContext)) {

            if ("text/javascript".equals(_contentType)) {

                // Javascript will only be given some local vars
                // TODO: Is this neccessary?
                out.append("// data-structr-type='").append(getType()).append("'\n// data-structr-id='")
                        .append(id).append("'\n");

            } else if ("text/css".equals(_contentType)) {

                // CSS will only be given some local vars
                // TODO: Is this neccessary?
                out.append("/* data-structr-type='").append(getType()).append("'*/\n/* data-structr-id='")
                        .append(id).append("'*/\n");

            } else {

                //            // In edit mode, add an artificial comment tag around content nodes within body to make them editable
                final String cleanedContent = StringUtils
                        .remove(StringUtils.remove(org.apache.commons.lang3.StringUtils
                                .replace(getProperty(Content.content), "\n", "\\\\n"), "<!--"), "-->");
                out.append("<!--data-structr-id=\"".concat(id).concat("\" data-structr-raw-value=\"")
                        .concat(escapeForHtmlAttributes(cleanedContent)).concat("\"-->"));

            }

        }

        // No contentType-specific rendering in DATA edit mode
        //if (!edit.equals(EditMode.DATA)) {

        // examine content type and apply converter

        if (_contentType != null) {

            final Adapter<String, String> converter = contentConverters.get(_contentType);

            if (converter != null) {

                try {

                    // apply adapter
                    _content = converter.adapt(_content);
                } catch (FrameworkException fex) {

                    logger.log(Level.WARNING, "Unable to convert content: {0}", fex.getMessage());

                }

            }

        }

        // replace newlines with <br /> for rendering
        if (((_contentType == null) || _contentType.equals("text/plain")) && (_content != null)
                && !_content.isEmpty()) {

            final DOMNode _parent = getProperty(Content.parent);
            if (_parent == null || !(_parent instanceof Textarea)) {

                _content = _content.replaceAll("[\\n]{1}", "<br>");
            }
        }
        //}

        if (_content != null) {

            //buffer.append(indent(depth, true)).append(_content);

            // insert whitespace to make element clickable
            if (EditMode.CONTENT.equals(edit) && _content.length() == 0) {
                _content = "--- empty ---";
            }

            out.append(_content);
        }

        if (EditMode.CONTENT.equals(edit) && inBody && !("text/javascript".equals(getProperty(contentType)))
                && !("text/css".equals(getProperty(contentType)))) {

            //         buffer.append("</span>");
            out.append("<!---->");
        }

    } catch (Throwable t) {

        // catch exception to prevent ugly status 500 error pages in frontend.
        t.printStackTrace();
    }

}

From source file:org.tanaguru.rules.generator.json.TanaguruJsTestCaseExtractor.java

/**
 * @param args the command line arguments
 * @throws java.net.MalformedURLException
 *///  w w  w. j  av a2s  .  c  o  m
public static void main(String[] args) throws MalformedURLException, IOException, InterruptedException {
    //        DesiredCapabilities caps = new DesiredCapabilities();
    //        caps.setJavascriptEnabled(true);
    //        WebDriver driver = new PhantomJSDriver(caps);
    //        FirefoxDriver driver = 
    //                new FirefoxDriver(
    //                        new FirefoxBinary(new File(PATH_TO_FF)), 
    //                        new FirefoxProfile());

    DesiredCapabilities ff = DesiredCapabilities.firefox();
    //        DesiredCapabilities chrome = DesiredCapabilities.chrome();
    RemoteWebDriver driver = null;
    try {
        driver = new RemoteWebDriver(new URL(HUB_URL), ff);
        //            driver = new RemoteWebDriver(new URL("http://172.17.0.23:4444/wd/hub"), chrome);
        String script = IOUtils.toString(
                TanaguruJsTestCaseExtractor.class.getClassLoader().getResourceAsStream(JS_SCRIPT_NAME));

        for (Element el : Jsoup.parse(new URL(URL_LIST), 5000).select("a")) {
            String url = el.attr("abs:href");
            String resourceName = StringUtils.remove(el.attr("href"), ".html");
            if (StringUtils.contains(url, "html")) {
                driver.get(url);
                driver.findElementByTagName("body").sendKeys(Keys.TAB);
                try {
                    FileUtils.write(new File(PATH_TO_WRITE + resourceName + ".json"),
                            new JSONArray(driver.executeScript(script).toString()).toString(4));
                } catch (JSONException ex) {
                }
            }
        }
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:org.thelq.stackexchange.dbimport.Utils.java

public static String genTablePrefix(String containerName) {
    String name = containerName.trim().toLowerCase();
    if (StringUtils.isBlank(name))
        return "";
    //Hardcoded conversions
    name = StringUtils.removeEnd(name, ".7z");
    name = StringUtils.removeEnd(name, ".stackexchange.com");
    if (StringUtils.contains(name, "stackoverflow"))
        name = StringUtils.replace(name, "stackoverflow", "so");
    else if (StringUtils.contains(name, "serverfault"))
        name = StringUtils.replace(name, "serverfault", "sf");
    else if (StringUtils.containsIgnoreCase(name, "superuser"))
        name = StringUtils.replace(name, "superuser", "su");

    //Remove unnessesary extensions
    name = StringUtils.removeEnd(name, ".com");

    //Meta handling
    if (StringUtils.startsWith(name, "meta"))
        name = StringUtils.removeStart(name, "meta") + "_m";
    else if (StringUtils.startsWith(name, "meta."))
        name = StringUtils.removeStart(name, "meta.") + "_m";

    //Basic make valid for SQL
    //TODO: more validation?
    name = StringUtils.remove(name, " ");
    name = StringUtils.remove(name, ".");
    return name + "_";
}

From source file:org.thorn.emma.model.HttpResponse.java

public void setHeaders(Map<String, List<String>> headers) {
    this.headers = headers;

    List<String> contentType = headers.get("Content-Type");

    if (contentType != null) {
        String ct = StringUtils.remove(contentType.get(0), " ");

        Pattern p = Pattern.compile("(\\w+[-]*\\w*)/(\\w+[-]*\\w*)(;charset=)?(.*)", Pattern.CASE_INSENSITIVE);
        Matcher matcher = p.matcher(ct);
        if (matcher.find()) {
            this.contentType = matcher.group(1);
            this.fileSuffix = matcher.group(2);
            this.charset = matcher.group(4);

            if (StringUtils.equalsIgnoreCase(this.contentType, "text") && StringUtils.isEmpty(this.charset)) {
                // ????, ?byte
                charset = CharsetDetector.guessEncoding(content);
            }//  w ww .  ja  v a 2 s  .  co m
        }
    }

}

From source file:org.xlrnet.metadict.engines.nobordbok.OrdbokEngine.java

/**
 * Extract both the general form and all syllables from the oppslagsord-node.
 *//*from  w ww.j av  a2s.co m*/
private void extractGeneralForm(DictionaryObjectBuilder objectBuilder, Element oppslagsord) {
    String rawForm = oppslagsord.text();
    String[] syllabification = StringUtils.split(rawForm, SYLLABLE_SEPARATOR_CHAR);

    String generalForm = StringUtils.remove(rawForm, SYLLABLE_SEPARATOR_CHAR);
    objectBuilder.setGeneralForm(generalForm);
    objectBuilder.setSyllabification(syllabification);
}

From source file:org.xlrnet.tibaija.processor.FullTIBasicVisitor.java

/**
 * {@inheritDoc}/* ww  w.  ja  v a  2s  .  c  om*/
 * <p/>
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitStringExpression(@NotNull TIBasicParser.StringExpressionContext ctx) {
    String text = ctx.STRING().getText();
    String stringValue = StringUtils.remove(text, "\"");

    return Value.of(stringValue);
}

From source file:org.xwiki.contrib.ldap.XWikiLDAPUtils.java

/**
 * Not everything is supported in XWiki user page name so clean clean it a bit.
 * //from  w w w .  jav  a 2  s .c  o  m
 * @param pageName the name of the XWiki user page
 * @return the clean name of the XWiki user page
 * @since 9.0
 */
public static String cleanXWikiUserPageName(String pageName) {
    // Protected from characters not well supported in user page name depending on the version of XWiki
    String cleanPageName = StringUtils.remove(pageName, '.');
    cleanPageName = StringUtils.remove(cleanPageName, ' ');
    cleanPageName = StringUtils.remove(cleanPageName, '/');

    return cleanPageName;
}