コード例 #1
0
  /**
   * Check if class template document exists in this context and update. Create if not exists.
   *
   * @param context the XWiki context.
   * @throws XWikiException error when saving document.
   */
  protected void checkClassTemplateDocument(XWikiContext context) throws XWikiException {
    if (this.checkingClassTemplate) {
      return;
    }

    this.checkingClassTemplate = true;

    try {
      XWikiDocument doc;
      XWiki xwiki = context.getWiki();
      boolean needsUpdate = false;

      try {
        doc = xwiki.getDocument(getClassTemplateFullName(), context);
      } catch (Exception e) {
        doc = new XWikiDocument();
        doc.setSpace(getClassTemplateSpace());
        doc.setName(getClassTemplateName());
        needsUpdate = true;
      }

      if (doc.getObject(getClassFullName()) == null) {
        doc.createNewObject(getClassFullName(), context);

        needsUpdate = true;
      }

      if (doc.isNew()) {
        String content =
            getResourceDocumentContent(
                DOCUMENTCONTENT_TEMPLATE_PREFIX + getClassTemplateFullName() + DOCUMENTCONTENT_EXT);
        doc.setContent(content != null ? content : getClassTemplateDefaultContent());
        doc.setSyntax(Syntax.XWIKI_1_0);

        doc.setParent(getClassFullName());
      }

      needsUpdate |= updateClassTemplateDocument(doc);

      if (doc.isNew() || needsUpdate) {
        xwiki.saveDocument(doc, context);
      }
    } finally {
      this.checkingClassTemplate = false;
    }
  }
コード例 #2
0
 private XWikiDocument addDocument(String documentName, String author, Date date, int vote)
     throws RatingsException {
   try {
     String ratingsClassName = RatingsManager.RATINGS_CLASSNAME;
     String pageName = getPageName(documentName);
     String parentDocName = documentName;
     XWiki xwiki = context.getWiki();
     XWikiDocument doc = xwiki.getDocument(pageName, context);
     doc.setParent(parentDocName);
     BaseObject obj = new BaseObject();
     obj.setClassName(ratingsClassName);
     obj.setName(pageName);
     obj.setStringValue(RatingsManager.RATING_CLASS_FIELDNAME_AUTHOR, author);
     obj.setDateValue(RatingsManager.RATING_CLASS_FIELDNAME_DATE, date);
     obj.setIntValue(RatingsManager.RATING_CLASS_FIELDNAME_VOTE, vote);
     obj.setStringValue(RatingsManager.RATING_CLASS_FIELDNAME_PARENT, parentDocName);
     doc.addObject(ratingsClassName, obj);
     return doc;
   } catch (XWikiException e) {
     throw new RatingsException(e);
   }
 }
コード例 #3
0
  /**
   * Check if class document exists in this context and update. Create if not exists.
   *
   * @param context the XWiki context.
   * @throws XWikiException error when saving document.
   */
  protected void checkClassDocument(XWikiContext context) throws XWikiException {
    if (this.checkingClass) {
      return;
    }

    this.checkingClass = true;

    try {
      XWikiDocument doc;
      XWiki xwiki = context.getWiki();
      boolean needsUpdate = false;

      try {
        doc = xwiki.getDocument(getClassFullName(), context);
      } catch (Exception e) {
        doc = new XWikiDocument();
        doc.setSpace(getClassSpace());
        doc.setName(getClassName());
        doc.setCreator(XWikiRightService.SUPERADMIN_USER);
        doc.setAuthor(doc.getCreator());
        needsUpdate = true;
      }

      if (doc.isNew()) {
        doc.setParent(DEFAULT_XWIKICLASS_PARENT);
      }

      this.baseClass = doc.getXClass();

      needsUpdate |= updateBaseClass(this.baseClass);

      if (doc.isNew() || needsUpdate) {
        xwiki.saveDocument(doc, context);
      }
    } finally {
      this.checkingClass = false;
    }
  }
コード例 #4
0
  /**
   * Check if class sheet document exists in this context and update. Create if not exists.
   *
   * @param context the XWiki context.
   * @throws XWikiException error when saving document.
   */
  protected void checkClassSheetDocument(XWikiContext context) throws XWikiException {
    if (this.checkingClassSheet) {
      return;
    }

    this.checkingClassSheet = true;

    try {
      XWikiDocument doc;
      XWiki xwiki = context.getWiki();
      boolean needsUpdate = false;

      try {
        doc = xwiki.getDocument(getClassSheetFullName(), context);
      } catch (Exception e) {
        doc = new XWikiDocument();
        doc.setSpace(getClassSheetSpace());
        doc.setName(getClassSheetName());
        needsUpdate = true;
      }

      if (doc.isNew()) {
        String documentContentPath =
            DOCUMENTCONTENT_SHEET_PREFIX + getClassSheetFullName() + DOCUMENTCONTENT_EXT;
        String content = getResourceDocumentContent(documentContentPath);
        doc.setContent(content != null ? content : getClassSheetDefaultContent());
        doc.setSyntax(Syntax.XWIKI_1_0);
        doc.setParent(getClassFullName());
      }

      if (doc.isNew() || needsUpdate) {
        xwiki.saveDocument(doc, context);
      }
    } finally {
      this.checkingClassSheet = false;
    }
  }