Esempio n. 1
0
  private void copyFile(IStorage source, IStorage destination) {
    try {
      destination.getParentFile().mkdirs();
      InputStream in = source.getInputStream();
      OutputStream out = destination.getOutputStream();
      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      in.close();
      out.close();

    } catch (IOException e) {
      e.printStackTrace();
      // throw new UserException(UserException.ERROR_COPYING_USER_BASE_DIRECTORY);
    }
  }
Esempio n. 2
0
    public List<ReviewerVersion> load(IStorage file) {
      ArrayList<ReviewerVersion> objects = new ArrayList<ReviewerVersion>();
      InputStream input = null;
      if (file.exists()) {
        try {
          DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          input = file.getInputStream();
          Document document = parser.parse(input);
          Element rootElement = document.getDocumentElement();
          NodeList versionElements = rootElement.getElementsByTagName("version");
          for (int i = 0; i < versionElements.getLength(); i++) {
            Element versionElement = (Element) versionElements.item(i);

            String designerID = versionElement.getAttribute("designerID");
            String time = versionElement.getAttribute("time");
            ReviewerVersion version = new ReviewerVersion(designerID, time);

            objects.add(version);
          }
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ParserConfigurationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SAXException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } finally {
          try {
            if (input != null) input.close();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      return objects;
    }
Esempio n. 3
0
    public List<Version> load(IStorage file) {
      ArrayList<Version> objects = new ArrayList<Version>();
      InputStream input = null;
      if (file.exists()) {
        try {
          DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          input = file.getInputStream();
          Document document = parser.parse(input);
          Element rootElement = document.getDocumentElement();
          NodeList latestVersion = rootElement.getElementsByTagName("latestVersion");
          latestVersionID = ((Element) latestVersion.item(0)).getAttribute("id");
          NodeList versionElements = rootElement.getElementsByTagName("version");
          for (int i = 0; i < versionElements.getLength(); i++) {
            Element versionElement = (Element) versionElements.item(i);

            String versionID = versionElement.getAttribute("id");
            String time = versionElement.getAttribute("time");
            String versionTitle = versionElement.getAttribute("title");
            String isDraftString = versionElement.getAttribute("isDraft");
            boolean isDraft = Boolean.parseBoolean(isDraftString);
            String dueDate = versionElement.getAttribute("dueDate");
            String width = versionElement.getAttribute("desireWidth");
            String height = versionElement.getAttribute("desireHeight");
            boolean isHasClosedManually =
                Boolean.parseBoolean(versionElement.getAttribute("hasClosedManually"));
            String restartFrom = versionElement.getAttribute("restartFrom");
            String description = versionElement.getAttribute("description");
            boolean receiveEmail =
                Boolean.parseBoolean(versionElement.getAttribute("receiveEmail"));
            boolean hasRestarted =
                Boolean.parseBoolean(versionElement.getAttribute("hasRestarted"));
            Version version = new Version(versionID, time, isDraft, dueDate, width, height);
            if (versionTitle == null) versionTitle = "";
            version.setVersionTitle(versionTitle);
            version.setHasClosedManually(isHasClosedManually);
            version.setRestartFrom(restartFrom);
            version.setDescription(description);
            version.setReceiveEmail(receiveEmail);
            version.setHasRestarted(hasRestarted);

            NodeList reviewers = versionElement.getElementsByTagName("reviewer");
            for (int j = 0; j < reviewers.getLength(); j++) {
              Element reviewer = (Element) reviewers.item(j);

              String reviewerName = reviewer.getAttribute("name");
              String reviewerEmail = reviewer.getAttribute("email");
              version.addReviewer(
                  ReviewManager.getReviewManager().getReviewer(reviewerName, reviewerEmail));
            }

            NodeList resources = versionElement.getElementsByTagName("resource");
            for (int j = 0; j < resources.getLength(); j++) {
              Element resource = (Element) resources.item(j);

              String path = resource.getAttribute("path");
              version.addResource(path);
            }
            objects.add(version);
          }
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ParserConfigurationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SAXException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } finally {
          try {
            if (input != null) input.close();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      return objects;
    }