/**
  * @param req The request.
  * @return The query string of the request in its raw (not URI-encoded) form. This is suitable for
  *     passing as the 'query' parameter to one of the multi-argument {@link URI} constructors.
  */
 private static String getQueryString(HttpServletRequest req) throws UnsupportedEncodingException {
   StringBuilder buf = new StringBuilder();
   Map<String, String[]> params = req.getParameterMap();
   if (params.size() == 0) return null;
   for (Entry<String, String[]> entry : params.entrySet()) {
     String name = entry.getKey();
     String[] values = entry.getValue();
     if (values.length == 0) {
       buf.append("&").append(name);
     } else {
       for (String value : values) {
         buf.append("&").append(name).append("=").append(value);
       }
     }
   }
   return buf.substring(1);
 }
Пример #2
0
  public Integer getSessionCount() throws IOException {
    Integer res = null;

    {
      synchronized (lookupSessionById) {
        res = lookupSessionById.size();
      }
    }

    return res;
  }
  /**
   * Parses HTTP parameters in an appropriate format and return back map of values to predefined
   * list of names.
   *
   * @param req Request.
   * @return Map of parsed parameters.
   */
  @SuppressWarnings({"unchecked"})
  private Map<String, Object> parameters(ServletRequest req) {
    Map<String, String[]> params = req.getParameterMap();

    if (F.isEmpty(params)) return Collections.emptyMap();

    Map<String, Object> map = U.newHashMap(params.size());

    for (Map.Entry<String, String[]> entry : params.entrySet())
      map.put(entry.getKey(), parameter(entry.getValue()));

    return map;
  }
Пример #4
0
  public static synchronized void sessionCreated(HttpSessionEvent ev) {
    HttpSession httpSession = ev.getSession();
    String id = httpSession.getId();

    // Remember HTTP-session:
    {
      lookupHttpSessionById.put(id, httpSession);
    }

    AbstractSession session = null;

    synchronized (lookupSessionById) {
      session = lookupSessionById.get(id);
    }

    if (session == null) {
      Principal userPrincipal = null;
      Date timeCreation = new Date(httpSession.getCreationTime());
      Date timeLastAccess = new Date(httpSession.getLastAccessedTime());
      List<String> urisForLastRequests = null;
      Properties properties = null;

      session =
          new DefaultSession(
              id, userPrincipal, timeCreation, timeLastAccess, urisForLastRequests, properties);

      synchronized (lookupSessionById) {
        lookupSessionById.put(id, session);

        // Update 'sessionCountMax':
        {
          int sessionCount = lookupSessionById.size();
          if (sessionCount > sessionCountMax) {
            sessionCountMax = sessionCount;
            sessionCountMaxTime = System.currentTimeMillis();
          }
        }
      }
    }
  }
