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

The following examples show how to use org.apache.commons.lang3.StringUtils#normalizeSpace() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void actionPerformed(IButton button) {
	if (button.getId() == 1) {
		The5zigMod.getVars().displayScreen(new GuiPartyInviteMembers(this));
	} else if (button.getId() == 2) {
		The5zigMod.getVars().displayScreen(new GuiPartyInvitations(this));
	} else if (button.getId() == 3) {
		The5zigMod.getVars().displayScreen(new GuiPartyManageMembers(this, The5zigMod.getPartyManager().getParty()));
	} else if (button.getId() == 4) {
		The5zigMod.getPartyManager().setParty(null);
		The5zigMod.getNetworkManager().sendPacket(new PacketPartyStatus(PacketPartyStatus.Action.DELETE));
		The5zigMod.getScheduler().postToMainThread(new Runnable() {
			@Override
			public void run() {
				initGui0();
			}
		}, true);
	} else if (button.getId() == 100) {
		if (!The5zigMod.getNetworkManager().isConnected())
			return;
		Party party = The5zigMod.getPartyManager().getParty();
		if (party == null) {
			return;
		}
		Conversation conversation = party.getPartyConversation();
		ITextfield textfield = getTextfieldById(1);
		String text = textfield.callGetText();
		text = StringUtils.normalizeSpace(text);
		if (text == null || text.isEmpty())
			return;
		The5zigMod.getNetworkManager().sendPacket(new PacketPartyStatus(PacketPartyStatus.Action.CHAT, text));
		Message message = new Message(conversation, 0, The5zigMod.getDataManager().getColoredName(), text, System.currentTimeMillis(), Message.MessageType.RIGHT);
		conversation.addLastSentMessage(text);
		The5zigMod.getPartyManager().addMessage(message);
		textfield.callSetText("");
		getButtonById(100).setEnabled(false);
	}
}
 
Example 2
Source Project: The-5zig-Mod   File: GuiParty.java    License: MIT License 5 votes vote down vote up
@Override
protected void actionPerformed(IButton button) {
	if (button.getId() == 1) {
		The5zigMod.getVars().displayScreen(new GuiPartyInviteMembers(this));
	} else if (button.getId() == 2) {
		The5zigMod.getVars().displayScreen(new GuiPartyInvitations(this));
	} else if (button.getId() == 3) {
		The5zigMod.getVars().displayScreen(new GuiPartyManageMembers(this, The5zigMod.getPartyManager().getParty()));
	} else if (button.getId() == 4) {
		The5zigMod.getPartyManager().setParty(null);
		The5zigMod.getNetworkManager().sendPacket(new PacketPartyStatus(PacketPartyStatus.Action.DELETE));
		The5zigMod.getScheduler().postToMainThread(new Runnable() {
			@Override
			public void run() {
				initGui0();
			}
		}, true);
	} else if (button.getId() == 100) {
		if (!The5zigMod.getNetworkManager().isConnected())
			return;
		Party party = The5zigMod.getPartyManager().getParty();
		if (party == null) {
			return;
		}
		Conversation conversation = party.getPartyConversation();
		ITextfield textfield = getTextfieldById(1);
		String text = textfield.getText();
		text = StringUtils.normalizeSpace(text);
		if (text == null || text.isEmpty())
			return;
		The5zigMod.getNetworkManager().sendPacket(new PacketPartyStatus(PacketPartyStatus.Action.CHAT, text));
		Message message = new Message(conversation, 0, The5zigMod.getDataManager().getColoredName(), text, System.currentTimeMillis(), Message.MessageType.RIGHT);
		conversation.addLastSentMessage(text);
		The5zigMod.getPartyManager().addMessage(message);
		textfield.setText("");
		getButtonById(100).setEnabled(false);
	}
}
 
Example 3
Source Project: cuba   File: WebTree.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getStyleName() {
    String styleName = super.getStyleName();
    for (String internalStyle : internalStyles) {
        styleName = styleName.replace(internalStyle, "");
    }
    return StringUtils.normalizeSpace(styleName);
}
 
Example 4
Source Project: ontopia   File: JunkNormalizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String normalize(String term) {
  // strip out repeated whitespace characters
  term = StringUtils.normalizeSpace(term);
  // drop 's endings
  if (term.length() >= 2 && term.endsWith("'s")) {
    term = term.substring(0, term.length()-2);
  }
  return term;
}
 
Example 5
public String getContent() {
	try {
		if (this.parameterMap.isEmpty()) {
			content = IOUtils.toByteArray(delegate.getInputStream());
		} else {
			content = getContentFromParameterMap(this.parameterMap);
		}
		String requestEncoding = delegate.getCharacterEncoding();
		String normalizedContent = StringUtils.normalizeSpace(new String(content, requestEncoding != null ? requestEncoding : StandardCharsets.UTF_8.name()));
		return StringUtils.isBlank(normalizedContent) ? "[EMPTY]" : normalizedContent;
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example 6
Source Project: cuba   File: WebAppWorkArea.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName()
            .replace(MODE_TABBED_STYLENAME, "")
            .replace(MODE_SINGLE_STYLENAME, "")
            .replace(STATE_INITIAL_STYLENAME, "")
            .replace(STATE_WINDOWS_STYLENAME, ""));
}
 
Example 7
Source Project: cuba   File: WebWindow.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(component.getStyleName().replace(C_WINDOW_LAYOUT, ""));
}
 
Example 8
/**
 * Normalise wikimedia texts according to embedding training requirements which
 * is a simple sequence of words.
 */
