List of usage examples for com.liferay.portal.kernel.util StringPool RETURN_NEW_LINE
String RETURN_NEW_LINE
To view the source code for com.liferay.portal.kernel.util StringPool RETURN_NEW_LINE.
Click Source Link
From source file:com.liferay.emailtombfilter.hook.sanitizer.EmailToMBMessageFilterSanitizerImpl.java
License:Open Source License
@Override public String sanitize(long companyId, long groupId, long userId, String className, long classPK, String contentType, String[] modes, String s, Map<String, Object> options) { if (Validator.isNull(className) || !className.equals(MBMessage.class.getName())) { return s; }/*from w ww . j a va 2s. c o m*/ if (options == null) { return s; } Object emailPartToMBMessageBody = options.get("emailPartToMBMessageBody"); if ((emailPartToMBMessageBody == null) || (emailPartToMBMessageBody != Boolean.TRUE)) { return s; } if (!contentType.startsWith(ContentTypes.TEXT_PLAIN)) { return s; } Matcher matcher = _pattern.matcher(s); if (!matcher.find()) { return s; } if (_log.isDebugEnabled()) { _log.debug("Sanitizing " + className + "#" + classPK); } StringBuilder sb = new StringBuilder(); sb.append(s.substring(0, matcher.start())); int lastTextPos = 0; int lastQuotedTextPos = 0; String quotedText = s.substring(matcher.end(), s.length()); String[] quotedTextLines = quotedText.split("\r\n|\n|\r"); for (int i = 0; i < quotedTextLines.length; i++) { if (Validator.isNull(quotedTextLines[i])) { continue; } if (quotedTextLines[i].startsWith(StringPool.GREATER_THAN)) { lastQuotedTextPos = i; if ((lastTextPos > 0) && (lastTextPos < lastQuotedTextPos)) { return s; } } else { lastTextPos = i; sb.append(quotedTextLines[i]); sb.append(StringPool.RETURN_NEW_LINE); } } return sb.toString(); }
From source file:com.liferay.message.boards.parser.bbcode.internal.HtmlBBCodeTranslatorImpl.java
License:Open Source License
protected String handleNewLine(List<BBCodeItem> bbCodeItems, Stack<String> tags, IntegerWrapper marker, String data) {// w w w . jav a 2 s .c o m BBCodeItem bbCodeItem = null; if ((marker.getValue() + 1) < bbCodeItems.size()) { if (data.matches("\\A\r?\n\\z")) { bbCodeItem = bbCodeItems.get(marker.getValue() + 1); if (bbCodeItem != null) { String value = bbCodeItem.getValue(); if (_excludeNewLineTypes.containsKey(value)) { int type = bbCodeItem.getType(); int excludeNewLineType = _excludeNewLineTypes.get(value); if ((type & excludeNewLineType) > 0) { data = StringPool.BLANK; } } } } else if (data.matches("(?s).*\r?\n\\z")) { bbCodeItem = bbCodeItems.get(marker.getValue() + 1); if ((bbCodeItem != null) && (bbCodeItem.getType() == BBCodeParser.TYPE_TAG_END)) { String value = bbCodeItem.getValue(); if (value.equals("*")) { data = data.substring(0, data.length() - 1); } } } } if (data.length() > 0) { data = StringUtil.replace(data, StringPool.RETURN_NEW_LINE, "<br />"); data = StringUtil.replace(data, CharPool.NEW_LINE, "<br />"); } return data; }
From source file:com.liferay.portlet.wiki.translators.BaseTranslator.java
License:Open Source License
private String _normalizeLineBreaks(String content) { content = StringUtil.replace(content, new String[] { StringPool.RETURN_NEW_LINE, StringPool.RETURN }, new String[] { StringPool.NEW_LINE, StringPool.NEW_LINE }); return content; }
From source file:com.liferay.rtl.tools.RtlCssBuilder.java
License:Open Source License
/** * @see com.liferay.portal.util.FileImpl#read(File file) *//*from w ww . j a v a 2s.c o m*/ private String _readFile(File file) throws IOException { if ((file == null) || !file.exists()) { return null; } RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); byte[] bytes = new byte[(int) randomAccessFile.length()]; randomAccessFile.readFully(bytes); randomAccessFile.close(); if (bytes == null) { return null; } String s = new String(bytes, StringPool.UTF8); return StringUtil.replace(s, StringPool.RETURN_NEW_LINE, StringPool.NEW_LINE); }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessorTestCase.java
License:Open Source License
protected void test(String fileName, String[] expectedErrorMessages, Integer[] lineNumbers) throws Exception { String fullFileName = _DIR_NAME + StringPool.SLASH + fileName; Tuple tuple = sourceFormatter.format(fullFileName); if (tuple == null) { return;//from w w w . j a va 2 s. c om } List<String> errorMessages = (List<String>) tuple.getObject(1); if (!errorMessages.isEmpty() || (expectedErrorMessages.length > 0)) { Assert.assertEquals(expectedErrorMessages.length, errorMessages.size()); for (int i = 0; i < errorMessages.size(); i++) { String actualErrorMessage = errorMessages.get(i); String expectedErrorMessage = expectedErrorMessages[i]; StringBundler sb = new StringBundler(5); sb.append(expectedErrorMessage); sb.append(StringPool.SPACE); sb.append(fullFileName); if (lineNumbers != null) { sb.append(StringPool.SPACE); sb.append(lineNumbers[i]); } Assert.assertEquals(sb.toString(), actualErrorMessage); } } else { String actualFormattedContent = (String) tuple.getObject(0); try { File file = new File(_DIR_NAME + "/expected/" + fileName); String expectedFormattedContent = FileUtils.readFileToString(file, StringPool.UTF8); expectedFormattedContent = StringUtil.replace(expectedFormattedContent, StringPool.RETURN_NEW_LINE, StringPool.NEW_LINE); Assert.assertEquals(expectedFormattedContent, actualFormattedContent); } catch (FileNotFoundException fnfe) { Assert.fail(); } } }
From source file:com.liferay.util.xml.XMLFormatter.java
License:Open Source License
public static String toCompactSafe(String xml) { return StringUtil.replace(xml, new String[] { StringPool.RETURN_NEW_LINE, StringPool.NEW_LINE, StringPool.RETURN }, new String[] { "[$NEW_LINE$]", "[$NEW_LINE$]", "[$NEW_LINE$]" }); }
From source file:com.liferay.wiki.engine.creole.TranslationToXHTMLTest.java
License:Open Source License
protected String toUnix(String text) { return StringUtil.replace(text, StringPool.RETURN_NEW_LINE, StringPool.NEW_LINE); }
From source file:it.smc.calendar.sync.caldav.CalDAVMethodFactory.java
License:Open Source License
public Method create(HttpServletRequest request) throws WebDAVException { String method = request.getMethod(); if (_log.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("Serving CalDAV request: "); sb.append(PortalUtil.getCurrentCompleteURL(request)); sb.append(StringPool.RETURN_NEW_LINE); sb.append(method);/* w ww .j a va 2 s. c o m*/ sb.append(StringPool.RETURN_NEW_LINE); sb.append("User: "); sb.append(PrincipalThreadLocal.getUserId()); Enumeration<String> headerNames = request.getHeaderNames(); String headerName; while (headerNames.hasMoreElements()) { headerName = headerNames.nextElement(); sb.append(headerName); sb.append(StringPool.COLON); sb.append(StringPool.SPACE); sb.append(request.getHeader(headerName)); sb.append(StringPool.RETURN_NEW_LINE); } _log.debug(sb.toString()); } Method methodImpl = (Method) _methods.get(StringUtil.toUpperCase(method)); if (methodImpl == null) { throw new WebDAVException("Method " + method + " is not implemented"); } try { String content = new String(FileUtil.getBytes(request.getInputStream())); if (Validator.isNotNull(content)) { CalDAVRequestThreadLocal.setRequestContent(content); if (_log.isDebugEnabled()) { String formattedContent = content; if (CalDAVUtil.isRequestContentXML(request)) { Document document = CalDAVRequestThreadLocal.getRequestDocument(); formattedContent = document.formattedString(StringPool.FOUR_SPACES); } _log.debug("Request content: \n" + formattedContent); } } } catch (Exception e) { _log.error(e, e); } return methodImpl; }