Пример #5
0
  public Properties getProperties() throws IOException {
    Properties res = null;

    {
      res = super.getProperties();

      if (res == null) {
        res = new Properties();
      }

      Integer sessionCount = null;
      Integer sessionCountMax = null;
      Long sessionCountMaxTime = null;

      synchronized (lookupSessionById) {
        sessionCount = lookupSessionById.size();
        sessionCountMax = this.sessionCountMax;
        sessionCountMaxTime = this.sessionCountMaxTime;
      }

      if (sessionCount != null) {
        res.setProperty("session.count", Integer.toString(sessionCount));
      }

      if (sessionCountMax != null) {
        res.setProperty("session.count-max", Integer.toString(sessionCountMax));
      }

      if (sessionCountMaxTime != null) {
        String sessionCountMaxTimeText =
            ApplicationConstants.FORMAT_DATE.format(sessionCountMaxTime);
        res.setProperty("session.count-max.timestamp", sessionCountMaxTimeText);
      }
    }

    return res;
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n\n\n\n\n");

      boolean exportUsers = request.getParameter("exportUsers") != null;
      boolean success = request.getParameter("success") != null;
      boolean exportToFile = ParamUtils.getBooleanParameter(request, "exporttofile", true);

      ImportExportPlugin plugin =
          (ImportExportPlugin)
              XMPPServer.getInstance().getPluginManager().getPlugin("userimportexport");

      String exportText = "";

      Map<String, String> errors = new HashMap<String, String>();
      if (exportUsers) {
        if (exportToFile) {
          String file = ParamUtils.getParameter(request, "exportFile");
          if ((file == null) || (file.length() <= 0)) {
            errors.put("missingFile", "missingFile");
          } else {
            response.sendRedirect("export-file.jsp?fileName=" + file);
          }
        } else {
          try {
            exportText = plugin.exportUsersToString();
          } catch (IOException e) {
            errors.put("IOException", "IOException");
          }
        }
      }

      out.write(
          "\n\n<html>\n    <head>\n        <title>Export User Data</title>\n        <meta name=\"pageID\" content=\"import-export-selection\"/>\n    </head>\n    <body>\n\n");
      if (errors.size() > 0) {
        out.write(
            "\n\n    <div class=\"jive-error\">\n    <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n    <tbody>\n        <tr>\n            <td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\"></td>\n            <td class=\"jive-icon-label\">\n            ");
        if (errors.containsKey("missingFile")) {
          out.write("\n                Missing or bad file name.\n            ");
        } else if (errors.containsKey("IOException") || errors.containsKey("fileNotCreated")) {
          out.write("\n                Couldn't create export file.\n            ");
        }
        out.write(
            "\n            </td>\n        </tr>\n    </tbody>\n    </table>\n    </div>\n    <br>\n\n");
      } else if (ParamUtils.getBooleanParameter(request, "success")) {
        out.write(
            "\n\n    <div class=\"jive-success\">\n    <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n    <tbody>\n        <tr>\n            <td class=\"jive-icon\"><img src=\"images/success-16x16.gif\" width=\"16\" height=\"16\" border=\"0\"></td>\n            <td class=\"jive-icon-label\">User data successfully exported.</td>\n        </tr>\n    </tbody>\n    </table>\n    </div>\n    <br>\n    \n");
      }
      out.write(
          "\n\n<form action=\"export-user-data.jsp?exportUsers\" method=\"post\">\n\n<div class=\"jive-contentBoxHeader\">Export Options</div>\n<div class=\"jive-contentBox\">\n    <p>\n    Select the radio button next to the desired export option and then click on the Export button.\n    </p>\n    \n    <table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n    <tbody>\n        <tr>\n            <td width=\"1%\"><input type=\"radio\" name=\"exporttofile\" value=\"true\" ");
      out.print(exportToFile ? "checked" : "");
      out.write(
          " id=\"rb01\"></td>\n            <td width=\"99%\"><label for=\"rb01\"><b>To File</b></label> - Save user data to the specified file location.</td>\n        </tr>\n        <tr>\n            <td width=\"1%\">&nbsp;</td>\n            <td width=\"99%\">Export File Name:&nbsp;<input type=\"text\" size=\"30\" maxlength=\"150\" name=\"exportFile\"></td>\n        </tr>\n        <tr>\n            <td width=\"1%\"><input type=\"radio\" name=\"exporttofile\" value=\"false\" ");
      out.print(!exportToFile ? "checked" : "");
      out.write(
          " id=\"rb02\"></td>\n            <td width=\"99%\"><label for=\"rb02\"><b>To Screen</b></label> - Display user data in the text area below.</td>            \n        </tr>\n        <tr>\n            <td width=\"1%\">&nbsp;</td>\n            <td width=\"99%\"><textarea cols=\"80\" rows=\"20\" wrap=off>");
      out.print(exportText);
      out.write(
          "</textarea></td>\n        </tr>\n    </tbody>\n    </table>\n</div>\n\n<input type=\"submit\" value=\"Export\">\n</form>\n\n</body>\n</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext =
          _jspxFactory.getPageContext(this, request, response, "error.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n\n\n\n\n\n\n\n\n");
      out.write('\n');
      org.jivesoftware.util.WebManager webManager = null;
      synchronized (_jspx_page_context) {
        webManager =
            (org.jivesoftware.util.WebManager)
                _jspx_page_context.getAttribute("webManager", PageContext.PAGE_SCOPE);
        if (webManager == null) {
          webManager = new org.jivesoftware.util.WebManager();
          _jspx_page_context.setAttribute("webManager", webManager, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\n');
      webManager.init(request, response, session, application, out);
      out.write('\n');
      out.write('\n');
      // Get paramters
      boolean doTest = request.getParameter("test") != null;
      boolean cancel = request.getParameter("cancel") != null;
      boolean sent = ParamUtils.getBooleanParameter(request, "sent");
      boolean success = ParamUtils.getBooleanParameter(request, "success");
      String from = ParamUtils.getParameter(request, "from");
      String to = ParamUtils.getParameter(request, "to");
      String subject = ParamUtils.getParameter(request, "subject");
      String body = ParamUtils.getParameter(request, "body");

      // Cancel if requested
      if (cancel) {
        response.sendRedirect("system-email.jsp");
        return;
      }

      // Variable to hold messaging exception, if one occurs
      Exception mex = null;

      // Validate input
      Map<String, String> errors = new HashMap<String, String>();
      if (doTest) {
        if (from == null) {
          errors.put("from", "");
        }
        if (to == null) {
          errors.put("to", "");
        }
        if (subject == null) {
          errors.put("subject", "");
        }
        if (body == null) {
          errors.put("body", "");
        }

        EmailService service = EmailService.getInstance();

        // Validate host - at a minimum, it needs to be set:
        String host = service.getHost();
        if (host == null) {
          errors.put("host", "");
        }

        // if no errors, continue
        if (errors.size() == 0) {
          // Create a message
          MimeMessage message = service.createMimeMessage();
          // Set the date of the message to be the current date
          SimpleDateFormat format =
              new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", java.util.Locale.US);
          format.setTimeZone(JiveGlobals.getTimeZone());
          message.setHeader("Date", format.format(new Date()));

          // Set to and from.
          message.setRecipient(Message.RecipientType.TO, new InternetAddress(to, null));
          message.setFrom(new InternetAddress(from, null));
          message.setSubject(subject);
          message.setText(body);
          // Send the message, wrap in a try/catch:
          try {
            service.sendMessagesImmediately(Collections.singletonList(message));
            // success, so indicate this:
            response.sendRedirect("system-emailtest.jsp?sent=true&success=true");
            return;
          } catch (MessagingException me) {
            me.printStackTrace();
            mex = me;
          }
        }
      }

      // Set var defaults
      Collection<JID> jids = webManager.getXMPPServer().getAdmins();
      User user = null;
      if (!jids.isEmpty()) {
        for (JID jid : jids) {
          if (webManager.getXMPPServer().isLocal(jid)) {
            user = webManager.getUserManager().getUser(jid.getNode());
            if (user.getEmail() != null) {
              break;
            }
          }
        }
      }
      if (from == null) {
        from = user.getEmail();
      }
      if (to == null) {
        to = user.getEmail();
      }
      if (subject == null) {
        subject = "Test email sent via Openfire";
      }
      if (body == null) {
        body = "This is a test message.";
      }

      out.write("\n\n<html>\n    <head>\n        <title>");
      if (_jspx_meth_fmt_message_0(_jspx_page_context)) return;
      out.write(
          "</title>\n        <meta name=\"pageID\" content=\"system-email\"/>\n    </head>\n    <body>\n\n<script language=\"JavaScript\" type=\"text/javascript\">\nvar clicked = false;\nfunction checkClick(el) {\n    if (!clicked) {\n        clicked = true;\n        return true;\n    }\n    return false;\n}\n</script>\n\n<p>\n");
      if (_jspx_meth_fmt_message_1(_jspx_page_context)) return;
      out.write("\n</p>\n\n");
      if (JiveGlobals.getProperty("mail.smtp.host") == null) {
        out.write(
            "\n\n    <div class=\"jive-error\">\n    <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n    <tbody>\n        <tr>\n        \t<td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n\t        <td class=\"jive-icon-label\">\n\t\t        ");
        if (_jspx_meth_fmt_message_2(_jspx_page_context)) return;
        out.write("\n\t        </td>\n        </tr>\n    </tbody>\n    </table>\n    </div>\n\n");
      }
      out.write('\n');
      out.write('\n');
      if (doTest || sent) {
        out.write("\n\n    ");
        if (success) {
          out.write(
              "\n\n        <div class=\"jive-success\">\n        <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n        <tbody>\n            <tr>\n            \t<td class=\"jive-icon\"><img src=\"images/success-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n            \t<td class=\"jive-icon-label\">");
          if (_jspx_meth_fmt_message_3(_jspx_page_context)) return;
          out.write(
              "</td>\n            </tr>\n        </tbody>\n        </table>\n        </div>\n\n    ");
        } else {
          out.write(
              "\n\n        <div class=\"jive-error\">\n        <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n        <tbody>\n            <tr><td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n            <td class=\"jive-icon-label\">\n                ");
          if (_jspx_meth_fmt_message_4(_jspx_page_context)) return;
          out.write("\n                ");
          if (mex != null) {
            out.write("\n                    ");
            if (mex instanceof AuthenticationFailedException) {
              out.write("\n                    \t");
              if (_jspx_meth_fmt_message_5(_jspx_page_context)) return;
              out.write("                        \n                    ");
            } else {
              out.write("\n                        (Message: ");
              out.print(mex.getMessage());
              out.write(")\n                    ");
            }
            out.write("\n                ");
          }
          out.write(
              "\n            </td></tr>\n        </tbody>\n        </table>\n        </div>\n\n    ");
        }
        out.write("\n\n    <br>\n\n");
      }
      out.write(
          "\n\n<form action=\"system-emailtest.jsp\" method=\"post\" name=\"f\" onsubmit=\"return checkClick(this);\">\n\n<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\">\n<tbody>\n    <tr>\n        <td>\n            ");
      if (_jspx_meth_fmt_message_6(_jspx_page_context)) return;
      out.write(":\n        </td>\n        <td>\n            ");
      String host = JiveGlobals.getProperty("mail.smtp.host");
      if (host == null) {

        out.write("\n                <i>");
        if (_jspx_meth_fmt_message_7(_jspx_page_context)) return;
        out.write("</i>\n            ");

      } else {

        out.write("\n                ");
        out.print(host);
        out.write(':');
        out.print(JiveGlobals.getIntProperty("mail.smtp.port", 25));
        out.write("\n\n                ");
        if (JiveGlobals.getBooleanProperty("mail.smtp.ssl", false)) {
          out.write("\n\n                    (");
          if (_jspx_meth_fmt_message_8(_jspx_page_context)) return;
          out.write(")\n\n                ");
        }
        out.write("\n            ");
      }
      out.write("\n        </td>\n    </tr>\n    <tr>\n        <td>\n            ");
      if (_jspx_meth_fmt_message_9(_jspx_page_context)) return;
      out.write(
          ":\n        </td>\n        <td>\n            <input type=\"hidden\" name=\"from\" value=\"");
      out.print(from);
      out.write("\">\n            ");
      out.print(StringUtils.escapeHTMLTags(from));
      out.write(
          "\n            <span class=\"jive-description\">\n            (<a href=\"user-edit-form.jsp?username="******"\">Update Address</a>)\n            </span>\n        </td>\n    </tr>\n    <tr>\n        <td>\n            ");
      if (_jspx_meth_fmt_message_10(_jspx_page_context)) return;
      out.write(
          ":\n        </td>\n        <td>\n            <input type=\"text\" name=\"to\" value=\"");
      out.print(((to != null) ? to : ""));
      out.write(
          "\"\n             size=\"40\" maxlength=\"100\">\n        </td>\n    </tr>\n    <tr>\n        <td>\n            ");
      if (_jspx_meth_fmt_message_11(_jspx_page_context)) return;
      out.write(
          ":\n        </td>\n        <td>\n            <input type=\"text\" name=\"subject\" value=\"");
      out.print(((subject != null) ? subject : ""));
      out.write(
          "\"\n             size=\"40\" maxlength=\"100\">\n        </td>\n    </tr>\n    <tr valign=\"top\">\n        <td>\n            ");
      if (_jspx_meth_fmt_message_12(_jspx_page_context)) return;
      out.write(
          ":\n        </td>\n        <td>\n            <textarea name=\"body\" cols=\"45\" rows=\"5\" wrap=\"virtual\">");
      out.print(body);
      out.write(
          "</textarea>\n        </td>\n    </tr>\n    <tr>\n        <td colspan=\"2\">\n            <br>\n            <input type=\"submit\" name=\"test\" value=\"");
      if (_jspx_meth_fmt_message_13(_jspx_page_context)) return;
      out.write("\">\n            <input type=\"submit\" name=\"cancel\" value=\"");
      if (_jspx_meth_fmt_message_14(_jspx_page_context)) return;
      out.write(
          "\">\n        </td>\n    </tr>\n</tbody>\n</table>\n\n</form>\n\n    </body>\n</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
Пример #8
0
  public static String getSimplePieChart(Map dataSource, String objectName, HttpSession session)
      throws Throwable {
    DefaultPieDataset dataset = new DefaultPieDataset();

    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    String title = chartObject.getAttributeValue("title");

    int width = Integer.parseInt(chartObject.getAttributeValue("width"));
    int height = Integer.parseInt(chartObject.getAttributeValue("height"));

    Element LabelKeys = chartObject.getChild("Labels");
    Element ValueKeys = chartObject.getChild("Values");

    String valueKey = ValueKeys.getText();
    String valueType = ValueKeys.getAttributeValue("type");
    List labelKeys = LabelKeys.getChildren("Label");
    String labelKey = LabelKeys.getText();

    if (valueType.equalsIgnoreCase("number")) {
      for (int i = 0; i < dataSource.size(); i++) {
        Map rec = (Map) dataSource.get("ROW" + i);
        Number value = (Number) rec.get(valueKey);
        String label;
        if (labelKeys.isEmpty()) {
          label = DataFilter.show(rec, labelKey);
        } else {
          label = ((Element) labelKeys.get(i)).getText();
        }
        dataset.setValue(label, value);
      }
    } else {
      for (int i = 0; i < dataSource.size(); i++) {
        Map rec = (Map) dataSource.get("ROW" + i);
        double value = (Double) rec.get(valueKey);
        String label;
        if (labelKeys.isEmpty()) {
          label = DataFilter.show(rec, labelKey);
        } else {
          label = ((Element) labelKeys.get(i)).getText();
        }
        dataset.setValue(label, value);
      }
    }

    JFreeChart chart =
        ChartFactory.createPieChart3D(
            title,
            dataset,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    PiePlot3D pie3dplot = (PiePlot3D) chart.getPlot();

    float alpha = 0.7F;
    if (chartObject.getAttribute("alpha") != null) {
      alpha = chartObject.getAttribute("alpha").getFloatValue();
    }
    pie3dplot.setForegroundAlpha(alpha);

    return ServletUtilities.saveChartAsPNG(chart, width, height, null, session);
  }
Пример #9
0
  public static String getBarSeries(Map dataSource, String objectName, HttpSession session)
      throws Exception {
    DefaultKeyedValues barValues = new DefaultKeyedValues();
    DefaultKeyedValues seriesValues = new DefaultKeyedValues();
    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    Element barField = chartObject.getChild("BarFields").getChild("Field");
    Element seriesField = chartObject.getChild("SeriesFields").getChild("Field");

    for (int i = 0; i < dataSource.size(); i++) {
      Map rec = (Map) dataSource.get("ROW" + i);
      barValues.addValue(
          DataFilter.show(rec, chartObject.getChildText("ColumnLabel")),
          Double.parseDouble(rec.get(barField.getAttributeValue("name")).toString()));
      seriesValues.addValue(
          DataFilter.show(rec, chartObject.getChildText("ColumnLabel")),
          Double.parseDouble(rec.get(seriesField.getAttributeValue("name")).toString()));
    }

    CategoryDataset dataset =
        DatasetUtilities.createCategoryDataset(barField.getAttributeValue("label"), barValues);

    PlotOrientation plotOrientation =
        chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL")
            ? PlotOrientation.VERTICAL
            : PlotOrientation.HORIZONTAL;
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            chartObject.getAttributeValue("title"),
            chartObject.getAttributeValue("categoryAxisLabel"),
            chartObject.getAttributeValue("valueAxisLabel"),
            dataset,
            plotOrientation,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    CategoryPlot categoryplot = chart.getCategoryPlot();
    LineRenderer3D lineRenderer = new LineRenderer3D();
    CategoryDataset datasetSeries =
        DatasetUtilities.createCategoryDataset(
            seriesField.getAttributeValue("label"), seriesValues);

    categoryplot.setDataset(1, datasetSeries);
    categoryplot.setRangeAxis(1, new NumberAxis3D(seriesField.getAttributeValue("label")));
    categoryplot.setRenderer(1, lineRenderer);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    BarRenderer3D barrenderer = (BarRenderer3D) categoryplot.getRenderer();
    barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    barrenderer.setPositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER));

    //	        lineRenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    //	        lineRenderer.setItemLabelsVisible(true);
    //	        lineRenderer.setPositiveItemLabelPosition(
    //	                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER));

    float alpha = 0.7F;
    if (chartObject.getAttribute("alpha") != null) {
      alpha = chartObject.getAttribute("alpha").getFloatValue();
    }
    categoryplot.setForegroundAlpha(alpha);

    int width, height;
    if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) {
      width = (50 * dataSource.size()) + 100;
    } else {
      width = Integer.parseInt(chartObject.getAttributeValue("width"));
    }
    if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) {
      height = (50 * dataSource.size()) + 100;
    } else {
      height = Integer.parseInt(chartObject.getAttributeValue("height"));
    }

    return ServletUtilities.saveChartAsPNG(chart, width, height, session);
  }
Пример #10
0
  public static String getSimpleBarChart(Map dataSource, String objectName, HttpSession session)
      throws Throwable {
    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    List invokeFields = chartObject.getChild("InvokeFields").getChildren("Field");
    double[][] data = new double[invokeFields.size()][dataSource.size()];
    String[] rowKeys = new String[invokeFields.size()];
    String[] columnKeys = new String[dataSource.size()];
    String columnLabel = chartObject.getChildText("ColumnLabel");

    for (int i = 0; i < dataSource.size(); i++) {
      Map rec = (Map) dataSource.get("ROW" + i);
      columnKeys[i] = DataFilter.show(rec, columnLabel);
      for (int j = 0; j < invokeFields.size(); j++) {
        data[j][i] =
            Double.parseDouble(
                rec.get(((Element) invokeFields.get(j)).getAttributeValue("name")).toString());
      }
    }
    for (int i = 0; i < invokeFields.size(); i++) {
      rowKeys[i] = ((Element) invokeFields.get(i)).getAttributeValue("label");
    }

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

    PlotOrientation plotOrientation =
        chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL")
            ? PlotOrientation.VERTICAL
            : PlotOrientation.HORIZONTAL;
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            chartObject.getAttributeValue("title"),
            chartObject.getAttributeValue("categoryAxisLabel"),
            chartObject.getAttributeValue("valueAxisLabel"),
            dataset,
            plotOrientation,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    CategoryPlot C3dplot = (CategoryPlot) chart.getPlot();
    if (chartObject.getAttribute("alpha") != null) {
      C3dplot.setForegroundAlpha(chartObject.getAttribute("alpha").getFloatValue());
    }

    BarRenderer3D barrenderer = (BarRenderer3D) C3dplot.getRenderer();
    barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    barrenderer.setPositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER));

    int width, height;
    if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) {
      width = (50 * dataSource.size()) * invokeFields.size() + 100;
    } else {
      width = Integer.parseInt(chartObject.getAttributeValue("width"));
    }
    if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) {
      height = (50 * dataSource.size()) * invokeFields.size() + 100;
    } else {
      height = Integer.parseInt(chartObject.getAttributeValue("height"));
    }

    return ServletUtilities.saveChartAsPNG(chart, width, height, session);
  }