View Javadoc
1   /*
2    * Copyright (C) 2003-2009 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.thumbnail.impl;
18  
19  import javax.jcr.ItemExistsException;
20  import javax.jcr.Node;
21  import javax.jcr.RepositoryException;
22  
23  import org.exoplatform.services.cms.thumbnail.ThumbnailService;
24  import org.exoplatform.services.log.ExoLogger;
25  import org.exoplatform.services.log.Log;
26  
27  /**
28   * Created by The eXo Platform SAS
29   * Author : eXoPlatform
30   *          nicolas.filotto@exoplatform.com
31   * 8 avr. 2009
32   */
33  public final class ThumbnailUtils {
34  
35    private static final Log LOG = ExoLogger.getLogger(ThumbnailUtils.class.getName());
36  
37    public static synchronized Node getThumbnailFolder(Node parentNode) throws RepositoryException {
38      if (!parentNode.hasNode(ThumbnailService.EXO_THUMBNAILS_FOLDER)) {
39        try {
40          Node thumbnailFolder = parentNode.addNode(ThumbnailService.EXO_THUMBNAILS_FOLDER,
41                                               ThumbnailService.EXO_THUMBNAILS);
42          parentNode.getSession().save();
43          if (thumbnailFolder.canAddMixin(ThumbnailService.HIDDENABLE_NODETYPE)) {
44            thumbnailFolder.addMixin(ThumbnailService.HIDDENABLE_NODETYPE);
45          }
46          parentNode.getSession().save();
47          return thumbnailFolder;
48        } catch (ItemExistsException e) {
49          return parentNode.getNode(ThumbnailService.EXO_THUMBNAILS_FOLDER);
50        }
51      }
52      return parentNode.getNode(ThumbnailService.EXO_THUMBNAILS_FOLDER);
53    }
54  
55    public static synchronized Node getThumbnailNode(Node thumbnailFolder, String identifier) throws RepositoryException {
56      if (!thumbnailFolder.hasNode(identifier)) {
57        try {
58          Node thumbnailNode = thumbnailFolder.addNode(identifier, ThumbnailService.EXO_THUMBNAIL);
59          thumbnailFolder.getSession().save();
60          return thumbnailNode;
61        } catch (ItemExistsException e) {
62          return thumbnailFolder.getNode(identifier);
63        }
64      }
65      return thumbnailFolder.getNode(identifier);
66    }
67  }