# HG changeset patch # User Eugene Ostroukhov # Date 1265060381 28800 # Node ID 3b6f16a767328dca09b641ed65a5af1617d0e041 # Parent fb430f25c33dda24a225d867fdf3f4fc0355ed8b More project templates were introduced. Several bugs were fixed. diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Mon Feb 01 13:39:41 2010 -0800 @@ -132,7 +132,7 @@ private String readFile(IProject project, String fileName) throws CoreException, UnsupportedEncodingException, IOException { - IFile file = project.getFile(fileName); + IFile file = getFile(project, fileName); if (file.isAccessible()) { InputStream contents = file.getContents(); final BufferedReader reader = new BufferedReader( @@ -152,6 +152,19 @@ return null; } + private IFile getFile(IProject project, String fileName) throws CoreException { + String n = fileName.toLowerCase(); + IResource[] members = project.members(); + for (IResource iResource : members) { + if (iResource.getType() == IResource.FILE + && n.equals(iResource.getName().toLowerCase()) + && iResource.isAccessible()) { + return (IFile) iResource; + } + } + return null; + } + private InputStream getPluginResourceStream(IPath path) throws IOException { URL url = FileLocator.find(PreviewerPlugin.getDefault().getBundle(), path, null); diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Mon Feb 01 13:39:41 2010 -0800 @@ -170,5 +170,8 @@ public void setSelection(ISelection selection) { // Do nothing } - + + public boolean isDisposed() { + return browser != null && browser.isDisposed(); + } } diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/IPreviewPage.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/IPreviewPage.java Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/IPreviewPage.java Mon Feb 01 13:39:41 2010 -0800 @@ -7,4 +7,5 @@ public interface IPreviewPage extends IPageBookViewPage { void process(Collection files); + boolean isDisposed(); } diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Mon Feb 01 13:39:41 2010 -0800 @@ -107,7 +107,7 @@ IProject project = resource.getProject(); IPreviewPage page = projectToPage.get(project); - if (page == null) { + if (page == null || page.isDisposed()) { page = createPreviewPage(project); initPage(page); page.createControl(getPageBook()); diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch --- a/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Windows).launch Mon Feb 01 13:39:41 2010 -0800 @@ -21,8 +21,8 @@ - - + + diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools.product/wrt-ide.product --- a/org.symbian.tools.wrttools.product/wrt-ide.product Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools.product/wrt-ide.product Mon Feb 01 13:39:41 2010 -0800 @@ -32,7 +32,6 @@ - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5 org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6 @@ -254,6 +253,7 @@ + diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools/plugin.xml Mon Feb 01 13:39:41 2010 -0800 @@ -145,6 +145,44 @@ This wizard generates an empty widget project with a minimal Info.plist, html,css and js. + + + This wizard generates an basic project with a minimal Info.plist, html,css and js along with WRTKit. + + + + + This wizard generates an Flickr project with a minimal Info.plist, html,css and js and WRTKit. + + + + + This wizard generates an RSS Reader project with a minimal Info.plist, html,css and js and WRTKit. + + diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/projecttemplates/flickr.zip Binary file org.symbian.tools.wrttools/projecttemplates/flickr.zip has changed diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/projecttemplates/rssreader.zip Binary file org.symbian.tools.wrttools/projecttemplates/rssreader.zip has changed diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/projecttemplates/wrtkit.zip Binary file org.symbian.tools.wrttools/projecttemplates/wrtkit.zip has changed diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java Mon Feb 01 13:26:14 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java Mon Feb 01 13:39:41 2010 -0800 @@ -19,51 +19,19 @@ package org.symbian.tools.wrttools; -import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.runtime.CoreException; -import org.symbian.tools.wrttools.core.validator.WidgetProjectValidator; - public class WidgetProjectNature implements IProjectNature { public static final String ID = Activator.PLUGIN_ID + ".WidgetProjectNature"; private IProject project; public void configure() throws CoreException { - IProjectDescription desc = project.getDescription(); - ICommand[] commands = desc.getBuildSpec(); - - for (int i = 0; i < commands.length; ++i) { - if (commands[i].getBuilderName().equals(WidgetProjectValidator.BUILDER_ID)) { - return; - } - } - - ICommand[] newCommands = new ICommand[commands.length + 1]; - System.arraycopy(commands, 0, newCommands, 0, commands.length); - ICommand command = desc.newCommand(); - command.setBuilderName(WidgetProjectValidator.BUILDER_ID); - newCommands[newCommands.length - 1] = command; - desc.setBuildSpec(newCommands); - project.setDescription(desc, null); } public void deconfigure() throws CoreException { - IProjectDescription description = getProject().getDescription(); - ICommand[] commands = description.getBuildSpec(); - for (int i = 0; i < commands.length; ++i) { - if (commands[i].getBuilderName().equals(WidgetProjectValidator.BUILDER_ID)) { - ICommand[] newCommands = new ICommand[commands.length - 1]; - System.arraycopy(commands, 0, newCommands, 0, i); - System.arraycopy(commands, i + 1, newCommands, i, - commands.length - i - 1); - description.setBuildSpec(newCommands); - return; - } - } } public IProject getProject() { diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetProjectValidator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetProjectValidator.java Mon Feb 01 13:26:14 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,466 +0,0 @@ -/** - * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). - * All rights reserved. - * This component and the accompanying materials are made available - * under the terms of the License "Eclipse Public License v1.0" - * which accompanies this distribution, and is available - * at the URL "http://www.eclipse.org/legal/epl-v10.html". - * - * Initial Contributors: - * Symbian Foundation - initial contribution. - * Contributors: - * Description: - * Overview: - * Details: - * Platforms/Drives/Compatibility: - * Assumptions/Requirement/Pre-requisites: - * Failures and causes: - */ - -package org.symbian.tools.wrttools.core.validator; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.osgi.framework.Bundle; - -import org.symbian.tools.wrttools.sdt.utils.DefaultMessageListener; -import org.symbian.tools.wrttools.sdt.utils.FileUtils; -import org.symbian.tools.wrttools.sdt.utils.MessageLocation; -import org.symbian.tools.wrttools.sdt.utils.VariableSubstitutionEngine; -import org.symbian.tools.wrttools.Activator; -import org.symbian.tools.wrttools.core.exception.ValidationException; -import org.symbian.tools.wrttools.core.packager.WRTPackagerConstants; -import org.symbian.tools.wrttools.core.widgetmodel.WidgetModel; -import org.symbian.tools.wrttools.previewer.preview.PreviewSupport; - -public class WidgetProjectValidator { - - static final String INFO_PLIST = "info.plist"; - boolean previewMainCreated = false; - private IProject project; - private WidgetModel model = null; - - public static final String BUILDER_ID = "org.symbian.tools.wrttools.core.validator.widgetProjectValidator"; - - public WidgetProjectValidator() { - super(); - ValidateAction validator = new ValidateAction(); - validator.isValidProject(project); - //return null; - } - void checkResource(IResource resource, IProject project ) { - if (resource instanceof IFile) { - try { - if(!previewMainCreated ) { - //createEmptyPreviewMainHTML(); - createPreviewFrameHTML(project); - - } - //if info.plist modified - if (isInfoPList(resource)) { - // did a change to info.plist result in a different main html file? - - IResource prevMainHTML = null; - String mainHtmlName = project.getPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY); - if (mainHtmlName != null) { - prevMainHTML = project.findMember(mainHtmlName, false); - } - model = null; - IFile currMainHTML = getMainHTMLFromModel(project); - - if ( currMainHTML != null){ - if(!currMainHTML.equals(prevMainHTML)) { - updateHTMLPreview(currMainHTML); - - } - } - else{ - createEmptyPreviewMainHTML(project); - project.setPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY, null); - } - - - } - else{ - IFile currMainHTML = getMainHTMLFromModel(project); - String mainHtmlPath = project.getPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY); - if(mainHtmlPath == null){ - if (currMainHTML != null && !currMainHTML.equals(resource)) { - updateHTMLPreview(currMainHTML); - } - } - else if (mainHtmlPath.equals(resource.getProjectRelativePath().toString())) { - updateHTMLPreview((IFile)resource); - - } - } - } catch (CoreException e) { - Activator.log(IStatus.ERROR, "Error building resource:"+resource.getFullPath().toString(), e); - } catch (IOException e) { - Activator.log(IStatus.ERROR, "Error building resource:"+resource.getFullPath().toString(), e); - } catch (URISyntaxException e) { - Activator.log(IStatus.ERROR, "Error building resource:"+resource.getFullPath().toString(), e); - } - } - } - - private void updateHTMLPreview(IFile htmlFile) throws CoreException, IOException, URISyntaxException { - createPreviewMainHTML(getMainHTML(project)); - //createPreviewFrameHTML(); - - } - - protected void updatePreviewFiles(IProject project) - throws CoreException { - final List filesToPackage = new ArrayList(); - try { - updatePreviewSupportFiles(project); - project.accept(new IResourceVisitor() { - - public boolean visit(IResource resource) throws CoreException { - if (resource instanceof IFile) { - IFile file = (IFile) resource; - boolean add = true; - // skip user-excluded and automatically-excluded files - String value = file - .getPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY); - if (value != null) { - add = false; - } - String name = file.getName(); - // skip Aptana temporarily generated files - if (name.startsWith(".tmp_")) { - add = false; - } - // if(name.endsWith(".wgz")){ - // add = false; - // } - if (name.equals("Thumbs.db")) { - add = false; - } - if (add) { - if (file.getProject().getLocation().toString() - .endsWith(file.getProject().getName())) { - - filesToPackage.add(file.getLocation() - .toString().substring( - file.getProject().getLocation() - .toString().length() - - file.getProject() - .getName() - .length())); - } else { - String projectDir = file.getProject() - .getLocation().toString().substring( - file.getProject().getLocation() - .toString() - .lastIndexOf("/") + 1); - String fullpath = file.getFullPath().toString(); - fullpath = fullpath.substring(fullpath - .indexOf(file.getProject().getName()) - + file.getProject().getName().length()); - fullpath = projectDir + fullpath; - filesToPackage.add(fullpath); - - } - } - } - return true; - } - }); - } catch (CoreException x) { - Activator.log(IStatus.ERROR, "Error updating widget preview", x); - } - } - - private boolean isInfoPList(IResource resource) { - return INFO_PLIST.equalsIgnoreCase(resource.getProjectRelativePath().toString()); - } - - private IFile getMainHTML(IProject project) { - IFile result = null; - try { - String mainHtmlName = project.getPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY); - if (mainHtmlName != null) { - IResource resource = project.findMember(mainHtmlName, false); - if (resource != null && resource instanceof IFile) { - result = (IFile) resource; - } else { - project.setPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY, null); - } - } - if (result == null) { - result = getMainHTMLFromModel(project); - } - } catch (CoreException x) { - Activator.log(IStatus.ERROR, "error getting main html property", x); - } - return result; - } - - private IFile getMainHTMLFromModel(IProject project) { - IFile result = null; - if(model == null) - model = getModel(project); - String mainHtml = model.getMainHtml(); - if(mainHtml != null) { - IResource resource = project.findMember(mainHtml, false); - if (resource != null && resource instanceof IFile) { - try { - project.setPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY, mainHtml); - result = (IFile) resource; - }catch (CoreException x) { - Activator.log(IStatus.ERROR, "error setting file persistent property", x); - } - }else{ - try { - project.setPersistentProperty(PreviewSupport.MAIN_HTML_PROPERTY, null); - result = (IFile) resource; - }catch (CoreException x) { - Activator.log(IStatus.ERROR, "error setting file persistent property", x); - } - } - } - return result; - } - - private WidgetModel getModel(IProject project) { - WidgetModel model = new WidgetModel(); - String path = project.getLocation().toString(); - model.setWidgetDirectory(path); - try { - model.getWidgetModel(new File(path)); - } catch (ValidationException x) { - Activator.log(IStatus.ERROR, "invalid widget", x); - } - return model; - } - - private String readFileIntoString(File file) throws CoreException, FileNotFoundException { - InputStream is = new FileInputStream(file); - return new String(FileUtils.readInputStreamContents(is, "UTF-8")); - } - - private void setFileFromString(IFile file, String contents) throws UnsupportedEncodingException, CoreException { - ByteArrayInputStream is = new ByteArrayInputStream(contents.getBytes("UTF-8")); - if (!file.exists()) { - file.create(is, true, new NullProgressMonitor()); - } else { - file.setContents(is, true, false, new NullProgressMonitor()); - } - } - - private void updatePreviewSupportFiles(IProject project) { - try { - PreviewSupport ps = new PreviewSupport(project); - IFolder previewFolder = ps.getPreviewFolder(); - IProgressMonitor progressMonitor = new NullProgressMonitor(); - IProject projects[] = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - - if (previewFolder.exists()) { - // Use File-based utility since IFolder.delete doesn't always delete subfolders - FileUtils.delTree(previewFolder.getLocation().toFile()); - previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - for(int u=0; u < projects.length; u++){ - projects[u].refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - } - if(!previewFolder.isSynchronized(IResource.DEPTH_INFINITE)){ - for(int u=0; u < projects.length; u++){ - projects[u].refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.getProject().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.getParent().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - //No need to delete empty folder, we will reuse the same folder for copying new files and sub folders into this. - //previewFolder.delete(IResource.FORCE|IFolder.INCLUDE_TEAM_PRIVATE_MEMBERS|IContainer.INCLUDE_PHANTOMS, progressMonitor); - - if(!previewFolder.isSynchronized(IResource.DEPTH_INFINITE)){ - for(int u=0; u < projects.length; u++){ - projects[u].refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.getProject().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.getParent().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - // No need to create preview folder as we are using existing empty preview folder and copying into that - //previewFolder.create(true, false, progressMonitor); - - if(!previewFolder.isSynchronized(IResource.DEPTH_INFINITE)){ - for(int u=0; u < projects.length; u++){ - projects[u].refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.getProject().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.getParent().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.setDerived(true); - - File destRootDir = previewFolder.getLocation().toFile(); - copyPreviewFiles("/preview", "/preview", destRootDir); - //previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - //previewFolder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - if(!previewFolder.isSynchronized(IResource.DEPTH_INFINITE)){ - for(int u=0; u < projects.length; u++){ - projects[u].refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.getProject().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.getParent().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - previewFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); - } - previewFolder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - - - previewFolder.accept(new IResourceVisitor() { - public boolean visit(IResource r) { - try { - // inhibit packaging for preview files - r.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - // inhibit version control for preview files - r.setDerived(true); - } catch (CoreException x) { - Activator.log(IStatus.ERROR, "error setting packager property on "+r.getFullPath().toString(), x); - } - return true; - } - }); - } - catch (IOException x) { - Activator.log(IStatus.ERROR, "Error updating preview support files", x); - } catch (CoreException x) { - Activator.log(IStatus.ERROR, "Error updating preview support files", x); - } - } - - private void copyPreviewFiles(String sourceRootDir, String topRootDir, File destRootDir) throws IOException, CoreException { - Bundle bundle = Activator.getDefault().getBundle(); - Enumeration e = bundle.getEntryPaths(sourceRootDir); - if (e != null) { - while (e.hasMoreElements()) { - String path = (String) e.nextElement(); - // paths indicating subdirectories end with '/'. - if (path.endsWith("/")) { - // need to trim first component off path, which is the base preview dir - IPath destPath = new Path(path); - destPath = destPath.removeFirstSegments(1); - File newDir = new File(destRootDir, destPath.toString()); - newDir.mkdirs(); - copyPreviewFiles(path, topRootDir, destRootDir); - } else { - // skip PREVIEW_HTML_TEMPLATE, we don't copy to preview folder - IPath destPath = new Path(path); - destPath = destPath.removeFirstSegments(1); - File newFile = new File(destRootDir, destPath.toString()); - if (!newFile.getName().equals(PreviewSupport.PREVIEW_HTML_TEMPLATE)) { - InputStream is = openBundleFile(new Path(path)); - FileUtils.copyFile(is, newFile); - } - } - } - } - } - - private InputStream openBundleFile(IPath path) throws IOException { - InputStream is = FileLocator.openStream(Activator.getDefault().getBundle(), - path, false); - return is; - } - - private void createPreviewFrameHTML(IProject project) throws IOException, CoreException, URISyntaxException { - - PreviewSupport ps = new PreviewSupport(project); - InputStream templateStream = openBundleFile(ps.getPreviewFrameTemplate()); - String templateText = new String(FileUtils.readInputStreamContents(templateStream, null)); - - Map vars = new HashMap(); - String previewBasePath = PreviewSupport.PREVIEW_FOLDER + "/"; - vars.put("preview_base", previewBasePath); - VariableSubstitutionEngine engine = new VariableSubstitutionEngine( - new DefaultMessageListener(), - new MessageLocation(ps.getProject(), 0, 0)); - engine.setVariableToken('('); - String resultText = engine.substitute(vars, templateText); - - IFile previewFrame = ps.getPreviewFrameHtml(); - boolean updateProperty = !previewFrame.exists(); - setFileFromString(previewFrame, resultText); - if (updateProperty) { - previewFrame.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - } - previewFrame.setDerived(true); - } - - private void createEmptyPreviewMainHTML(IProject project) throws CoreException, UnsupportedEncodingException, FileNotFoundException { - if(previewMainCreated) - return; - - previewMainCreated = true; - PreviewSupport ps = new PreviewSupport(project); - - IFile previewMainHtml = ps.getPreviewMainHtml(); - - setFileFromString(previewMainHtml, ""); - previewMainHtml.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - previewMainHtml.setDerived(true); - - } - - private void createPreviewMainHTML(IFile src) throws CoreException, UnsupportedEncodingException, FileNotFoundException { - - PreviewSupport ps = new PreviewSupport(project); - File inputFile = src.getLocation().toFile(); - String contents = readFileIntoString(inputFile); - Pattern headPattern = Pattern.compile("]*>", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); - - String previewBasePath = PreviewSupport.PREVIEW_FOLDER; - StringBuffer buf = new StringBuffer(); - buf.append("\t\n"); - String previewScripts = buf.toString(); - - Matcher matcher = headPattern.matcher(contents); - if (matcher.find()) { - String replacement = "\n" + previewScripts; - contents = matcher.replaceFirst(replacement); - } else { - Pattern bodyPattern = Pattern.compile("]*>", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); - matcher = bodyPattern.matcher(contents); - if (matcher.find()) { - String replacement = "\n" + previewScripts + ""; - contents = matcher.replaceFirst(replacement); - } - } - - IFile previewMainHtml = ps.getPreviewMainHtml(); - setFileFromString(previewMainHtml, contents); - previewMainHtml.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); - previewMainHtml.setDerived(true); - } -} diff -r fb430f25c33d -r 3b6f16a76732 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/previewer/preview/PreviewSupport.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/previewer/preview/PreviewSupport.java Mon Feb 01 13:26:14 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/** - * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). - * All rights reserved. - * This component and the accompanying materials are made available - * under the terms of the License "Eclipse Public License v1.0" - * which accompanies this distribution, and is available - * at the URL "http://www.eclipse.org/legal/epl-v10.html". - * - * Initial Contributors: - * Symbian Foundation - initial contribution. - * Contributors: - * Description: - * Overview: - * Details: - * Platforms/Drives/Compatibility: - * Assumptions/Requirement/Pre-requisites: - * Failures and causes: - */ - -package org.symbian.tools.wrttools.previewer.preview; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; - -import org.symbian.tools.wrttools.sdt.utils.Check; -import org.symbian.tools.wrttools.sdt.utils.TrackedResource; - - /** - * This class encapsulates the creation and naming - * of the preview folder and support files - * @author dpodwall - * - */ -public class PreviewSupport { - - public static final String PREVIEW_FOLDER = "preview"; - public static final String PREVIEW_MAIN_HTML = "wrt_preview_main.html"; - public static final String PREVIEW_FRAME_HTML = "wrt_preview_frame.html"; - public static final String PREVIEW_HTML_TEMPLATE = "wrt_preview.html"; - public static final QualifiedName MAIN_HTML_PROPERTY = new QualifiedName("org.symbian.tools.wrttools", "mainHTML"); - //public static final String PREVIEW_BROWSER_NAME1 = "WRT Widget (S60)"; - public static final String PREVIEW_BROWSER_NAME = "Web Runtime (WRT)"; - - private TrackedResource projectTracker; - - public PreviewSupport(IProject project) { - Check.checkArg(project); - this.projectTracker = new TrackedResource(project); - } - - public void dispose() { - if (projectTracker != null) { - projectTracker.dispose(); - } - } - - public IProject getProject() { - return projectTracker.getProject(); - } - - /** - * Returns the folder containing preview support files, creating it - * if needed. - * @throws CoreException - */ - public IFolder getPreviewFolder() throws CoreException { - IFolder result = getProject().getFolder(PREVIEW_FOLDER); - if (!result.exists()) { - result.create(true, true, new NullProgressMonitor()); - } - return result; - } - - /** - * Returns the main file, which is a copy of the user's main html - * file. The copy is modified to include the widget preview environment - * JavaScript files. - * The returned IFile may not exist yet - * @throws CoreException - */ - public IFile getPreviewMainHtml() throws CoreException { - IFile result = getProject().getFile(PREVIEW_MAIN_HTML); - return result; - } - - /** - * Returns the preview file, which is the outermost html - * file of the preview environment. It includes the main - * file in an iframe. - * The returned IFile may not exist yet - * @throws CoreException - */ - public IFile getPreviewFrameHtml() throws CoreException { - IFile result = getProject().getFile(PREVIEW_FRAME_HTML); - return result; - } - public IFile getMainHtml() throws CoreException { - IFile result = null; - String mainFilePath = getProject().getPersistentProperty(MAIN_HTML_PROPERTY); - if (mainFilePath != null) { - IResource resource = getProject().findMember(mainFilePath); - if (resource instanceof IFile) { - result = (IFile) resource; - } - } - return result; - } - - /** - * Returns the base path for preview support files - * in the plugin - * @return - */ - public IPath getPreviewPluginBase() { - return new Path("preview"); - } - - public IPath getPreviewFrameTemplate() { - return getPreviewPluginBase().append(PREVIEW_HTML_TEMPLATE); - } - -}