Java源码示例:com.android.io.IAbstractFolder

示例1
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
示例2
/**
 * Returns the {@link ResourceFolder} associated with a {@link IAbstractFolder}.
 * @param folder The {@link IAbstractFolder} object.
 * @return the {@link ResourceFolder} or null if it was not found.
 */
@Nullable
public ResourceFolder getResourceFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    Collection<List<ResourceFolder>> values = mFolderMap.values();

    for (List<ResourceFolder> list : values) {
        for (ResourceFolder resFolder : list) {
            IAbstractFolder wrapper = resFolder.getFolder();
            if (wrapper.equals(folder)) {
                return resFolder;
            }
        }
    }

    return null;
}
 
示例3
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
示例4
/**
 * Returns the {@link ResourceFolder} associated with a {@link IAbstractFolder}.
 * @param folder The {@link IAbstractFolder} object.
 * @return the {@link ResourceFolder} or null if it was not found.
 */
@Nullable
public ResourceFolder getResourceFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    Collection<List<ResourceFolder>> values = mFolderMap.values();

    for (List<ResourceFolder> list : values) {
        for (ResourceFolder resFolder : list) {
            IAbstractFolder wrapper = resFolder.getFolder();
            if (wrapper.equals(folder)) {
                return resFolder;
            }
        }
    }

    return null;
}
 
示例5
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
示例6
/**
 * Returns the {@link ResourceFolder} associated with a {@link IAbstractFolder}.
 * @param folder The {@link IAbstractFolder} object.
 * @return the {@link ResourceFolder} or null if it was not found.
 */
@Nullable
public ResourceFolder getResourceFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    Collection<List<ResourceFolder>> values = mFolderMap.values();

    for (List<ResourceFolder> list : values) {
        for (ResourceFolder resFolder : list) {
            IAbstractFolder wrapper = resFolder.getFolder();
            if (wrapper.equals(folder)) {
                return resFolder;
            }
        }
    }

    return null;
}
 
示例7
/**
 * Loads a project properties file and return a {@link ProjectProperties} object
 * containing the properties.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 */
public static ProjectProperties load(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                return new ProjectProperties(projectFolder, map, type);
            }
        }
    }
    return null;
}
 
示例8
/**
 * Deletes a project properties file.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 * @return true if success.
 */
public static boolean delete(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            return propFile.delete();
        }
    }

    return false;
}
 
示例9
/**
 * Private constructor.
 * <p/>
 * Use {@link #load(String, PropertyType)} or {@link #create(String, PropertyType)}
 * to instantiate.
 */
protected ProjectProperties(
        @NonNull IAbstractFolder projectFolder,
        @NonNull Map<String, String> map,
        @NonNull PropertyType type) {
    mProjectFolder = projectFolder;
    mProperties = map;
    mType = type;
}
 
示例10
/**
 * Returns an {@link IAbstractFile} object representing the manifest for the given project.
 *
 * @param projectFolder The project containing the manifest file.
 * @return An IAbstractFile object pointing to the manifest or null if the manifest
 *         is missing.
 */
public static IAbstractFile getManifest(IAbstractFolder projectFolder) {
    IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (file != null && file.exists()) {
        return file;
    }

    return null;
}
 
示例11
/**
 * Returns the package for a given project.
 * @param projectFolder the folder of the project.
 * @return the package info or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getPackage(IAbstractFolder projectFolder)
        throws XPathExpressionException, StreamException {
    IAbstractFile file = getManifest(projectFolder);
    if (file != null) {
        return getPackage(file);
    }

    return null;
}
 
示例12
/**
 * Creates a new {@link ResourceFolder}
 * @param type The type of the folder
 * @param config The configuration of the folder
 * @param folder The associated {@link IAbstractFolder} object.
 * @param repository The associated {@link ResourceRepository}
 */
protected ResourceFolder(ResourceFolderType type, FolderConfiguration config,
        IAbstractFolder folder, ResourceRepository repository) {
    mType = type;
    mConfiguration = config;
    mFolder = folder;
    mRepository = repository;
}
 
