knguyen     2005/06/07 18:07:45 CEST

  Modified files:
    core/src/java/org/jahia/data/containers JahiaContainerSet.java 
  Log:
  - alias
  
  Revision  Changes    Path
  1.9       +49 -153   
jahia/core/src/java/org/jahia/data/containers/JahiaContainerSet.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/containers/JahiaContainerSet.java.diff?r1=1.8&r2=1.9&f=h
  
  
  
  Index: JahiaContainerSet.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/containers/JahiaContainerSet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JahiaContainerSet.java    27 May 2005 15:15:49 -0000      1.8
  +++ JahiaContainerSet.java    7 Jun 2005 16:07:44 -0000       1.9
  @@ -40,6 +40,7 @@
   import org.jahia.services.pages.ContentPage;
   import org.jahia.services.version.EntryLoadRequest;
   import org.jahia.utils.JahiaConsole;
  +import org.jahia.utils.JahiaTools;
   
   public class JahiaContainerSet implements Map {
   
  @@ -404,160 +405,9 @@
                                     Vector containerFields, int windowSize,
                                     int windowOffset)
           throws JahiaException {
  -
  -        synchronized ( JahiaContainerSet.CLASS_NAME ) {
  -            /** @todo ensure that the data provided by the user has no 
special chars in it */
  -            // check if a container has already been declared with the same 
name
  -            if ( (!checkDeclared(containerName)) &&
  -                 // checks if container name and title are not empty
  -                 (!containerName.equals("")) && (!containerTitle.equals("")) 
&&
  -                 // checks if a field has not the same name
  -                 (!jData.fields().checkDeclared(containerName)) &&
  -                 (!this.checkDeclaredField(containerName))) {
  -                // first, let's check that all the fields in the 
containerFields exist
  -                for (int i = 0; i < containerFields.size(); i++) {
  -                    String theName = (String) containerFields.elementAt(i);
  -                    if (theName.equals("_self")) {
  -                        containerFields.setElementAt(containerName, i);
  -                    } else if ( (!checkDeclared(theName)) &&
  -                                (!checkDeclaredField(theName))) {
  -
  -                        // one of the fields or containers in 
containerFields doesn't exist !!
  -                        String errorMsg = "Element not defined in container 
" +
  -                                containerName + " : " + theName;
  -                        logger.error(errorMsg + " -> BAILING OUT");
  -                        throw new JahiaException(errorMsg, errorMsg,
  -                                JahiaException.TEMPLATE_ERROR,
  -                                JahiaException.CRITICAL_SEVERITY);
  -                    }
  -                }
  -
  -                // second, let's build the property set of the container 
definition
  -                Properties ctnDefProperties = new Properties();
  -                if ( (windowSize >= 1)) {
  -                    if (windowOffset < 0) {
  -                        windowOffset = 0;
  -                    }
  -                    ctnDefProperties.setProperty("windowSize",
  -                            Integer.toString(windowSize));
  -                    ctnDefProperties.setProperty("windowOffset",
  -                            Integer.toString(windowOffset));
  -
  -                }
  -
  -                // third, let's check to see if the declared container has 
already a container definition in the
  -                // ContainersDefinitionsRegistry
  -                JahiaContainerDefinition aDef = 
JahiaContainerDefinitionsRegistry.
  -                        getInstance().getDefinition(jData.
  -                        params().getSiteID(), containerName);
  -                int pageDefID = 
jData.params().getPage().getPageTemplateID(); // get the page template ID no 
matter in which language it is.
  -                if (aDef != null) {
  -                    // okay, it seems the definition already exists.
  -                    // now has it the same data than in the database ?
  -                    boolean havePropertiesChanged = aDef.mergeProperties(
  -                            ctnDefProperties);
  -                    // checks if title changed
  -                    if ( (!aDef.getTitle(pageDefID).equals(containerTitle)) 
||
  -                         // checks if structure changed
  -                         (aDef.structureChanged(containerFields, pageDefID)) 
||
  -                         (havePropertiesChanged)) {
  -                        // well, data is not the same in the registry and in 
the declare() method !
  -                        // this means the user has changed the container 
declaration in the template...
  -                        aDef.setTitle(containerTitle, pageDefID);
  -                        aDef.composeStructure(containerFields, pageDefID);
  -                        // okay, let's synchronize the data between :
  -                        //  - the template declaration (file)
  -                        //  - the database declaration (database)
  -                        //  - the registry declaration (memory)
  -                        JahiaContainerDefinitionsRegistry.getInstance().
  -                                setDefinition(aDef);
  -
  -                        /** @todo we should now reload the container list 
since a lot
  -                         *  of things have changed, including window 
parameters.
  -                         */
  -                        if (havePropertiesChanged) {
  -
  -                            logger.debug("Reloading containerList " +
  -                                         containerName + "...");
  -                            // small hack to avoid doing this everywhere and 
to
  -                            // be able to call checkDeclared in the next 
call...
  -                            declaredContainers.add(containerName);
  -                            containerLists.remove(containerName);
  -                            getContainerList(containerName);
  -                            // hack, will be added below...
  -                            declaredContainers.remove(containerName);
  -                        }
  -                    }
  -                } else {
  -                    // hell, the definition doesn't exist in the memory !
  -                    // this can mean two things :
  -                    //  - either this is the first time Jahia encounters 
this template
  -                    //  - or the database data was screwed
  -                    // in any case, we got to :
  -                    //  - add it into the registry (memory)
  -                    //  - add it into the database (database)
  -                    //  - change the values in jData (memory)
  -
  -                    Hashtable subDefs = new Hashtable();
  -                    JahiaContainerSubDefinition subDef = new
  -                            JahiaContainerSubDefinition(0, pageDefID, 
containerTitle, null);
  -                    subDefs.put(new Integer(pageDefID), subDef);
  -                    aDef = new JahiaContainerDefinition(0,
  -                            jData.params().getPage().getJahiaID(),
  -                            containerName, subDefs);
  -                    // insert new properties.
  -                    aDef.setProperties(ctnDefProperties);
  -                    
JahiaContainerDefinitionsRegistry.getInstance().setDefinition(
  -                            aDef);
  -                    aDef.composeStructure(containerFields, pageDefID);
  -                    
JahiaContainerDefinitionsRegistry.getInstance().setDefinition(
  -                            aDef);
  -
  -                /*
  -                                 Hashtable subDefs = new Hashtable();
  -                                 JahiaContainerSubDefinition subDef = new 
JahiaContainerSubDefinition( 0, pageDefID, containerTitle, null );
  -                                 subDef.composeStructure( containerFields );
  -                                 subDefs.put( new Integer(pageDefID), subDef 
);
  -                     aDef = new JahiaContainerDefinition( 0, 
jData.params().getPage().getJahiaID(),
  -                                                containerName, subDefs );
  -                     
JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );
  -                 */
  -                }
  -
  -                // fourth, we declare that the container has been loaded, in 
order to avoid double definitions
  -                if ( aDef.getID() != 0){
  -                    // last check that the definition was really created
  -                    declaredContainers.add(containerName);
  -                    // last, we create a new fake container list if the 
container list is empty
  -                    int clistID = ServicesRegistry.getInstance().
  -                                  getJahiaContainersService().
  -                                  getContainerListID(containerName,
  -                                                     
jData.params().getPage().getID());
  -                    if (clistID == -1) {
  -                    // if (getContainerList(containerName) == null) {
  -                        // we create a fake container list, and save it into 
memory
  -                        JahiaContainerList fakeContainerList = new 
JahiaContainerList(0,
  -                                0, jData.params().getPage().getID(),
  -                                aDef.getID(), 0);
  -                        // we can't create a *real* container list in the 
database here
  -                        // since we might be in the case of a sub container 
list and
  -                        // these can only be instantiated when the parent 
container is
  -                        // created.
  -                        addContainerList(fakeContainerList);
  -                    }
  -                }
  -            } else {
  -                // the container is already declared, or has a null 
name/title : let the user have it... ;)
  -                String errorMsg =
  -                        "Container already declared or has a null name - 
title : " +
  -                        containerName;
  -                logger.error(errorMsg + " -> BAILING OUT");
  -                throw new JahiaException(errorMsg, errorMsg,
  -                        JahiaException.TEMPLATE_ERROR,
  -                        JahiaException.CRITICAL_SEVERITY);
  -            }
  -        }
  +        declareContainer(containerName, containerTitle, containerFields, 
windowSize, windowOffset, "", "");
       }
  +    
       /**
        * enables a jahia template programmer to declare a container, specifying
        * scrollable window size and offset for container lists that will grow 
very
  @@ -589,6 +439,46 @@
                                     int windowOffset, String validatorKey,
                                     String containerBeanName)
           throws JahiaException {
  +        declareContainer(containerName, containerTitle,
  +                containerFields, windowSize, windowOffset,
  +                validatorKey, containerBeanName, new String[]{});
  +    }
  +
  +    /**
  +     * enables a jahia template programmer to declare a container, specifying
  +     * scrollable window size and offset for container lists that will grow 
very
  +     * large in size.
  +     *
  +     * @param        containerName      the container name
  +     * @param        containerTitle     the container title
  +     * @param        containerFields    the fields (or containers) in the 
container
  +     * @param        windowSize         an integer specifying the size of the
  +     * display window in number of containers. Valid values are >= 1, -1 to
  +     * deactivate this feature
  +     * @param        windowOffset       an integer specifying the offset in 
the
  +     * list of containers, to be used only when windowSize >= 1. Valid 
values are
  +     * >= 0, and -1 is used to deactivate this feature
  +     * @param        validatorKey       the key specifying the validator 
rules set to be
  +     *                                  applied to this container
  +     * @param        containerBeanName  the name of the bean class being 
wrapped around
  +     *                                  the container facade
  +     * @param        aliasNames         this container's alias ( Container 
Definition Names )
  +     *                                  Commas separated names without 
spaces , i.e : containerName1,containerName2,containerName3
  +     *                                  Theses alias state that a container 
is of same structure as another container of given alias name
  +     * 
  +     * @exception    raises a critical JahiaException if the container has 
been already declared
  +     * @exception    raises a critical JahiaException if one of the 
containerFields have not been declared
  +     * @exception    raises a critical JahiaException if one of the fields 
has the same name as the container
  +     *
  +     * In order to let a container include itself, the keyword "_self" in 
the containeFields must be used.
  +     *
  +     */
  +    public void declareContainer (String containerName, String 
containerTitle,
  +                                  Vector containerFields, int windowSize,
  +                                  int windowOffset, String validatorKey,
  +                                  String containerBeanName,
  +                                  String[] aliasNames)
  +        throws JahiaException {
           synchronized ( JahiaContainerSet.CLASS_NAME ) {
               /** @todo ensure that the data provided by the user has no 
special chars in it */
               // check if a container has already been declared with the same 
name
  @@ -639,6 +529,11 @@
                               containerBeanName);
                   }
   
  +                // save container definition aliasNames
  +                if ( aliasNames != null && aliasNames.length>0 ){
  +                    
ctnDefProperties.setProperty(JahiaContainerDefinition.ALIAS_PROP_NAME,
  +                            
JahiaTools.getStringArrayToString(aliasNames,","));
  +                }
   
                   // third, let's check to see if the declared container has 
already a container definition in the
                   // ContainersDefinitionsRegistry
  @@ -756,6 +651,7 @@
               }
           }
       }
  +
       /**
        * enables a jahia template programmer to declare an edit view 
definition to use for a given container list.
        *
  

Reply via email to