当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.normalizeSpace方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.StringUtils.normalizeSpace方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.normalizeSpace方法的具体用法?Java StringUtils.normalizeSpace怎么用?Java StringUtils.normalizeSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.StringUtils的用法示例。


在下文中一共展示了StringUtils.normalizeSpace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeErrorMessage

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:DonutReport,项目名称:donut-nunit-adapter,代码行数:12,代码来源:NUnitAdapter.java

示例2: readFile

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@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;
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:13,代码来源:FileReaderServiceImpl.java

示例3: normalizeString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
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;
}
 
开发者ID:ajoabraham,项目名称:hue,代码行数:32,代码来源:CommonUtils.java

示例4: getSmartContract

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
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;
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:12,代码来源:SmartContractTest.java

示例5: processChatMessage

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:47,代码来源:NetHandlerPlayServer.java

示例6: processChatMessage

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:47,代码来源:NetHandlerPlayServer.java

示例7: processChatMessage

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
 * 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");
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:49,代码来源:NetHandlerPlayServer.java


注:本文中的org.apache.commons.lang3.StringUtils.normalizeSpace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。