com.android.io.IAbstractFolder Java Examples

The following examples show how to use com.android.io.IAbstractFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: AndroidManifestParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: ProjectProperties.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: ProjectProperties.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: AndroidManifest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: AndroidManifestParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: ProjectProperties.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: ProjectProperties.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #18
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: ResourceFolder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: ProjectProperties.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #23
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: ProjectProperties.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source File: AndroidManifest.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: ResourceFolder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}