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.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
public void installApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String installMethod = ParamUtil.getString(uploadPortletRequest, "installMethod"); if (installMethod.equals("local")) { String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isEmpty(bytes)) { SessionErrors.add(actionRequest, UploadException.class.getName()); } else {//from www . j a v a 2 s.c om String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName); SessionMessages.add(actionRequest, "pluginUploaded"); } } else { try { String url = ParamUtil.getString(uploadPortletRequest, "url"); URL urlObj = new URL(url); String host = urlObj.getHost(); if (host.endsWith("sf.net") || host.endsWith("sourceforge.net")) { doInstallSourceForgeApp(urlObj.getPath(), uploadPortletRequest, actionRequest); } else { doInstallRemoteApp(url, uploadPortletRequest, actionRequest, true); } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } } String redirect = ParamUtil.getString(uploadPortletRequest, "redirect"); actionResponse.sendRedirect(redirect); }
From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
protected int doInstallRemoteApp(String url, UploadPortletRequest uploadPortletRequest, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; String deploymentContext = ParamUtil.getString(uploadPortletRequest, "deploymentContext"); try {//from www. ja v a 2 s .c om String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } Http.Options options = new Http.Options(); options.setFollowRedirects(false); options.setLocation(url); options.setPortletRequest(actionRequest); options.setPost(false); String progressId = ParamUtil.getString(uploadPortletRequest, Constants.PROGRESS_ID); options.setProgressId(progressId); byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); responseCode = response.getResponseCode(); if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) { String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); FileUtil.write(destinationFile, bytes); SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } return responseCode; }
From source file:com.liferay.marketplace.model.impl.AppImpl.java
License:Open Source License
@Override public String getFilePath() { return getFileDir() + StringPool.SLASH + getFileName(); }
From source file:com.liferay.marketplace.service.impl.AppLocalServiceImpl.java
License:Open Source License
@Override public void installApp(long remoteAppId) throws PortalException { App app = appPersistence.findByRemoteAppId(remoteAppId); if (!DLStoreUtil.hasFile(app.getCompanyId(), CompanyConstants.SYSTEM, app.getFilePath())) { throw new NoSuchFileException(); }//from www .jav a 2 s .c o m String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR) + StringPool.SLASH + Time.getTimestamp(); InputStream inputStream = null; ZipFile zipFile = null; try { inputStream = DLStoreUtil.getFileAsStream(app.getCompanyId(), CompanyConstants.SYSTEM, app.getFilePath()); if (inputStream == null) { throw new IOException("Unable to open file at " + app.getFilePath()); } File liferayPackageFile = FileUtil.createTempFile(inputStream); zipFile = new ZipFile(liferayPackageFile); Enumeration<ZipEntry> enu = (Enumeration<ZipEntry>) zipFile.entries(); while (enu.hasMoreElements()) { ZipEntry zipEntry = enu.nextElement(); String fileName = zipEntry.getName(); if (!fileName.endsWith(".jar") && !fileName.endsWith(".war") && !fileName.endsWith(".xml") && !fileName.endsWith(".zip") && !fileName.equals("liferay-marketplace.properties")) { continue; } if (_log.isInfoEnabled()) { _log.info("Extracting " + fileName + " from app " + app.getAppId()); } InputStream zipInputStream = null; try { zipInputStream = zipFile.getInputStream(zipEntry); if (fileName.equals("liferay-marketplace.properties")) { String propertiesString = StringUtil.read(zipInputStream); Properties properties = PropertiesUtil.load(propertiesString); processMarketplaceProperties(properties); } else { File pluginPackageFile = new File(tmpDir + StringPool.SLASH + fileName); FileUtil.write(pluginPackageFile, zipInputStream); String bundleSymbolicName = StringPool.BLANK; String bundleVersion = StringPool.BLANK; String contextName = StringPool.BLANK; AutoDeploymentContext autoDeploymentContext = new AutoDeploymentContext(); if (fileName.endsWith(".jar")) { Manifest manifest = BundleUtil.getManifest(pluginPackageFile); Attributes attributes = manifest.getMainAttributes(); bundleSymbolicName = GetterUtil.getString(attributes.getValue("Bundle-SymbolicName")); bundleVersion = GetterUtil.getString(attributes.getValue("Bundle-Version")); contextName = GetterUtil.getString(attributes.getValue("Web-ContextPath")); } else { contextName = getContextName(fileName); autoDeploymentContext.setContext(contextName); } autoDeploymentContext.setFile(pluginPackageFile); DeployManagerUtil.deploy(autoDeploymentContext); if (Validator.isNotNull(bundleSymbolicName) || Validator.isNotNull(contextName)) { moduleLocalService.addModule(app.getUserId(), app.getAppId(), bundleSymbolicName, bundleVersion, contextName); } } } finally { StreamUtil.cleanUp(zipInputStream); } } } catch (ZipException ze) { if (_log.isInfoEnabled()) { _log.info("Deleting corrupt package from app " + app.getAppId(), ze); } deleteApp(app); } catch (IOException ioe) { throw new PortalException(ioe.getMessage()); } catch (Exception e) { _log.error(e, e); } finally { FileUtil.deltree(tmpDir); if (zipFile != null) { try { zipFile.close(); } catch (IOException ioe) { } } StreamUtil.cleanUp(inputStream); clearInstalledAppsCache(); } }
From source file:com.liferay.marketplace.util.MarketplaceConstants.java
License:Open Source License
public static String getPathPurchased() { if (_pathPurchased == null) { _pathPurchased = _MARKETPLACE_PATH_PURCHASED + _MARKETPLACE_CLIENT_BUILD + StringPool.SLASH; }//from w w w .j av a 2s .c om return _pathPurchased + ReleaseInfo.getBuildNumber(); }
From source file:com.liferay.marketplace.util.MarketplaceConstants.java
License:Open Source License
public static String getPathStore() { if (_pathStore == null) { _pathStore = _MARKETPLACE_PATH_STORE + _MARKETPLACE_CLIENT_BUILD + StringPool.SLASH; }/* w w w .j a va 2s .c o m*/ return _pathStore + ReleaseInfo.getBuildNumber(); }
From source file:com.liferay.meeting.webex.request.BaseMeetingRequestTranslator.java
License:Open Source License
public String getSiteURL(MeetingContext meetingContext) { StringBundler siteURL = new StringBundler(6); siteURL.append(Http.HTTP_WITH_SLASH); siteURL.append(meetingContext.getName()); siteURL.append(StringPool.PERIOD);// w w w .j a va 2 s . co m siteURL.append(WebExConstants.DOMAIN); siteURL.append(StringPool.SLASH); siteURL.append(meetingContext.getApiURL()); return siteURL.toString(); }
From source file:com.liferay.modules.wiki.extractor.service.impl.WikiContentServiceImpl.java
License:Open Source License
private String _postProcessHTMLContent(String content, long groupId, long folderId, String attachmentURLPrefix, long width) { if (folderId == 0) { return content; }/* www. j av a 2s . c om*/ StringBundler sb = new StringBundler(); int idx = 0; int endIdx = 0; boolean start = true; while ((idx = content.indexOf(attachmentURLPrefix, idx)) > -1) { if (start) { sb.append(content.substring(0, idx)); start = false; } if (endIdx > 0) { sb.append(content.substring(endIdx + 1, idx)); } endIdx = content.indexOf(CharPool.GREATER_THAN, idx); sb.append(content.substring(idx, endIdx - 3)); System.out.println("idx: " + idx + ", endidx: " + endIdx); String title = content.substring(idx + attachmentURLPrefix.length(), endIdx - 3); System.out.println("Title: " + title); idx = endIdx; try { DLFileEntry entry = _dlFileEntryLocalService.getFileEntry(groupId, folderId, title); sb.append(StringPool.SLASH); sb.append(entry.getUuid()); sb.append("\" width=\""); sb.append(width); sb.append("px\"/>"); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (endIdx < content.length()) { sb.append(content.substring(endIdx + 1)); } return sb.toString(); }
From source file:com.liferay.mvc.freemarker.internal.FreeMarkerMVCContextHelper.java
License:Open Source License
public static void addPortletJSPTaglibSupport(FreeMarkerContext freeMarkerContext, PortletRequest portletRequest, PortletResponse portletResponse, Set<String> templateRegistry) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse); FreeMarkerVariablesUtil.insertVariables(freeMarkerContext, request); Portlet portlet = (Portlet) request.getAttribute(WebKeys.RENDER_PORTLET); String servletContextName = portlet.getPortletApp().getServletContextName(); final ServletContext servletContext = ServletContextPool.get(servletContextName); Object templateRegistryAttribute = servletContext.getAttribute(TEMPLATE_REGISTRY_ATTRIBUTE); if ((templateRegistry != null) && (templateRegistryAttribute == null)) { servletContext.setAttribute(TEMPLATE_REGISTRY_ATTRIBUTE, templateRegistry); }//from w w w. j ava 2s.c o m freeMarkerContext.put("fullTemplatesPath", StringPool.SLASH + servletContextName + FreeMarkerTemplateLoader.SERVLET_SEPARATOR); TemplateHashModel taglibsFactory = FreeMarkerTaglibFactoryUtil.createTaglibFactory(servletContext); freeMarkerContext.put("PortletJspTagLibs", taglibsFactory); ServletConfig servletConfig = (ServletConfig) portletRequest .getAttribute(PortletServlet.PORTLET_SERVLET_CONFIG); final PortletServlet portletServlet = new PortletServlet(); portletServlet.init(servletConfig); ServletContextHashModel servletContextHashModel = new ServletContextHashModel(portletServlet, ObjectWrapper.DEFAULT_WRAPPER); freeMarkerContext.put("Application", servletContextHashModel); HttpRequestHashModel httpRequestHashModel = new HttpRequestHashModel(request, response, ObjectWrapper.DEFAULT_WRAPPER); freeMarkerContext.put("Request", httpRequestHashModel); }
From source file:com.liferay.opensocial.shindig.service.LiferayPersonService.java
License:Open Source License
protected Person getUserPerson(User user, Set<String> fields, SecurityToken securityToken) throws Exception { Name name = new NameImpl(user.getFullName()); Person person = new PersonImpl(String.valueOf(user.getUserId()), user.getScreenName(), name); StringBundler sb = new StringBundler(4); sb.append(securityToken.getDomain()); sb.append(PortalUtil.getPathFriendlyURLPublic()); sb.append(StringPool.SLASH); sb.append(user.getScreenName());/* www . jav a2s . com*/ person.setProfileUrl(sb.toString()); sb.setIndex(0); sb.append(securityToken.getDomain()); sb.append(PortalUtil.getPathImage()); sb.append("/user_"); sb.append(user.isFemale() ? "female" : "male"); sb.append("_portrait?img_id="); sb.append(user.getPortraitId()); sb.append("&t="); sb.append(WebServerServletTokenUtil.getToken(user.getPortraitId())); person.setThumbnailUrl(sb.toString()); if (fields.contains(Person.Field.ABOUT_ME.toString())) { person.setAboutMe(user.getComments()); } if (fields.contains(Person.Field.AGE.toString())) { Calendar birthday = new GregorianCalendar(); birthday.setTime(user.getBirthday()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birthday.get(Calendar.YEAR); birthday.add(Calendar.YEAR, age); if (today.before(birthday)) { age--; } person.setAge(age); } if (fields.contains(Person.Field.BIRTHDAY.toString())) { person.setBirthday(user.getBirthday()); } if (fields.contains(Person.Field.EMAILS)) { person.setEmails(getEmails(user)); } if (fields.contains(Person.Field.GENDER.toString())) { if (user.isFemale()) { person.setGender(Gender.female); } else { person.setGender(Gender.male); } } if (fields.contains(Person.Field.NICKNAME.toString())) { person.setNickname(user.getScreenName()); } if (fields.contains(Person.Field.PHONE_NUMBERS.toString())) { List<ListField> phoneNumbers = getPhoneNumbers(Contact.class.getName(), user.getContactId()); person.setPhoneNumbers(phoneNumbers); } if (fields.contains(Person.Field.UTC_OFFSET.toString())) { person.setUtcOffset(new Long(user.getTimeZone().getRawOffset())); } if (securityToken.getOwnerId().equals(person.getId())) { person.setIsOwner(true); } if (securityToken.getViewerId().equals(person.getId())) { person.setIsViewer(true); } return person; }