Package edu.hawaii.ics.csdl.jupiter.file.property

Examples of edu.hawaii.ics.csdl.jupiter.file.property.Review


   * @return Returns a <code>Property</code> representing the data in the file.
   * @throws XMLStreamException Thrown if there is an error reading the file.
   */
  public static Property parsePropertyFile(XMLStreamReader reader) throws XMLStreamException {
    Property property = null;
    Review review = null;

    int eventType = reader.getEventType();
    while (reader.hasNext()) {
      eventType = reader.next();

      if (eventType == XMLStreamConstants.START_ELEMENT) {
        QName elementQName = reader.getName();
        String elementName = elementQName.toString();

        if (PropertyConstraints.ELEMENT_PROPERTY.equals(elementName)) {
          // create a new property object, this is the root element
          property = new Property();
        }
        else if (PropertyConstraints.ELEMENT_REVIEW.equals(elementName)) {
          // create a new review and add it to the property object
          review = new Review();
          property.getReview().add(review);

          // get the attributes of review
          String id = reader.getAttributeValue(null, PropertyConstraints.ATTRIBUTE_ID);
          review.setId(id);
        }
        else if (PropertyConstraints.ELEMENT_DESCRIPTION.equals(elementName)) {
          eventType = reader.next(); // we need the CHARACTERS event
          if (eventType == XMLStreamConstants.CHARACTERS) {
            String description = reader.getText();
            review.setDescription(description);
          }
        }
        else if (PropertyConstraints.ELEMENT_AUTHOR.equals(elementName)) {
          eventType = reader.next(); // we need the CHARACTERS event
          if (eventType == XMLStreamConstants.CHARACTERS) {
            String author = reader.getText();
            review.setAuthor(author == null ? "" : author);
          }
        }
        else if (PropertyConstraints.ELEMENT_CREATION_DATE.equals(elementName)) {
          CreationDate creationDate = new CreationDate();

          String format = reader.getAttributeValue(null, PropertyConstraints.ATTRIBUTE_FORMAT);
          creationDate.setFormat(format);

          eventType = reader.next(); // we need the CHARACTERS event
          if (eventType == XMLStreamConstants.CHARACTERS) {
            String dateValue = reader.getText();
            creationDate.setValue(dateValue);
          }

          review.setCreationDate(creationDate);
        }
        else if (PropertyConstraints.ELEMENT_DIRECTORY.equals(elementName)) {
          eventType = reader.next(); // we need the CHARACTERS event
          if (eventType == XMLStreamConstants.CHARACTERS) {
            String directory = reader.getText();
            review.setDirectory(directory);
          }
        }
        else if (PropertyConstraints.ELEMENT_REVIEWERS.equals(elementName)) {
          StaxPropertyXmlUtil.parseReviewers(reader, review);
        }
        else if (PropertyConstraints.ELEMENT_FILES.equals(elementName)) {
          StaxPropertyXmlUtil.parseFiles(reader, review);
        }
        else if (PropertyConstraints.ELEMENT_FIELD_ITEMS.equals(elementName)) {
          review.setFieldItems(new FieldItems());
        }
        else if (PropertyConstraints.ELEMENT_FIELD_ITEM.equals(elementName)) {
          StaxPropertyXmlUtil.parseFieldItem(reader, review);
        }
        else if (PropertyConstraints.ELEMENT_FILTERS.equals(elementName)) {
          review.setFilters(new Filters());
        }
        else if (PropertyConstraints.ELEMENT_PHASE.equals(elementName)) {
          StaxPropertyXmlUtil.parsePhase(reader, review);
        }
      }
View Full Code Here


   *          element. false if it contains the review element of the document.
   * @return the <code>ReviewResource</code> instance associating with the review id. Returns
   *         null if the review id does not exist.
   */
  public ReviewResource getReviewResource(String reviewId, boolean isClone) {
    Review review = this.reviewIdReviewMap.get(reviewId);
    if (review != null) {
      review = (isClone) ? copyReview(review) : review;
      return new ReviewResource(review);
    }
    return null;
View Full Code Here

  private Review copyReview(Review review) {
    if (review == null) {
      return null;
    }

    Review copiedReview = new Review();
    copiedReview.setAuthor(review.getAuthor());
    copiedReview.setDescription(review.getDescription());
    copiedReview.setDirectory(review.getDirectory());
    copiedReview.setId(review.getId());

    CreationDate creationDate = review.getCreationDate();
    if (creationDate != null) {
      CreationDate copiedCreationDate = new CreationDate();
      copiedCreationDate.setFormat(creationDate.getFormat());
      copiedCreationDate.setValue(creationDate.getValue());
      copiedReview.setCreationDate(copiedCreationDate);
    }

    Reviewers reviewers = review.getReviewers();
    if (reviewers != null) {
      Reviewers copiedReviewers = new Reviewers();

      List<Reviewers.Entry> entryList = reviewers.getEntry();
      for (Reviewers.Entry entry : entryList) {
        Reviewers.Entry copiedReviewersEntry = new Reviewers.Entry();
        copiedReviewersEntry.setId(entry.getId());
        copiedReviewersEntry.setName(entry.getName());
        copiedReviewers.getEntry().add(copiedReviewersEntry);
      }
      copiedReview.setReviewers(copiedReviewers);
    }

    Files files = review.getFiles();
    if (files != null) {
      Files copiedFiles = new Files();

      List<Files.Entry> entryList = files.getEntry();
      for (Files.Entry entry : entryList) {
        Files.Entry copiedFilesEntry = new Files.Entry();
        copiedFilesEntry.setName(entry.getName());
        copiedFiles.getEntry().add(copiedFilesEntry);
      }
      copiedReview.setFiles(copiedFiles);
    }

    FieldItems fieldItems = review.getFieldItems();
    if (fieldItems != null) {
      FieldItems copiedFieldItems = new FieldItems();
      List<FieldItem> fieldItemList = fieldItems.getFieldItem();
      for (FieldItem fieldItem : fieldItemList) {
        FieldItem copiedFieldItem = new FieldItem();
        copiedFieldItem.setDefault(fieldItem.getDefault());
        copiedFieldItem.setId(fieldItem.getId());

        List<FieldItem.Entry> entryList = fieldItem.getEntry();
        for (FieldItem.Entry entry : entryList) {
          FieldItem.Entry copiedFieldItemEntry = new FieldItem.Entry();
          copiedFieldItemEntry.setName(entry.getName());
          copiedFieldItem.getEntry().add(copiedFieldItemEntry);
        }
        copiedFieldItems.getFieldItem().add(copiedFieldItem);
      }
      copiedReview.setFieldItems(copiedFieldItems);
    }

    Filters filters = review.getFilters();
    if (filters != null) {
      Filters copiedFilters = new Filters();

      List<Phase> phaseList = filters.getPhase();
      for (Phase phase : phaseList) {
        Phase copiedPhase = new Phase();
        copiedPhase.setName(phase.getName());
        copiedPhase.setEnabled(phase.isEnabled());

        // filter objects
        List<Filter> filterList = phase.getFilter();
        for (Filter filter : filterList) {
          Filter copiedFilter = new Filter();
          copiedFilter.setName(filter.getName());
          copiedFilter.setValue(filter.getValue());
          copiedFilter.setEnabled(filter.isEnabled());
          copiedPhase.getFilter().add(copiedFilter);
        }
        copiedFilters.getPhase().add(copiedPhase);
      }
      copiedReview.setFilters(copiedFilters);
    }

    return copiedReview;
  }
View Full Code Here

   * @return <code>true</code> if review id does not exist and could be written.
   *         <code>false</code> if review id already exist.
   */
  public boolean addReviewResource(ReviewResource reviewResource) throws ReviewException {
    if (reviewResource != null) {
      Review review = reviewResource.getReview();
      ReviewId reviewId = reviewResource.getReviewId();

      this.property.getReview().add(review);
      PropertyXmlSerializer.serializeProperty(this.property, this.project);
      this.reviewIdReviewMap.put(reviewId.getReviewId(), review);
View Full Code Here

   *         review id does not exist.
   */
  public boolean removeReviewResource(ReviewId reviewId) throws ReviewException {
    ReviewResource reviewResource = getReviewResource(reviewId.getReviewId(), false);
    if (reviewResource != null) {
      Review review = reviewResource.getReview();
      this.property.getReview().remove(review);
      PropertyXmlSerializer.serializeProperty(this.property, this.project);
      this.reviewIdReviewMap.remove(reviewId.getReviewId());
      this.reviewIdMap.remove(reviewId.getReviewId());
      return true;
View Full Code Here

   */
  protected void restoreItemEntries() {
    ReviewResource reviewResource = null;
    if (reviewId.getReviewId().equals(PropertyConstraints.DEFAULT_REVIEW_ID)) {
      // read from master property.xml
      Review defaultReview = PropertyXmlSerializer.cloneDefaultReview();
      reviewResource = new ReviewResource(defaultReview);
    }
    else {
      // read from .jupiter.
      PropertyResource propertyResource = PropertyResource.getInstance(project, true);
View Full Code Here

TOP

Related Classes of edu.hawaii.ics.csdl.jupiter.file.property.Review

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.