示例13
/**
 * Ensures that the repository has been initialized again after a call to
 * {@link ResourceRepository#clear()}
 *
 * @return true if the repository was just re-initialized.
 */
public synchronized boolean ensureInitialized() {
    if (mCleared && !mInitializing) {
        ScanningContext context = new ScanningContext(this);
        mInitializing = true;

        IAbstractResource[] resources = mResourceFolder.listMembers();

        for (IAbstractResource res : resources) {
            if (res instanceof IAbstractFolder) {
                IAbstractFolder folder = (IAbstractFolder)res;
                ResourceFolder resFolder = processFolder(folder);

                if (resFolder != null) {
                    // now we process the content of the folder
                    IAbstractResource[] files = folder.listMembers();

                    for (IAbstractResource fileRes : files) {
                        if (fileRes instanceof IAbstractFile) {
                            IAbstractFile file = (IAbstractFile)fileRes;

                            resFolder.processFile(file, ResourceDeltaKind.ADDED, context);
                        }
                    }
                }
            }
        }

        mInitializing = false;
        mCleared = false;
        return true;
    }

    return false;
}
 
示例14
/**
 * Removes a {@link ResourceFolder} associated with the specified {@link IAbstractFolder}.
 * @param type The type of the folder
 * @param removedFolder the IAbstractFolder object.
 * @param context the scanning context
 * @return the {@link ResourceFolder} that was removed, or null if no matches were found.
 */
@Nullable
public ResourceFolder removeFolder(
        @NonNull ResourceFolderType type,
        @NonNull IAbstractFolder removedFolder,
        @Nullable ScanningContext context) {
    ensureInitialized();

    // get the list of folders for the resource type.
    List<ResourceFolder> list = mFolderMap.get(type);

    if (list != null) {
        int count = list.size();
        for (int i = 0 ; i < count ; i++) {
            ResourceFolder resFolder = list.get(i);
            IAbstractFolder folder = resFolder.getFolder();
            if (removedFolder.equals(folder)) {
                // we found the matching ResourceFolder. we need to remove it.
                list.remove(i);

                // remove its content
                resFolder.dispose(context);

                return resFolder;
            }
        }
    }

    return null;
}
 
示例15
/**
 * Looks up the {@link ResourceFile} for the given {@link File}, if possible
 *
 * @param file the file
 * @return the corresponding {@link ResourceFile}, or null if not a known {@link ResourceFile}
 */
@Nullable
protected ResourceFile findResourceFile(@NonNull File file) {
    // Look up the right resource file for this path
    String parentName = file.getParentFile().getName();
    IAbstractFolder folder = getResFolder().getFolder(parentName);
    if (folder != null) {
        ResourceFolder resourceFolder = getResourceFolder(folder);
        if (resourceFolder == null) {
            FolderConfiguration configForFolder = FolderConfiguration
                    .getConfigForFolder(parentName);
            if (configForFolder != null) {
                ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
                if (folderType != null) {
                    resourceFolder = add(folderType, configForFolder, folder);
                }
            }
        }
        if (resourceFolder != null) {
            ResourceFile resourceFile = resourceFolder.getFile(file.getName());
            if (resourceFile != null) {
                return resourceFile;
            }
        }
    }

    return null;
}
 
示例16
public static ManifestData parse(IAbstractFolder projectFolder)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder);
    if (manifestFile == null) {
        throw new FileNotFoundException();
    }

    return parse(manifestFile, true, null);
}
 
示例17
/**
 * Loads a project properties file and return a {@link ProjectProperties} object
 * containing the properties.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 */
public static ProjectProperties load(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                return new ProjectProperties(projectFolder, map, type);
            }
        }
    }
    return null;
}
 
示例18
/**
 * Deletes a project properties file.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 * @return true if success.
 */
public static boolean delete(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            return propFile.delete();
        }
    }

    return false;
}
 
示例19
/**
 * Private constructor.
 * <p/>
 * Use {@link #load(String, PropertyType)} or {@link #create(String, PropertyType)}
 * to instantiate.
 */
protected ProjectProperties(
        @NonNull IAbstractFolder projectFolder,
        @NonNull Map<String, String> map,
        @NonNull PropertyType type) {
    mProjectFolder = projectFolder;
    mProperties = map;
    mType = type;
}
 
