### Eclipse Workspace Patch 1.0 #P web Index: standard/src/main/webapp/templates/editobject.vm =================================================================== --- standard/src/main/webapp/templates/editobject.vm (revision 14906) +++ standard/src/main/webapp/templates/editobject.vm (working copy) @@ -1,89 +1,159 @@ #if($request.xpage && $request.xpage=="editobject") -$response.sendRedirect($doc.getURL($context.action, "editor=object")) -#else -#set($formname = "update") -#set($saveaction = "save") -#set($hasCustomClass = ($request.classname && (!$request.classname.trim().equals("")))) -#set($hasCustomObject = ($hasCustomClass && $request.nb && (!$request.nb.trim().equals("")))) -#set($hasCustomField = ($hasCustomClass && ("$!request.property.trim()" != ""))) -#if($hasCustomClass) -#set($classes = [$xwiki.getDocument($request.classname).getxWikiClass()]) + $response.sendRedirect($doc.getURL($context.action, "editor=object")) #else -#set($classes = $doc.getxWikiClasses()) -#end -#set($redirect = $xwiki.getRequestURL()) + #set($formname = "update") + #set($saveaction = "save") + #set($hasCustomClass = ($request.classname && (!$request.classname.trim().equals("")))) + #set($hasCustomObject = ($hasCustomClass && $request.nb && (!$request.nb.trim().equals("")))) + #set($hasCustomField = ($hasCustomClass && ("$!request.property.trim()" != ""))) + #if($hasCustomClass) + #set($classes = [$xwiki.getDocument($request.classname).getxWikiClass()]) + #else + #set($classes = $doc.getxWikiClasses()) + #end + #set($redirect = $xwiki.getRequestURL()) +
-
-#set($q = "editor=object") -#if($hasCustomClass) -#set($q = "${q}&classname=${request.classname}") -#if($hasCustomObject) -#set($q = "${q}&nb=${request.nb}") -#end -#if($hasCustomField) -#set($q = "${q}&property=${request.property}") -#end -#end - -
-#foreach($class in $classes) -#set($props = $class.getProperties()) -#foreach($prop in $props) -#if ($velocityCount==1) -#set($firstfield = $prop.name) -#end -#end -#set($first = 1) -#set($nb = $doc.getObjectNumbers("${class.name}")) -#if($hasCustomObject) -#set($object = $doc.getObject($class.name, $util.parseInt($request.nb))) -#if($object) -#set($objects = [$object]) -#else -#set($objects = []) -#warning($msg.get("nosuchobject")) -#end -#else -#set($objects = $doc.getObjects($class.name)) + + +
+ #set($q = "editor=object") + #if($hasCustomClass) + #set($q = "${q}&classname=${request.classname}") + #if($hasCustomObject) + #set($q = "${q}&nb=${request.nb}") + #end + #if($hasCustomField) + #set($q = "${q}&property=${request.property}") + #end + #end + + +
+ #foreach($class in $classes) + #set($props = $class.getProperties()) + #foreach($prop in $props) + #if ($velocityCount==1) + #set($firstfield = $prop.name) + #end + #end + #set($first = 1) + #set($nb = $doc.getObjectNumbers("${class.name}")) + #if($hasCustomObject) + #set($object = $doc.getObject($class.name, $util.parseInt($request.nb))) + #if($object) + #set($objects = [$object]) + #else + #set($objects = []) + #warning($msg.get("nosuchobject")) + #end + #else + #set($objects = $doc.getObjects($class.name)) + #end + #set($hasobjs = false) + #foreach($obj in $objects) + #if(!$hasCustomObject) + #set($hasobjs = true) +
+
+
${class.name}[${obj.number}]: $doc.display($firstfield, $obj)
+
+
+
+ #end + + + #if($first == 1) + + #set($first = 0) + #end + #if($hasCustomField) +
+ #set($properties = $util.arrayList) + #foreach($propName in $request.property.split(',')) + #set($discard = $properties.add($class.get($propName))) + #end + #foreach($prop in $properties) +
+
$doc.displayEdit($prop, "${class.name}_${obj.number}_" , $obj)
+
+ #end + #else +
+
$msg.get("enabledproperties")
+ #set($hasenabled = false) + #foreach($prop in $class.enabledProperties) + #if($hasenabled == false) #set($hasenabled = true) #end +
+
$doc.displayEditSafe($prop, "${class.name}_${obj.number}_" , $obj)
+ #end + #if($hasenabled == false) +
+ #end +
+
+
+
+
$msg.get("disabledproperties")
+ #set($hasdisabled = false) + #foreach($prop in $class.disabledProperties) + #if($hasdisabled == false) #set($hasdisabled = true) #end +
+
$doc.displayEditSafe($prop, "${class.name}_${obj.number}_" , $obj)
+ #end + #if($hasdisabled == false) +
+ #end +
+
+
+
$msg.get("deprecatedproperties")
+ #set($hasdeprecated = false) + #foreach($objprop in $class.getDeprecatedObjectProperties($obj)) + #if($hasdeprecated == false) #set($hasdeprecated = true) #end +
+
+ #end + #if($hasdeprecated == false) +
+ #end +
+
+ #end + #if(!$hasCustomObject) +
+
+
+ #end + #end #end -#set($hasobjs = false) -#foreach($obj in $objects) -#if(!$hasCustomObject) -#set($hasobjs = true) -
-
${class.name}[${obj.number}]: $doc.display($firstfield, $obj)
-
-#end -#if($first == 1) - -#set($first = 0) -#end -
-#if($hasCustomField) - #set($properties = $util.arrayList) - #foreach($propName in $request.property.split(',')) - #set($discard = $properties.add($class.get($propName))) - #end -#else - #set($properties = $class.properties) -#end -#foreach($prop in $properties) -
-
$doc.displayEdit($prop, "${class.name}_${obj.number}_" , $obj)
-#end -
- -#if(!$hasCustomObject) -
-
-#end -#end -#end -
-
-
#template("editactions.vm")
+
+
+
#template("editactions.vm")
+ #if($hasobjs) -#end #end \ No newline at end of file #P skins Index: toucan/src/main/resources/toucan/toucan.css =================================================================== --- toucan/src/main/resources/toucan/toucan.css (revision 14906) +++ toucan/src/main/resources/toucan/toucan.css (working copy) @@ -125,17 +125,6 @@ border: none; } -pre { - background-color: #F1F7FF; - border: 1px dotted #555555; - float: left; - white-space: pre; - padding: 10px; - margin: 0; - overflow: auto; - position: relative; /*word-wrap:break-word;*/ -} - /* Used to signify a rendering error in the rendered page. Valid only with new rendering */ .xwikirenderingerror { background-color: #FF5555; @@ -292,8 +281,8 @@ border: 1px dotted #555555; } -#xwikimaincontainerinner .code p { - font-family: courier, courier new, monospace; +#xwikimaincontainerinner .code pre { + font-family: courier, courier new, monospace; } .java-keyword { @@ -2421,7 +2410,7 @@ padding-right: 4px; } -#xwikiclassproperties, #xwikiobjects { +.xwikiclassproperties, .xwikiobjects { border: 1px solid #DDD !important; } @@ -2742,8 +2731,9 @@ width: 100%; } -div#xwikiclassproperties.accordion dt label, - div#xwikiobjects.accordion label { +#editcolumn div.xwikiclassproperties.accordion dt label, +div.xwikiclassproperties.accordion dt label, + div.xwikiobjects.accordion label { display: block; font: normal 0.8em sans-serif; text-transform: uppercase; @@ -2758,21 +2748,21 @@ border-bottom: 1px dashed #ccc; } -#editcolumn div.alleditcontent div#xwikiclassproperties.accordion dd label { +#editcolumn div.alleditcontent div.xwikiclassproperties.accordion dd label { text-align: left; margin: 0; font-size: 0.8em; font-weight: normal; } -div#xwikiclassproperties.accordion textarea, - div#xwikiobjects.accordion textarea, - div#xwikiclassproperties.accordion input[type=text], - div#xwikiobjects.accordion input[type=text] { +div.xwikiclassproperties.accordion textarea, + div.xwikiobjects.accordion textarea, + div.xwikiclassproperties.accordion input[type=text], + div.xwikiobjects.accordion input[type=text] { width: 98%; } -div#xwikiclassproperties.accordion +div.xwikiclassproperties.accordion #xwikidoctitleinput { width: 40%; #P core Index: xwiki-core/src/main/resources/ApplicationResources.properties =================================================================== --- xwiki-core/src/main/resources/ApplicationResources.properties (revision 14906) +++ xwiki-core/src/main/resources/ApplicationResources.properties (working copy) @@ -70,8 +70,14 @@ actions=Actions default=default confirmobjectremove=Are you sure you want to remove this object? +confirmobjectpropdelete=Are you sure you want to delete this property from this object? +confirmobjectpropsynchronize=Are you sure you want to synchronize this object with the class (all deprecated properties will be removed DEFINITELY)? +confirmobjectpropallclasssynchronize=Are you sure you want to synchronize all the objects of this class (ALL deprecated properties of ALL objects will be removed DEFINITELY)? confirmdelete=This action is not reversible. Are you sure you want to delete this document? confirmdelete2=Please confirm you want to delete this document? +confirmpropdisable=Please confirm you want to disable this property? +confirmpropenable=Please confirm you want to enable this property? +confirmpropdelete=This action is not reversible. Are you sure you want to delete this property? backlinkswarningdelete=There are pages that link here! confirmdelattachment=Please confirm you want to delete this attachment? deleted=The document has been deleted. @@ -83,6 +89,15 @@ propname=Name selectproptype=Select a type addproperty=Add Property +disablethisprop= Disable Property +enablethisprop= Enable Property +deletethisprop= Delete Property +enabledproperties= Enabled Properties +disabledproperties= Disabled Properties +deprecatedproperties= Deprecated Properties +noenabledproperties= No Enabled Properties +nodisabledproperties= No Disabled Properties +nodeprecatedproperties= No Deprecated Properties saveclass=Save Class welcometoclasseditor=Welcome to the class editor. Choose a field to edit or add a field to the class. editfield=Edit Field @@ -91,11 +106,15 @@ welcometoobjecteditor=Welcome to the objects editor. Choose an object to edit or add an object to the document. saveobjects=Save Objects youcan=You can -removethisobject=remove this object +removethisobject=Remove this object +synchronizethisobject=Synchronize this object +synchronizethisobject_title=Synchronize this object properties with current class properties +synchronizeallobjects=Synchronize all objects +synchronizeallobjects_title=Synchronize all objects'properties with their class properties (remove deprecated properties) rightseditor=Access Rights Editor addrightentry=Add Access Right Entry welcometorightseditor=Welcome to the Access Rights editor. Choose a right entry to edit or add a new right entry: -removethisrightentry=remove this right entry +removethisrightentry=Remove this right entry saverights=Save Access Rights accountdisabled=Your account has been disabled. Please contact the administrator if you think this is a problem. accountnotactive=Your account is not yet active, because your email has not yet been confirmed. @@ -756,11 +775,17 @@ core.comment.addObject=Added object core.comment.updateObject=Updated object core.comment.deleteObject=Deleted object +core.comment.deleteObjectProp=Deleted object property +core.comment.synchronizeObjectProp=Synchronized object property +core.comment.synchronizeObjectPropAllClass=Synchronized object property for the whole class core.comment.addProperty=Added property core.comment.updateProperty=Updated property core.comment.updatePropertyName=Updated property name core.comment.addClassProperty=Added class property core.comment.updateClassProperty=Updated class property +core.comment.disableClassProperty=Disabled class property +core.comment.enableClassProperty=Enabled class property +core.comment.removeClassProperty=Removed class property core.comment.updateClassPropertyName=Updated class property name core.comment.createdUser=Created user core.comment.addedUserToGroup=Added user to group @@ -1053,6 +1078,7 @@ platform.core.action.objectRemove.noClassnameSpecified=No object type specified. platform.core.action.objectRemove.noObjectSpecified=No object specified. platform.core.action.objectRemove.invalidObject=Invalid object specified. +platform.core.action.objectRemove.noPropnameSpecified=No object property specified. tags.save=Save tags.save.success=Tags saved successfuly Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableForm.java (revision 0) @@ -0,0 +1,71 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + + +public class PropDisableForm extends XWikiForm { + + private static final Log LOG = LogFactory.getLog(PropDisableForm.class); + + private String className; + private String propName; + + public void readRequest() + { + try { + setClassName(getRequest().getParameter("classname")); + } catch (Exception ex) { + setClassName(null); + LOG.warn("No or bad classname found while processing an propdelete request: " + + getRequest().getParameter("classname")); + } + + try { + setPropName(getRequest().getParameter("propname")); + } catch (Exception ex) { + setPropName(null); + LOG.warn("No or bad propname found while processing an propdelete request: " + + getRequest().getParameter("propname")); + } + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + +} Index: xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java (working copy) @@ -62,6 +62,7 @@ setPrettyName(prettyname); setxWikiClass(xWikiClass); setUnmodifiable(false); + setEnabled(true); } public BaseClass getxWikiClass() @@ -471,6 +472,20 @@ } } + public boolean isEnabled() + { + return (getIntValue("enabled") == 1); + } + + public void setEnabled(boolean enabled) + { + if (enabled) { + setIntValue("enabled", 1); + } else { + setIntValue("enabled", 0); + } + } + public BaseProperty fromStringArray(String[] strings) { return fromString(strings[0]); Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeAction.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeAction.java (revision 0) @@ -0,0 +1,127 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package com.xpn.xwiki.web; + +import java.io.IOException; +import java.util.Collection; +import java.util.Vector; + +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.VelocityContext; + +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.BaseObject; +import com.xpn.xwiki.objects.BaseProperty; +import com.xpn.xwiki.objects.classes.BaseClass; +import com.xpn.xwiki.objects.classes.PropertyClass; + +public class ObjectPropAllClassSynchronizeAction extends XWikiAction +{ + + /** + * {@inheritDoc} + * + * @see XWikiAction#action(XWikiContext) + */ + public boolean action(XWikiContext context) throws XWikiException + { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + + ObjectPropAllClassSynchronizeForm form = (ObjectPropAllClassSynchronizeForm) context.getForm(); + + Collection> allobjs = doc.getxWikiObjects().values(); + + // looks in the object for deprecated or disabled properties + // and adds them to the properties to be removed + for(Vector objs: allobjs) + for(BaseObject obj: objs) + { + BaseClass objClass = obj.getxWikiClass(context); + Collection + objProps = (Collection)obj.getFieldList(); + Vector propToRemove = new Vector(); + + for(BaseProperty objProp : objProps) + { + PropertyClass objClassProp = (PropertyClass)objClass.get(objProp.getName()); + // Deprecated properties are removed (BUT NOT disabled properties) + // Enabled/disabled object properties with type mismatching class properties are removed + if(objClassProp == null) + propToRemove.add(objProp.getName()); + else { + String propClass = objClassProp.newProperty().getClassType();; + String objPropClass = objProp.getClassType(); + + if(!propClass.equals(objPropClass)) + { + propToRemove.add(objProp.getName()); + } + } + } + + for(String prop: propToRemove) + { + obj.removeField(prop); + } + } + + xwiki.saveDocument(doc, + context.getMessageTool().get("core.comment.synchronizeObjectPropAllClass"), true, context); + + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + response.setStatus(204); + response.setContentLength(0); + } else { + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + } + return false; + } + + /** + * {@inheritDoc} + * + * @see XWikiAction#render(XWikiContext) + */ + public String render(XWikiContext context) throws XWikiException + { + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + XWikiResponse response = context.getResponse(); + response.setStatus(409); + response.setContentType("text/plain"); + try { + response.getWriter().write("failed"); + response.setContentLength(6); + } catch (IOException e) { + } + return null; + } else { + return "error"; + } + } +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteForm.java (revision 0) @@ -0,0 +1,71 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + + +public class PropDeleteForm extends XWikiForm { + + private static final Log LOG = LogFactory.getLog(PropDeleteForm.class); + + private String className; + private String propName; + + public void readRequest() + { + try { + setClassName(getRequest().getParameter("classname")); + } catch (Exception ex) { + setClassName(null); + LOG.warn("No or bad classname found while processing an propremove request: " + + getRequest().getParameter("classname")); + } + + try { + setPropName(getRequest().getParameter("propname")); + } catch (Exception ex) { + setPropName(null); + LOG.warn("No or bad propname found while processing an propremovee request: " + + getRequest().getParameter("propname")); + } + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + +} Index: xwiki-core/src/main/java/com/xpn/xwiki/api/Class.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/api/Class.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/api/Class.java (working copy) @@ -40,6 +40,10 @@ return (BaseClass) getCollection(); } + /** + * returns a String table of the property names (non-Javadoc) + * @see com.xpn.xwiki.api.Collection#getPropertyNames() + */ public java.lang.Object[] getPropertyNames() { Element[] properties = getProperties(); @@ -55,6 +59,88 @@ } /** + * returns a String table of the enabled property names + */ + public java.lang.Object[] getEnabledPropertyNames() + { + Element[] properties = getEnabledProperties(); + if (properties == null) { + return super.getPropertyNames(); + } + String[] props = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + if(properties[i] != null) { + String propname = properties[i].getName(); + props[i] = propname; + } + } + return props; + } + + /** + * returns a String table of the disabled property names + */ + public java.lang.Object[] getDisabledPropertyNames() + { + Element[] properties = getDisabledProperties(); + if (properties == null) { + return null; + } + String[] props = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + if(properties[i] != null) { + String propname = properties[i].getName(); + props[i] = propname; + } + } + return props; + } + + /** + * returns a String table of the disabled property names of the given object. + */ + public java.lang.Object[] getDisabledObjectPropertyNames(Collection objCol) + { + Element[] properties = getDisabledObjectProperties(objCol); + if (properties == null) { + return null; + } + String[] props = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + if(properties[i] != null) { + String propname = properties[i].getName(); + props[i] = propname; + } + } + return props; + } + + /** + * Retrieves deprecated property names of the given object compared to the class. + * A deprecated property is a property which exists in the BaseObject but + * doesn't exist anymore in the BaseClass. + * This is used for synchronization of existing Objects with respect to the + * modifications of its associated BaseClass. + * + * returns a String table of the deprecated property names of the given object. + */ + public java.lang.Object[] getDeprecatedObjectPropertyNames(Collection objCol) + { + Element[] properties = getDeprecatedObjectProperties(objCol); + if (properties == null) { + return null; + } + String[] props = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + if(properties[i] != null) { + String propname = properties[i].getName(); + props[i] = propname; + } + } + return props; + } + + /** * @return an array with the properties of the class */ public Element[] getProperties() @@ -74,6 +160,159 @@ } /** + * @return an array with the enabled properties of the class + */ + public Element[] getEnabledProperties() + { + java.util.Collection coll = + getCollection().getFieldList(); + if (coll == null) { + return null; + } + + // creates a Vector to store found enabled properties + java.util.Vector vect = + new java.util.Vector(); + boolean isEmpty = true; + + for (com.xpn.xwiki.objects.classes.PropertyClass prop : coll) { + if(prop.isEnabled()) + { + // converts classes.PropertyClass into api.PropertyClass + vect.add(new PropertyClass(prop, getXWikiContext())); + isEmpty = false; + } + } + + PropertyClass[] properties = new PropertyClass[vect.size()]; + if(!isEmpty) { + vect.toArray(properties); + Arrays.sort(properties, new PropertyComparator()); + } + return properties; + } + + + /** + * @return an array with the disabled properties of the class + */ + public Element[] getDisabledProperties() + { + java.util.Collection coll = + getCollection().getFieldList(); + if (coll == null) { + return null; + } + + // the Vector to store found disabled properties + java.util.Vector vect = + new java.util.Vector(); + boolean isEmpty = true; + + for (com.xpn.xwiki.objects.classes.PropertyClass prop : coll) { + if(!prop.isEnabled()) + { + // converts classes.PropertyClass into api.PropertyClass + vect.add(new PropertyClass(prop, getXWikiContext())); + isEmpty = false; + } + } + + PropertyClass[] properties = new PropertyClass[vect.size()]; + if(!isEmpty){ + vect.toArray(properties); + Arrays.sort(properties, new PropertyComparator()); + } + return properties; + } + + /** + * @return an array with the disabled properties of the given object. + */ + public Element[] getDisabledObjectProperties(Collection objCol) + { + java.util.Collection coll = + getCollection().getFieldList(); + if (coll == null) { + return null; + } + + // the Vector to store found disabled properties + java.util.Vector vect = + new java.util.Vector(); + boolean isEmpty = true; + + for (com.xpn.xwiki.objects.classes.PropertyClass prop : coll) { + if(!prop.isEnabled()) + { + if(objCol.getProperty(prop.getName()) != null) + { + // converts classes.PropertyClass into api.PropertyClass + vect.add(new PropertyClass(prop, getXWikiContext())); + isEmpty = false; + } + } + } + + PropertyClass[] properties = new PropertyClass[vect.size()]; + if(!isEmpty){ + vect.toArray(properties); + Arrays.sort(properties, new PropertyComparator()); + } + return properties; + } + + /** + * Retrieves deprecated properties of the given object compared to the class. + * A deprecated property is a property which exists in the BaseObject but + * doesn't exist anymore in the BaseClass. + * This is used for synchronization of existing Objects with respect to the + * modifications of its associated BaseClass. + * + * @return an array with the properties of the object which doesn't exist in the class + */ + public Element[] getDeprecatedObjectProperties(Collection theCol) + { + // the class properties + java.util.Collection coll = + getCollection().getFieldList(); + + // the object properties + java.util.Collection theColl = + theCol.getCollection().getFieldList(); + if (theColl == null) { + return null; + } + + // if no property in the class, returns all properties of theColl + if (coll == null) { + Property[] properties = new Property[theColl.size()]; + theColl.toArray(properties); + return properties; + } + + // the Vector to store found deprecated properties + java.util.Vector vect = + new java.util.Vector(); + + com.xpn.xwiki.objects.classes.PropertyClass prop = null; + + // goes through the object property and searches it in the class properties. + // If not found, it is a deprecated property. + for (com.xpn.xwiki.objects.BaseProperty theProp : theColl) { + prop = (com.xpn.xwiki.objects.classes.PropertyClass) getCollection() + .safeget(theProp.getName()); + if(prop == null) + vect.add(new Property(theProp, getXWikiContext())); + } + + Property[] properties = new Property[vect.size()]; + vect.toArray(properties); + + return properties; + } + + /** * @param name the name of the element * @return the PropertyClass for the given name * @see PropertyClass Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableAction.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropDisableAction.java (revision 0) @@ -0,0 +1,63 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package com.xpn.xwiki.web; + +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.classes.BaseClass; + +// TODO: What should this action do? +// (it was left out in the last implementation) +public class PropDisableAction extends XWikiAction { + public boolean action(XWikiContext context) throws XWikiException { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + XWikiForm form = context.getForm(); + + String className = ((PropDisableForm) form).getClassName(); + String propName = ((PropDisableForm) form).getPropName(); + + BaseClass bclass = doc.getxWikiClass(); + // bclass should have the same classname as the one received + if(!bclass.getName().equals(className)) + return false; + + if (bclass.get(propName)!=null) { + bclass.disableField(propName); + + xwiki.saveDocument(doc, context.getMessageTool().get("core.comment.deleteClassProperty"), true, + context); + } + else return true; + + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + return false; + } + + public String render(XWikiContext context) throws XWikiException{ + return "exception"; + } +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeAction.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeAction.java (revision 0) @@ -0,0 +1,145 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package com.xpn.xwiki.web; + +import java.io.IOException; +import java.util.Collection; +import java.util.Vector; + +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.VelocityContext; + +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.api.Object; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.BaseObject; +import com.xpn.xwiki.objects.BaseProperty; +import com.xpn.xwiki.objects.PropertyInterface; +import com.xpn.xwiki.objects.classes.BaseClass; +import com.xpn.xwiki.objects.classes.PropertyClass; + +public class ObjectPropSynchronizeAction extends XWikiAction +{ + protected BaseObject getObject(XWikiDocument doc, XWikiContext context) + { + ObjectPropSynchronizeForm form = (ObjectPropSynchronizeForm) context.getForm(); + BaseObject obj = null; + + String className = form.getClassName(); + int classId = form.getClassId(); + if (StringUtils.isBlank(className)) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.noClassnameSpecified")); + } else if (classId < 0) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.noObjectSpecified")); + } else { + obj = doc.getObject(className, classId); + if (obj == null) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.invalidObject")); + } + } + + return obj; + } + /** + * {@inheritDoc} + * + * @see XWikiAction#action(XWikiContext) + */ + public boolean action(XWikiContext context) throws XWikiException + { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + BaseObject obj = getObject(doc, context); + if (obj == null) { + return true; + } + + BaseClass objClass = obj.getxWikiClass(context); + Collection + objProps = (Collection)obj.getFieldList(); + Vector propToRemove = new Vector(); + + for(BaseProperty objProp : objProps) + { + PropertyClass objClassProp = (PropertyClass)objClass.get(objProp.getName()); + // Deprecated properties are removed (BUT NOT disabled properties) + // Enabled/disabled object properties with type mismatching class properties are removed + if(objClassProp == null) + propToRemove.add(objProp.getName()); + else { + String propClass = objClassProp.newProperty().getClassType();; + String objPropClass = objProp.getClassType(); + + if(!propClass.equals(objPropClass)) + { + propToRemove.add(objProp.getName()); + } + } + } + + for(String prop: propToRemove) + { + obj.removeField(prop); + } + + xwiki.saveDocument(doc, + context.getMessageTool().get("core.comment.synchronizeObjectProp"), true, context); + + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + response.setStatus(204); + response.setContentLength(0); + } else { + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + } + return false; + } + + /** + * {@inheritDoc} + * + * @see XWikiAction#render(XWikiContext) + */ + public String render(XWikiContext context) throws XWikiException + { + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + XWikiResponse response = context.getResponse(); + response.setStatus(409); + response.setContentType("text/plain"); + try { + response.getWriter().write("failed"); + response.setContentLength(6); + } catch (IOException e) { + } + return null; + } else { + return "error"; + } + } +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableForm.java (revision 0) @@ -0,0 +1,71 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + + +public class PropEnableForm extends XWikiForm { + + private static final Log LOG = LogFactory.getLog(PropEnableForm.class); + + private String className; + private String propName; + + public void readRequest() + { + try { + setClassName(getRequest().getParameter("classname")); + } catch (Exception ex) { + setClassName(null); + LOG.warn("No or bad classname found while processing an proprestore request: " + + getRequest().getParameter("classname")); + } + + try { + setPropName(getRequest().getParameter("propname")); + } catch (Exception ex) { + setPropName(null); + LOG.warn("No or bad propname found while processing an proprestore request: " + + getRequest().getParameter("propname")); + } + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + +} Index: xwiki-core/src/main/java/com/xpn/xwiki/objects/meta/PropertyMetaClass.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/objects/meta/PropertyMetaClass.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/objects/meta/PropertyMetaClass.java (working copy) @@ -91,6 +91,12 @@ validationMessage_class.setPrettyName("Validation Message"); validationMessage_class.setSize(80); safeput("validationMessage", validationMessage_class); + + BooleanClass enabled_class = new BooleanClass(this); + enabled_class.setName("enabled"); + enabled_class.setPrettyName("Enabled"); + enabled_class.setDisplayType("yesno"); + safeput("enabled", enabled_class); } public BaseCollection getObject() Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableAction.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropEnableAction.java (revision 0) @@ -0,0 +1,61 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package com.xpn.xwiki.web; + +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.classes.BaseClass; + +public class PropEnableAction extends XWikiAction { + public boolean action(XWikiContext context) throws XWikiException { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + XWikiForm form = context.getForm(); + + String className = ((PropEnableForm) form).getClassName(); + String propName = ((PropEnableForm) form).getPropName(); + + BaseClass bclass = doc.getxWikiClass(); + // bclass should have the same classname as the one received + if(!bclass.getName().equals(className)) + return false; + + if (bclass.get(propName)!=null) { + bclass.enableField(propName); + + xwiki.saveDocument(doc, context.getMessageTool().get("core.comment.restoreClassProperty"), true, + context); + } + else return true; + + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + return false; + } + + public String render(XWikiContext context) throws XWikiException{ + return "exception"; + } +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropAllClassSynchronizeForm.java (revision 0) @@ -0,0 +1,37 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ObjectPropAllClassSynchronizeForm extends XWikiForm +{ + private static final Log LOG = LogFactory.getLog(ObjectPropAllClassSynchronizeForm.class); + + @Override + public void readRequest() + { + } + + +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteAction.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteAction.java (revision 0) @@ -0,0 +1,121 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package com.xpn.xwiki.web; + +import java.io.IOException; + +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.VelocityContext; + +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.BaseObject; + +public class ObjectPropDeleteAction extends XWikiAction +{ + protected BaseObject getObject(XWikiDocument doc, XWikiContext context) + { + ObjectPropDeleteForm form = (ObjectPropDeleteForm) context.getForm(); + BaseObject obj = null; + + String className = form.getClassName(); + int classId = form.getClassId(); + if (StringUtils.isBlank(className)) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.noClassnameSpecified")); + } else if (classId < 0) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.noObjectSpecified")); + } else { + obj = doc.getObject(className, classId); + if (obj == null) { + ((VelocityContext) context.get("vcontext")).put("message", context.getMessageTool() + .get("platform.core.action.objectRemove.invalidObject")); + } + } + + return obj; + } + /** + * {@inheritDoc} + * + * @see XWikiAction#action(XWikiContext) + */ + public boolean action(XWikiContext context) throws XWikiException + { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + BaseObject obj = getObject(doc, context); + if (obj == null) { + return true; + } + + ObjectPropDeleteForm form = (ObjectPropDeleteForm) context.getForm(); + String propName = form.getPropName(); + + if (StringUtils.isBlank(propName)) { + ((VelocityContext) + context.get("vcontext")).put("message", + context.getMessageTool().get("platform.core.action.objectRemove.noPropnameSpecified")); + } + + obj.removeField(propName); + + xwiki.saveDocument(doc, + context.getMessageTool().get("core.comment.deleteObjectProp"), true, context); + + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + response.setStatus(204); + response.setContentLength(0); + } else { + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + } + return false; + } + + /** + * {@inheritDoc} + * + * @see XWikiAction#render(XWikiContext) + */ + public String render(XWikiContext context) throws XWikiException + { + if (BooleanUtils.isTrue((Boolean) context.get("ajax"))) { + XWikiResponse response = context.getResponse(); + response.setStatus(409); + response.setContentType("text/plain"); + try { + response.getWriter().write("failed"); + response.setContentLength(6); + } catch (IOException e) { + } + return null; + } else { + return "error"; + } + } +} Index: xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteAction.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteAction.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/PropDeleteAction.java (working copy) @@ -20,8 +20,42 @@ */ package com.xpn.xwiki.web; -// TODO: What should this action do? -// (it was left out in the last implementation) +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.classes.BaseClass; + public class PropDeleteAction extends XWikiAction { + public boolean action(XWikiContext context) throws XWikiException { + XWiki xwiki = context.getWiki(); + XWikiResponse response = context.getResponse(); + XWikiDocument doc = context.getDoc(); + XWikiForm form = context.getForm(); + String className = ((PropDeleteForm) form).getClassName(); + String propName = ((PropDeleteForm) form).getPropName(); + + BaseClass bclass = doc.getxWikiClass(); + // bclass should have the same classname as the one received + if(!bclass.getName().equals(className)) + return false; + + if (bclass.get(propName)!=null) { + bclass.removeField(propName); + + xwiki.saveDocument(doc, context.getMessageTool().get("core.comment.deleteClassProperty"), true, + context); + } + else return true; + + // forward to edit + String redirect = Utils.getRedirect("edit", context); + sendRedirect(response, redirect); + return false; + } + + public String render(XWikiContext context) throws XWikiException{ + return "exception"; + } } Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropSynchronizeForm.java (revision 0) @@ -0,0 +1,56 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ObjectPropSynchronizeForm extends ObjectAddForm +{ + private int classId; + + private static final Log LOG = LogFactory.getLog(ObjectPropSynchronizeForm.class); + + public void readRequest() + { + super.readRequest(); + try { + setClassId(Integer.parseInt(getRequest().getParameter("classid"))); + } catch (Exception ex) { + setClassId(-1); + LOG.warn("No or bad classid found while processing an objectremove request: " + + getRequest().getParameter("classid")); + } + } + + public int getClassId() + { + return classId; + } + + public void setClassId(int classId) + { + this.classId = classId; + } + + +} Index: xwiki-core/src/main/java/com/xpn/xwiki/api/Document.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/api/Document.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/api/Document.java (working copy) @@ -32,6 +32,7 @@ import org.apache.commons.fileupload.FileItem; import org.apache.commons.lang.StringUtils; +import org.apache.ecs.xhtml.input; import org.suigeneris.jrcs.diff.DifferentiationFailedException; import org.suigeneris.jrcs.rcs.Version; @@ -988,6 +989,48 @@ return this.doc.displayEdit(pclass.getBasePropertyClass(), prefix, object.getCollection(), getXWikiContext()); } + /** + * a safe displayedit which verifies the type of the object property + * is the same as the type of the class property. + * If they are different, a warning message is displayed asking + * the end-user to synchronize the object with its class. + */ + public String displayEditSafe(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) + { + if ((pclass == null) || (object == null)) { + return ""; + } + String propClassName = pclass.getBasePropertyClass().newProperty().getClassType(); + String objPropClassName = ""; + + Property bprop = ((Object)object).getProperty(pclass.getName()); + if(bprop != null) + objPropClassName = bprop.getProperty().getClassType(); + + if(bprop!=null && !propClassName.equals(objPropClassName)) + { + java.lang.Object oldValue = ((Object)object).getProperty(pclass.getName()).getValue(); + + input input = new input(); + input.setType("text"); + input.setDisabled(true); + input.setValue(oldValue.toString()); + + /* + * TODO Use the message service to manage the translation + * of this message + */ + return "" + + "Please synchronize this object, existing value: " + + input.toString() + + " with type "+objPropClassName+" mismatches current property type "+propClassName+"." + + " The value will be lost." + + ""; + } + + return this.doc.displayEdit(pclass.getBasePropertyClass(), prefix, object.getCollection(), getXWikiContext()); + } + public String displayHidden(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) { if ((pclass == null) || (object == null)) { Index: xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java (working copy) @@ -86,6 +86,26 @@ super.addField(name, element); } + public void disableField(String name) + { + PropertyClass pclass = (PropertyClass)safeget(name); + + if(pclass != null) + { + pclass.setEnabled(false); + } + } + + public void enableField(String name) + { + PropertyClass pclass = (PropertyClass)safeget(name); + + if(pclass != null) + { + pclass.setEnabled(true); + } + } + /** * {@inheritDoc} * Index: xwiki-core/src/main/java/com/xpn/xwiki/api/PropertyClass.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/api/PropertyClass.java (revision 14906) +++ xwiki-core/src/main/java/com/xpn/xwiki/api/PropertyClass.java (working copy) @@ -80,5 +80,9 @@ { return getBasePropertyClass().getTooltip(); } - + + public boolean isEnabled() + { + return getBasePropertyClass().isEnabled(); + } } Index: xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteForm.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteForm.java (revision 0) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/ObjectPropDeleteForm.java (revision 0) @@ -0,0 +1,73 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ + +package com.xpn.xwiki.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ObjectPropDeleteForm extends ObjectAddForm +{ + private int classId; + private String propName; + + private static final Log LOG = LogFactory.getLog(ObjectPropDeleteForm.class); + + public void readRequest() + { + super.readRequest(); + try { + setClassId(Integer.parseInt(getRequest().getParameter("classid"))); + } catch (Exception ex) { + setClassId(-1); + LOG.warn("No or bad classid found while processing an objectremove request: " + + getRequest().getParameter("classid")); + } + + try { + setPropName(getRequest().getParameter("propname")); + } catch (Exception ex) { + setPropName(null); + LOG.warn("No or bad propname found while processing an objpropremove request: " + + getRequest().getParameter("propname")); + } + } + + public int getClassId() + { + return classId; + } + + public void setClassId(int classId) + { + this.classId = classId; + } + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + + +}