return false;
}
public void enforceDesignEncoding() throws CoreException {
getDesignRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
final Map<String,String> fDefaultCharsetsByExtension = new HashMap<String,String>();
fDefaultCharsetsByExtension.put("xml", "UTF-8");
fDefaultCharsetsByExtension.put("css", "UTF-8");
// no explicit encoding for design root & file container root
if (getDesignRoot() != null && getDesignRoot().isAccessible()) {
getDesignRoot().setDefaultCharset(null, new NullProgressMonitor());
}
if (getFileContainerRoot() != null && getFileContainerRoot().isAccessible()) {
getFileContainerRoot().setDefaultCharset(null, new NullProgressMonitor());
}
// set explicit encodings where necessary
final String fEncoding = determineDesignEncoding();
if (getTmlRoot() != null && getTmlRoot().isAccessible()) {
getTmlRoot().setDefaultCharset(fEncoding, new NullProgressMonitor());
}
if (getScriptsRoot() != null && getScriptsRoot().isAccessible()) {
getScriptsRoot().setDefaultCharset(fEncoding, new NullProgressMonitor());
getScriptsRoot().accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
String defaultEncoding = fDefaultCharsetsByExtension.get(file.getFileExtension().toLowerCase());
if (defaultEncoding != null) {
String resourceCharset = file.getCharset();
if (resourceCharset == null) {
resourceCharset = defaultEncoding;
}
if (!fEncoding.equals(resourceCharset)) {
// if design encoding differ from default encoding we define it explicit
file.setCharset(fEncoding, new NullProgressMonitor());
} else {
file.setCharset(null, new NullProgressMonitor());
}
}
}
return true;
}