Exemplo n.º 1
0
  protected static BaseClass getXWikiGroupRelationClass(XWikiContext context)
      throws XWikiException {
    XWikiDocument doc;
    XWiki xwiki = context.getWiki();
    boolean needsUpdate = false;

    try {
      doc = xwiki.getDocument("XWiki.GroupRelationClass", context);
    } catch (Exception e) {
      doc = new XWikiDocument();
      doc.setSpace("XWiki");
      doc.setName("GroupRelationClass");
      needsUpdate = true;
    }

    BaseClass bclass = doc.getxWikiClass();
    bclass.setName("XWiki.GroupRelationClass");
    needsUpdate |= bclass.addTextField("name", "Name", 30);
    needsUpdate |= bclass.addTextField("parentpage", "Parent", 30);
    needsUpdate |= bclass.addTextAreaField("description", "Description", 40, 5);

    String content = doc.getContent();
    if ((content == null) || (content.equals(""))) {
      needsUpdate = true;
      doc.setContent("1 XWikiGroup");
      doc.setSyntax(Syntax.XWIKI_1_0);
    }

    if (needsUpdate) xwiki.saveDocument(doc, context);
    return bclass;
  }
  private BaseClass getCalendarEventClass(XWikiContext context) throws XWikiException {
    XWikiDocument doc;
    XWiki xwiki = context.getWiki();
    boolean needsUpdate = false;

    try {
      doc = xwiki.getDocument(CelementsCalendarPlugin.CLASS_EVENT, context);
    } catch (Exception e) {
      doc = new XWikiDocument();
      doc.setSpace(CelementsCalendarPlugin.CLASS_EVENT_SPACE);
      doc.setName(CelementsCalendarPlugin.CLASS_EVENT_DOC);
      needsUpdate = true;
    }

    BaseClass bclass = doc.getxWikiClass();
    bclass.setName(CelementsCalendarPlugin.CLASS_EVENT);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_LANG, CelementsCalendarPlugin.PROPERTY_LANG, 30);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_TITLE, CelementsCalendarPlugin.PROPERTY_TITLE, 30);
    needsUpdate |=
        bclass.addTextAreaField(
            CelementsCalendarPlugin.PROPERTY_TITLE_RTE,
            CelementsCalendarPlugin.PROPERTY_TITLE_RTE,
            80,
            15);
    needsUpdate |=
        bclass.addTextAreaField(
            CelementsCalendarPlugin.PROPERTY_DESCRIPTION,
            CelementsCalendarPlugin.PROPERTY_DESCRIPTION,
            80,
            15);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_LOCATION,
            CelementsCalendarPlugin.PROPERTY_LOCATION,
            30);
    needsUpdate |=
        bclass.addTextAreaField(
            CelementsCalendarPlugin.PROPERTY_LOCATION_RTE,
            CelementsCalendarPlugin.PROPERTY_LOCATION_RTE,
            80,
            15);
    needsUpdate |=
        bclass.addDateField(
            CelementsCalendarPlugin.PROPERTY_EVENT_DATE,
            CelementsCalendarPlugin.PROPERTY_EVENT_DATE,
            null,
            0);
    needsUpdate |=
        bclass.addDateField(
            CelementsCalendarPlugin.PROPERTY_EVENT_DATE_END,
            CelementsCalendarPlugin.PROPERTY_EVENT_DATE_END,
            null,
            0);
    needsUpdate |=
        bclass.addBooleanField(
            CelementsCalendarPlugin.PROPERTY_EVENT_IS_SUBSCRIBABLE,
            CelementsCalendarPlugin.PROPERTY_EVENT_IS_SUBSCRIBABLE,
            "yesno");

    if (!"internal".equals(bclass.getCustomMapping())) {
      needsUpdate = true;
      bclass.setCustomMapping("internal");
    }

    String content = doc.getContent();
    if ((content == null) || (content.equals(""))) {
      needsUpdate = true;
      doc.setContent(" ");
    }

    if (needsUpdate) {
      xwiki.saveDocument(doc, context);
    }
    return bclass;
  }