Ejemplo n.º 1
0
  @Override
  public BaseClass clone() {
    BaseClass bclass = (BaseClass) super.clone();
    bclass.setCustomClass(getCustomClass());
    bclass.setCustomMapping(getCustomMapping());
    bclass.setDefaultWeb(getDefaultWeb());
    bclass.setDefaultViewSheet(getDefaultViewSheet());
    bclass.setDefaultEditSheet(getDefaultEditSheet());
    bclass.setNameField(getNameField());
    bclass.setDirty(this.isDirty);
    bclass.setOwnerDocument(this.ownerDocument);

    return bclass;
  }
Ejemplo n.º 2
0
  @Override
  public boolean apply(ElementInterface newElement, boolean clean) {
    boolean modified = super.apply(newElement, clean);

    BaseClass newBaseClass = (BaseClass) newElement;

    if (!StringUtils.equals(getCustomClass(), newBaseClass.getCustomClass())) {
      setCustomClass(newBaseClass.getCustomClass());
      modified = true;
    }

    if (!StringUtils.equals(getCustomMapping(), newBaseClass.getCustomMapping())) {
      setCustomMapping(newBaseClass.getCustomMapping());
      modified = true;
    }

    if (!StringUtils.equals(getDefaultWeb(), newBaseClass.getDefaultWeb())) {
      setDefaultWeb(newBaseClass.getDefaultWeb());
      modified = true;
    }

    if (!StringUtils.equals(getDefaultViewSheet(), newBaseClass.getDefaultViewSheet())) {
      setDefaultViewSheet(newBaseClass.getDefaultViewSheet());
      modified = true;
    }

    if (!StringUtils.equals(getDefaultEditSheet(), newBaseClass.getDefaultEditSheet())) {
      setDefaultEditSheet(newBaseClass.getDefaultEditSheet());
      modified = true;
    }

    if (!StringUtils.equals(getNameField(), newBaseClass.getNameField())) {
      setNameField(newBaseClass.getNameField());
      modified = true;
    }

    return modified;
  }
Ejemplo n.º 3
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);
    }
  }
Ejemplo n.º 4
0
  @Override
  public void merge(
      ElementInterface previousElement,
      ElementInterface newElement,
      MergeConfiguration configuration,
      XWikiContext context,
      MergeResult mergeResult) {
    BaseClass previousClass = (BaseClass) previousElement;
    BaseClass newClass = (BaseClass) newElement;

    setCustomClass(
        MergeUtils.mergeCharacters(
            previousClass.getCustomClass(),
            newClass.getCustomClass(),
            getCustomClass(),
            mergeResult));

    setCustomMapping(
        MergeUtils.mergeCharacters(
            previousClass.getCustomMapping(),
            newClass.getCustomMapping(),
            getCustomMapping(),
            mergeResult));

    setDefaultWeb(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultWeb(), newClass.getDefaultWeb(), getDefaultWeb(), mergeResult));

    setDefaultViewSheet(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultViewSheet(),
            newClass.getDefaultViewSheet(),
            getDefaultViewSheet(),
            mergeResult));

    setDefaultEditSheet(
        MergeUtils.mergeCharacters(
            previousClass.getDefaultEditSheet(),
            newClass.getDefaultEditSheet(),
            getDefaultEditSheet(),
            mergeResult));

    setNameField(
        MergeUtils.mergeCharacters(
            previousClass.getNameField(), newClass.getNameField(), getNameField(), mergeResult));

    // Properties

    List<ObjectDiff> classDiff = newClass.getDiff(previousClass, context);
    for (ObjectDiff diff : classDiff) {
      PropertyClass propertyResult = (PropertyClass) getField(diff.getPropName());
      PropertyClass previousProperty = (PropertyClass) previousClass.getField(diff.getPropName());
      PropertyClass newProperty = (PropertyClass) newClass.getField(diff.getPropName());

      if (diff.getAction() == ObjectDiff.ACTION_PROPERTYADDED) {
        if (propertyResult == null) {
          // Add if none has been added by user already
          addField(
              diff.getPropName(),
              configuration.isProvidedVersionsModifiables()
                  ? newClass.getField(diff.getPropName())
                  : newClass.getField(diff.getPropName()).clone());
          mergeResult.setModified(true);
        } else if (!propertyResult.equals(newProperty)) {
          // XXX: collision between DB and new: property to add but already exists in the DB
          mergeResult
              .getLog()
              .error("Collision found on class property [{}]", newProperty.getReference());
        }
      } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYREMOVED) {
        if (propertyResult != null) {
          if (propertyResult.equals(previousProperty)) {
            // Delete if it's the same as previous one
            removeField(diff.getPropName());
            mergeResult.setModified(true);
          } else {
            // XXX: collision between DB and new: property to remove but not the same as previous
            // version
            mergeResult
                .getLog()
                .error("Collision found on class property [{}]", previousProperty.getReference());
          }
        } else {
          // Already removed from DB, lets assume the user is prescient
          mergeResult
              .getLog()
              .warn("Object property [{}] already removed", previousProperty.getReference());
        }
      } else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYCHANGED) {
        if (propertyResult != null) {
          if (propertyResult.equals(previousProperty)) {
            // Let some automatic migration take care of that modification between DB and new
            addField(diff.getPropName(), newClass.getField(diff.getPropName()));
            mergeResult.setModified(true);
          } else if (!propertyResult.equals(newProperty)) {
            propertyResult.merge(
                previousProperty, newProperty, configuration, context, mergeResult);
          }
        } else {
          // XXX: collision between DB and new: property to modify but does not exists in DB
          // Lets assume it's a mistake to fix
          mergeResult
              .getLog()
              .warn("Collision found on class property [{}]", newProperty.getReference());

          addField(diff.getPropName(), newClass.getField(diff.getPropName()));
          mergeResult.setModified(true);
        }
      }
    }
  }