예제 #1
0
  protected void process() {
    if (!checkWriteAccess()) {
      return;
    }

    String path = getParameter("path");

    if (!accessAllowed(path)) {
      Logger.getLogger(getClass())
          .warn("user " + uid + " tried to access folder outside of his document root: " + path);

      return;
    }

    String shortPath = CommonUtils.shortName(getHeadlinePath(path), 50);

    Element folderWatchElement = doc.createElement("folderWatch");

    doc.appendChild(folderWatchElement);

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

    doc.insertBefore(xslRef, folderWatchElement);

    XmlUtil.setChildText(folderWatchElement, "css", userMgr.getCSS(uid), false);
    XmlUtil.setChildText(folderWatchElement, "path", path.replace('\\', '/'), false);
    XmlUtil.setChildText(folderWatchElement, "shortPath", shortPath, false);

    if (FolderWatchManager.getInstance().isListener(path, uid)) {
      XmlUtil.setChildText(folderWatchElement, "watched", "true");
    }

    addMsgResource(
        "label.readWriteStatus", getResource("label.readWriteStatus", "Read/Write status"));

    addMsgResource(
        "folderWatchStatusOn",
        getResource(
            "folderWatchStatusOn", "The content of the folder is being watched for changes."));
    addMsgResource(
        "folderWatchStatusOff",
        getResource(
            "folderWatchStatusOff", "Watch this folder for changes and get notified by e-mail."));

    addMsgResource("button.startWatch", getResource("button.startWatch", "start watch"));
    addMsgResource("button.stopWatch", getResource("button.stopWatch", "stop watch"));

    addMsgResource("button.cancel", getResource("button.cancel", "Cancel"));

    processResponse();
  }
예제 #2
0
  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);
  }
