# HG changeset patch # User Eugene Ostroukhov # Date 1265390278 28800 # Node ID b6d252d808df4abaf83c9f59ec0c62ea4a53c79b # Parent e5c37ce1b00363ae20ac6d1d4326471097f78a85 Nokia validation code is now integrated with WTP framework diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools.debug.core/.classpath --- a/org.symbian.tools.wrttools.debug.core/.classpath Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools.debug.core/.classpath Fri Feb 05 09:17:58 2010 -0800 @@ -1,6 +1,6 @@ - + diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools.jseditors/.classpath --- a/org.symbian.tools.wrttools.jseditors/.classpath Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools.jseditors/.classpath Fri Feb 05 09:17:58 2010 -0800 @@ -1,6 +1,6 @@ - + diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools.previewer/.classpath --- a/org.symbian.tools.wrttools.previewer/.classpath Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/.classpath Fri Feb 05 09:17:58 2010 -0800 @@ -1,6 +1,6 @@ - + diff -r e5c37ce1b003 -r b6d252d808df 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 Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WorkspaceResourcesServlet.java Fri Feb 05 09:17:58 2010 -0800 @@ -47,14 +47,13 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.symbian.tools.wrttools.previewer.PreviewerPlugin; +import org.symbian.tools.wrttools.util.CoreUtil; public class WorkspaceResourcesServlet extends HttpServlet { private static final String STARTING_PAGE = "preview-frame.html"; private static final String INDEX_PAGE = "wrt_preview_main.html"; private static final long serialVersionUID = -3217197074249607950L; - private static final Pattern HTML_FILE_NAME_PROPERTY = Pattern - .compile("\\s*MainHTML\\s*\\s*\\s*(.*)\\s*", Pattern.CASE_INSENSITIVE); private static final Pattern HEAD_TAG_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE); private static final String SCRIPT = ""; @@ -103,7 +102,7 @@ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName); if (project.isAccessible()) { - String indexFileName = getIndexFileName(project); + String indexFileName = CoreUtil.getIndexFileName(readFile(project, "Info.plist")); if (indexFileName != null) { String string = readFile(project, indexFileName); if (string != null) { @@ -118,18 +117,6 @@ return null; } - private String getIndexFileName(IProject project) throws CoreException, - UnsupportedEncodingException, IOException { - String buffer = readFile(project, "Info.plist"); - if (buffer != null) { - Matcher matcher = HTML_FILE_NAME_PROPERTY.matcher(buffer); - if (matcher.find()) { - return matcher.group(1); - } - } - return null; - } - private String readFile(IProject project, String fileName) throws CoreException, UnsupportedEncodingException, IOException { IFile file = getFile(project, fileName); diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools.product/.classpath --- a/org.symbian.tools.wrttools.product/.classpath Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools.product/.classpath Fri Feb 05 09:17:58 2010 -0800 @@ -1,6 +1,6 @@ - + diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/.classpath --- a/org.symbian.tools.wrttools/.classpath Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/.classpath Fri Feb 05 09:17:58 2010 -0800 @@ -1,6 +1,6 @@ - + diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/plugin.xml Fri Feb 05 09:17:58 2010 -0800 @@ -42,22 +42,18 @@ - - - - - - + --> @@ -614,4 +610,23 @@ id="org.symbian.wrtkit"> + + + + + + + + + + diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/HtmlValidator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/HtmlValidator.java Wed Feb 03 10:45:34 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,259 +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.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.MessageFormat; -import java.util.List; -import java.util.Stack; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.w3c.tidy.Node; -import org.w3c.tidy.Tidy; -import org.w3c.tidy.TidyMessage; -import org.w3c.tidy.TidyMessageListener; - -import org.symbian.tools.wrttools.core.report.Message; -import org.symbian.tools.wrttools.core.report.MessageHandler; -import org.symbian.tools.wrttools.core.status.IWRTConstants; -import org.symbian.tools.wrttools.core.widgetmodel.WidgetModel; -import org.symbian.tools.wrttools.util.FileUtil; -import org.symbian.tools.wrttools.util.Util; - -/** -* Html Validator -* Accepts the MessageManager . -* Accept File projDir. -* Use xmlParser to get all elements in a stack. -* Call rule methods() passing the MessageManager and the stack of elements. -* -* @author Sailaja duvvuri -*/ -public class HtmlValidator implements IValidator { - boolean htmlValidationStaus; - private String htmlFileName=null; - private String htmlPlistFileName=null; - private File htmlFile=null; - private Logger log = Logger.getLogger(getClass().getName()); - private MessageHandler messageHandler; - private WidgetModel widgetModel; - private boolean allRulesPassed; - - - - public WidgetModel getWidgetModel() { - return widgetModel; - } - - public void setWidgetModel(WidgetModel widgetModel) { - this.widgetModel = widgetModel; - } - - - public MessageHandler getMessageHandler() { - return messageHandler; - } - - - public void setMessageHandler(MessageHandler messageHandler) { - this.messageHandler = messageHandler; - } - - public boolean validate( File projDir) { - - Stack htmlElements = null; - FileUtil fileUtil = new FileUtil(); - List dirList = fileUtil.getCurrDirFiles(projDir); - htmlFileName=widgetModel.getMainHtml(); - - try { - - htmlFile = fileUtil.getFile(dirList, htmlFileName); - - if (htmlFile != null){ - htmlFileName = htmlFile.getName(); - if (widgetModel.getHtmlXmlFile()!=null) { - checkWellformed(htmlFile,true); - for(int i=0;i> - private boolean checkWellformed(File htmlfile, boolean isParsingNeeded) { - String userDir = System.getProperty("user.dir"); - String outputFile = userDir+ "/tidy.html"; - //htmlfile will behave as directory when src field in html is blank (src =""), so skipping that. - if(htmlfile.isDirectory()){ - return true; - } - InputStream inStream; - try { - inStream = new FileInputStream(htmlfile); - OutputStream outStream = new FileOutputStream(outputFile); - //Parsing here is required only for html, coz js, css files cannot have reference files. - //fixing bug 742 - if(isParsingNeeded){ - Tidy jtidy = new Tidy(); - TMessageListener msglis= new TMessageListener(); - jtidy.setMessageListener(msglis); - Node xmlDocument = jtidy.parse(inStream, outStream); - } - inStream.close(); - } catch (FileNotFoundException e) { - Message msg = new Message(); - msg.setMessageSource(IWRTConstants.VALIDATOR); - msg.setMessageKey("no.element"); - msg.setMessage(htmlfile.getName()+ " referred in main html" + " could not be found"); - msg.setFileTypeZip(messageHandler.isFileTypeZip()); - msg.setTargetObject(htmlfile.toString()); - msg.setFullPath(htmlfile.getAbsolutePath()); - msg.setSeverity(IWRTConstants.WARN); - msg.setRecommendAction(ValidatorPropMessages.getString("todo.no.html.element")); - messageHandler.publishMessage(msg); - Util.logEvent(log, Level.SEVERE, e); - log.severe(e.getMessage()); - } catch (IOException e) { - Util.logEvent(log, Level.SEVERE, e); - log.severe(e.getMessage()); - } - return false; -} - - public class TMessageListener implements TidyMessageListener { - - public void messageReceived(TidyMessage tdyMsg) { - - if (tdyMsg.getLevel().equals(TidyMessage.Level.ERROR)) { - log.info("line :" + tdyMsg.getLine()); - log.info("message :" + tdyMsg.getMessage()); - Message msg = new Message(); - msg.setMessageSource(IWRTConstants.VALIDATOR); - msg.setMessageKey("html.wellform.error"); - msg.setMessage(tdyMsg.getMessage()); - msg.setFileTypeZip(messageHandler.isFileTypeZip()); - msg.setTargetObject(htmlFileName); - msg.setFullPath(htmlFile.getAbsolutePath()); - msg.setSeverity(IWRTConstants.WARN); - msg.setLineNumber(tdyMsg.getLine()); - // msg.setRecommendAction(ValidatorPropMessages.getString("todo.correct.html.tag")+ - // tdyMsg.getLine()+" of "+htmlFileName); - Object[] arguments = { tdyMsg.getLine(), " of , ", htmlFileName }; - String message = MessageFormat.format(ValidatorPropMessages - .getString("todo.correct.html.tag") - + "{0}" + "{1}" + "{2}", arguments); - msg.setRecommendAction(message); - - // set all msg fields - // For generating TO DO list - messageHandler.publishMessage(msg); - allRulesPassed = false; - - } - - } - } -//////<<<-----------------------------------code for Jtidy---------------------------------------// - - -} \ No newline at end of file diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetValidator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetValidator.java Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/WidgetValidator.java Fri Feb 05 09:17:58 2010 -0800 @@ -68,7 +68,6 @@ private boolean htmlVal; private MandatoryFilesValidator manFilevalidator; private PlistValidator plistValidator; - private HtmlValidator htmlValidator; private MessageHandler messageHandler; private IMessageListener msgListener; @@ -160,7 +159,6 @@ log.info("ValidateMandatoryFiles is done"); validatePlist( widgetProjFile); log.info("Validate plist is done"); - validateHtml( widgetProjFile); } catch (ReportException e) { Util.logEvent(log, Level.INFO, e); @@ -199,7 +197,6 @@ ValidateMandatoryFiles(widgetProjFile); validatePlist( widgetProjFile); log.info("Validate plist is done"); - validateHtml( widgetProjFile); } catch (ReportException e) { Util.logEvent(log, Level.INFO, e); @@ -276,32 +273,6 @@ return plistVal; } - - private boolean validateHtml(File fileName) throws ReportException { - log.info("validateHtml-->>-->>"); - try{ - emitStatus(ValidatorPropMessages.getString("validate.html.started")); -// statusHandler.emitStatus(status); - htmlValidator=new HtmlValidator(); - htmlValidator.setWidgetModel(widgetModel); - htmlValidator.setMessageHandler(getMessageHandler()); - - if (widgetModel.isHtmlPresent()) { - htmlValidator.setHtmlPlistFileName(widgetModel.getMainHtml()); - htmlVal = htmlValidator.validate( fileName); - } - log.info("validateHtml--<<--<<"); - emitStatus(ValidatorPropMessages.getString("validate.html.finished")); -// statusHandler.emitStatus(status); - } catch (Exception e) { - Util.logEvent(log, Level.INFO, e); - status.setStatusDescription("Exception "+e.getMessage()); - - } - return htmlVal; - - } - protected void emitStatus(String statusDescription) { WRTStatus status = new WRTStatus(); status.setStatusSource(IWRTConstants.StatusSourceType.VALIDATOR.name()); diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CoreUtil.java Fri Feb 05 09:17:58 2010 -0800 @@ -1,8 +1,15 @@ package org.symbian.tools.wrttools.util; +import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; public class CoreUtil { + public static final String PROPERTY_PATTERN = "\\s*{0}\\s*\\s*\\s*(.*)\\s*"; public static boolean isWindows() { return "windows".equals(Platform.getOS()); @@ -15,4 +22,27 @@ public static boolean isLinux() { return "linux".equals(Platform.getOS()); } + + public static String getIndexFileName(String buffer) { + if (buffer != null) { + Matcher matcher = getPropertyLookupPattern("MainHTML").matcher(buffer); + if (matcher.find()) { + return matcher.group(1); + } + } + return null; + } + + public static Pattern getPropertyLookupPattern(String propertyName) { + return Pattern.compile(MessageFormat.format(PROPERTY_PATTERN, propertyName), Pattern.CASE_INSENSITIVE); + } + + public static IRegion getIndexFileNameRegion(String string) { + Matcher matcher = getPropertyLookupPattern("MainHTML").matcher(string); + if (matcher.find()) { + int start = matcher.start(1); + return new Region(start, matcher.end(1) - start); + } + return null; + } } diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Fri Feb 05 09:17:58 2010 -0800 @@ -217,4 +217,9 @@ ((IFolder) parent).create(false, true, new NullProgressMonitor()); } } + + public static boolean isPlist(IResource resource) { + return resource.getType() == IResource.FILE + && resource.getName().equalsIgnoreCase("info.plist"); + } } diff -r e5c37ce1b003 -r b6d252d808df org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Wed Feb 03 10:45:34 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Feb 05 09:17:58 2010 -0800 @@ -59,7 +59,6 @@ import org.eclipse.wst.jsdt.core.IIncludePathEntry; import org.eclipse.wst.jsdt.core.IJavaScriptProject; import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; import org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer; import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.core.ProjectTemplate; @@ -78,6 +77,7 @@ public WrtWidgetWizard() { setWindowTitle("New WRT Widget"); + setNeedsProgressMonitor(true); } public boolean performFinish() { @@ -135,17 +135,17 @@ ((IWrtIdeContainer) containerInitializer).populateProject(project, new SubProgressMonitor(progressMonitor, perContainer)); } } - IJavaScriptProject js = JavaScriptCore.create(project); - IIncludePathEntry[] rawIncludepath = js.getRawIncludepath(); - int preconfigured = rawIncludepath.length; - IIncludePathEntry[] newIncludepath = new IIncludePathEntry[preconfigured + libraryIds.length]; - System.arraycopy(rawIncludepath, 0, newIncludepath, 0, preconfigured); - for (int i = 0; i < libraryIds.length; i++) { - String string = libraryIds[i]; - IIncludePathEntry entry = JavaScriptCore.newContainerEntry(new Path(string)); - newIncludepath[preconfigured + i] = entry; - } - js.setRawIncludepath(newIncludepath, new SubProgressMonitor(progressMonitor, 10)); +// IJavaScriptProject js = JavaScriptCore.create(project); +// IIncludePathEntry[] rawIncludepath = js.getRawIncludepath(); +// int preconfigured = rawIncludepath.length; +// IIncludePathEntry[] newIncludepath = new IIncludePathEntry[preconfigured + libraryIds.length]; +// System.arraycopy(rawIncludepath, 0, newIncludepath, 0, preconfigured); +// for (int i = 0; i < libraryIds.length; i++) { +// String string = libraryIds[i]; +// IIncludePathEntry entry = JavaScriptCore.newContainerEntry(new Path(string)); +// newIncludepath[preconfigured + i] = entry; +// } +// js.setRawIncludepath(newIncludepath, new SubProgressMonitor(progressMonitor, 10)); progressMonitor.done(); }