示例#1
0
 /**
  * metodo che stampa il titolo di un campionato
  *
  * @param champ campionato
  * @param doc documento su cui stampare
  * @throws DocumentException
  */
 private void printChampTitle(ChampionshipEntity champ, Document doc) throws DocumentException {
   doc.add(
       new Phrase(
           new Chunk(
               "\nCampionato " + champ.getName(),
               FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD))));
 }
示例#2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Logger logger = GenericUtilities.checkLoggedIn(request, response, false);
    String todo = request.getParameter("todo");
    if (todo != null && todo.equals("printPDF")) {
      // --- stampa PDF ---
      Document doc = new Document();
      File file = new File("filePDF_" + logger.getUser().getId() + ".pdf");
      FileOutputStream os = new FileOutputStream(file);
      String str = file.getAbsolutePath();
      Boolean printTeams = request.getParameter("hire") != null;
      Boolean printMatches = request.getParameter("match") != null;
      Boolean printChampResults = request.getParameter("champ") != null;
      try {

        // campionati a cui l'utente partecipa
        List<ChampionshipEntity> cl =
            MySQLConnection.getChampionshipOfUser(logger.getUser().getId());
        // apri il documento PDF
        PdfWriter.getInstance(doc, os);
        doc.open();
        doc.add(
            new Phrase(
                new Chunk(
                    "Fantaservlet: utente " + logger.getUser().getName(),
                    FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD))));
        // per ogni campionato
        for (Iterator<ChampionshipEntity> it = cl.iterator(); it.hasNext(); ) {
          ChampionshipEntity champ = it.next();
          printChampTitle(champ, doc);

          // --- stampa le rose di calciatori ---
          if (printTeams) {
            // prendi la lista delle squadre
            List<TeamEntity> teams = MySQLConnection.getTeamsOfChampionship(champ.getId());
            for (Iterator<TeamEntity> it2 = teams.iterator(); it2.hasNext(); ) {
              TeamEntity team = it2.next();
              printHiring(
                  GenericUtilities.getPlayersListByRule(
                      MySQLConnection.getHiring(team.getId()), 'D'),
                  GenericUtilities.getPlayersListByRule(
                      MySQLConnection.getHiring(team.getId()), 'C'),
                  GenericUtilities.getPlayersListByRule(
                      MySQLConnection.getHiring(team.getId()), 'A'),
                  GenericUtilities.getPlayersListByRule(
                      MySQLConnection.getHiring(team.getId()), 'P'),
                  team,
                  doc);
            }
          }

          if (printMatches || printChampResults) {
            // prendi la lista degli scontri
            List<Match> lm = GenericUtilities.getListOfMatches(champ.getId());
            if (lm.size() > 0) {
              // --- stampa le partite del campionato ---
              if (printMatches) {
                printMatches(lm, GenericUtilities.getNumOfTeams(lm), doc);
              }
              // --- stampa la classifica ---
              if (printChampResults) {
                printRanking(GenericUtilities.getRanking(lm), GenericUtilities.isConcluse(lm), doc);
              }
            }
          }
        }
      } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SQLException sqle) {
        // TODO errore SQL

      } finally {
        // chiudi documento PDF
        doc.close();
      }
      // stampa il pdf
      doDownload(request, response, str, "filepdf");
    } else {
      // --- stamp pagina e form ---
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println(Style.pageHeader(TITLE));

      out.println("<form action=\"PrintPDF\" method=\"POST\">");
      out.println("<input type=\"checkbox\"/ name=\"hire\" checked>Dati squadre<br/>");
      out.println("<input type=\"checkbox\" name=\"match\"/ checked>Risultati partite<br/>");
      out.println(
          "<input type=\"checkbox\" name=\"champ\"/ checked>Classifiche dei campionati<br/><br/>");
      out.println(Style.hidden("todo", "printPDF"));
      out.println("<input type=\"submit\"/>");
      out.println("</form>");
      out.println(Style.pageFooter());
    }
  }