Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] fix for 69768


69768: TVT3.0: Preferences -> Ant has text showing up in english.
This problem was for code templates for Ant and extended to Java.

CDT had a similar problem, the default-templates.xml wasn't accessed correctly.
Although it didn't use the eclipse extension point for templates, the code
still needed to pick up the $nl$ variable in the path to the file.


To go to Head and 2.0 branch.
Tested on Windows and Linux.

Thanks,
Tanya

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.530
diff -u -r1.530 ChangeLog
--- ChangeLog	28 Jul 2004 21:55:05 -0000	1.530
+++ ChangeLog	29 Jul 2004 18:42:24 -0000
@@ -1,3 +1,8 @@
+2004-07-29 Tanya Wolff
+
+	Part Fix for 69768: CDT wasn't displaying non-English templates.
+	*org.eclipse.cdt.internal.corext.template/Templates.java
+	
 2004-07-27 Tanya Wolff
 
 	Fix for 70124 -- allow buttons to be expandable for translation
Index: src/org/eclipse/cdt/internal/corext/template/Templates.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/Templates.java,v
retrieving revision 1.3
diff -u -r1.3 Templates.java
--- src/org/eclipse/cdt/internal/corext/template/Templates.java	4 Feb 2003 20:00:46 -0000	1.3
+++ src/org/eclipse/cdt/internal/corext/template/Templates.java	29 Jul 2004 18:42:24 -0000
@@ -8,12 +8,21 @@
 import org.eclipse.cdt.ui.CUIPlugin;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionRegistry;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
 
 import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.ui.internal.util.BundleUtility;
+import org.osgi.framework.Bundle;
 
 /**
  * <code>Templates</code> gives access to the available templates.
@@ -21,6 +30,8 @@
 public class Templates extends TemplateSet {
 
 	private static final String DEFAULT_FILE= "default-templates.xml"; //$NON-NLS-1$
+	private static final String NL_DEFAULT_FILE= "$nl$/org/eclipse/cdt/internal/corext/template/default-templates.xml"; //$NON-NLS-1$
+	
 	private static final String TEMPLATE_FILE= "templates.xml"; //$NON-NLS-1$
 
 	/** Singleton. */
@@ -84,8 +95,39 @@
 	}
 
 	private static InputStream getDefaultsAsStream() {
-		return Templates.class.getResourceAsStream(DEFAULT_FILE);
+		URL defFile = getDefaultTemplateFile();
+		if (defFile == null) return Templates.class.getResourceAsStream(DEFAULT_FILE);
+		try {
+            return defFile.openStream();
+        } catch (IOException e) {
+            return null;
+        }
+		
+		//return Templates.class.getResourceAsStream(getDefaultTemplateFile());
 	}
+	/**
+	 * Gets the resolved $nl$ path to the NL_DEFAULT_TEMPLATE file as a URL.
+	 * If it doesn't exist, then null is returned. Calling procedures use
+	 * DEFAULT_TEMPLATES if null is returned from this.
+	 */
+	public static URL getDefaultTemplateFile() {
+    
+	    Bundle bundle = Platform.getBundle("org.eclipse.cdt.ui"); //$NON-NLS-1$
+		if (!BundleUtility.isReady(bundle))
+			return null;
+
+		URL fullPathString = BundleUtility.find(bundle, NL_DEFAULT_FILE);
+		if (fullPathString == null) {
+			try {
+				fullPathString = new URL(NL_DEFAULT_FILE);
+			} catch (MalformedURLException e) {
+				return null;
+			}
+		}
+
+		return fullPathString;
+	    
+	} 
 
 	private static File getTemplateFile() {
 		IPath path= CUIPlugin.getDefault().getStateLocation();

Back to the top