示例#1
0
 public static Document getHostDocument(final File spec) {
   Document doc = null;
   try {
     final BufferedReader reader = new BufferedReader(new FileReader(spec));
     String line = "";
     String xml = "";
     while ((line = reader.readLine()) != null) xml += line;
     reader.close();
     doc = DocumentUtils.impl.createDocumentFromString(xml);
   } catch (Exception e) {
     TrivialExceptionHandler.ignore(spec, e);
   }
   return doc;
 }
  public void send(final Collection<WorkflowUserInfo> recipients) {
    final Mailer mailer =
        new GMailer("gogoego.tests@gmail.com", "gg3t3sts"); // SISMailer.getGMailer();
    mailer.setSubject("SIS working set submission notification");

    for (WorkflowUserInfo recipient : recipients) {
      mailer.setTo(recipient.getEmailForMailer());
      mailer.setTo("carl.scott@solertium.com");

      mailer.setBody(buildBody(recipient));

      try {
        mailer.background_send();
      } catch (Exception e) {
        TrivialExceptionHandler.ignore(this, e);
      }
    }
  }
示例#3
0
  private boolean buildSite() {
    String url = hostRoot + "/" + siteID + "/vfs";
    final File spec = new File(url);
    boolean dirsMade;
    try {
      dirsMade = spec.mkdirs();
    } catch (SecurityException e) {
      return false;
    }
    if (!dirsMade) // Either site exists or didnt make dirs
    return false;

    String[] reqDirs = new String[] {"HEAD", "META", "UNDO"};
    for (int i = 0; i < reqDirs.length && dirsMade; i++) {
      try {
        dirsMade = new File(url + "/" + reqDirs[i]).mkdir();
      } catch (SecurityException e) {
        return false;
      }
    }

    if (!dirsMade) return false;

    vfs = null;
    try {
      vfs = VFSFactory.getVersionedVFS(spec);
    } catch (final NotFoundException nf) {
      setErrorMessage("VFS " + spec.getPath() + " could not be opened.");
    }

    final VFSPathToken[] defaultDirectories =
        new VFSPathToken[] {
          new VFSPathToken("templates"), new VFSPathToken("includes"),
          new VFSPathToken("images"), new VFSPathToken("css")
        };

    for (VFSPathToken directory : defaultDirectories) {
      try {
        vfs.makeCollections(VFSPath.ROOT.child(directory));
      } catch (IOException e) {
        TrivialExceptionHandler.ignore(this, e);
      }
    }

    return DocumentUtils.writeVFSFile(
        "/index.html",
        vfs,
        DocumentUtils.impl.createDocumentFromString(
            "<html><head><title>"
                + siteID
                + " Index Page</title></head>"
                + "<body><h1>Hello, World!</h1>"
                + "<p>Welcome to your new GoGoEgo Site!</p>"
                + "<p><b>Site ID:</b> "
                + siteID
                + "</p>"
                + "<p><b>Regex Match:</b> "
                + matches
                + "</p>"
                + "<p><b>HTTPS Host:</b> "
                + (httpsHost == null ? "None" : httpsHost)
                + "</p>"
                + (repositoryURI == null
                    ? ""
                    : "<p><b>Repository URI:</b> " + repositoryURI + "</p>")
                + "<h2>Admin Tool</h2>"
                + "<p>To begin editing your site, please login to the "
                + "<a href=\"/admin/index.html\"> admin tool.</a></p>"
                + "</body></html>"));
  }
示例#4
0
  public Document doImport(final ZipInputStream zis, final ImportMode mode)
      throws ResourceException {
    final Document document = BaseDocumentUtils.impl.newDocument();
    final Element root = document.createElement("results");
    root.setAttribute("mode", mode.toString());

    ZipEntry ze;
    try {
      ze = zis.getNextEntry();
    } catch (IOException e) {
      throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
    }
    byte[] buf = new byte[1024];
    while (ze != null) {
      final VFSPath path;
      try {
        path = VFSUtils.parseVFSPath(ze.getName());
      } catch (VFSUtils.VFSPathParseException e) {
        e.printStackTrace();
        try {
          ze = zis.getNextEntry();
          continue;
        } catch (IOException f) {
          throw new ResourceException(Status.SERVER_ERROR_INTERNAL, f);
        }
      }

      if (isRestricted(path)) {
        if (restrictionListener != null && !ze.isDirectory()) {
          try {
            final VFSPath restrictedUri = VFSUtils.parseVFSPath(ze.getName());
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] in_bytes = buf;
            int n;
            while ((n = zis.read(in_bytes, 0, 1024)) > -1) baos.write(in_bytes, 0, n);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

            restrictionListener.handle(restrictedUri, bais);
          } catch (Exception e) {
            e.printStackTrace();
            TrivialExceptionHandler.ignore(this, e);
          }
        }
        try {
          ze = zis.getNextEntry();
          continue;
        } catch (IOException f) {
          throw new ResourceException(Status.SERVER_ERROR_INTERNAL, f);
        }
      }

      final Element el;

      if (ze.isDirectory()) {
        el = document.createElement("folder");
        el.setAttribute("path", path.toString());

        if (!vfs.exists(path)) {
          try {
            vfs.makeCollections(path);
          } catch (IOException e) {
            // Let it fail below for proper iteration behavior
            TrivialExceptionHandler.ignore(this, e);
          }
        } else {
          try {
            el.setAttribute("status", "skipped");
            root.appendChild(el);
            ze = zis.getNextEntry();
            continue;
          } catch (IOException e) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
          }
        }
      } else {
        el = document.createElement("file");
        el.setAttribute("path", path.toString());

        if (ImportMode.FRESHEN.equals(mode) && vfs.exists(path)) {
          try {
            long localTime = vfs.getLastModified(path);
            long remoteTime = ze.getTime();

            if (localTime >= remoteTime) {
              el.setAttribute("status", "skipped");
              root.appendChild(el);
              ze = zis.getNextEntry();
              continue;
            }
          } catch (Exception e) {
            TrivialExceptionHandler.ignore(this, e);
          }
        }

        // Create parent dir if it does not already exist
        if (!vfs.exists(path.getCollection())) {
          try {
            vfs.makeCollections(path.getCollection());
          } catch (IOException e) {
            // Let it fail below for proper iteration behavior
            TrivialExceptionHandler.ignore(this, e);
          }
        }

        final OutputStream os;
        try {
          os = vfs.getOutputStream(path);
        } catch (IOException e) {
          try {
            ze = zis.getNextEntry();
            el.setAttribute("status", "error");
            root.appendChild(el);
            continue;
          } catch (IOException f) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, f);
          }
        }

        int n;
        try {
          while ((n = zis.read(buf, 0, 1024)) > -1) os.write(buf, 0, n);
        } catch (IOException e) {
          el.setAttribute("status", "error");
          root.appendChild(el);
          continue;
        } finally {
          try {
            os.close();
          } catch (IOException e) {
            TrivialExceptionHandler.ignore(this, e);
          }
        }
      }

      el.setAttribute("status", "success");
      root.appendChild(el);

      try {
        ze = zis.getNextEntry();
      } catch (IOException e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
      }
    }

    try {
      zis.close();
    } catch (IOException e) {
      TrivialExceptionHandler.ignore(this, e);
    }

    document.appendChild(root);

    return document;
  }