/**
   * loads a context defined by its absolut path passed in URL encoded parameter 'FILENAME'
   *
   * @throws PortalException
   */
  void doLoadwmc(User user) throws PortalException {

    String filename = null;
    try {
      filename = URLDecoder.decode(parameter.get("FILENAME"), CharsetUtils.getSystemCharset());
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }
    File file = new File(filename);
    String cntxid = file.getName();

    PortletSet ps = portlet.getPortletConfig().getPortletSet();
    String mapid = ps.getPortletByName("iGeoPortal:MapActionPortlet").getID();
    Portlet port = ps.getPortletByID(mapid);
    port.getPortletConfig().setInitParameter(INIT_WMC, cntxid);

    String mwinid = getInitParam(INIT_MAPPORTLETID);
    port = ps.getPortletByID(mwinid);
    port.getPortletConfig().setInitParameter(INIT_WMC, cntxid);

    request.setAttribute(PARAM_MAPPORTLET, mwinid);

    ViewContext vc = null;
    try {
      vc = WebMapContextFactory.createViewContext(file.toURI().toURL(), user, null);
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
      return;
    }

    setCurrentMapContext(vc, getInitParam(INIT_MAPPORTLETID));
    setCurrentMapContextName(getInitParam(INIT_MAPPORTLETID), cntxid);
  }
Exemplo n.º 2
0
  /**
   * @param rundata
   * @param context
   * @throws Exception
   */
  @Override
  protected void doOutput(RunData rundata, Context context) throws Exception {

    try {
      String portletId = ActivityUtils.getGlobalPortletId(rundata);
      context.put("portletId", ActivityUtils.getGlobalPortletId(rundata));
      Portlet portlet = ALEipUtils.getPortlet(rundata, portletId);
      String desktopNotificationParam =
          portlet.getPortletConfig().getInitParameter("desktopNotification");
      context.put("desktopNotification", "T".equals(desktopNotificationParam));
      String support = rundata.getParameters().getString("s");
      context.put("notifySupport", "1".equals(support));
      String permission = rundata.getParameters().getString("p");
      context.put("notifyPermission", "0".equals(permission) || "granted".equals(permission));

      ActivitySelectData listData = new ActivitySelectData();
      listData.initField();
      listData.setRowsNum(5);
      listData.doViewList(this, rundata, context);
      String layout_template = "portlets/html/ja/ajax-activity-list.vm";
      setTemplate(rundata, context, layout_template);
    } catch (Exception ex) {
      logger.error("ActivityListScreen.doOutput", ex);
      ALEipUtils.redirectDBError(rundata);
    }
  }
  /**
   * selects the current context of a MapWindowPortlet
   *
   * @throws PortalException
   */
  void doSelectwmc() throws PortalException {

    String cntxid = parameter.get("WMCID");

    PortletSet ps = portlet.getPortletConfig().getPortletSet();
    String mapid = ps.getPortletByName("iGeoPortal:MapActionPortlet").getID();
    Portlet port = ps.getPortletByID(mapid);
    port.getPortletConfig().setInitParameter(INIT_WMC, cntxid);

    String mwinid = getInitParam(INIT_MAPPORTLETID);
    port = ps.getPortletByID(mwinid);
    port.getPortletConfig().setInitParameter(INIT_WMC, cntxid);

    request.setAttribute(PARAM_MAPPORTLET, mwinid);

    ViewContext vc = null;
    if ("true".equals(getInitParam(INIT_KEEP_BBOX))) {
      // get old current context to read its bounding box
      vc = getCurrentViewContext(parameter.get("MAPPORTLET"));
      Point[] currentEnv = vc.getGeneral().getBoundingBox();

      // get new current context to set its bounding box with value of the
      // old current context bounding box to keep viewing area
      vc = getNamedViewContext(cntxid);
      try {
        vc.getGeneral().setBoundingBox(currentEnv);
      } catch (ContextException e) {
        LOG.logError(e.getMessage(), e);
        throw new PortalException(e.getMessage(), e);
      }
    } else {
      vc = getNamedViewContext(cntxid);
    }

    setCurrentMapContext(vc, getInitParam(INIT_MAPPORTLETID));
    setCurrentMapContextName(getInitParam(INIT_MAPPORTLETID), cntxid);
  }
  /**
   * Build the normal state content for this portlet.
   *
   * @param portlet The jsp-based portlet that is being built.
   * @param rundata The turbine rundata context for this request.
   */
  protected void buildNormalContext(Portlet portlet, RunData rundata) {
    PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());
    Iterator i = entry.getParameterNames();
    Hashtable qa = new Hashtable();

    while (i.hasNext()) {
      String name = (String) i.next();
      Parameter param = entry.getParameter(name);
      if (param.isHidden() == false) {
        String title = param.getTitle();
        String value = portlet.getPortletConfig().getInitParameter(name);
        qa.put(title, value);
      }
    }

    rundata.getRequest().setAttribute("questions", qa);

    // After successful send, the user may or may not click the Continue button so
    // reset to default template here
    if (rundata.getRequest().getAttribute("email") == null) {
      // this.setTemplate(rundata, portlet, null);
      resetTemplate(rundata);
    }
  }
