shuber      2005/02/14 12:59:44 CET

  Modified files:
    core/src/java/org/jahia/params ParamBean.java 
    core/src/java/org/jahia/services/containers 
                                                ContainerFactory.java 
    core/src/java/org/jahia/services/webdav/listeners 
                                                      
CMSSlideContentListener.java 
  Log:
  Added support for existing file container lookup.
  
  Revision  Changes    Path
  1.15      +8 -1      jahia/core/src/java/org/jahia/params/ParamBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/params/ParamBean.java.diff?r1=1.14&r2=1.15&f=h
  1.7       +56 -37    
jahia/core/src/java/org/jahia/services/containers/ContainerFactory.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/containers/ContainerFactory.java.diff?r1=1.6&r2=1.7&f=h
  1.4       +142 -65   
jahia/core/src/java/org/jahia/services/webdav/listeners/CMSSlideContentListener.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/webdav/listeners/CMSSlideContentListener.java.diff?r1=1.3&r2=1.4&f=h
  
  
  
  Index: ParamBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/params/ParamBean.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ParamBean.java    14 Jan 2005 13:08:12 -0000      1.14
  +++ ParamBean.java    14 Feb 2005 11:59:43 -0000      1.15
  @@ -963,6 +963,9 @@
   
       public HttpSession getSession ()
           throws JahiaSessionExpirationException {
  +        if (getRequest() == null) {
  +            return null;
  +        }
           HttpSession session = getRequest().getSession(false);
           if (session == null) {
               throw new JahiaSessionExpirationException();
  @@ -1463,7 +1466,11 @@
           if (customParameters.get(sParameter) != null) {
               return (String) customParameters.get(sParameter);
           } else {
  -            return getRequest().getParameter(sParameter);
  +            if (getRequest() != null) {
  +                return getRequest().getParameter(sParameter);
  +            } else {
  +                return null;
  +            }
           }
       }
   
  
  
  
  Index: ContainerFactory.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/containers/ContainerFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContainerFactory.java     17 Nov 2004 15:01:06 -0000      1.6
  +++ ContainerFactory.java     14 Feb 2005 11:59:43 -0000      1.7
  @@ -468,18 +468,25 @@
                                                     int clistID)
               throws JahiaException {
   
  -        ContainerSearcher cSearcher = (ContainerSearcher) params.getRequest 
()
  -                .getAttribute (containerListName +
  -                "_search_handler");
  -
  -        // retrieve the previous searcher cached in session
  +        ContainerSearcher cSearcher = null;
           ContainerSearcher cachedContainerSearcher = null;
  -        HttpSession session = params.getSession ();
  -        if (session != null) {
  -            cachedContainerSearcher =
  -                    (ContainerSearcher) session.getAttribute (clistID + "_"
  -                    + params.getPageID () + "_" + containerListName +
  -                    "_search_handler"+ "_" + 
params.getEntryLoadRequest().toString());
  +        HttpSession session = null;
  +
  +        // first we check if the request is null in the ParamBean, which 
might
  +        // happen if we created the context from a non-request context, such
  +        // as the SoapParamBean for example.
  +        if (params.getRequest() != null) {
  +            cSearcher = (ContainerSearcher) params.getRequest()
  +                        .getAttribute(containerListName +
  +                                      "_search_handler");
  +            // retrieve the previous searcher cached in session
  +            session = params.getSession();
  +            if (session != null) {
  +                cachedContainerSearcher =
  +                    (ContainerSearcher) session.getAttribute(clistID + "_"
  +                    + params.getPageID() + "_" + containerListName +
  +                    "_search_handler" + "_" + 
params.getEntryLoadRequest().toString());
  +            }
           }
   
           // Check if a search must be applyed to this container list.
  @@ -573,23 +580,28 @@
       private ContainerFilters getCtnListFilters (ParamBean params,
                                                   String containerListName,
                                                   int clistID)
  -            throws JahiaException {
  -
  -        logger.debug ("Started for container list : " +
  -                containerListName + "[" + clistID + "]");
  +        throws JahiaException {
   
  -        ContainerFilters cFilters = (ContainerFilters) params.getRequest ()
  -                .getAttribute (containerListName +
  -                "_filter_handler");
  +        logger.debug("Started for container list : " +
  +                     containerListName + "[" + clistID + "]");
   
  -        // retrieve the previous searcher cached in session
  +        ContainerFilters cFilters = null;
           ContainerFilters cachedContainerFilters = null;
  -        HttpSession session = params.getSession ();
  -        if (session != null) {
  -            cachedContainerFilters =
  +        HttpSession session = null;
  +
  +        if (params.getRequest() != null) {
  +            cFilters = (ContainerFilters) params.getRequest ()
  +                       .getAttribute (containerListName +
  +                                      "_filter_handler");
  +
  +            // retrieve the previous searcher cached in session
  +            session = params.getSession ();
  +            if (session != null) {
  +                cachedContainerFilters =
                       (ContainerFilters) session.getAttribute (clistID + "_"
                       + params.getPageID () + "_" + containerListName +
                       "_filter_handler"+ "_" + 
params.getEntryLoadRequest().toString());
  +            }
           }
   
           if (cFilters == null || !cFilters.isQueryValid ()) {
  @@ -666,24 +678,31 @@
        * @author NK
        */
       private ContainerSorterInterface getContainerSorter (ParamBean params,
  -                                                         String 
containerListName,
  -                                                         int clistID,
  -                                                         boolean 
resultHasChanged,
  -                                                         BitSet resultBitSet)
  -            throws JahiaException {
  -        ContainerSorterInterface sorter = (ContainerSorterInterface) 
params.getRequest ()
  -                .getAttribute (containerListName +
  -                "_sort_handler");
  +        String containerListName,
  +        int clistID,
  +        boolean resultHasChanged,
  +        BitSet resultBitSet)
  +        throws JahiaException {
   
  -        // retrieve the previous sorter cached in session
  +        ContainerSorterInterface sorter = null;
  +        HttpSession session = null;
           ContainerSorterInterface cachedSorter = null;
  -        HttpSession session = params.getSession ();
  -        if (session != null) {
  -            cachedSorter =
  -                    (ContainerSorterInterface) session.getAttribute (clistID 
+ "_"
  -                    + params.getPageID () + "_" + containerListName + 
"_sort_handler"+ "_" + params.getEntryLoadRequest().toString());
  -        }
   
  +        if (params.getRequest() != null) {
  +            sorter = (ContainerSorterInterface) params.
  +                     getRequest()
  +                     .getAttribute(containerListName +
  +                                   "_sort_handler");
  +
  +            // retrieve the previous sorter cached in session
  +            session = params.getSession();
  +            if (session != null) {
  +                cachedSorter =
  +                    (ContainerSorterInterface) session.getAttribute(clistID 
+ "_"
  +                    + params.getPageID() + "_" + containerListName + 
"_sort_handler" +
  +                    "_" + params.getEntryLoadRequest().toString());
  +            }
  +        }
           if (sorter == null || !sorter.isValid ()) {
   
               // create a fake sorter
  
  
  
  Index: CMSSlideContentListener.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/webdav/listeners/CMSSlideContentListener.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CMSSlideContentListener.java      2 Feb 2005 15:20:31 -0000       1.3
  +++ CMSSlideContentListener.java      14 Feb 2005 11:59:44 -0000      1.4
  @@ -49,14 +49,15 @@
    * Time: 15:23:17
    * <p/>
    * $Author: shuber $
  - * $Date: 2005/02/02 15:20:31 $
  - * $Id: CMSSlideContentListener.java,v 1.3 2005/02/02 15:20:31 shuber Exp $
  + * $Date: 2005/02/14 11:59:44 $
  + * $Id: CMSSlideContentListener.java,v 1.4 2005/02/14 11:59:44 shuber Exp $
    * $RCSfile: CMSSlideContentListener.java,v $
  - * $Revision: 1.3 $
  + * $Revision: 1.4 $
    * $Source: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/webdav/listeners/CMSSlideContentListener.java,v
 $
    * $State: Exp $
    */
  -public class CMSSlideContentListener implements ContentListener, 
MacroListener, WebdavListener {
  +public class CMSSlideContentListener implements ContentListener, 
MacroListener,
  +    WebdavListener {
   
       private static org.apache.log4j.Logger logger =
           org.apache.log4j.Logger.getLogger(CMSSlideContentListener.class);
  @@ -108,22 +109,27 @@
               int pageId = 
Integer.parseInt(props.getProperty("parent.page.id"));
               String pageTemplate = props.getProperty("page.template.name");
   
  -            /**
  -             * @todo add code to detect if we don't already have an object
  -             * with the name we are trying to create.
  -             */
  -
               SoapParamBean jParams = new SoapParamBean(Jahia.
                   getStaticServletConfig().getServletContext(), 
Jahia.getSettings(),
                   System.currentTimeMillis(), site, user);
  -            jParams.setSubstituteEntryLoadRequest(EntryLoadRequest.CURRENT);
  +            jParams.setSubstituteEntryLoadRequest(EntryLoadRequest.STAGED);
               Jahia.setThreadParamBean(jParams);
               JahiaContainersService jahiaContainersService = ServicesRegistry.
                   getInstance().getJahiaContainersService();
               String relativeFileName = filename.substring(props.getProperty(
                   "filecreation.filter").length(), filename.length());
   
  -            JahiaPage curPage = findPageInHierarchy(pageId, jParams, 
relativeFileName, false);
  +            // now let's test if we already have a container for this file,
  +            // which means that this is probably an update of a file rather
  +            // than a new file.
  +            JahiaContainer existingContainer = 
findContainerInHierarchy(pageId, props.getProperty("file.container.name"), 
jParams, relativeFileName, filename, jahiaContainersService);
  +            if (existingContainer != null) {
  +                logger.debug("There already is an existing container for 
this file, we won't add another one");
  +                return;
  +            }
  +
  +            JahiaPage curPage = findPageInHierarchy(pageId, jParams,
  +                relativeFileName, false);
   
               if (WebdavUtils.isCollection(event.getRevisionDescriptor())) {
                   logger.debug("URI is a collection, let's create a page for 
it");
  @@ -133,7 +139,8 @@
                   // add a container on an existing page.
                   logger.debug(
                       "URI is a file, let's create a container for it, on the 
found parent page");
  -                String justFileName = 
filename.substring(filename.lastIndexOf("/") + 1);
  +                String justFileName = 
filename.substring(filename.lastIndexOf(
  +                    "/") + 1);
                   createContainer(justFileName,
                                   filename,
                                   event.getRevisionDescriptor(),
  @@ -153,7 +160,8 @@
       }
   
       private JahiaPage findPageInHierarchy (int pageId, SoapParamBean jParams,
  -                                           String relativeFileName, boolean 
exactMatch)
  +                                           String relativeFileName,
  +                                           boolean exactMatch)
           throws JahiaException {
           // first we must find the parent page for the new file being added.
           // this page will have the same name.
  @@ -190,6 +198,39 @@
           return curPage;
       }
   
  +    private JahiaContainer findContainerInHierarchy (int pageId,
  +        String containerName,
  +        SoapParamBean jParams, String relativeFileName, String filenameUri,
  +        JahiaContainersService jahiaContainersService)
  +        throws JahiaException {
  +        JahiaPage containerPage = findPageInHierarchy(pageId, jParams,
  +            relativeFileName, true);
  +        if (containerPage == null) {
  +            return null;
  +        }
  +        int demandsContainerListID = 
jahiaContainersService.getContainerListID(
  +            containerName, containerPage.getID());
  +        JahiaContainerList containerList = jahiaContainersService.
  +                                           loadContainerList(
  +            demandsContainerListID, LoadFlags.ALL, jParams);
  +
  +        if (containerList == null) {
  +            return null;
  +        }
  +
  +        Enumeration containerEnum = containerList.getContainers();
  +        while (containerEnum.hasMoreElements()) {
  +            JahiaContainer jahiaContainer = (JahiaContainer) containerEnum.
  +                                            nextElement();
  +            JahiaField jahiaField = 
jahiaContainer.getField(props.getProperty(
  +                "file.field.name"));
  +            if (jahiaField.getValue().equals(filenameUri)) {
  +                return jahiaContainer;
  +            }
  +        }
  +        return null;
  +    }
  +
       private void createPage (String filename, JahiaSite site,
                                String containerName, int pageId,
                                String pageTemplate, ParamBean jParams,
  @@ -336,28 +377,32 @@
           pageContainer.setLanguageCode(locale.toString());
           pageContainer.fieldsStructureCheck(jParams);
   
  -        JahiaField jahiaField = 
pageContainer.getField(props.getProperty("file.field.name"));
  +        JahiaField jahiaField = pageContainer.getField(props.getProperty(
  +            "file.field.name"));
           jahiaField.setValue(uri);
  -        JahiaFile file = new JahiaFile (-1, // filemanager id
  -                -1, // folder id
  -                jParams.getUser().getName(),
  -                uri, // realname
  -                uri, // storage name
  -                revisionDescriptor.getLastModifiedAsDate ().getTime (), // 
modif date
  -                revisionDescriptor.getContentLength (), // size
  -                revisionDescriptor.getContentType (), // type
  -                filename, // title
  -                "", // descr
  -                String.valueOf (ServicesRegistry.getInstance ()
  -                .getJahiaVersionService ().getCurrentVersionID ()), // 
version
  -                JahiaFile.STATE_ACTIVE);
  -        JahiaFileField fieldObject = new JahiaFileField (file, new 
Properties ());
  -        fieldObject.setID (0);
  +        JahiaFile file = new JahiaFile( -1, // filemanager id
  +                                       -1, // folder id
  +                                       jParams.getUser().getName(),
  +                                       uri, // realname
  +                                       uri, // storage name
  +                                       
revisionDescriptor.getLastModifiedAsDate().
  +                                       getTime(), // modif date
  +                                       
revisionDescriptor.getContentLength(), // size
  +                                       revisionDescriptor.getContentType(), 
// type
  +                                       filename, // title
  +                                       "", // descr
  +                                       String.valueOf(ServicesRegistry.
  +            getInstance()
  +            .getJahiaVersionService().getCurrentVersionID()), // version
  +                                       JahiaFile.STATE_ACTIVE);
  +        JahiaFileField fieldObject = new JahiaFileField(file, new 
Properties());
  +        fieldObject.setID(0);
           URI url = null;
  -        url = new URI ();
  -        url.setPath (Jahia.getContextPath() + "/webdav/site/" + 
site.getSiteKey() + uri);
  -        url.setURIStartingAtPath (true);
  -        fieldObject.setDownloadUrl (url.toString ());
  +        url = new URI();
  +        url.setPath(Jahia.getContextPath() + "/webdav/site/" + 
site.getSiteKey() +
  +                    uri);
  +        url.setURIStartingAtPath(true);
  +        fieldObject.setDownloadUrl(url.toString());
           jahiaField.setObject(fieldObject);
           jahiaField.save(jParams);
       }
  @@ -397,7 +442,8 @@
           logger.debug("Copy event called " + macroEvent);
       }
   
  -    public void move(MacroEvent macroEvent) throws VetoException {
  +    public void move (MacroEvent macroEvent)
  +        throws VetoException {
           logger.debug("Move event called " + macroEvent);
           String filename = macroEvent.getSourceURI();
           Principal p = 
macroEvent.getToken().getCredentialsToken().getPrincipal();
  @@ -433,11 +479,14 @@
               String relativeFileName = filename.substring(props.getProperty(
                   "filecreation.filter").length(), filename.length());
   
  -            JahiaPage curPage = findPageInHierarchy(pageId, jParams, 
relativeFileName, false);
  +            JahiaPage curPage = findPageInHierarchy(pageId, jParams,
  +                relativeFileName, false);
   
               // for the moment only renames are supported.
  -            String oldPageTitle = 
macroEvent.getSourceURI().substring(macroEvent.getSourceURI().lastIndexOf('/') 
+ 1);
  -            String newPageTitle = 
macroEvent.getTargetURI().substring(macroEvent.getTargetURI().lastIndexOf('/') 
+ 1);
  +            String oldPageTitle = macroEvent.getSourceURI().substring(
  +                macroEvent.getSourceURI().lastIndexOf('/') + 1);
  +            String newPageTitle = macroEvent.getTargetURI().substring(
  +                macroEvent.getTargetURI().lastIndexOf('/') + 1);
   
               if (curPage.getTitle().equals(oldPageTitle)) {
                   logger.debug("URI is a collection, let's create a page for 
it");
  @@ -454,117 +503,145 @@
           inMoveThreadLocal.set(null);
       }
   
  -    public void delete(MacroEvent macroEvent) throws VetoException {
  +    public void delete (MacroEvent macroEvent)
  +        throws VetoException {
           logger.debug("Delete event called " + macroEvent);
       }
   
       // WebDav listener methods :
  -    public void get(WebdavEvent event) throws VetoException {
  +    public void get (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void put(WebdavEvent event) throws VetoException {
  +    public void put (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void propFind(WebdavEvent event) throws VetoException {
  +    public void propFind (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void propPatch(WebdavEvent event) throws VetoException {
  +    public void propPatch (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void bind(WebdavEvent event) throws VetoException {
  +    public void bind (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void rebind(WebdavEvent event) throws VetoException {
  +    public void rebind (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void unbind(WebdavEvent event) throws VetoException {
  +    public void unbind (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void mkcol(WebdavEvent event) throws VetoException {
  +    public void mkcol (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void copy(WebdavEvent event) throws VetoException {
  +    public void copy (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void move(WebdavEvent event) throws VetoException {
  +    public void move (WebdavEvent event)
  +        throws VetoException {
           logger.debug("WebDav move event" + event);
           inMoveThreadLocal.set(new Boolean(true));
       }
   
  -    public void delete(WebdavEvent event) throws VetoException {
  +    public void delete (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void lock(WebdavEvent event) throws VetoException {
  +    public void lock (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void unlock(WebdavEvent event) throws VetoException {
  +    public void unlock (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void acl(WebdavEvent event) throws VetoException {
  +    public void acl (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void report(WebdavEvent event) throws VetoException {
  +    public void report (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void search(WebdavEvent event) throws VetoException {
  +    public void search (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void versionControl(WebdavEvent event) throws VetoException {
  +    public void versionControl (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void options(WebdavEvent event) throws VetoException {
  +    public void options (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void update(WebdavEvent event) throws VetoException {
  +    public void update (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void checkin(WebdavEvent event) throws VetoException {
  +    public void checkin (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void checkout(WebdavEvent event) throws VetoException {
  +    public void checkout (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void uncheckout(WebdavEvent event) throws VetoException {
  +    public void uncheckout (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void label(WebdavEvent event) throws VetoException {
  +    public void label (WebdavEvent event)
  +        throws VetoException {
           logger.debug("WebDAV Label event " + event);
       }
   
  -    public void mkworkspace(WebdavEvent event) throws VetoException {
  +    public void mkworkspace (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void subscribe(WebdavEvent event) throws VetoException {
  +    public void subscribe (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void unsubscribe(WebdavEvent event) throws VetoException {
  +    public void unsubscribe (WebdavEvent event)
  +        throws VetoException {
   
       }
   
  -    public void poll(WebdavEvent event) throws VetoException {
  +    public void poll (WebdavEvent event)
  +        throws VetoException {
   
       }
   }
  

Reply via email to