List of usage examples for com.liferay.portal.kernel.util MethodHandler invoke
public Object invoke(Object target) throws Exception
From source file:com.liferay.mail.messaging.MailMessageListener.java
License:Open Source License
protected void doMethodHandler(MethodHandler methodHandler) throws Exception { methodHandler.invoke(HookFactory.getInstance()); }
From source file:com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.java
License:Open Source License
public String processCustomizationSettings(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, PageContext pageContext, String velocityTemplateId, String velocityTemplateContent) throws Exception { if (Validator.isNull(velocityTemplateContent)) { return StringPool.BLANK; }// w w w . ja v a 2 s. c o m UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); CustomizationSettingsProcessor processor = new CustomizationSettingsProcessor(request, new PipingPageContext(pageContext, unsyncStringWriter), unsyncStringWriter); VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext(); velocityContext.put("processor", processor); // Velocity variables VelocityVariablesUtil.insertVariables(velocityContext, request); // liferay:include tag library MethodHandler methodHandler = new MethodHandler(_initMethodKey, servletContext, request, new PipingServletResponse(response, unsyncStringWriter), pageContext); Object velocityTaglib = methodHandler.invoke(true); velocityContext.put("taglibLiferay", velocityTaglib); velocityContext.put("theme", velocityTaglib); try { VelocityEngineUtil.mergeTemplate(velocityTemplateId, velocityTemplateContent, velocityContext, unsyncStringWriter); } catch (Exception e) { _log.error(e, e); throw e; } return unsyncStringWriter.toString(); }
From source file:com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.java
License:Open Source License
public void processTemplate(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, PageContext pageContext, JspWriter jspWriter, String portletId, String velocityTemplateId, String velocityTemplateContent) throws Exception { if (Validator.isNull(velocityTemplateContent)) { return;//from w w w.j ava2s . co m } TemplateProcessor processor = new TemplateProcessor(servletContext, request, response, portletId); VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext(); velocityContext.put("processor", processor); // Velocity variables VelocityVariablesUtil.insertVariables(velocityContext, request); // liferay:include tag library UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); MethodHandler methodHandler = new MethodHandler(_initMethodKey, servletContext, request, new PipingServletResponse(response, unsyncStringWriter), pageContext); Object velocityTaglib = methodHandler.invoke(true); velocityContext.put("taglibLiferay", velocityTaglib); velocityContext.put("theme", velocityTaglib); try { VelocityEngineUtil.mergeTemplate(velocityTemplateId, velocityTemplateContent, velocityContext, unsyncStringWriter); } catch (Exception e) { _log.error(e, e); throw e; } String output = unsyncStringWriter.toString(); Map<Portlet, Object[]> portletsMap = processor.getPortletsMap(); Map<String, StringBundler> contentsMap = new HashMap<String, StringBundler>(portletsMap.size()); for (Map.Entry<Portlet, Object[]> entry : portletsMap.entrySet()) { Portlet portlet = entry.getKey(); Object[] value = entry.getValue(); String queryString = (String) value[0]; String columnId = (String) value[1]; Integer columnPos = (Integer) value[2]; Integer columnCount = (Integer) value[3]; UnsyncStringWriter portletUnsyncStringWriter = new UnsyncStringWriter(); PipingServletResponse pipingServletResponse = new PipingServletResponse(response, portletUnsyncStringWriter); processPortlet(servletContext, request, pipingServletResponse, portlet, queryString, columnId, columnPos, columnCount, null, true); contentsMap.put(portlet.getPortletId(), portletUnsyncStringWriter.getStringBundler()); } StringBundler sb = StringUtil.replaceWithStringBundler(output, "[$TEMPLATE_PORTLET_", "$]", contentsMap); sb.writeTo(jspWriter); }
From source file:com.liferay.portlet.layoutconfiguration.util.velocity.CustomizationSettingsProcessor.java
License:Open Source License
public String processColumn(String columnId, String classNames) throws Exception { String customizableKey = CustomizedPages.namespaceColumnId(columnId); boolean templateCustomizable = true; if (_templateLayout != null) { templateCustomizable = GetterUtil.getBoolean(_templateLayout.getTypeSettingsProperty(customizableKey)); }//from ww w .j a v a 2 s . co m boolean customizable = false; if (templateCustomizable) { customizable = GetterUtil .getBoolean(_layoutTypeSettings.getProperty(customizableKey, String.valueOf(false))); } _writer.append("<div class=\""); _writer.append(classNames); _writer.append("\">"); _writer.append("<h1>"); _writer.append(columnId); _writer.append("</h1>"); Object inputTag = _inputTagClass.newInstance(); BeanPropertiesUtil.setProperty(inputTag, "disabled", !templateCustomizable); BeanPropertiesUtil.setProperty(inputTag, "label", "customizable"); BeanPropertiesUtil.setProperty(inputTag, "name", "TypeSettingsProperties--".concat(customizableKey).concat("--")); BeanPropertiesUtil.setProperty(inputTag, "pageContext", _pageContext); BeanPropertiesUtil.setProperty(inputTag, "type", "checkbox"); BeanPropertiesUtil.setProperty(inputTag, "value", customizable); MethodHandler doEndMethodHandler = new MethodHandler(_doEndTagMethodKey); MethodHandler doStartMethodHandler = new MethodHandler(_doStartTagMethodKey); int result = (Integer) doStartMethodHandler.invoke(inputTag); if (result == Tag.EVAL_BODY_INCLUDE) { doEndMethodHandler.invoke(inputTag); } _writer.append("</div>"); return StringPool.BLANK; }
From source file:com.liferay.util.bridges.alloy.BaseAlloyIndexer.java
License:Open Source License
@Override protected void doReindex(String className, long classPK) throws Exception { MethodHandler methodHandler = new MethodHandler(getModelMethodKey, classPK); Object model = methodHandler.invoke(false); doReindex(model);//from ww w .j a va 2s .c o m }
From source file:com.liferay.util.bridges.alloy.BaseAlloyIndexer.java
License:Open Source License
protected void reindexModels(long companyId) throws Exception { MethodHandler methodHandler = new MethodHandler(getModelsCountMethodKey); int count = (Integer) methodHandler.invoke(false); int pages = count / Indexer.DEFAULT_INTERVAL; for (int i = 0; i <= pages; i++) { int start = (i * Indexer.DEFAULT_INTERVAL); int end = start + Indexer.DEFAULT_INTERVAL; reindexModels(companyId, start, end); }/*from ww w.j a v a 2 s .co m*/ }
From source file:com.liferay.util.bridges.alloy.BaseAlloyIndexer.java
License:Open Source License
protected void reindexModels(long companyId, int start, int end) throws Exception { MethodHandler methodHandler = new MethodHandler(getModelsMethodKey, start, end); List<Object> models = (List<Object>) methodHandler.invoke(false); if (models.isEmpty()) { return;/*from w w w .j a v a2s .c o m*/ } Collection<Document> documents = new ArrayList<Document>(); for (Object model : models) { Document document = getDocument(model); documents.add(document); } SearchEngineUtil.updateDocuments(companyId, documents); }
From source file:org.kmworks.liferay.rpc.server.RPCTunnelServlet.java
License:Open Source License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { ObjectInputStream ois;/*from w w w . j ava2 s. co m*/ try { ois = new ObjectInputStream(request.getInputStream()); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe, ioe); } return; } Object returnObj = null; boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess(); try { AccessControlThreadLocal.setRemoteAccess(true); Object obj = ois.readObject(); @SuppressWarnings("unchecked") ObjectValuePair<HttpPrincipal, MethodHandler> ovp = (ObjectValuePair<HttpPrincipal, MethodHandler>) obj; //HttpPrincipal principal = ovp.getKey(); // not used here MethodHandler methodHandler = ovp.getValue(); if (methodHandler != null) { MethodKey methodKey = methodHandler.getMethodKey(); if (!isValidRequest(methodKey.getDeclaringClass())) { return; } returnObj = methodHandler.invoke(true); } } catch (InvocationTargetException ite) { returnObj = ite.getCause(); if (!(returnObj instanceof PortalException)) { _log.error(ite, ite); if (returnObj != null) { Throwable throwable = (Throwable) returnObj; returnObj = new SystemException(throwable.getMessage()); } else { returnObj = new SystemException(); } } } catch (Exception e) { _log.error(e, e); } finally { AccessControlThreadLocal.setRemoteAccess(remoteAccess); } if (returnObj != null) { try { try (ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream())) { oos.writeObject(returnObj); oos.flush(); } } catch (IOException ioe) { _log.error(ioe, ioe); throw ioe; } } }
From source file:org.kmworks.portal.rpc.server.RPCTunnelServlet.java
License:Open Source License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader(); ObjectInputStream ois;//from www . ja va2s .c o m try { ois = new ClassLoaderObjectInputStream(request.getInputStream(), classLoader); } catch (IOException ioe) { if (LOG.isWarnEnabled()) { LOG.warn(ioe, ioe); } return; } Object returnObj = null; boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess(); try { AccessControlThreadLocal.setRemoteAccess(true); Object obj = ois.readObject(); @SuppressWarnings("unchecked") ObjectValuePair<HttpPrincipal, MethodHandler> ovp = (ObjectValuePair<HttpPrincipal, MethodHandler>) obj; //HttpPrincipal principal = ovp.getKey(); MethodHandler methodHandler = ovp.getValue(); if (methodHandler != null) { MethodKey methodKey = methodHandler.getMethodKey(); if (!isValidRequest(methodKey.getDeclaringClass())) { return; } if (isServiceRequest(methodKey.getDeclaringClass())) { // Simulate login PrincipalThreadLocal.setName(ovp.getKey().getLogin()); PrincipalThreadLocal.setPassword(ovp.getKey().getPassword()); } returnObj = methodHandler.invoke(true); } } catch (InvocationTargetException ite) { returnObj = ite.getCause(); if (!(returnObj instanceof PortalException)) { LOG.error(ite, ite); if (returnObj != null) { Throwable throwable = (Throwable) returnObj; returnObj = new SystemException(throwable.getMessage()); } else { returnObj = new SystemException(); } } } catch (Exception e) { LOG.error(e, e); } finally { AccessControlThreadLocal.setRemoteAccess(remoteAccess); } if (returnObj != null) { try { returnObj = makeSerializable(returnObj); try (ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream())) { oos.writeObject(returnObj); oos.flush(); } } catch (Exception ioe) { LOG.error(ioe, ioe); throw ioe; } } }