Exemplo n.º 5
0
  /** Subclasses must override this method to provide default behavior for the portlet action */
  protected void buildNormalContext(Portlet portlet, Context context, RunData rundata) {
    String regName = portlet.getPortletConfig().getInitParameter("registry", Registry.PORTLET);

    Boolean refresh =
        (Boolean)
            PortletSessionState.getAttribute(
                rundata, PREFIX + regName + ":" + REFRESH, Boolean.FALSE);

    if (refresh.equals(Boolean.TRUE)) {
      PortletSessionState.clearAttribute(portlet, rundata, START);
      PortletSessionState.clearAttribute(portlet, rundata, RESULTS);
      PortletSessionState.clearAttribute(portlet, rundata, FILTERED_RESULTS);
      PortletSessionState.clearAttribute(rundata, PREFIX + regName + ":" + REFRESH);
    }

    int start = getStart(rundata, portlet);
    if (start < 0) start = 0;

    String pageSize = portlet.getPortletConfig().getInitParameter("page-size", "20");

    int size = Integer.parseInt(pageSize);

    int prev = start - size;

    if (prev < 0) {
      prev = 0;
    }

    String[] filterFields =
        (String[]) PortletSessionState.getAttribute(portlet, rundata, FILTER_FIELDS);
    String[] filterValues =
        (String[]) PortletSessionState.getAttribute(portlet, rundata, FILTER_VALUES);

    List regEntries = (List) PortletSessionState.getAttribute(portlet, rundata, RESULTS);
    List filteredEntries =
        (List) PortletSessionState.getAttribute(portlet, rundata, FILTERED_RESULTS);
    if (regEntries == null) {
      Iterator i = Registry.get(regName).listEntryNames();
      regEntries = new ArrayList();

      while (i.hasNext()) {
        String name = (String) i.next();

        RegistryEntry regEntry = Registry.getEntry(regName, name);

        if ((regEntry != null) && (!regEntry.isHidden())) {
          regEntries.add(regEntry);
        }
      }

      Collections.sort(
          regEntries,
          new Comparator() {
            public int compare(Object o1, Object o2) {
              String t1 = ((RegistryEntry) o1).getName().toLowerCase();
              String t2 = ((RegistryEntry) o2).getName().toLowerCase();

              return t1.compareTo(t2);
            }
          });

      PortletSessionState.setAttribute(portlet, rundata, RESULTS, regEntries);

      filteredEntries = filter(regEntries, filterFields, filterValues);
      PortletSessionState.setAttribute(portlet, rundata, FILTERED_RESULTS, filteredEntries);
    }

    if (filterFields != null
        && filterValues != null
        && filterFields.length == filterValues.length) {
      for (int i = 0; i < filterFields.length; i++) {
        String field = filterFields[i];
        String value = filterValues[i];

        context.put(field + "_filter_value", value);
      }
    }

    int end = start + size;
    if (end > filteredEntries.size()) {
      end = filteredEntries.size();
    }
    List pageEntries = filteredEntries.subList(start, end);

    context.put("registry", pageEntries);
    context.put("filtered_entries", filteredEntries);
    if (start > 0) {
      context.put("prev", String.valueOf(prev));
    }
    if (end < filteredEntries.size()) {
      context.put("next", String.valueOf(end));
    }
  }
  /**
   * Sort the quotes.
   *
   * @param portlet The jsp-based portlet that is being built.
   * @param rundata The turbine rundata context for this request.
   */
  public void doEmail(RunData rundata, Portlet portlet) {
    StringBuffer emailBody = new StringBuffer();
    PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());
    Iterator i = entry.getParameterNames();

    while (i.hasNext()) {
      String name = (String) i.next();
      Parameter param = entry.getParameter(name);
      if (param.isHidden() == false) {
        String title = param.getTitle();
        String value = portlet.getPortletConfig().getInitParameter(name);
        value = value == null || value.length() == 0 ? "NOT PROVIDED" : value;
        emailBody.append(title);
        emailBody.append(" ===> ");
        emailBody.append(value);
        emailBody.append("\n\n");
      }
    }

    String emailSmtp = JetspeedResources.getString(JetspeedResources.MAIL_SERVER_KEY);
    String emailFrom = JetspeedResources.getString("mail.support", "*****@*****.**");
    String emailTo =
        rundata.getParameters().getString("emailTo", "*****@*****.**");
    String emailAttachment = rundata.getRequest().getParameter("emailAttachment");
    try {
      String emailText = emailBody.toString();

      // Create the JavaMail session
      java.util.Properties properties = System.getProperties();
      properties.put("mail.smtp.host", emailSmtp);
      Session emailSession = Session.getInstance(properties, null);

      // Construct the message
      MimeMessage message = new MimeMessage(emailSession);

      // Set the from address
      Address fromAddress = new InternetAddress(emailFrom);
      message.setFrom(fromAddress);

      // Parse and set the recipient addresses
      Address[] toAddresses = InternetAddress.parse(emailTo);
      message.setRecipients(Message.RecipientType.TO, toAddresses);

      // Set the subject and text
      message.setSubject("Jetspeed Questionnaire from " + rundata.getUser().getEmail());
      message.setText(emailText);

      // Attach file with message
      if (emailAttachment != null) {
        File file = new File(emailAttachment);
        if (file.exists()) {
          // create and fill the first message part
          MimeBodyPart mbp1 = new MimeBodyPart();
          mbp1.setText(emailText);

          // create the second message part
          MimeBodyPart mbp2 = new MimeBodyPart();

          // attach the file to the message
          FileDataSource fds = new FileDataSource(emailAttachment);
          mbp2.setDataHandler(new DataHandler(fds));
          mbp2.setFileName(fds.getName());

          // create the Multipart and its parts to it
          Multipart mp = new MimeMultipart();
          mp.addBodyPart(mbp1);
          mp.addBodyPart(mbp2);

          // add the Multipart to the message
          message.setContent(mp);
        } else {
          message.setText(emailBody.toString());
        }
      }

      // send the message
      Transport.send(message);

      // Display confirmation
      rundata.getRequest().setAttribute("email", emailBody.toString());
      String confirmTemplate =
          portlet
              .getPortletConfig()
              .getInitParameter("confirm.template", "JetspeedQuestionnaireConfirmation.jsp");
      // this.setTemplate(rundata, portlet, confirmTemplate);
      setTemplate(rundata, confirmTemplate, true);

      rundata.setMessage("Email successfully sent");
    } catch (Exception e) {
      logger.error("Exception", e);
      rundata.setMessage("Error sending email: " + e);
    }

    // buildNormalContext(portlet, rundata);

  }