예제 #3
0
  protected void process() {
    String actPath = getParameter("actPath");

    if ((actPath == null) || (actPath.trim().length() == 0)) {
      actPath = getCwd();
    }

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

    String ftpServerName = getParameter("ftpServerName");

    if (ftpServerName == null) {
      ftpParamForm(null);

      return;
    }

    StringBuffer alertText = new StringBuffer();

    if (ftpServerName.trim().length() == 0) {
      alertText.append(
          getResource("alert.missingFtpServer", "FTP Server is a required field") + "\\n");
    }

    String userid = getParameter("userid");

    if (userid.trim().length() == 0) {
      alertText.append(getResource("alert.missingFtpUserid", "Userid is a required field") + "\\n");
    }

    String password = getParameter("password");

    if (password.trim().length() == 0) {
      alertText.append(
          getResource("alert.missingFtpPassword", "Password is a required field") + "\\n");
    }

    String remoteDir = getParameter("remoteDir");

    if (alertText.length() > 0) {
      ftpParamForm(alertText.toString());

      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.ftpBackupHead", "Backup to FTP Server"));

    output.println("<br>");

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

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

    output.println("<tr><td class=\"formParm1\">");
    output.println(getResource("label.ftpServerName", "Name or IP of FTP server") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(ftpServerName);
    output.println("</td></tr>");

    output.println("<tr><td colspan=\"2\" class=\"formParm1\">");
    output.println(getResource("label.ftpLocalDir", "Local Folder to backup") + ":");
    output.println("</td></tr>");

    output.println("<tr><td colspan=\"2\" class=\"formParm2\">");
    output.println(CommonUtils.shortName(getHeadlinePath(actPath), 70));
    output.println("</td></tr>");

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

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

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

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

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

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

    String subDir = null;

    int lastSepIdx = actPath.lastIndexOf(File.separator);

    if ((lastSepIdx >= 0) && (lastSepIdx < (actPath.length() - 1))) {
      subDir = actPath.substring(lastSepIdx + 1);
    }

    boolean recursive = (getParameter("recursive") != null);

    FTPClient ftpClient = new FTPClient();

    try {
      ftpClient.connect(ftpServerName);

      Logger.getLogger(getClass())
          .debug("FTP connect to " + ftpServerName + " response: " + ftpClient.getReplyString());

      int reply = ftpClient.getReplyCode();

      if (FTPReply.isPositiveCompletion(reply)) {
        if (ftpClient.login(userid, password)) {
          ftpClient.setFileType(FTP.IMAGE_FILE_TYPE);

          if ((remoteDir.trim().length() > 0) && (!ftpClient.changeWorkingDirectory(remoteDir))) {
            javascriptAlert("FTP remote directory " + remoteDir + " does not exist!");
          } else {
            boolean remoteChdirOk = true;

            if (!ftpClient.changeWorkingDirectory(subDir)) {
              if (!ftpClient.makeDirectory(subDir)) {
                Logger.getLogger(getClass()).warn("FTP cannot create remote directory " + subDir);
                remoteChdirOk = false;
              } else {
                Logger.getLogger(getClass()).debug("FTP created new remote directory " + subDir);

                if (!ftpClient.changeWorkingDirectory(subDir)) {
                  Logger.getLogger(getClass())
                      .warn("FTP cannot chdir to remote directory " + subDir);
                  remoteChdirOk = false;
                }
              }
            }

            if (remoteChdirOk) {
              if (!backupDir(ftpClient, actPath, recursive, output)) {
                javascriptAlert("FTP backup failed");
              } else {
                output.println("<script language=\"javascript\">");
                output.println("document.getElementById('currentFile').innerHTML='';");
                output.println("</script>");
              }
            } else {
              javascriptAlert("FTP cannot create remote subdirectory " + subDir);
            }
          }
        } else {
          Logger.getLogger(getClass()).info("FTP connect to " + ftpServerName + " login failed");
          javascriptAlert("Login to FTP server " + ftpServerName + " failed");
        }
      } else {
        Logger.getLogger(getClass())
            .warn("FTP connect to " + ftpServerName + " response: " + reply);
        javascriptAlert("Login to FTP server " + ftpServerName + " failed");
      }

      ftpClient.logout();

      ftpClient.disconnect();

      // output.println("<br>" + filesTransferred + " files (" + bytesTransferred / 1024 + " KB)
      // transferred");
    } catch (SocketException sockEx) {
      Logger.getLogger(getClass()).warn(sockEx);
      javascriptAlert("FTP transfer failed: " + sockEx);
    } catch (IOException ioEx) {
      Logger.getLogger(getClass()).warn(ioEx);
      javascriptAlert("FTP transfer failed: " + ioEx);
    }

    output.println(
        "<center><FORM><INPUT type=\"Button\" VALUE=\""
            + getResource("button.closewin", "Close Window")
            + "\" onClick=\"self.close()\"></FORM></center>");

    output.flush();
  }
예제 #4
0
  private boolean backupDir(
      FTPClient ftpClient, String localPath, boolean recursive, PrintWriter output)
      throws IOException {
    boolean error = false;

    File localDirFile = new File(localPath);

    if (localDirFile.isDirectory() && (localDirFile.canRead())) {
      File localFileList[] = localDirFile.listFiles();

      if (localFileList != null) {
        for (int i = 0; i < localFileList.length; i++) {
          File localFile = localFileList[i];

          if (localFile.isDirectory()) {
            if (recursive) {
              String subDir = localFile.getName();

              String localPathChild = null;

              if (localPath.endsWith(File.separator)) {
                localPathChild = localPath + subDir;
              } else {
                localPathChild = localPath + File.separator + subDir;
              }

              boolean remoteChdirOk = true;

              if (!ftpClient.changeWorkingDirectory(subDir)) {
                if (!ftpClient.makeDirectory(subDir)) {
                  Logger.getLogger(getClass()).warn("FTP cannot create remote directory " + subDir);
                  remoteChdirOk = false;
                } else {
                  Logger.getLogger(getClass()).debug("FTP created new remote directory " + subDir);

                  if (!ftpClient.changeWorkingDirectory(subDir)) {
                    Logger.getLogger(getClass())
                        .warn("FTP cannot chdir to remote directory " + subDir);
                    remoteChdirOk = false;
                  }
                }
              }

              if (remoteChdirOk) {
                if (!backupDir(ftpClient, localPathChild, recursive, output)) {
                  error = true;
                }

                if (!ftpClient.changeWorkingDirectory("..")) {
                  Logger.getLogger(getClass()).warn("FTP cannot chdir .. from " + subDir);
                  return (false);
                }
              } else {
                error = true;
              }
            }
          } else {
            output.println("<script language=\"javascript\">");
            output.println(
                "document.getElementById('currentFile').innerHTML='"
                    + insertDoubleBackslash(
                        CommonUtils.shortName(
                            localPath.replace('\\', '/') + "/" + localFile.getName(), 64))
                    + "';");
            output.println("</script>");
            try {
              FileInputStream fin = new FileInputStream(localFile);

              if (!ftpClient.storeFile(localFile.getName(), fin)) {
                Logger.getLogger(getClass())
                    .warn("FTP put file " + localPath + "/" + localFile.getName() + " failed");

                error = true;
              } else {
                Logger.getLogger(getClass())
                    .debug(
                        "FTP put of file " + localPath + "/" + localFile.getName() + " successful");

                filesTransferred++;

                bytesTransferred += localFile.length();

                String temp =
                    filesTransferred
                        + " files ("
                        + numFormat.format(bytesTransferred / 1024)
                        + " KB)";

                output.println("<script language=\"javascript\">");
                output.println("document.getElementById('xferStatus').innerHTML='" + temp + "';");
                output.println("</script>");
              }

              output.flush();

              fin.close();
            } catch (IOException ioex) {
              Logger.getLogger(getClass())
                  .warn(
                      "FTP put file " + localPath + "/" + localFile.getName() + " failed: " + ioex);

              output.println(
                  "<br>FTP put file " + localPath + "/" + localFile.getName() + " failed: " + ioex);

              error = true;
            }
          }
        }
      }
    } else {
      Logger.getLogger(getClass()).warn("FTP local directory " + localPath + " is not readable");

      return (false);
    }

    return (!error);
  }
예제 #5
0
  protected void ftpParamForm(String alertText) {
    String actPath = getParameter("actPath");

    if ((actPath == null) || (actPath.trim().length() == 0)) {
      actPath = getCwd();
    }

    output.println("<html><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("<script language=\"javascript\">");
    output.println("function validate()");
    output.println("{if (document.form1.ftpServerName.value.length()==0')");
    output.println("{alert('" + getResource("alert.destEqualsSource","new file name must be different") + "');}");
    output.println("else");
    output.println("{document.form1.submit();}}");
    output.println("</script>");
          */

    if (alertText != null) {
      javascriptAlert(alertText);
    }

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

    headLine(getResource("label.ftpBackupHead", "Backup to FTP Server"));

    output.print(
        "<form accept-charset=\"utf-8\" name=\"form1\" method=\"post\" action=\"/webfilesys/servlet\">");
    output.print("<input type=\"hidden\" name=\"command\" value=\"ftpBackup\">");
    output.print("<input type=\"hidden\" name=\"actPath\" value=\"" + actPath + "\">");

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

    output.println("<tr>");
    output.println("<td class=\"formParm1\">");
    output.println(getResource("label.ftpLocalDir", "Local Folder to backup") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(CommonUtils.shortName(getHeadlinePath(actPath), 40));
    output.println("</td>");
    output.println("</tr>");

    String val = getParameter("ftpServerName");
    if (val == null) {
      val = "";
    }

    output.println("<tr>");
    output.println("<td class=\"formParm1\">");
    output.println(getResource("label.ftpServerName", "Name or IP of FTP server") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(
        "<input name=\"ftpServerName\" value=\""
            + val
            + "\" maxlength=\"128\" style=\"width:250px\">");
    output.println("</td>");
    output.println("</tr>");

    val = getParameter("userid");
    if (val == null) {
      val = "";
    }

    output.println("<tr>");
    output.println("<td class=\"formParm1\">");
    output.println(getResource("label.ftpUserid", "Userid") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(
        "<input type=\"text\" name=\"userid\" value=\""
            + val
            + "\" maxlength=\"64\" style=\"width:250px;\">");
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td class=\"formParm1\">");
    output.println(getResource("label.ftpPassword", "Password") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(
        "<input type=\"password\" name=\"password\" maxlength=\"64\" style=\"width:250px;\">");
    output.println("</td>");
    output.println("</tr>");

    val = getParameter("remoteDir");
    if (val == null) {
      val = "";
    }

    output.println("<tr>");
    output.println("<td class=\"formParm1\">");
    output.println(getResource("label.ftpDir", "Remote Directory (optional)") + ":");
    output.println("</td>");
    output.println("<td class=\"formParm2\">");
    output.println(
        "<input type=\"text\" name=\"remoteDir\" value=\""
            + val
            + "\" maxlength=\"256\" style=\"width:250px;\">");
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr>");
    output.println("<td colspan=\"2\" class=\"formParm1\">");
    output.print("<input type=\"checkbox\" class=\"cb2\" name=\"recursive\" value=\"true\"");
    if (getParameter("recursive") != null) {
      output.print(" checked");
    }
    output.println(">&nbsp;");
    output.println(getResource("label.ftpRecurse", "Include Subfolders"));
    output.println("</td>");
    output.println("</tr>");

    output.println("<tr><td colspan=\"2\">&nbsp;</td></tr>");

    output.println("<tr>");
    output.println("<td>");
    output.println(
        "<input type=\"submit\" value=\""
            + getResource("button.ftpBackup", "Start FTP Backup")
            + "\">");
    output.println("</td>");
    output.println("<td align=\"right\">");
    output.println(
        "<input type=\"button\" value=\""
            + getResource("button.cancel", "Cancel")
            + "\" onclick=\"self.close()\">");
    output.println("</td>");
    output.println("</tr>");

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

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

    output.println("<script language=\"javascript\">");
    output.println("document.form1.ftpServerName.focus();");
    output.println("</script>");

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

    output.println("</html>");
    output.flush();
  }
예제 #6
0
  protected void process() {
    if (!checkWriteAccess()) {
      return;
    }

    String relPath = null;

    String path = getParameter("path");

    if (isMobile()) {
      relPath = path;
      path = getAbsolutePath(path);
    }

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

    Element resultElement = doc.createElement("result");

    String success = null;

    String resultMsg = "";

    String lowerCaseDocRoot = userMgr.getLowerCaseDocRoot(uid);

    if (path.toLowerCase().replace('\\', '/').equals(lowerCaseDocRoot)) {
      success = "error";

      resultMsg = getResource("alert.delhomedir", "The home directory may not be deleted!");
    } else {
      File dirToBeDeleted = new File(path);

      if (!dirToBeDeleted.canWrite() || (!dirToBeDeleted.isDirectory())) {
        Logger.getLogger(getClass())
            .warn(dirToBeDeleted + " cannot be deleted (is not a writable directory)");

        success = "error";

        resultMsg = getResource("alert.delDirError", "could not be deleted!");
      } else {
        String fileList[] = dirToBeDeleted.list();

        if (fileList.length > 0) {
          if ((fileList.length > 1) || (!fileList[0].equals(MetaInfManager.METAINF_FILE))) {
            String confirmed = getParameter("confirmed");

            if ((confirmed == null) || (!confirmed.equalsIgnoreCase("true"))) {
              success = "notEmpty";

              String shortPath = null;

              if (relPath != null) {
                shortPath = CommonUtils.shortName(relPath, 35);
              } else {
                shortPath = CommonUtils.shortName(path, 35);
              }

              resultMsg =
                  shortPath
                      + "\n"
                      + getResource("confirm.forcedirdel", "is not empty.\nDelete it anyway?");
            }
          }
        }

        if (success == null) {
          File parentDir = dirToBeDeleted.getParentFile();

          if (delDirTree(path)) {
            MetaInfManager.getInstance().removePath(path);

            SubdirExistCache.getInstance().cleanupExistSubdir(path);

            FastPathManager.getInstance().removeTree(uid, path);

            success = "deleted";

            XmlUtil.setChildText(resultElement, "parentPath", parentDir.getAbsolutePath());
          } else {
            success = "error";

            resultMsg = getResource("alert.delDirError", "could not be deleted!");
          }

          // even if only a part of the tree could be deleted we have to refresh the
          // subdir status

          (new TestSubDirThread(parentDir.getAbsolutePath())).start();
        }
      }
    }

    XmlUtil.setChildText(resultElement, "success", success);

    XmlUtil.setChildText(resultElement, "message", resultMsg);

    XmlUtil.setChildText(resultElement, "path", path);

    doc.appendChild(resultElement);

    this.processResponse();
  }
예제 #7
0
  private void checkSubscriberNotifications() {
    if (Logger.getLogger(getClass()).isDebugEnabled()) {
      Logger.getLogger(getClass()).debug("checking subscriber notifications");
    }

    NodeList invitationList = invitationRoot.getElementsByTagName("invitation");

    if (invitationList == null) {
      return;
    }

    int listLength = invitationList.getLength();

    for (int i = 0; i < listLength; i++) {
      Element invitationElem = (Element) invitationList.item(i);

      Element notifyElem = XmlUtil.getChildByTagName(invitationElem, "notifySubscribers");
      if (notifyElem != null) {
        Element changedElem = XmlUtil.getChildByTagName(notifyElem, "changed");

        if (changedElem != null) {
          long lastChangeTime = 0;
          try {
            lastChangeTime = Long.parseLong(XmlUtil.getElementText(changedElem));
          } catch (NumberFormatException numEx) {
            Logger.getLogger(getClass()).error("invalid change time", numEx);
          }

          if (System.currentTimeMillis() - lastChangeTime > NOTIFIY_DELAY_AFTER_CHANGE) {
            // wait some time after blog change until subscribers are notified, in case more entries
            // will be created soon
            long lastNotified = 0;
            String lastNotificationTime = XmlUtil.getChildText(notifyElem, "lastNotified");
            if (!CommonUtils.isEmpty(lastNotificationTime)) {
              try {
                lastNotified = Long.parseLong(lastNotificationTime);
              } catch (NumberFormatException numEx) {
                Logger.getLogger(getClass())
                    .error("invalid lastNotified time: " + lastNotificationTime);
              }
            }

            if (System.currentTimeMillis() - lastNotified > MIN_SUBSCRIBER_NOTIFICATION_INTERVAL) {
              Element subscriberListElem =
                  XmlUtil.getChildByTagName(invitationElem, "subscriberList");
              if (subscriberListElem != null) {
                NodeList subscriberList = subscriberListElem.getElementsByTagName("subscriber");

                if (subscriberList != null) {
                  String blogPath = XmlUtil.getChildText(invitationElem, "path");

                  String virtualUser = XmlUtil.getChildText(invitationElem, "virtualUser");

                  String blogTitle = MetaInfManager.getInstance().getDescription(blogPath, ".");
                  if (CommonUtils.isEmpty(blogTitle)) {
                    blogTitle = virtualUser;
                  }

                  String blogAccessCode = invitationElem.getAttribute("accessCode");

                  int subscriberListLength = subscriberList.getLength();

                  for (int k = 0; k < subscriberListLength; k++) {
                    Element subscriberElement = (Element) subscriberList.item(k);
                    String email = XmlUtil.getChildText(subscriberElement, "email");
                    String code = XmlUtil.getChildText(subscriberElement, "code");
                    sendSubscriberNotification(email, code, blogTitle, virtualUser, blogAccessCode);
                  }
                }
              }

              notifyElem.removeChild(changedElem);
              XmlUtil.setChildText(
                  notifyElem, "lastNotified", Long.toString(System.currentTimeMillis()));

              changed = true;
            }
          }
        }
      }
    }
  }
예제 #8
0
  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();
  }