示例20
/**
 * Creates a new {@link ResourceFolder}
 * @param type The type of the folder
 * @param config The configuration of the folder
 * @param folder The associated {@link IAbstractFolder} object.
 * @param repository The associated {@link ResourceRepository}
 */
protected ResourceFolder(ResourceFolderType type, FolderConfiguration config,
        IAbstractFolder folder, ResourceRepository repository) {
    mType = type;
    mConfiguration = config;
    mFolder = folder;
    mRepository = repository;
}
 
示例21
/**
 * Ensures that the repository has been initialized again after a call to
 * {@link ResourceRepository#clear()}
 *
 * @return true if the repository was just re-initialized.
 */
public synchronized boolean ensureInitialized() {
    if (mCleared && !mInitializing) {
        ScanningContext context = new ScanningContext(this);
        mInitializing = true;

        IAbstractResource[] resources = mResourceFolder.listMembers();

        for (IAbstractResource res : resources) {
            if (res instanceof IAbstractFolder) {
                IAbstractFolder folder = (IAbstractFolder)res;
                ResourceFolder resFolder = processFolder(folder);

                if (resFolder != null) {
                    // now we process the content of the folder
                    IAbstractResource[] files = folder.listMembers();

                    for (IAbstractResource fileRes : files) {
                        if (fileRes instanceof IAbstractFile) {
                            IAbstractFile file = (IAbstractFile)fileRes;

                            resFolder.processFile(file, ResourceDeltaKind.ADDED, context);
                        }
                    }
                }
            }
        }

        mInitializing = false;
        mCleared = false;
        return true;
    }

    return false;
}
 
示例22
/**
 * Removes a {@link ResourceFolder} associated with the specified {@link IAbstractFolder}.
 * @param type The type of the folder
 * @param removedFolder the IAbstractFolder object.
 * @param context the scanning context
 * @return the {@link ResourceFolder} that was removed, or null if no matches were found.
 */
@Nullable
public ResourceFolder removeFolder(
        @NonNull ResourceFolderType type,
        @NonNull IAbstractFolder removedFolder,
        @Nullable ScanningContext context) {
    ensureInitialized();

    // get the list of folders for the resource type.
    List<ResourceFolder> list = mFolderMap.get(type);

    if (list != null) {
        int count = list.size();
        for (int i = 0 ; i < count ; i++) {
            ResourceFolder resFolder = list.get(i);
            IAbstractFolder folder = resFolder.getFolder();
            if (removedFolder.equals(folder)) {
                // we found the matching ResourceFolder. we need to remove it.
                list.remove(i);

                // remove its content
                resFolder.dispose(context);

                return resFolder;
            }
        }
    }

    return null;
}
 
示例23
/**
 * Looks up the {@link ResourceFile} for the given {@link File}, if possible
 *
 * @param file the file
 * @return the corresponding {@link ResourceFile}, or null if not a known {@link ResourceFile}
 */
@Nullable
protected ResourceFile findResourceFile(@NonNull File file) {
    // Look up the right resource file for this path
    String parentName = file.getParentFile().getName();
    IAbstractFolder folder = getResFolder().getFolder(parentName);
    if (folder != null) {
        ResourceFolder resourceFolder = getResourceFolder(folder);
        if (resourceFolder == null) {
            FolderConfiguration configForFolder = FolderConfiguration
                    .getConfigForFolder(parentName);
            if (configForFolder != null) {
                ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
                if (folderType != null) {
                    resourceFolder = add(folderType, configForFolder, folder);
                }
            }
        }
        if (resourceFolder != null) {
            ResourceFile resourceFile = resourceFolder.getFile(file.getName());
            if (resourceFile != null) {
                return resourceFile;
            }
        }
    }

    return null;
}
 
示例24
public static ManifestData parse(IAbstractFolder projectFolder)
        throws SAXException, IOException, StreamException, ParserConfigurationException {
    IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder);
    if (manifestFile == null) {
        throw new FileNotFoundException();
    }

    return parse(manifestFile, true, null);
}
 
