View Javadoc

1   /**
2    * Copyright 2008 WebPhotos
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.webphotos.netbeans.project;
17  
18  import java.io.IOException;
19  import org.netbeans.api.project.Project;
20  import org.netbeans.spi.project.ProjectFactory;
21  import org.netbeans.spi.project.ProjectState;
22  import org.openide.filesystems.FileObject;
23  import org.openide.util.lookup.ServiceProvider;
24  
25  /**
26   *
27   * @author Guilherme
28   */
29  @ServiceProvider(service = ProjectFactory.class)
30  public class WebPhotosProjectFactory implements ProjectFactory {
31  
32      public static final String[] PROJECT_ARCHIVES;
33  
34      static {
35          PROJECT_ARCHIVES = new String[]{
36              Constants.ProjectFactory.CONFIG_WEBPHOTOS_PROPERTIES, Constants.ProjectFactory.ALBUNS_WEBPHOTOS_XML
37          };
38      }
39  
40      /**
41       * Determine if this directory is a WebPhotos Project looking up for files
42       * that must be present.
43       *
44       * @param projectDirectory chosen directory
45       * @return
46       */
47      @Override
48      public boolean isProject(FileObject projectDirectory) {
49          if(projectDirectory == null) {
50              return false;
51          }
52          boolean isProject = true;
53          for (String file : PROJECT_ARCHIVES) {
54              isProject = (isProject && projectDirectory.getFileObject(file) != null);
55          }
56          return isProject;
57      }
58  
59      @Override
60      public Project loadProject(FileObject dir, ProjectState state) throws IOException {
61          return isProject(dir) ? new WebPhotosProject(dir, state) : null;
62      }
63  
64      @Override
65      public void saveProject(Project project) throws IOException, ClassCastException {
66          if (project != null && !isProject(project.getProjectDirectory())) {
67              throw new IOException("Project dir " + project.getProjectDirectory().getPath()
68                      + " deleted,"
69                      + " cannot save project");
70          }
71          throw new UnsupportedOperationException("Not supported yet.");
72      }
73  }