Esempio 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 getSubscriptionClass(XWikiContext context) throws XWikiException {
    XWikiDocument doc;
    XWiki xwiki = context.getWiki();
    boolean needsUpdate = false;

    try {
      doc = xwiki.getDocument(CelementsCalendarPlugin.SUBSCRIPTION_CLASS, context);
    } catch (Exception e) {
      doc = new XWikiDocument();
      doc.setSpace(CelementsCalendarPlugin.SUBSCRIPTION_CLASS_SPACE);
      doc.setName(CelementsCalendarPlugin.SUBSCRIPTION_CLASS_DOC);
      needsUpdate = true;
    }

    BaseClass bclass = doc.getxWikiClass();
    bclass.setName(CelementsCalendarPlugin.SUBSCRIPTION_CLASS);
    needsUpdate |= bclass.addTextField("subscriber", "subscriber", 30);
    needsUpdate |= bclass.addBooleanField("doSubscribe", "doSubscribe", "yesno");

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

    if (needsUpdate) {
      xwiki.saveDocument(doc, context);
    }
    return bclass;
  }
  /**
   * Configure BaseClass.
   *
   * @param baseClass the baseClass to configure.
   * @return true if <code>baseClass</code> modified.
   */
  protected boolean updateBaseClass(BaseClass baseClass) {
    boolean needUpdate = false;

    if (!baseClass.getName().equals(getClassFullName())) {
      baseClass.setName(getClassFullName());
      needUpdate = true;
    }

    return needUpdate;
  }
Esempio n. 4
0
  public void fromXML(Element cel) throws XWikiException {
    try {
      int j = 1;
      setName(cel.element("name").getText());
      Element cclel = cel.element("customClass");
      if (cclel != null) {
        setCustomClass(cclel.getText());
        j++;
      }
      Element cmapel = cel.element("customMapping");
      if (cmapel != null) {
        setCustomMapping(cmapel.getText());
        j++;
      }
      Element cdvsel = cel.element("defaultViewSheet");
      if (cdvsel != null) {
        setDefaultViewSheet(cdvsel.getText());
        j++;
      }
      Element cdesel = cel.element("defaultEditSheet");
      if (cdesel != null) {
        setDefaultViewSheet(cdesel.getText());
        j++;
      }
      Element cdwel = cel.element("defaultWeb");
      if (cdwel != null) {
        setDefaultWeb(cdwel.getText());
        j++;
      }
      Element cnfel = cel.element("nameField");
      if (cnfel != null) {
        setNameField(cnfel.getText());
        j++;
      }

      Element valel = cel.element("validationScript");
      if (valel != null) {
        setValidationScript(valel.getText());
        j++;
      }

      @SuppressWarnings("unchecked")
      List<Element> list = cel.elements();
      for (int i = j; i < list.size(); i++) {
        Element pcel = list.get(i);
        String name = pcel.getName();
        String classType = pcel.element("classType").getText();
        PropertyClassProvider provider = null;
        try {
          // First try to use the specified class type as hint.
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        } catch (Exception e) {
          // In previous versions the class type was the full Java class name of the property class
          // implementation. Extract the hint by removing the Java package prefix and the Class
          // suffix.
          classType =
              StringUtils.removeEnd(StringUtils.substringAfterLast(classType, "."), "Class");
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        }
        // We should use PropertyClassInterface (instead of PropertyClass, its default
        // implementation) but it
        // doesn't have the fromXML method and adding it breaks the backwards compatibility. We make
        // the
        // assumption that all property classes extend PropertyClass.
        PropertyClass property = (PropertyClass) provider.getInstance();
        property.setName(name);
        property.setObject(this);
        property.fromXML(pcel);
        safeput(name, property);
      }
    } catch (Exception e) {
      throw new XWikiException(
          XWikiException.MODULE_XWIKI_CLASSES,
          XWikiException.ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION,
          "Error instanciating property class",
          e,
          null);
    }
  }
  private BaseClass getCalendarClass(XWikiContext context) throws XWikiException {
    XWikiDocument doc;
    XWiki xwiki = context.getWiki();
    boolean needsUpdate = false;

    try {
      doc = xwiki.getDocument(CelementsCalendarPlugin.CLASS_CALENDAR, context);
    } catch (Exception e) {
      doc = new XWikiDocument();
      doc.setSpace(CelementsCalendarPlugin.CLASS_CALENDAR_SPACE);
      doc.setName(CelementsCalendarPlugin.CLASS_CALENDAR_DOC);
      needsUpdate = true;
    }

    BaseClass bclass = doc.getxWikiClass();
    bclass.setName(CelementsCalendarPlugin.CLASS_CALENDAR);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_CALENDAR_SPACE,
            CelementsCalendarPlugin.PROPERTY_CALENDAR_SPACE,
            30);
    String hql = "select doc.fullName from XWikiDocument as doc, BaseObject as obj,";
    hql += " IntegerProperty as int ";
    hql += "where obj.name=doc.fullName ";
    hql += "and not doc.fullName='$doc.getFullName()' ";
    hql += "and obj.className='" + CelementsCalendarPlugin.CLASS_CALENDAR + "' ";
    hql += "and int.id.id=obj.id ";
    hql += "and int.id.name='" + CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE + "' ";
    hql += "and int.value='1' ";
    hql += "order by doc.fullName asc";
    needsUpdate |=
        bclass.addDBListField(
            CelementsCalendarPlugin.PROPERTY_SUBSCRIBE_TO,
            CelementsCalendarPlugin.PROPERTY_SUBSCRIBE_TO,
            5,
            true,
            hql);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_OVERVIEW_COLUMN_CONFIG,
            CelementsCalendarPlugin.PROPERTY_OVERVIEW_COLUMN_CONFIG,
            30);
    needsUpdate |=
        bclass.addTextField(
            CelementsCalendarPlugin.PROPERTY_EVENT_COLUMN_CONFIG,
            CelementsCalendarPlugin.PROPERTY_EVENT_COLUMN_CONFIG,
            30);
    needsUpdate |=
        bclass.addNumberField(
            CelementsCalendarPlugin.PROPERTY_EVENT_PER_PAGE,
            CelementsCalendarPlugin.PROPERTY_EVENT_PER_PAGE,
            5,
            "integer");
    needsUpdate |=
        bclass.addBooleanField(
            CelementsCalendarPlugin.PROPERTY_HAS_MORE_LINK,
            CelementsCalendarPlugin.PROPERTY_HAS_MORE_LINK,
            "yesno");
    needsUpdate |=
        bclass.addBooleanField(
            CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE,
            CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE,
            "yesno");

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

    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;
  }