Bug 344066 - DBCS3.7 DBCS (shift JIS) characters are corrupted in Outline view of ANT
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/IAntCoreConstants.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/IAntCoreConstants.java
index 1c84381..d969f33 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/IAntCoreConstants.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/IAntCoreConstants.java
@@ -115,4 +115,13 @@
 	 * @since org.eclipse.ant.core 3.2.200
 	 */
 	public static final String DESCRIPTION = "description"; //$NON-NLS-1$
+
+	/**
+	 * Constant for the encoding <code>UTF-8</code>
+	 * <br><br>
+	 * Value is: <code>UTF-8</code>
+	 * 
+	 * @since org.eclipse.ant.core 3.3.0
+	 */
+	public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
 }
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/utils/ProjectHelper.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/utils/ProjectHelper.java
index 2affffa..093bfa0 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/utils/ProjectHelper.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/utils/ProjectHelper.java
@@ -62,7 +62,7 @@
 	private static FileUtils fu= null;
     
 	/**
-	 * The buildfile that is to be parsed. Must be set if parsing is to
+	 * The build file that is to be parsed. Must be set if parsing is to
 	 * be successful.
 	 */
 	private File buildFile= null;
@@ -553,7 +553,12 @@
                 stream = new FileInputStream(buildFile);
                 inputSource = new InputSource(stream);
         	} else if (source instanceof String) {
-        		stream = new ByteArrayInputStream(((String)source).getBytes("UTF-8")); //$NON-NLS-1$
+        		IAntModel model = getAntModel();
+        		String encoding = IAntCoreConstants.UTF_8;
+        		if(model != null) {
+        			encoding = model.getEncoding();
+        		}
+        		stream = new ByteArrayInputStream(((String)source).getBytes(encoding));
         		inputSource = new InputSource(stream);
         	}
         	
@@ -607,7 +612,7 @@
         }
     }
 
-	/**
+    /**
 	 * Sets the buildfile that is about to be parsed or <code>null</code> if
 	 * parsing has completed.
 	 * 
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
index 31ecc23..ea47b54 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
@@ -13,6 +13,7 @@
 package org.eclipse.ant.internal.ui.model;
 
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -61,7 +62,10 @@
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.content.IContentDescription;
 import org.eclipse.core.variables.IStringVariableManager;
 import org.eclipse.core.variables.VariablesPlugin;
 import org.eclipse.jface.text.BadLocationException;
@@ -89,6 +93,7 @@
     private AntElementNode fLastNode;
     private AntElementNode fNodeBeingResolved;
     private int fNodeBeingResolvedIndex= -1;
+    private String fEncoding = null;
     
     private Map fEntityNameToPath;
     
@@ -199,6 +204,7 @@
     	if(helper == null) {
     		ProjectHelperRepository.getInstance().registerProjectHelper(ProjectHelper.class);
     	}
+    	computeEncoding();
     }
     
     /**
@@ -265,6 +271,7 @@
             IntrospectionHelper.getHelper(projectNode.getProject(), Small.class);
             projectNode.getProject().fireBuildFinished(null);
         }
+        fEncoding = null;
     }
 
     /* (non-Javadoc)
@@ -1837,4 +1844,52 @@
      */
     class Small {
     }
+
+    /**
+     * Compute the encoding for the backing build file
+     * 
+     * @since 3.7
+     */
+    void computeEncoding() { 
+    	try {
+			IFile file = getFile();
+			if(file != null) {
+				fEncoding = getFile().getCharset(true);
+				return;
+			}
+		} catch (CoreException e) {
+			//do nothing. default to UTF-8 
+		}
+		//try the file buffer manager - likely an external file
+		IPath path = getLocationProvider().getLocation();
+		if(path != null) {
+			File buildfile = path.toFile();
+			FileReader reader = null;
+			try {
+				reader = new FileReader(buildfile);
+				QualifiedName[] options= new QualifiedName[] {IContentDescription.CHARSET};
+				IContentDescription desc = Platform.getContentTypeManager().getDescriptionFor(reader,  buildfile.getName(), options);
+				if(desc != null) {
+					fEncoding = desc.getCharset();
+					return;
+				}
+			}
+			catch(IOException ioe) {}
+			finally {
+				if(reader != null) {
+					try {
+						reader.close();
+					} catch (IOException e) {}
+				}
+			}
+		}
+		fEncoding = IAntCoreConstants.UTF_8;
+    }
+    
+	/* (non-Javadoc)
+	 * @see org.eclipse.ant.internal.ui.model.IAntModel#getEncoding()
+	 */
+	public String getEncoding() {
+		return fEncoding;
+	}
 }
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/IAntModel.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/IAntModel.java
index 6175880..d7c44ef 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/IAntModel.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/IAntModel.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 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
@@ -80,6 +80,16 @@
     IFile getFile();
 
     /**
+     * Returns the encoding from the backing {@link IAntModel}. If the model is <code>null</code>
+     * or the encoding cannot be computed from the location backing the model, <code>UTF-8</code> 
+     * is returned
+     * 
+     * @return the encoding
+     * @since 3.7
+     */
+    String getEncoding();
+    
+    /**
      * Handles a <code>BuildException</code> that occurred during parsing.
      * @param be the build exception that occurred
      * @param node the node associated with the problem