private static String normaliseDescription(String wikiText, boolean lowercase, boolean removePunctuation, String lang) {
    String text = MediaWikiParser.getInstance().toTextOnly(wikiText, lang);
    text = text.replace("\t", " ");

    /* following fastText-type string normalisation: 
       1. All punctuation-and-numeric. Things in this bucket get
          their numbers flattened, to prevent combinatorial explosions.
          They might be specific numbers, prices, etc.
          -> all numerical chars are actually all transformed to '0'
          punctuations are removed if parameter removePunctuation is true
       2. All letters: case-flattened if parameter lowercase is true.
       3. Mixed letters and numbers: e.g. a product ID? Flatten case if 
          parameter lowercase is true and transform numbers digit to 0.
    */

    // unicode normalization
    text = UnicodeUtil.normaliseText(text);

    // wikipedia unicode encoding to Java encoding
    // <U+00AD> -> \u00AD
    //text.replaceAll();

    // remove all xml scories
    text = text.replaceAll("<[^>]+>", " ");

    // remove all punctuation
    if (removePunctuation)
        text = text.replaceAll("\\p{P}", " ");

    // flatten numerical chars
    text = text.replaceAll("\\d", "0");

    text = text.replaceAll("\\|", " ");

    // lower case everything 
    if (lowercase)  
        text = text.toLowerCase();

    // collapse spaces amd clean
    text = StringUtils.normalizeSpace(text);
    text = text.replace("()", "");

    // remove stopword - this could be made optional, depending on the task
    // tokenize
    /*List<String> tokens = GrobidAnalyzer.getInstance().tokenize(text, new Language(lang, 1.0));
    StringBuilder textBuilder = new StringBuilder();
    for(String word : tokens) {
        try {
            if (!Stopwords.getInstance().isStopword(word, lang))
                textBuilder.append(word).append(" ");
        } catch(Exception e) {
            LOGGER.warn("Problem getting Stopwords instance", e);
            textBuilder.append(word).append(" ");
        }
    }*/

    //return textBuilder.toString().replaceAll("( )*"," ").trim();
    return StringUtils.normalizeSpace(text);
}
 
Example 9
Source Project: cuba   File: WebScrollBoxLayout.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(SCROLLBOX_STYLENAME, ""));
}
 
Example 10
Source Project: cuba   File: WebSearchField.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(SEARCHSELECT_STYLENAME, ""));
}
 
Example 11
Source Project: cuba   File: WebListEditor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(LISTEDITOR_STYLENAME, ""));
}
 
Example 12
Source Project: cuba   File: WebButtonsPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(BUTTONS_PANEL_STYLENAME, ""));
}
 
Example 13
Source Project: cuba   File: WebFlowBoxLayout.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(FLOWLAYOUT_STYLENAME, ""));
}
 
Example 14
/**
 * Normalise wikimedia texts according to embedding training requirements which
 * is a simple sequence of words.
 */
private static String normaliseDescription(String wikitext, String lang) {
	String text = MediaWikiParser.getInstance().toTextOnly(wikitext, lang);
	text = text.replace("\t", " ");

	// following fastText string normalisation: 
	// 1. All punctuation-and-numeric. Things in this bucket get
       // 	  their numbers flattened, to prevent combinatorial explosions.
       //    They might be specific numbers, prices, etc.
       //    -> all numerical chars are actually all transformed to '0'
   	// 2. All letters: case-flattened.
  	    // 3. Mixed letters and numbers: a product ID? Flatten case and leave
   	//    numbers alone.

	// unicode normalization
	text = UnicodeUtil.normaliseText(text);

	// wikipedia unicode encoding to Java encoding
	// <U+00AD> -> \u00AD
	//text.replaceAll();

   	// remove all xml scories
	text = text.replaceAll("<[^>]+>", " ");

	// remove all punctuation
	text = text.replaceAll("\\p{P}", " ");

	// flatten numerical chars
	text = text.replaceAll("\\d", "0");

	text = text.replaceAll("\\|", " ");

	// lower case everything (to be evaluated!)
	text = text.toLowerCase();

	// collapse spaces
	text = StringUtils.normalizeSpace(text);

	// remove stopword
	// tokenize
	List<String> tokens = GrobidAnalyzer.getInstance().tokenize(text, new Language(lang, 1.0));
	StringBuilder textBuilder = new StringBuilder();
	for(String word : tokens) {
		try {
			if (!Stopwords.getInstance().isStopword(word, lang))
				textBuilder.append(word).append(" ");
		} catch(Exception e) {
			LOGGER.warn("Problem getting Stopwords instance", e);
			textBuilder.append(word).append(" ");
		}
	}

	//return textBuilder.toString().replaceAll("( )*"," ").trim();
	return StringUtils.normalizeSpace(textBuilder.toString());
}
 
Example 15
Source Project: cuba   File: WebLinkButton.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(ValoTheme.BUTTON_LINK, ""));
}
 
Example 16
Source Project: cuba   File: WebTimeZoneIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(USER_TIMEZONE_LABEL_STYLENAME, ""));
}
 
Example 17
Source Project: cuba   File: WebUserActionsButton.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(
            super.getStyleName().replace(USERACTIONS_BUTTON_STYLENAME, ""));
}
 
Example 18
Source Project: cuba   File: WebLogoutButton.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(LOGOUT_BUTTON_STYLENAME, ""));
}
 
Example 19
Source Project: cuba   File: WebNewWindowButton.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(NEW_WINDOW_BUTTON_STYLENAME, ""));
}
 
Example 20
Source Project: cuba   File: WebFoldersPane.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(C_FOLDERS_PANE, ""));
}