Java Code Examples for org.apache.commons.lang3.StringUtils.normalizeSpace()

The following are Jave code examples for showing how to use normalizeSpace() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hue   File: CommonUtils.java   View Source Code Vote up 5 votes
public static String normalizeString(String input) {
	// Contain only ASCII letters, digits, or underscore characters (_).
	// Begin with an alphabetic character or underscore character.
	// Subsequent characters may include letters, digits, underscores.
	// Be between 1 and 127 characters in length, not including quotes for
	// delimited identifiers.
	// Contain no quotation marks and no spaces.
	StringBuffer sb = new StringBuffer();
	// To lowercase and remove all extra whitespaces.
	input = StringUtils.normalizeSpace(input.toLowerCase());
	for (char c : input.toCharArray()) {
		if (VALID_CHARS.contains(String.valueOf(c))) {
			if (sb.length() == 0 && INVALID_FIRST_CHARS.contains(String.valueOf(c))) {
				sb.append(REPLACEMENT_CHAR);
			}
			else {
				sb.append(c);
			}
		}
		else {
			sb.append(REPLACEMENT_CHAR);
		}
	}

	String normalizedName = sb.toString();
	// Remove leading and trailing underscore and multiple underscores
	normalizedName = StringUtils.replacePattern(normalizedName, "_{2,}", REPLACEMENT_CHAR);
	normalizedName = StringUtils.strip(normalizedName, REPLACEMENT_CHAR);

	return normalizedName.length() > 127 ? normalizedName.substring(0, 127) : normalizedName;
}
 
Example 2
Project: donut-nunit-adapter   File: NUnitAdapter.java   View Source Code Vote up 5 votes
private String makeErrorMessage(DeferredElementImpl testCaseElem) {
    try {
        Node failureNode = getNodeByTagName(testCaseElem.getChildNodes(), "failure");
        Node messageNode = getNodeByTagName(failureNode.getChildNodes(), "message");
        Node stackTraceNode = getNodeByTagName(failureNode.getChildNodes(), "stack-trace");

        return "Error message: " + StringUtils.normalizeSpace(messageNode.getTextContent()) + " Stack trace: " + StringUtils.normalizeSpace(stackTraceNode.getTextContent());
    } catch (Exception e) {
        return null;
    }
}
 
Example 3
Project: Blockchain-Academic-Verification-Service   File: FileReaderServiceImpl.java   View Source Code Vote up 5 votes
@Override
public String readFile(final String fileName) {
    try {
        return StringUtils.normalizeSpace(
                IOUtils.toString(
                        this.getClass().getClassLoader().getResourceAsStream(fileName)));
    }
    catch (IOException e) {
        LOGGER.error("File could not be loaded from resource: {}", e.getMessage());
    }
    return null;
}
 
Example 4
Project: Blockchain-Academic-Verification-Service   File: SmartContractTest.java   View Source Code Vote up 5 votes
private String getSmartContract(final String contract) {
    try {
        return StringUtils.normalizeSpace(
                IOUtils.toString(
                        this.getClass().getClassLoader().getResourceAsStream(contract)));
    }
    catch (IOException e) {
        LOGGER.error("Failed to serialize contract", e);
    }
    return null;
}
 
Example 5
Project: DecompiledMinecraft   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(C01PacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.sendPacket(new S02PacketChat(chatcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 6
Project: DecompiledMinecraft   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(C01PacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.sendPacket(new S02PacketChat(chatcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 7
Project: BaseClient   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(C01PacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.sendPacket(new S02PacketChat(chatcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 8
Project: BaseClient   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(C01PacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.sendPacket(new S02PacketChat(chatcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 9
Project: Zombe-Modpack   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(CPacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.sendPacket(new SPacketChat(textcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 10
Project: Backmemed   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(CPacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.sendPacket(new SPacketChat(textcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
Example 11
Project: CustomWorldGen   File: NetHandlerPlayServer.java   View Source Code Vote up 4 votes
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(CPacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.sendPacket(new SPacketChat(textcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", this.playerEntity.getDisplayName(), net.minecraftforge.common.ForgeHooks.newChatWithLinks(s));
            itextcomponent = net.minecraftforge.common.ForgeHooks.onServerChatEvent(this, s, itextcomponent);
            if (itextcomponent == null) return;
            this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}