Esempio n. 1
0
  private void sendSubscriberNotification(
      String email, String code, String blogTitle, String virtualUser, String blogAccessCode) {

    String userLanguage = WebFileSys.getInstance().getUserMgr().getLanguage(virtualUser);

    try {
      String templateFilePath =
          WebFileSys.getInstance().getConfigBaseDir()
              + "/languages/blogChangeNotification_"
              + userLanguage
              + ".template";

      MailTemplate notificationTemplate = new MailTemplate(templateFilePath);

      notificationTemplate.setVarValue("BLOGTITLE", blogTitle);

      String blogURL =
          WebFileSys.getInstance().getClientUrl()
              + "/visitor/"
              + virtualUser
              + "/"
              + blogAccessCode;
      notificationTemplate.setVarValue("BLOGURL", blogURL);

      String unsubscribeURL =
          WebFileSys.getInstance().getClientUrl()
              + "/servlet?command=blog&cmd=unsubscribe&virtualUser="******"&email="
              + UTF8URLEncoder.encode(email)
              + "&code="
              + code;
      notificationTemplate.setVarValue("UNSUBSCRIBEURL", unsubscribeURL);

      String mailText = notificationTemplate.getText();

      String subject =
          LanguageManager.getInstance()
              .getResource(
                  userLanguage, "blog.subjectChangeNotification", "New entries in the Blog");

      (new SmtpEmail(email, subject, mailText)).send();

      Logger.getLogger(getClass())
          .info("blog subscriber notification mail sent to " + email + " for blog " + blogTitle);

    } catch (IllegalArgumentException iaex) {
      System.out.println(iaex);
    }
  }
  protected void process() {
    String imgFileName = getParameter("imgFile");

    if (!this.checkAccess(imgFileName)) {
      return;
    }

    Element cameraDataElement = doc.createElement("cameraData");

    doc.appendChild(cameraDataElement);

    ProcessingInstruction xslRef =
        doc.createProcessingInstruction(
            "xml-stylesheet", "type=\"text/xsl\" href=\"/webfilesys/xsl/cameraData.xsl\"");

    doc.insertBefore(xslRef, cameraDataElement);

    XmlUtil.setChildText(cameraDataElement, "css", userMgr.getCSS(uid), false);

    String shortImgName = CommonUtils.shortName(this.getHeadlinePath(imgFileName), 48);

    XmlUtil.setChildText(cameraDataElement, "shortImgName", shortImgName, false);

    addMsgResource("alt.cameradata", getResource("alt.cameradata", "Camera Data"));
    addMsgResource(
        "alert.nocameradata", getResource("alert.nocameradata", "No camera data available"));
    addMsgResource("label.picturefile", getResource("label.picturefile", "picture file"));
    addMsgResource("label.manufacturer", getResource("label.manufacturer", "camera manufacturer"));
    addMsgResource("label.cameramodel", getResource("label.cameramodel", "camera model"));
    addMsgResource("label.exposuredate", getResource("label.exposuredate", "exposure date"));
    addMsgResource("label.exposuretime", getResource("label.exposuretime", "exposure time"));
    addMsgResource("label.aperture", getResource("label.aperture", "aperture"));
    addMsgResource("label.isoValue", getResource("label.isoValue", "ISO equivalent"));
    addMsgResource("label.flashfired", getResource("label.flashfired", "flash fired"));
    addMsgResource("label.imgwidth", getResource("label.imgwidth", "image width"));
    addMsgResource("label.imgheight", getResource("label.imgheight", "image height"));
    addMsgResource("label.thumbexists", getResource("label.thumbexists", "thumbnail included"));
    addMsgResource("label.gpsLatitude", getResource("label.gpsLatitude", "GPS latitude"));
    addMsgResource("label.gpsLongitude", getResource("label.gpsLongitude", "GPS longitude"));
    addMsgResource("button.closewin", getResource("button.closewin", "Close Window"));

    CameraExifData exifData = new CameraExifData(imgFileName);

    if (exifData.hasExifData()) {
      Element exifDataElement = doc.createElement("exifData");

      cameraDataElement.appendChild(exifDataElement);

      String manufacturer = exifData.getManufacturer();

      if (manufacturer != null) {
        XmlUtil.setChildText(exifDataElement, "manufacturer", manufacturer);
      }

      String cameraModel = exifData.getCameraModel();

      if (cameraModel != null) {
        XmlUtil.setChildText(exifDataElement, "cameraModel", cameraModel);
      }

      Date exposureDate = exifData.getExposureDate();

      if (exposureDate != null) {
        SimpleDateFormat dateFormat = LanguageManager.getInstance().getDateFormat(language);

        String formattedDate = dateFormat.format(exposureDate);

        XmlUtil.setChildText(exifDataElement, "exposureDate", formattedDate);
      }

      String exposureTime = exifData.getExposureTime();

      if (exposureTime != null) {
        XmlUtil.setChildText(exifDataElement, "exposureTime", exposureTime);
      }

      String aperture = exifData.getAperture();

      if (aperture != null) {
        XmlUtil.setChildText(exifDataElement, "aperture", aperture);
      }

      String isoValue = exifData.getISOValue();

      if (isoValue != null) {
        XmlUtil.setChildText(exifDataElement, "isoValue", isoValue);
      }

      int flashFired = exifData.getFlashFired();

      if (flashFired >= 0) {
        if ((flashFired == 0) || (flashFired == 16) || (flashFired == 24) || (flashFired == 32)) {
          XmlUtil.setChildText(exifDataElement, "flashFired", getResource("label.no", "no"));
        } else {
          XmlUtil.setChildText(exifDataElement, "flashFired", getResource("label.yes", "yes"));
        }
      }

      int imageWidth = exifData.getImageWidth();

      if (imageWidth >= 0) {
        XmlUtil.setChildText(exifDataElement, "imgWidth", Integer.toString(imageWidth));
      }

      int imageHeight = exifData.getImageHeigth();

      if (imageHeight >= 0) {
        XmlUtil.setChildText(exifDataElement, "imgHeight", Integer.toString(imageHeight));
      }

      int thumbLength = exifData.getThumbnailLength();

      if (thumbLength > 0) {
        String srcFileName =
            "/webfilesys/servlet?command=exifThumb&imgFile=" + UTF8URLEncoder.encode(imgFileName);

        XmlUtil.setChildText(exifDataElement, "thumbnailPath", srcFileName);
      }

      int thumbWidth = exifData.getThumbWidth();
      int thumbHeight = exifData.getThumbHeight();

      if ((thumbWidth > 0) && (thumbHeight > 0)) {
        XmlUtil.setChildText(exifDataElement, "thumbnailWidth", Integer.toString(thumbWidth));
        XmlUtil.setChildText(exifDataElement, "thumbnailHeight", Integer.toString(thumbHeight));
      }

      float gpsLatitude = exifData.getGpsLatitude();

      if (gpsLatitude >= 0.0f) {
        XmlUtil.setChildText(
            exifDataElement,
            "gpsLatitude",
            Float.toString(gpsLatitude) + " " + exifData.getGpsLatitudeRef());
      }

      float gpsLongitude = exifData.getGpsLongitude();

      if (gpsLongitude >= 0.0f) {
        XmlUtil.setChildText(
            exifDataElement,
            "gpsLongitude",
            Float.toString(gpsLongitude) + " " + exifData.getGpsLongitudeRef());
      }

      int orientation = exifData.getOrientation();

      if (orientation != CameraExifData.ORIENTATION_UNKNOWN) {
        XmlUtil.setChildText(exifDataElement, "orientation", Integer.toString(orientation));

        addMsgResource("label.imgOrientation", getResource("label.imgOrientation", "orientation"));
        addMsgResource("orientation.landscape", getResource("orientation.landscape", "lanscape"));
        addMsgResource("orientation.portrait", getResource("orientation.portrait", "portrait"));
      }
    }

    this.processResponse("cameraData.xsl", false);
  }
  protected void process() {
    if (!checkWriteAccess()) {
      return;
    }

    String filePath = getParameter("filePath");

    if (!checkAccess(filePath)) {
      return;
    }

    output.println("<html>");
    output.println("<head>");

    output.println(
        "<link rel=\"stylesheet\" type=\"text/css\" href=\"/webfilesys/styles/common.css\">");
    output.println(
        "<link rel=\"stylesheet\" type=\"text/css\" href=\"/webfilesys/styles/skins/"
            + userMgr.getCSS(uid)
            + ".css\">");

    output.println("</head>");
    output.println("<body>");

    headLine(getResource("label.untarhead", "Extract from TAR archive"));

    output.println("<br/>");

    output.println("<form accept-charset=\"utf-8\" name=\"form1\">");

    output.println("<table class=\"dataForm\" width=\"100%\">");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm1\">");
    output.println(getResource("label.extractfrom", "extracting from") + ":");
    output.println("</td>");
    output.println("</tr>");
    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm2\">");
    output.println(this.getHeadlinePath(filePath));
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm1\">");
    output.println(getResource("label.currentzip", "current file") + ":");
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm2\">");
    output.println("<div id=\"currentFile\" />");
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm1\">");
    output.println(getResource("label.untarResult", "files extracted") + ":");
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm2\">");
    output.println("<div id=\"extractCount\" />");
    output.println("</td>");
    output.println("</tr>");

    boolean untarOkay = true;

    int untarNum = 0;

    boolean dirCreated = false;

    try {
      TarInputStream tarFile = new TarInputStream(new FileInputStream(filePath));

      TarEntry tarEntry = null;

      byte buff[] = new byte[4096];

      while ((tarEntry = tarFile.getNextEntry()) != null) {

        output.println("<script language=\"javascript\">");
        output.println(
            "document.getElementById('currentFile').innerHTML='"
                + CommonUtils.shortName(tarEntry.getName(), 45)
                + " ("
                + tarEntry.getSize()
                + " bytes)';");
        output.println("document.getElementById('extractCount').innerHTML='" + untarNum + "';");
        output.println("</script>");
        output.flush();

        File untarOutFile = createUntarFile(tarEntry.getName());

        if (!(untarOutFile.isDirectory())) {
          FileOutputStream destination = null;
          try {
            destination = new FileOutputStream(untarOutFile);

            boolean done = false;
            while (!done) {
              int bytesRead = tarFile.read(buff);

              if (bytesRead == -1) {
                done = true;
              } else {
                destination.write(buff, 0, bytesRead);
              }
            }

            destination.close();
          } catch (IOException ioex) {
            Logger.getLogger(getClass()).error("untar error in file " + untarOutFile, ioex);

            output.println("<font class=\"error\">");
            output.println(
                getResource("label.untarError", "Failed to extract from TAR archive")
                    + ": "
                    + untarOutFile);
            output.println("</font><br><br>");
            untarOkay = false;

            try {
              if (destination != null) {
                destination.close();
              }
              untarOutFile.delete();
            } catch (Exception ex) {
            }
          }

          untarNum++;
        } else {
          dirCreated = true;
        }
      }

      tarFile.close();
    } catch (IOException ioex) {
      Logger.getLogger(getClass()).error("failed to extract from tar archive", ioex);

      output.println("<font class=\"error\">");
      output.println(getResource("label.untarError", "Failed to extract from TAR archive"));
      output.println("</font><br><br>");
      untarOkay = false;
    }

    if (dirCreated) {
      TestSubDirThread subDirThread = new TestSubDirThread(getCwd());

      subDirThread.start();
    }

    String filenameWithoutPath = filePath.substring(filePath.lastIndexOf(File.separator) + 1);

    output.println("<script language=\"javascript\">");
    output.println("document.getElementById('extractCount').innerHTML='" + untarNum + "';");
    output.println("</script>");
    output.flush();

    String returnUrl = null;

    if (!untarOkay) {
      output.println("<tr>");
      output.println("<td colspan=\"2\" class=\"formButton\">");
      returnUrl = "/webfilesys/servlet?command=listFiles";
      output.println(
          "<input type=\"button\" value=\""
              + getResource("button.return", "Return")
              + "\" onclick=\"window.location.href='"
              + returnUrl
              + "'\">");
      output.println("</td>");
      output.println("</tr>");
    } else {
      output.println("<tr>");
      output.println("<td class=\"formButton\">");

      String mobile = (String) session.getAttribute("mobile");

      if (mobile != null) {
        returnUrl = "/webfilesys/servlet?command=mobile&cmd=folderFileList&keepListStatus=true";
      } else {
        returnUrl = "/webfilesys/servlet?command=listFiles&keepListStatus=true";
      }
      output.print(
          "<input type=\"button\" value=\""
              + getResource("button.keepTarArchive", "keep TAR archive")
              + "\" onclick=\"");

      if ((mobile == null) && (dirCreated)) {
        output.print(
            "window.parent.frames[1].location.href='/webfilesys/servlet?command=refresh&path="
                + UTF8URLEncoder.encode(getCwd())
                + "';");
      }
      output.println("window.location.href='" + returnUrl + "'\">");

      output.println("</td>");

      output.println("<td class=\"formButton\" style=\"text-align:right\">");

      returnUrl =
          "/webfilesys/servlet?command=fmdelete&fileName="
              + UTF8URLEncoder.encode(filenameWithoutPath)
              + "&deleteRO=no";
      output.print(
          "<input type=\"button\" value=\""
              + getResource("button.delTarArchive", "delete TAR archive")
              + "\" onclick=\"");

      if ((mobile == null) && (dirCreated)) {
        output.print(
            "window.parent.frames[1].location.href='/webfilesys/servlet?command=refresh&path="
                + UTF8URLEncoder.encode(getCwd())
                + "';");
      }

      output.println("window.location.href='" + returnUrl + "'\">");

      output.println("</td>");
      output.println("</tr>");

      if (WebFileSys.getInstance().isAutoCreateThumbs()) {
        if (dirCreated) {
          AutoThumbnailCreator.getInstance().queuePath(getCwd(), AutoThumbnailCreator.SCOPE_TREE);
        } else {
          AutoThumbnailCreator.getInstance().queuePath(getCwd(), AutoThumbnailCreator.SCOPE_DIR);
        }
      }
    }

    output.println("</table>");

    output.println("</form>");

    output.print("</body>");
    output.println("</html>");
    output.flush();
  }