List of usage examples for com.liferay.portal.kernel.util StringPool SLASH
String SLASH
To view the source code for com.liferay.portal.kernel.util StringPool SLASH.
Click Source Link
From source file:com.liferay.testhttpclient.servlet.TestHTTPClientServlet.java
License:Open Source License
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean result = false; try {//from www . j av a2 s .com String pathInfo = request.getPathInfo(); if (pathInfo.startsWith(StringPool.SLASH)) { pathInfo = pathInfo.substring(1); } if (pathInfo.equals("testPostFileAndStringParts")) { result = testPostFileAndStringParts(request); } else if (pathInfo.equals("testPostFilePart")) { result = testPostFilePart(request); } else if (pathInfo.equals("testPostFileParts")) { result = testPostFileParts(request); } else if (pathInfo.equals("testPostStringPart")) { result = testPostStringPart(request); } else if (pathInfo.equals("testPostStringParts")) { result = testPostStringParts(request); } } catch (Exception e) { _log.error(e, e); } response.setContentType(ContentTypes.TEXT_HTML); ServletOutputStream servletOutputStream = response.getOutputStream(); if (result) { servletOutputStream.print("PASSED"); } else { servletOutputStream.print("FAILED"); } servletOutputStream.flush(); }
From source file:com.liferay.testopensocialoauthconsumer.messaging.TestOpenSocialOAuthConsumerHotDeployMessageListener.java
License:Open Source License
protected String getFileEntryURL(FileEntry fileEntry) { StringBundler sb = new StringBundler(10); sb.append("http://localhost:8080"); sb.append(PortalUtil.getPathContext()); sb.append("/documents/"); sb.append(fileEntry.getRepositoryId()); sb.append(StringPool.SLASH); sb.append(fileEntry.getFolderId());/*from w w w . j a va 2 s . c om*/ sb.append(StringPool.SLASH); sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()))); sb.append(StringPool.SLASH); sb.append(fileEntry.getUuid()); return sb.toString(); }
From source file:com.liferay.tool.datamanipulator.handler.BaseHandler.java
License:Open Source License
private Object[] _getArgs(String[] argNames, Class<?>[] argClazzs, RequestContext requestContext, Map<String, Object> entrySpecifiedArgs) throws Exception { long companyId = requestContext.getCompanyId(); long groupId = requestContext.getGroupId(); long userId = requestContext.getUserId(); Date now = new Date(); ServiceContext serviceContext = HandlerUtil.getServiceContext(groupId, userId); Map<String, Calendar> dateMap = new HashMap<String, Calendar>(entryDateFields.size()); for (String entryDateField : entryDateFields) { String dateVarName = entryDateField + "Date"; String dateKeyName = entryDateField + "-date"; Date serviceContextDate = (Date) BeanUtil.getPropertySilently(serviceContext, dateVarName); Calendar dateVarValue;/*w w w .jav a2s . com*/ if (requestContext.contains(dateKeyName + "-from") && requestContext.contains(dateKeyName + "-to")) { dateVarValue = requestContext.getBetweenCalendar(dateKeyName); } else if (Validator.isNotNull(serviceContextDate)) { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(serviceContextDate); } else { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(now); } dateMap.put(dateVarName, dateVarValue); } StringBuilder sb = new StringBuilder(); sb.append(_entryName); sb.append(requestContext.getString("entryCount")); sb.append(" ${fieldName} "); if (requestContext.contains("editCount")) { sb.append("Edited "); sb.append(requestContext.getString("editCount")); sb.append(" times "); } sb.append(requestContext.getRandomString()); String entryTemplate = sb.toString(); User user = UserLocalServiceUtil.fetchUser(userId); List<Object> argValues = new ArrayList<Object>(argNames.length); for (int i = 0; i < argNames.length; i++) { String argName = argNames[i]; Class<?> argClazz = argClazzs[i]; if (entrySpecifiedArgs.containsKey(argName)) { argValues.add(entrySpecifiedArgs.get(argName)); } else if (argName.equals(Field.COMPANY_ID)) { argValues.add(companyId); } else if (argName.matches(".*Date.*")) { int x = argName.indexOf("Date") + 4; String dateKey = argName.substring(0, x); Calendar calendar = dateMap.get(dateKey); String calendarFieldName = argName.substring(x).toUpperCase(); if (calendarFieldName.equals("DAY")) { calendarFieldName = "DATE"; } int calendarFieldValue = (Integer) GetterUtil.getFieldValue(Calendar.class.getName(), calendarFieldName); argValues.add(calendar.get(calendarFieldValue)); } else if (entryStringFields.contains(argName)) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(content); } else if (entryMapFields.contains(argName)) { argName = argName.substring(0, (argName.length() - 3)); Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(StringUtil.getLocalizationMap(content)); } else if (argName.equals("friendlyURL")) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", "name"); String friendlyURL = StringUtil.getStringFieldValue(argName, context, entryTemplate); friendlyURL = StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(friendlyURL); argValues.add(friendlyURL); } else if (argName.equals(Field.GROUP_ID)) { argValues.add(groupId); } else if (argName.equals(getParentClassPKName())) { argValues.add(Long.valueOf(_getParentClassPK(requestContext))); } else if (argName.equals("locale")) { argValues.add(LocaleUtil.getDefault()); } else if (argName.equals("serviceContext")) { argValues.add(serviceContext); } else if (argName.equals(Field.USER_ID)) { argValues.add(userId); } else if (argName.equals(Field.USER_NAME)) { argValues.add(user.getFullName()); } else if (requestContext.contains(argName)) { argValues.add(requestContext.get(argName)); } else { Object argValue = null; try { Object object = argClazz.newInstance(); if (object instanceof String) { argValue = StringPool.BLANK; } } catch (InstantiationException e) { Type type = argClazz; if (type.equals(Boolean.TYPE)) { argValue = false; } else if (type.equals(Integer.TYPE)) { argValue = (int) 0; } else if (type.equals(List.class)) { argValue = new ArrayList<Object>(0); } else if (type.equals(Long.TYPE)) { argValue = (long) 0; } } argValues.add(argValue); } } return (Object[]) argValues.toArray(new Object[argValues.size()]); }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected String format(String fileName) throws Exception { File file = new File(fileName); if (!file.exists()) { file = new File(BASEDIR + fileName); }/*from w ww.j a v a 2s. c o m*/ fileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH); String absolutePath = getAbsolutePath(file); String content = fileUtil.read(file); String newContent = format(file, fileName, absolutePath, content); processFormattedFile(file, fileName, content, newContent); return newContent; }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected String getAbsolutePath(File file) { String absolutePath = fileUtil.getAbsolutePath(file); return StringUtil.replace(absolutePath, "/./", StringPool.SLASH); }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected Map<String, String> getCompatClassNamesMap() throws IOException { if (_compatClassNamesMap != null) { return _compatClassNamesMap; }//from ww w. ja v a 2s. c o m Map<String, String> compatClassNamesMap = new HashMap<String, String>(); String[] includes = new String[] { "**\\portal-compat-shared\\src\\com\\liferay\\compat\\**\\*.java" }; String basedir = BASEDIR; List<String> fileNames = new ArrayList<String>(); for (int i = 0; i < 3; i++) { fileNames = getFileNames(basedir, new String[0], includes); if (!fileNames.isEmpty()) { break; } basedir = "../" + basedir; } for (String fileName : fileNames) { if (!fileName.startsWith("shared")) { break; } File file = new File(basedir + fileName); String content = fileUtil.read(file); fileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH); fileName = StringUtil.replace(fileName, StringPool.SLASH, StringPool.PERIOD); int pos = fileName.indexOf("com."); String compatClassName = fileName.substring(pos); compatClassName = compatClassName.substring(0, compatClassName.length() - 5); String extendedClassName = StringUtil.replace(compatClassName, "compat.", StringPool.BLANK); if (content.contains("extends " + extendedClassName)) { compatClassNamesMap.put(compatClassName, extendedClassName); } } _compatClassNamesMap = compatClassNamesMap; return _compatClassNamesMap; }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected String getCustomCopyright(String absolutePath) throws IOException { for (int x = absolutePath.length();;) { x = absolutePath.lastIndexOf(StringPool.SLASH, x); if (x == -1) { break; }//from w w w . j av a 2s .c om String copyright = fileUtil.read(absolutePath.substring(0, x + 1) + "copyright.txt"); if (Validator.isNotNull(copyright)) { return copyright; } x = x - 1; } return null; }
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;//w w w. ja va 2 s . c o m } 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.tools.sourceformatter.CSSSourceProcessor.java
License:Open Source License
protected String fixComments(String content) { Matcher matcher = _commentPattern.matcher(content); while (matcher.find()) { String[] words = StringUtil.split(matcher.group(1), CharPool.SPACE); for (int i = 1; i < words.length; i++) { String previousWord = words[i - 1]; if (previousWord.endsWith(StringPool.PERIOD) || previousWord.equals(StringPool.SLASH)) { continue; }/*from w ww .j a va2 s.c o m*/ String word = words[i]; if ((word.length() > 1) && Character.isUpperCase(word.charAt(0)) && StringUtil.isLowerCase(word.substring(1))) { content = StringUtil.replaceFirst(content, word, StringUtil.toLowerCase(word), matcher.start()); } } } return content; }
From source file:com.liferay.tools.sourceformatter.JavaClass.java
License:Open Source License
protected boolean hasAnnotationCommentOrJavadoc(String s) { if (s.startsWith(_indent + StringPool.AT) || s.startsWith(_indent + StringPool.SLASH) || s.startsWith(_indent + " *")) { return true; } else {/*from w ww . j a v a 2s . co m*/ return false; } }