// If the property is final, the property wins. If it is not final, // the portlet preferences take precedence. public String getTitleString(RenderRequest request) { Placement placement = ToolManager.getCurrentPlacement(); return placement.getTitle(); }
// Render the portlet - this is not supposed to change the state of the portlet // Render may be called many times so if it changes the state - that is tacky // Render will be called when someone presses "refresh" or when another portlet // onthe same page is handed an Action. public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); // System.out.println("==== doView called ===="); // Grab that underlying request to get a GET parameter ServletRequest req = (ServletRequest) ThreadLocalManager.get(CURRENT_HTTP_REQUEST); String popupDone = req.getParameter("sakai.popup"); PrintWriter out = response.getWriter(); Placement placement = ToolManager.getCurrentPlacement(); response.setTitle(placement.getTitle()); String source = placement.getPlacementConfig().getProperty(SOURCE); if (source == null) source = ""; String height = placement.getPlacementConfig().getProperty(HEIGHT); if (height == null) height = "1200px"; boolean maximize = "true".equals(placement.getPlacementConfig().getProperty(MAXIMIZE)); boolean popup = false; // Comes from content item boolean oldPopup = "true".equals(placement.getPlacementConfig().getProperty(POPUP)); // Retrieve the corresponding content item and tool to check the launch Map<String, Object> content = null; Map<String, Object> tool = null; Long key = getContentIdFromSource(source); if (key == null) { out.println(rb.getString("get.info.notconfig")); M_log.warn("Cannot find content id placement=" + placement.getId() + " source=" + source); return; } try { content = m_ltiService.getContent(key); // If we are supposed to popup (per the content), do so and optionally // copy the calue into the placement to communicate with the portal popup = getLongNull(content.get("newpage")) == 1; if (oldPopup != popup) { placement.getPlacementConfig().setProperty(POPUP, popup ? "true" : "false"); placement.save(); } String launch = (String) content.get("launch"); Long tool_id = getLongNull(content.get("tool_id")); if (launch == null && tool_id != null) { tool = m_ltiService.getTool(tool_id); launch = (String) tool.get("launch"); } // Force http:// to pop-up if we are https:// String serverUrl = ServerConfigurationService.getServerUrl(); if (request.isSecure() || (serverUrl != null && serverUrl.startsWith("https://"))) { if (launch != null && launch.startsWith("http://")) popup = true; } } catch (Exception e) { out.println(rb.getString("get.info.notconfig")); e.printStackTrace(); return; } if (source != null && source.trim().length() > 0) { Context context = new VelocityContext(); context.put("tlang", rb); context.put("validator", validator); context.put("source", source); context.put("height", height); sendAlert(request, context); context.put("popupdone", Boolean.valueOf(popupDone != null)); context.put("popup", Boolean.valueOf(popup)); context.put("maximize", Boolean.valueOf(maximize)); vHelper.doTemplate(vengine, "/vm/main.vm", context, out); } else { out.println(rb.getString("get.info.notconfig")); } // System.out.println("==== doView complete ===="); }
/** Populate the state with configuration settings */ protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRunData rundata) { // TODO: we might want to keep this from running for each request - but by letting it we get // fresh info each time... -ggolden super.initState(state, portlet, rundata); Placement placement = ToolManager.getCurrentPlacement(); Properties config = placement.getConfig(); // set the pass_pid parameter boolean passPid = false; String passPidStr = config.getProperty(PASS_PID, "false"); state.removeAttribute(PASS_PID); if ("true".equalsIgnoreCase(passPidStr)) { state.setAttribute(PASS_PID, Boolean.TRUE); passPid = true; } // Assume macro expansion (disable on request) boolean macroExpansion = true; String macroExpansionStr = config.getProperty(MACRO_EXPANSION, "true"); state.removeAttribute(MACRO_EXPANSION); if ("false".equalsIgnoreCase(macroExpansionStr)) { state.setAttribute(MACRO_EXPANSION, Boolean.FALSE); macroExpansion = false; } // set the special setting String special = config.getProperty(SPECIAL); final String sakaiPropertiesUrlKey = config.getProperty(SAKAI_PROPERTIES_URL_KEY); final String hideOptions = config.getProperty(HIDE_OPTIONS); // check for an older way the ChefWebPagePortlet took parameters, converting to our "special" // values if (special == null) { if ("true".equals(config.getProperty("site"))) { special = SPECIAL_SITE; } else if ("true".equals(config.getProperty("workspace"))) { special = SPECIAL_WORKSPACE; } else if ("true".equals(config.getProperty("worksite"))) { special = SPECIAL_WORKSITE; } else if ("true".equals(config.getProperty("annotatedurl"))) { special = SPECIAL_ANNOTATEDURL; } } state.removeAttribute(SPECIAL); if ((special != null) && (special.trim().length() > 0)) { state.setAttribute(SPECIAL, special); } state.removeAttribute(HIDE_OPTIONS); if ((hideOptions != null) && (hideOptions.trim().length() > 0)) { state.setAttribute(HIDE_OPTIONS, hideOptions); } // set the source url setting String source = StringUtils.trimToNull(config.getProperty(SOURCE)); // check for an older way the ChefWebPagePortlet took parameters, converting to our "source" // value if (source == null) { source = StringUtils.trimToNull(config.getProperty("url")); } // store the raw as-configured source url state.removeAttribute(SOURCE); if (source != null) { state.setAttribute(SOURCE, source); } // compute working URL, modified from the configuration URL if special String url = sourceUrl( special, source, placement.getContext(), macroExpansion, passPid, placement.getId(), sakaiPropertiesUrlKey); state.setAttribute(URL, url); // set the height state.setAttribute(HEIGHT, config.getProperty(HEIGHT, "600px")); state.setAttribute(ANNOTATED_TEXT, config.getProperty(ANNOTATED_TEXT, "")); if (config.getProperty(TARGETPAGE_URL) != null) { // set Target page url for Annotated URL Tool state.setAttribute(TARGETPAGE_URL, config.getProperty(TARGETPAGE_URL)); // set Target page name for Annotated URL Tool state.setAttribute(TARGETPAGE_NAME, config.getProperty(TARGETPAGE_NAME)); } // set the title state.setAttribute(TITLE, placement.getTitle()); if (state.getAttribute(STATE_PAGE_TITLE) == null) { SitePage p = SiteService.findPage(getCurrentSitePageId()); state.setAttribute(STATE_PAGE_TITLE, p.getTitle()); } // if events found in tool registration file put them in state if ((StringUtils.trimToNull(config.getProperty(EVENT_ACCESS_WEB_CONTENT)) != null)) { state.setAttribute(EVENT_ACCESS_WEB_CONTENT, config.getProperty(EVENT_ACCESS_WEB_CONTENT)); } if ((StringUtils.trimToNull(config.getProperty(EVENT_REVISE_WEB_CONTENT)) != null)) { state.setAttribute(EVENT_REVISE_WEB_CONTENT, config.getProperty(EVENT_REVISE_WEB_CONTENT)); } if (m_eventTrackingService == null) { m_eventTrackingService = (EventTrackingService) ComponentManager.get("org.sakaiproject.event.api.EventTrackingService"); } }