コード例 #1
0
 public void generarArchivo() {
   String salida = "nombres";
   System.out.println("tamanho " + contenido.size());
   for (int x = 0; x < contenido.size(); x++) {
     salida += "\n" + contenido.get(x).getNombre();
   }
   salida += "\nimagenes";
   for (int x = 0; x < contenido.size(); x++) {
     salida += "\n" + contenido.get(x).getDirImagen();
   }
   salida += "\nsonidos";
   for (int x = 0; x < contenido.size(); x++) {
     salida += "\n" + contenido.get(x).getDirSonido();
   }
   // crear archivo de texto
   try {
     ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
     File file =
         new File(extContext.getRealPath("//resources//txtLecciones//" + nombreLeccion + ".txt"));
     // if file doesnt exists, then create it
     if (!file.exists()) {
       file.createNewFile();
     }
     FileWriter fw = new FileWriter(file.getAbsoluteFile());
     BufferedWriter bw = new BufferedWriter(fw);
     bw.write(salida);
     bw.close();
     System.out.println("Done");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
  @Override
  public Object getConvertedValue(
      FacesContext context, UIComponent component, Object submittedValue)
      throws ConverterException {
    String coords = (String) submittedValue;

    if (isValueBlank(coords)) {
      return null;
    }

    String[] cropCoords = coords.split("_");

    int x = (int) Double.parseDouble(cropCoords[0]);
    int y = (int) Double.parseDouble(cropCoords[1]);
    int w = (int) Double.parseDouble(cropCoords[2]);
    int h = (int) Double.parseDouble(cropCoords[3]);

    ImageCropper cropper = (ImageCropper) component;
    Resource resource = getImageResource(context, cropper);
    InputStream inputStream;
    String imagePath = cropper.getImage();
    String contentType = null;

    try {

      if (resource != null && !"RES_NOT_FOUND".equals(resource.toString())) {
        inputStream = resource.getInputStream();
        contentType = resource.getContentType();
      } else {

        boolean isExternal = imagePath.startsWith("http");

        if (isExternal) {
          URL url = new URL(imagePath);
          URLConnection urlConnection = url.openConnection();
          inputStream = urlConnection.getInputStream();
          contentType = urlConnection.getContentType();
        } else {
          ExternalContext externalContext = context.getExternalContext();
          File file = new File(externalContext.getRealPath("") + imagePath);
          inputStream = new FileInputStream(file);
        }
      }

      BufferedImage outputImage = ImageIO.read(inputStream);
      inputStream.close();
      BufferedImage cropped = outputImage.getSubimage(x, y, w, h);
      ByteArrayOutputStream croppedOutImage = new ByteArrayOutputStream();
      String format = guessImageFormat(contentType, imagePath);
      ImageIO.write(cropped, format, croppedOutImage);

      return new CroppedImage(cropper.getImage(), croppedOutImage.toByteArray(), x, y, w, h);
    } catch (IOException e) {
      throw new ConverterException(e);
    }
  }
コード例 #3
0
  private BufferedImage getSourceImage(FacesContext context, String imagePath) throws IOException {
    BufferedImage outputImage = null;
    boolean isExternal = imagePath.startsWith("http");

    if (isExternal) {
      URL url = new URL(imagePath);

      outputImage = ImageIO.read(url);
    } else {
      ExternalContext externalContext = context.getExternalContext();

      outputImage = ImageIO.read(new File(externalContext.getRealPath("") + imagePath));
    }

    return outputImage;
  }
コード例 #4
0
  public void preProcessPDF(Object document)
      throws IOException, BadElementException, DocumentException {
    String sep = File.separator;
    Document pdf = (Document) document;
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    Map<String, String> params =
        FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

    String logo =
        extContext.getRealPath(
            "resources" + sep + "images" + sep + "LogoEncabezadoLiquidacion2.png");
    String titulo = params.get("titulo");

    pdf.open();
    pdf.setPageSize(PageSize.A4);
    pdf.addTitle(titulo);
    pdf.add(Image.getInstance(logo));
  }
コード例 #5
0
  /**
   * @param contexto
   * @param directorioReporte
   * @param nombreReporte
   * @return
   * @throws JRException
   */
  public boolean compilaReporte(
      ExternalContext contexto, String directorioReporte, String nombreReporte) throws JRException {
    String reporteJasper = contexto.getRealPath(directorioReporte + nombreReporte + ".jasper");
    File archivoJasper = new File(reporteJasper);

    if (archivoJasper.exists()) {
      return true;
    }
    try {
      compila(contexto, directorioReporte);
      String archivoJRXML = reporteJasper.substring(0, reporteJasper.indexOf(".jasper")) + ".jrxml";
      JasperCompileManager.compileReportToFile(archivoJRXML);
      return true;
    } catch (JRException e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #6
0
  public void listadoMarcasPDF(Object document)
      throws IOException, BadElementException, DocumentException {

    Font fuenteNegra18 = new Font(Font.TIMES_ROMAN, 18, Font.BOLD, Color.BLACK);

    Paragraph titulo = new Paragraph();
    titulo.add(new Paragraph("Listado de Marcas de vehiculos en el Sistema ", fuenteNegra18));
    agregarLineasEnBlanco(titulo, 2);
    titulo.setAlignment(Element.ALIGN_CENTER);
    String sep = File.separator;
    Document pdf = (Document) document;
    pdf.open();
    pdf.setPageSize(PageSize.A4);
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    String logo = extContext.getRealPath("resources" + sep + "images" + sep + "transacciones.png");
    pdf.addTitle("Usuarios");
    pdf.add(Image.getInstance(logo));
    pdf.add(titulo);
  }
コード例 #7
0
 /**
  * @param contexto
  * @param pathReporte
  */
 private void compila(ExternalContext contexto, String pathReporte) {
   System.setProperty("jasper.reports.compile.temp", contexto.getRealPath(pathReporte));
 }