Search in sources :

Example 1 with ResourceStatus

use of org.eclipse.core.internal.resources.ResourceStatus in project translationstudio8 by heartsome.

the class NewFolderDialogOfHs method validateFolderName.

/**
		 * Checks if the folder name is valid.
		 *
		 * @return null if the new folder name is valid.
		 * 	a message that indicates the problem otherwise.
		 */
@SuppressWarnings("restriction")
private boolean validateFolderName() {
    String name = folderNameField.getText();
    IWorkspace workspace = container.getWorkspace();
    IStatus nameStatus = workspace.validateName(name, IResource.FOLDER);
    if ("".equals(name)) {
        //$NON-NLS-1$
        updateStatus(IStatus.ERROR, IDEWorkbenchMessages.NewFolderDialog_folderNameEmpty);
        return false;
    }
    if (nameStatus.isOK() == false) {
        updateStatus(nameStatus);
        return false;
    }
    // 修改创建文件夹时,所进行的文件名特殊字符验证	--robert	2013-07-01
    String result = null;
    if ((result = CommonFunction.validResourceName(name)) != null) {
        updateStatus(new ResourceStatus(IResourceStatus.INVALID_VALUE, null, result));
        return false;
    }
    IPath path = new Path(name);
    if (container.getFolder(path).exists() || container.getFile(path).exists()) {
        updateStatus(IStatus.ERROR, NLS.bind(IDEWorkbenchMessages.NewFolderDialog_alreadyExists, name));
        return false;
    }
    //$NON-NLS-1$
    updateStatus(IStatus.OK, "");
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus)

Example 2 with ResourceStatus

use of org.eclipse.core.internal.resources.ResourceStatus in project webtools.sourceediting by eclipse.

the class SimpleWebFacetInstallDataModelProvider method validateContextRoot.

protected IStatus validateContextRoot(String contextRoot) {
    if (contextRoot == null || contextRoot.length() == 0) {
        return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, ResourceHandler.Context_Root_cannot_be_empty_2);
    } else if (contextRoot.trim().equals(contextRoot)) {
        // $NON-NLS-1$
        StringTokenizer stok = new StringTokenizer(contextRoot, ".");
        while (stok.hasMoreTokens()) {
            String token = stok.nextToken();
            int cp;
            for (int i = 0; i < token.length(); i += UTF16.getCharCount(cp)) {
                cp = UTF16.charAt(token, i);
                if (token.charAt(i) == ' ') {
                    return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, ResourceHandler.Names_cannot_contain_whitespace);
                } else if (!(token.charAt(i) == '_') && !(token.charAt(i) == '-') && !(token.charAt(i) == '/') && Character.isLetterOrDigit(token.charAt(i)) == false) {
                    String invalidCharString = null;
                    if (UTF16.getCharCount(cp) > 1) {
                        invalidCharString = UTF16.valueOf(cp);
                    } else {
                        invalidCharString = (new Character(token.charAt(i))).toString();
                    }
                    Object[] invalidChar = new Object[] { invalidCharString };
                    String errorStatus = ResourceHandler.getString(ResourceHandler.The_character_is_invalid_in_a_context_root, invalidChar);
                    return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, errorStatus);
                }
            }
        }
    } else {
        return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, ResourceHandler.Names_cannot_contain_whitespace);
    }
    return OK_STATUS;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus)

Example 3 with ResourceStatus

use of org.eclipse.core.internal.resources.ResourceStatus in project polymap4-core by Polymap4.

the class Bucket method load.

/**
 * Loads the contents from a file under the given directory. If <code>force</code> is
 * <code>false</code>, if this bucket already contains the contents from the current location,
 * avoids reloading.
 */
public void load(String newProjectName, File baseLocation, boolean force) throws CoreException {
    try {
        // avoid reloading
        if (!force && this.location != null && baseLocation.equals(this.location.getParentFile()) && (projectName == null ? (newProjectName == null) : projectName.equals(newProjectName))) {
            this.projectName = newProjectName;
            return;
        }
        // previously loaded bucket may not have been saved... save before loading new one
        save();
        this.projectName = newProjectName;
        this.location = new File(baseLocation, getIndexFileName());
        this.entries.clear();
        if (!this.location.isFile())
            return;
        DataInputStream source = new DataInputStream(new BufferedInputStream(new FileInputStream(location), 8192));
        try {
            int version = source.readByte();
            if (version != getVersion()) {
                // unknown version
                String message = NLS.bind(Messages.resources_readMetaWrongVersion, location.getAbsolutePath(), Integer.toString(version));
                ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, message);
                throw new ResourceException(status);
            }
            int entryCount = source.readInt();
            for (int i = 0; i < entryCount; i++) this.entries.put(readEntryKey(source), readEntryValue(source));
        } finally {
            source.close();
        }
    } catch (IOException ioe) {
        String message = NLS.bind(Messages.resources_readMeta, location.getAbsolutePath());
        ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, null, message, ioe);
        throw new ResourceException(status);
    }
}
Also used : ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 4 with ResourceStatus

use of org.eclipse.core.internal.resources.ResourceStatus in project polymap4-core by Polymap4.

the class Bucket method save.

/**
 * Saves this bucket's contents back to its location.
 */
public void save() throws CoreException {
    if (!needSaving)
        return;
    try {
        if (entries.isEmpty()) {
            needSaving = false;
            cleanUp(location);
            return;
        }
        // ensure the parent location exists
        File parent = location.getParentFile();
        if (parent == null)
            // caught and rethrown below
            throw new IOException();
        parent.mkdirs();
        DataOutputStream destination = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(location), 8192));
        try {
            destination.write(getVersion());
            destination.writeInt(entries.size());
            for (Iterator i = entries.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry entry = (Map.Entry) i.next();
                writeEntryKey(destination, (String) entry.getKey());
                writeEntryValue(destination, entry.getValue());
            }
        } finally {
            destination.close();
        }
        needSaving = false;
    } catch (IOException ioe) {
        String message = NLS.bind(Messages.resources_writeMeta, location.getAbsolutePath());
        ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_WRITE_METADATA, null, message, ioe);
        throw new ResourceException(status);
    }
}
Also used : ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Aggregations

ResourceStatus (org.eclipse.core.internal.resources.ResourceStatus)4 IResourceStatus (org.eclipse.core.resources.IResourceStatus)4 ResourceException (org.eclipse.core.internal.resources.ResourceException)2 StringTokenizer (com.ibm.icu.util.StringTokenizer)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1