From 135894a6ae0fb0c60c847385648bbc4c0f03ba4a Mon Sep 17 00:00:00 2001 From: Kevin Doyle Date: Tue, 12 Feb 2008 16:50:30 +0000 Subject: [PATCH] [efs][nls] Externalize Strings in RSEFileStore and RSEFileStoreImpl --- .../eclipse/rse/internal/efs/Messages.java | 37 +++++++++++++ .../rse/internal/efs/RSEFileStore.java | 5 +- .../rse/internal/efs/RSEFileStoreImpl.java | 52 ++++++++++--------- .../rse/internal/efs/messages.properties | 20 +++++++ 4 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/Messages.java create mode 100644 rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/messages.properties diff --git a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/Messages.java b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/Messages.java new file mode 100644 index 00000000000..f006fd8956b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/Messages.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2008 IBM Corporation. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: Kevin Doyle. + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.efs; + +import org.eclipse.osgi.util.NLS; + +public class Messages { + private static final String BUNDLE_NAME = "org.eclipse.rse.internal.efs.messages"; //$NON-NLS-1$ + + public static String RESOURCES_NOT_LOADED; + public static String CONNECTION_NOT_FOUND; + public static String NO_FILE_SUBSYSTEM; + public static String COULD_NOT_CONNECT; + public static String COULD_NOT_GET_REMOTE_FILE; + public static String FILE_STORE_DOES_NOT_EXIST; + public static String UNKNOWN_EXCEPTION; + public static String FILE_NAME_EXISTS; + public static String CANNOT_OPEN_STREAM_ON_FOLDER; + public static String DELETE_FAILED; + + static { + // initialize resource bundles + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } +} diff --git a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStore.java b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStore.java index d3c2fbd7ada..e9ca1303b35 100644 --- a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStore.java +++ b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStore.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved. + * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -19,6 +19,7 @@ * Martin Oberhuber (Wind River) - [188360] renamed from plugin org.eclipse.rse.eclipse.filesystem * Martin Oberhuber (Wind River) - [189441] fix EFS operations on Windows (Local) systems * Martin Oberhuber (Wind River) - [191589] fix Rename by adding putInfo() for RSE EFS, and fetch symlink info + * Kevin Doyle (IBM) - [210673] [efs][nls] Externalize Strings in RSEFileStore and RSEFileStoreImpl ********************************************************************************/ package org.eclipse.rse.internal.efs; @@ -193,7 +194,7 @@ public class RSEFileStore extends FileStore implements IFileStore if (!isResourcesPluginUp()) { throw new CoreException(new Status(IStatus.WARNING, Activator.getDefault().getBundle().getSymbolicName(), - "Cannot access file: Resources not loaded yet")); + Messages.RESOURCES_NOT_LOADED)); } _impl = new RSEFileStoreImpl(this); } diff --git a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStoreImpl.java b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStoreImpl.java index 66c01d986c8..d86dcbbabc0 100644 --- a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStoreImpl.java +++ b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/RSEFileStoreImpl.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved. + * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -25,6 +25,7 @@ * Martin Oberhuber (Wind River) - [199552] fix deadlock with dstore-backed efs access * David McKnight (IBM) - [207178] changing list APIs for file service and subsystems * Kevin Doyle (IBM) - [208778] [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND + * Kevin Doyle (IBM) - [210673] [efs][nls] Externalize Strings in RSEFileStore and RSEFileStoreImpl ********************************************************************************/ package org.eclipse.rse.internal.efs; @@ -44,6 +45,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osgi.util.NLS; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.ISystemRegistry; @@ -229,13 +231,13 @@ public class RSEFileStoreImpl extends FileStore if (con == null) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Connection not found for host: "+hostNameOrAddr)); + NLS.bind(Messages.CONNECTION_NOT_FOUND, hostNameOrAddr))); } IRemoteFileSubSystem subSys = RSEFileStoreImpl.getRemoteFileSubSystem(con); if (subSys == null) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "No file subsystem found on host: "+hostNameOrAddr+" connection "+con.getAliasName())); + NLS.bind(Messages.NO_FILE_SUBSYSTEM, hostNameOrAddr, con.getAliasName()))); } if (!subSys.isConnected()) { try { @@ -245,7 +247,7 @@ public class RSEFileStoreImpl extends FileStore catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not connect to host: "+hostNameOrAddr+" subsystem "+subSys.getConfigurationId(), e)); + NLS.bind(Messages.COULD_NOT_CONNECT, hostNameOrAddr, subSys.getConfigurationId()), e)); } } return subSys; @@ -293,14 +295,14 @@ public class RSEFileStoreImpl extends FileStore if (parent==null) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get remote file")); + Messages.COULD_NOT_GET_REMOTE_FILE)); } try { remoteFile = parent.getParentRemoteFileSubSystem().getRemoteFileObject(parent, getName(), monitor); - } catch(Exception e) { + } catch(SystemMessageException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get remote file", e)); + getExceptionMessage(null, e), e)); } } else { //Handle was created with an absolute name @@ -308,11 +310,11 @@ public class RSEFileStoreImpl extends FileStore try { remoteFile = subSys.getRemoteFileObject(_store.getAbsolutePath(), monitor); } - catch (Exception e) { + catch (SystemMessageException e) { throw new CoreException(new Status( IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get remote file", e)); + getExceptionMessage(null, e), e)); } } @@ -320,7 +322,7 @@ public class RSEFileStoreImpl extends FileStore if (forceExists && (remoteFile == null || !remoteFile.exists())) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "The file store does not exist")); + Messages.FILE_STORE_DOES_NOT_EXIST)); } return remoteFile; } @@ -542,7 +544,7 @@ public class RSEFileStoreImpl extends FileStore exceptionText = e.getClass().getName(); } } else { - exceptionText = "Unknown exception"; + exceptionText = Messages.UNKNOWN_EXCEPTION; } if (item!=null && item.length()>0) { return exceptionText + ": " + item; //$NON-NLS-1$ @@ -591,7 +593,7 @@ public class RSEFileStoreImpl extends FileStore if (remoteFile.isDirectory()) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "The file store represents a directory")); + Messages.CANNOT_OPEN_STREAM_ON_FOLDER)); } if (remoteFile.isFile()) { @@ -602,7 +604,7 @@ public class RSEFileStoreImpl extends FileStore cacheRemoteFile(null); throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get input stream", e)); + getExceptionMessage(null, e), e)); } } @@ -620,7 +622,7 @@ public class RSEFileStoreImpl extends FileStore if (remoteFile==null) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get remote file")); + Messages.COULD_NOT_GET_REMOTE_FILE)); } IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem(); if (!remoteFile.exists()) { @@ -628,17 +630,17 @@ public class RSEFileStoreImpl extends FileStore remoteFile = subSys.createFolder(remoteFile, monitor); cacheRemoteFile(remoteFile); } - catch (Exception e) { + catch (SystemMessageException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "The directory could not be created", e)); + getExceptionMessage(null, e), e)); } return _store; } else if (remoteFile.isFile()) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "A file of that name already exists")); + Messages.FILE_NAME_EXISTS)); } else { return _store; @@ -655,7 +657,7 @@ public class RSEFileStoreImpl extends FileStore if (remoteFile==null) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get remote file")); + Messages.COULD_NOT_GET_REMOTE_FILE)); } IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem(); if (!remoteFile.exists()) { @@ -663,10 +665,10 @@ public class RSEFileStoreImpl extends FileStore remoteFile = subSys.createFile(remoteFile, monitor); cacheRemoteFile(remoteFile); } - catch (Exception e) { + catch (SystemMessageException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not create file", e)); + getExceptionMessage(null, e), e)); } } @@ -683,13 +685,13 @@ public class RSEFileStoreImpl extends FileStore catch (SystemMessageException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not get output stream", e)); + Messages.CANNOT_OPEN_STREAM_ON_FOLDER, e)); } } else if (remoteFile.isDirectory()) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "This is a directory")); + Messages.CANNOT_OPEN_STREAM_ON_FOLDER)); } else { //TODO check what to do for symbolic links and other strange stuff @@ -711,13 +713,13 @@ public class RSEFileStoreImpl extends FileStore if (!success) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not delete file")); + Messages.DELETE_FAILED)); } } - catch (Exception e) { + catch (SystemMessageException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), - "Could not delete file", e)); + getExceptionMessage(null, e), e)); } } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/messages.properties b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/messages.properties new file mode 100644 index 00000000000..d25e9d982db --- /dev/null +++ b/rse/plugins/org.eclipse.rse.efs/src/org/eclipse/rse/internal/efs/messages.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2008 IBM Corporation and others. All rights reserved. +# This program and the accompanying materials are made available under the terms +# of the Eclipse Public License v1.0 which accompanies this distribution, and is +# available at http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Kevin Doyle (IBM) - [210628] Externalize Strings in RSEFileStore and RSEFileStoreImpl +################################################################################ + +RESOURCES_NOT_LOADED=Cannot access file: Resources not loaded yet +CONNECTION_NOT_FOUND=Connection not found for host: {0} +NO_FILE_SUBSYSTEM=No file subsystem found on host: {0} connection {1} +COULD_NOT_CONNECT=Could not connect to host: {0} subsystem {1} +COULD_NOT_GET_REMOTE_FILE=Could not get remote file +FILE_STORE_DOES_NOT_EXIST=The file store does not exist +UNKNOWN_EXCEPTION=Unknown exception +FILE_NAME_EXISTS=A file of that name already exists +CANNOT_OPEN_STREAM_ON_FOLDER=Can't open a stream on a folder +DELETE_FAILED=Could not delete file \ No newline at end of file