示例25
/**
 * Returns an {@link IAbstractFile} object representing the manifest for the given project.
 *
 * @param projectFolder The project containing the manifest file.
 * @return An IAbstractFile object pointing to the manifest or null if the manifest
 *         is missing.
 */
public static IAbstractFile getManifest(IAbstractFolder projectFolder) {
    IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (file != null && file.exists()) {
        return file;
    }

    return null;
}
 
示例26
/**
 * Returns the package for a given project.
 * @param projectFolder the folder of the project.
 * @return the package info or null (or empty) if not found.
 * @throws XPathExpressionException
 * @throws StreamException If any error happens when reading the manifest.
 */
public static String getPackage(IAbstractFolder projectFolder)
        throws XPathExpressionException, StreamException {
    IAbstractFile file = getManifest(projectFolder);
    if (file != null) {
        return getPackage(file);
    }

    return null;
}
 
示例27
/**
 * Creates a new {@link ResourceFolder}
 * @param type The type of the folder
 * @param config The configuration of the folder
 * @param folder The associated {@link IAbstractFolder} object.
 * @param repository The associated {@link ResourceRepository}
 */
protected ResourceFolder(ResourceFolderType type, FolderConfiguration config,
        IAbstractFolder folder, ResourceRepository repository, ResourceNamespace namespace) {
    mType = type;
    mConfiguration = config;
    mFolder = folder;
    mRepository = repository;
    this.namespace = namespace;
}
 
示例28
/**
 * Makes a resource repository.
 *
 * @param resFolder the resource folder of the repository.
 * @param isFrameworkRepository whether the repository is for framework resources.
 */
protected ResourceRepository(@NonNull IAbstractFolder resFolder,
        boolean isFrameworkRepository, ResourceNamespace namespace) {
    mResourceFolder = resFolder;
    mFrameworkRepository = isFrameworkRepository;
    this.namespace = namespace;
}
 
示例29
/**
 * Ensures that the repository has been initialized again after a call to
 * {@link ResourceRepository#clear()}.
 *
 * @return true if the repository was just re-initialized.
 */
public synchronized boolean ensureInitialized() {
    if (mCleared && !mInitializing) {
        ScanningContext context = new ScanningContext();
        mInitializing = true;

        IAbstractResource[] resources = mResourceFolder.listMembers();

        for (IAbstractResource res : resources) {
            if (res instanceof IAbstractFolder) {
                IAbstractFolder folder = (IAbstractFolder)res;
                ResourceFolder resFolder = processFolder(folder);

                if (resFolder != null) {
                    // now we process the content of the folder
                    IAbstractResource[] files = folder.listMembers();

                    for (IAbstractResource fileRes : files) {
                        if (fileRes instanceof IAbstractFile) {
                            IAbstractFile file = (IAbstractFile)fileRes;

                            resFolder.processFile(file, ResourceDeltaKind.ADDED, context);
                        }
                    }
                }
            }
        }

        mInitializing = false;
        mCleared = false;
        return true;
    }

    return false;
}
 
示例30
/**
 * Removes a {@link ResourceFolder} associated with the specified {@link IAbstractFolder}.
 *
 * @param type The type of the folder
 * @param removedFolder the IAbstractFolder object.
 * @param context the scanning context
 * @return the {@link ResourceFolder} that was removed, or null if no matches were found.
 */
@Nullable
public ResourceFolder removeFolder(
        @NonNull ResourceFolderType type,
        @NonNull IAbstractFolder removedFolder,
        @Nullable ScanningContext context) {
    ensureInitialized();

    // get the list of folders for the resource type.
    List<ResourceFolder> list = mFolderMap.get(type);

    if (list != null) {
        int count = list.size();
        for (int i = 0 ; i < count ; i++) {
            ResourceFolder resFolder = list.get(i);
            IAbstractFolder folder = resFolder.getFolder();
            if (removedFolder.equals(folder)) {
                // we found the matching ResourceFolder. we need to remove it.
                list.remove(i);

                // remove its content
                resFolder.dispose(context);

                return resFolder;
            }
        }
    }

    return null;
}