1/*2 * ModeShape (http://www.modeshape.org)3 * See the COPYRIGHT.txt file distributed with this work for information4 * regarding copyright ownership. Some portions may be licensed5 * to Red Hat, Inc. under one or more contributor license agreements.6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors.8 *9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape10 * is licensed to you under the terms of the GNU Lesser General Public License as11 * published by the Free Software Foundation; either version 2.1 of12 * the License, or (at your option) any later version.13 * 14 * ModeShape is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU17 * Lesser General Public License for more details.18 *19 * You should have received a copy of the GNU Lesser General Public20 * License along with this software; if not, write to the Free21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.23 */24package org.modeshape.connector.filesystem;
2526import java.io.File;
27import java.io.Serializable;
28import java.util.Collection;
29import java.util.Map;
30import java.util.Set;
31import net.jcip.annotations.Immutable;
32import org.modeshape.graph.ExecutionContext;
33import org.modeshape.graph.JcrLexicon;
34import org.modeshape.graph.Location;
35import org.modeshape.graph.connector.RepositorySourceException;
36import org.modeshape.graph.property.Name;
37import org.modeshape.graph.property.Property;
3839/**40 * A simple interface that allows an implementer to define additional properties for "nt:folder", "nt:file", and "nt:resource"41 * nodes created by the file system connector.42 * <p>43 * To use, supply the implementation to a {@link FileSystemSource} object (or register the factory in a subclass of44 * FileSystemSource). Implementations should be immutable because they are shared between all the connections.45 * </p>46 */47 @Immutable
48publicinterfaceCustomPropertiesFactoryextends Serializable {
4950/**51 * Construct the custom properties that should be created for the supplied directory that is to be treated as an "nt:folder".52 * The resulting properties should not include the standard {@link JcrLexicon#PRIMARY_TYPE} or {@link JcrLexicon#CREATED}53 * properties, which are set automatically and will override any returned Property with the same name.54 * 55 * @param context the execution context; never null56 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null57 * @param directory the file system object; never null and {@link File#isDirectory()} will always return true58 * @return the custom properties; never null but possibly empty59 */60 Collection<Property> getDirectoryProperties( ExecutionContext context,
61Location location,
62 File directory );
6364/**65 * Construct the custom properties that should be created for the supplied file that is to be treated as an "nt:resource",66 * which is the node that contains the content-oriented properties and that is a child of a "nt:file" node. The resulting67 * properties should not include the standard {@link JcrLexicon#PRIMARY_TYPE}, {@link JcrLexicon#LAST_MODIFIED}, or68 * {@link JcrLexicon#DATA} properties, which are set automatically and will override any returned Property with the same name.69 * 70 * @param context the execution context; never null71 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null72 * @param file the file system object; never null and {@link File#isFile()} will always return true73 * @param mimeType the mime type for the file, as determined by the {@link ExecutionContext#getMimeTypeDetector() MIME type74 * detector}, or null if the MIME type could not be determined75 * @return the custom properties; never null but possibly empty76 */77 Collection<Property> getResourceProperties( ExecutionContext context,
78Location location,
79 File file,
80 String mimeType );
8182/**83 * Construct the custom properties that should be created for the supplied file that is to be treated as an "nt:file". The84 * resulting properties should not include the standard {@link JcrLexicon#PRIMARY_TYPE} or {@link JcrLexicon#CREATED}85 * properties, which are set automatically and will override any returned Property with the same name.86 * <p>87 * Although the connector does not automatically determine the MIME type for the "nt:file" nodes, an implementation can88 * determine the MIME type by using the context's {@link ExecutionContext#getMimeTypeDetector() MIME type detector}. Note,89 * however, that this may be an expensive operation, so it should be used only when needed.90 * </p>91 * 92 * @param context the execution context; never null93 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null94 * @param file the file system object; never null and {@link File#isFile()} will always return true95 * @return the custom properties; never null but possibly empty96 */97 Collection<Property> getFileProperties( ExecutionContext context,
98Location location,
99 File file );
100101/**102 * Record the supplied properties as being set on the designated "nt:folder" node.103 * 104 * @param context the execution context; never null105 * @param sourceName the name of the repository source; never null106 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null107 * @param file the file system object; never null, and both {@link File#exists()} and {@link File#isDirectory()} will always108 * return true109 * @param properties the properties that are to be set110 * @return the names of the properties that were created, or an empty or null set if no properties were created on the file111 * @throws RepositorySourceException if any properties are invalid or cannot be set on these nodes112 */113 Set<Name> recordDirectoryProperties( ExecutionContext context,
114 String sourceName,
115Location location,
116 File file,
117 Map<Name, Property> properties ) throws RepositorySourceException;
118119/**120 * Record the supplied properties as being set on the designated "nt:file" node.121 * 122 * @param context the execution context; never null123 * @param sourceName the name of the repository source; never null124 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null125 * @param file the file system object; never null, and both {@link File#exists()} and {@link File#isFile()} will always return126 * true127 * @param properties the properties that are to be set128 * @return the names of the properties that were created, or an empty or null set if no properties were created on the file129 * @throws RepositorySourceException if any properties are invalid or cannot be set on these nodes130 */131 Set<Name> recordFileProperties( ExecutionContext context,
132 String sourceName,
133Location location,
134 File file,
135 Map<Name, Property> properties ) throws RepositorySourceException;
136137/**138 * Record the supplied properties as being set on the designated "nt:resource" node.139 * 140 * @param context the execution context; never null141 * @param sourceName the name of the repository source; never null142 * @param location the Location of the node, which always contains a {@link Location#getPath() path}; never null143 * @param file the file system object; never null, and both {@link File#exists()} and {@link File#isFile()} will always return144 * true145 * @param properties the properties that are to be set146 * @return the names of the properties that were created, or an empty or null set if no properties were created on the file147 * @throws RepositorySourceException if any properties are invalid or cannot be set on these nodes148 */149 Set<Name> recordResourceProperties( ExecutionContext context,
150 String sourceName,
151Location location,
152 File file,
153 Map<Name, Property> properties ) throws RepositorySourceException;
154155 }