Revision: 6278 Author: [email protected] Date: Thu Oct 1 06:38:59 2009 Log: Changes to hyperlink, indexable hyperlink, and Showcase
Review by: rice, zundel http://code.google.com/p/google-web-toolkit/source/detail?r=6278 Modified: /branches/crawlability/eclipse/README.txt /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/server/CrawlServlet.java /branches/crawlability/servlet/build.xml /branches/crawlability/user/src/com/google/gwt/user/client/History.java /branches/crawlability/user/src/com/google/gwt/user/client/ui/IndexableHyperlink.java ======================================= --- /branches/crawlability/eclipse/README.txt Mon Sep 28 07:05:23 2009 +++ /branches/crawlability/eclipse/README.txt Thu Oct 1 06:38:59 2009 @@ -240,6 +240,39 @@ 4) Now you should be able to run the 'Hello' project from the Run dialog! +== Launching 'Showcase' == + +1) Import the 'Showcase' project if you haven't already. + + File->Import->General->Existing Projects into Workspace->Next + Browse to the 'trunk/eclipse' folder and select it + Deselect All + Select 'Showcase' + +2) Non-windows users: Replace the windows project dependency. + + Right-click on the Showcase project and select 'Properties'. + Select 'Java Build Path', the 'Libraries'. + Click on GWT_ROOT/build/staging/gwt-windows-0.0.0/gwt-servlet.jar and + 'Edit'. Change gwt-windows-0.0.0 to "gwt-linux-0.0.0" or "gwt-mac-0.0.0". + +3) Non-windows users: Replace the gwt-dev-windows project dependency and paths. + + Run->Open Run Dialog...->Java Application->Showcase + Select the 'Classpath' tab + Remove gwt-dev-windows paths + Select 'User Entries' + Advanced->Add Folder-> Add gwt-dev-<platform>/core/super + Select the (default classpath) item and use the 'Down' button + to make it the last item in the list. + You could also just edit Showcase.launch and search/replace "windows" with + "linux" or "mac". + +4) Repeat step 2 for the 'Showcase compile' project. + +5) Now you should be able to run the 'Showcase' project from the + Run dialog! + == Creating a Launch config for a new project == ======================================= --- /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java Tue Sep 29 07:49:01 2009 +++ /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java Thu Oct 1 06:38:59 2009 @@ -222,8 +222,6 @@ app.getMainMenu().ensureSelectedItemVisible(); Window.setTitle(item.getText()); - - // Show the associated ContentWidget displayContentWidget(itemWidgets.get(item)); } @@ -234,9 +232,9 @@ app.addSelectionHandler(new SelectionHandler<TreeItem>() { public void onSelection(SelectionEvent<TreeItem> event) { TreeItem item = event.getSelectedItem(); - String historyToken = ((Hyperlink) item.getWidget()).getTargetHistoryToken(); ContentWidget content = itemWidgets.get(item); if (content != null && !content.equals(app.getContent())) { + String historyToken = ((Hyperlink) item.getWidget()).getTargetHistoryToken(); History.newItem(historyToken); } } @@ -415,11 +413,11 @@ */ private void setupMainMenuOption(TreeItem parent, ContentWidget content, AbstractImagePrototype image) { - // Create the TreeItem - Hyperlink hl = new IndexableHyperlink(image.getHTML() + " " + content.getName(),true,getContentWidgetToken(content)); + Hyperlink hl = new IndexableHyperlink(image.getHTML() + " " + + content.getName(), true, getContentWidgetToken(content)); TreeItem option = parent.addItem(hl); - + // Map the item to its history token and content widget itemWidgets.put(option, content); itemTokens.put(getContentWidgetToken(content), option); ======================================= --- /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/server/CrawlServlet.java Mon Sep 28 07:05:23 2009 +++ /branches/crawlability/samples/showcase/src/com/google/gwt/sample/showcase/server/CrawlServlet.java Thu Oct 1 06:38:59 2009 @@ -38,26 +38,54 @@ */ public final class CrawlServlet implements Filter { + /** + * Special URL token that gets passed from the crawler to the servlet filter. + * This token is used in case there are already existing query parameters. + */ + private static final String ESCAPED_FRAGMENT_FORMAT1 = "&_escaped_fragment_="; + /** + * Special URL token that gets passed from the crawler to the servlet filter. + * This token is used in case there are not already existing query parameters. + */ + private static final String ESCAPED_FRAGMENT_FORMAT2 = "?_escaped_fragment_="; + /** + * Length of the special URL tokens. + */ + private static final int ESCAPED_FRAGMENT_LENGTH = ESCAPED_FRAGMENT_FORMAT1.length(); + + /** + * Maps from the query string that contains _escaped_fragment_ to one that + * doesn't, but is instead followed by a hash fragment. It also unescapes any + * characters that were escaped by the crawler. If the query string does not + * contain _escaped_fragment_, it is not modified. + * + * @param queryString + * @return A modified query string followed by a hash fragment if applicable. + * The non-modified query string otherwise. + * @throws UnsupportedEncodingException + */ private static String rewriteQueryString(String queryString) throws UnsupportedEncodingException { - StringBuilder queryStringSb = new StringBuilder(queryString); - int i = queryStringSb.indexOf("&_escaped_fragment_="); - if (i == -1) { - i = queryStringSb.indexOf("?_escaped_fragment_="); - } - if (i != -1) { - StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i - 1)); - System.out.println("|" + tmpSb + "|"); - tmpSb.append("#!"); - System.out.println("|" + tmpSb + "|"); - tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 20, - queryStringSb.length()), "UTF-8")); - System.out.println("|" + tmpSb + "|"); - queryStringSb = tmpSb; - } - return queryStringSb.toString(); + int index = queryString.indexOf(ESCAPED_FRAGMENT_FORMAT1); + if (index == -1) { + index = queryString.indexOf(ESCAPED_FRAGMENT_FORMAT2); + } + if (index != -1) { + StringBuilder queryStringSb = new StringBuilder(); + if (index > 0) { + queryStringSb.append(queryString.substring(0, index - 1)); + } + queryStringSb.append("#!"); + queryStringSb.append(URLDecoder.decode(queryStringSb.substring(index + + ESCAPED_FRAGMENT_LENGTH, queryStringSb.length()), "UTF-8")); + return queryStringSb.toString(); + } + return queryString; } + /** + * The configuration for the servlet filter. + */ private FilterConfig filterConfig = null; /** @@ -110,11 +138,11 @@ out.println(page.asXml()); webClient.closeAllWindows(); out.close(); - } else { try { chain.doFilter(request, response); } catch (ServletException e) { + System.err.println("Servlet exception caught: " + e); e.printStackTrace(); } } ======================================= --- /branches/crawlability/servlet/build.xml Mon Sep 28 07:22:01 2009 +++ /branches/crawlability/servlet/build.xml Thu Oct 1 06:38:59 2009 @@ -20,27 +20,23 @@ <exclude name="com/google/gwt/junit/server/**" /> <exclude name="com/google/gwt/benchmarks/*" /> </fileset> - - <!-- htmlunit dependencies not already included: BEGIN --> - <zipfileset src="${gwt.tools.lib}/apache/commons/commons-codec-1.3.jar" /> - <zipfileset src="${gwt.tools.lib}/apache/commons/commons-httpclient-3.1.jar" /> - <zipfileset src="${gwt.tools.lib}/apache/commons/commons-io-1.4.jar" /> - <zipfileset src="${gwt.tools.lib}/apache/commons/commons-lang-2.4.jar" /> - <zipfileset src="${gwt.tools.lib}/cssparser/cssparser-0.9.5.jar" /> - <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-2.5.jar" /> - <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-core-js-2.5.jar" /> - <zipfileset src="${gwt.tools.lib}/nekohtml/nekohtml-1.9.12.jar" /> - <zipfileset src="${gwt.tools.lib}/xalan/xalan-2.7.1.jar" /> - <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/serializer.jar" /> - <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/xercesImpl-NoMetaInf.jar" /> - <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/xml-apis.jar" /> - <zipfileset src="${gwt.tools.lib}/w3c/sac/sac-1.3.jar" /> - <!-- htmlunit dependencies not already included: END --> - - <!-- also needed for HtmlUnit --> - <zipfileset src="${gwt.tools.lib}/tomcat/commons-logging-1.0.jar" /> - <zipfileset src="${gwt.tools.lib}/tomcat/commons-collections-3.1.jar" /> - <!-- also needed for HtmlUnit: END --> + <!-- HtmlUnit dependencies not already included: BEGIN --> + <zipfileset src="${gwt.tools.lib}/apache/commons/commons-codec-1.3.jar" /> + <zipfileset src="${gwt.tools.lib}/apache/commons/commons-httpclient-3.1.jar" /> + <zipfileset src="${gwt.tools.lib}/apache/commons/commons-io-1.4.jar" /> + <zipfileset src="${gwt.tools.lib}/apache/commons/commons-lang-2.4.jar" /> + <zipfileset src="${gwt.tools.lib}/cssparser/cssparser-0.9.5.jar" /> + <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-2.5.jar" /> + <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-core-js-2.5.jar" /> + <zipfileset src="${gwt.tools.lib}/nekohtml/nekohtml-1.9.12.jar" /> + <zipfileset src="${gwt.tools.lib}/xalan/xalan-2.7.1.jar" /> + <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/serializer.jar" /> + <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/xercesImpl-NoMetaInf.jar" /> + <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/xml-apis.jar" /> + <zipfileset src="${gwt.tools.lib}/w3c/sac/sac-1.3.jar" /> + <zipfileset src="${gwt.tools.lib}/tomcat/commons-logging-1.0.jar" /> + <zipfileset src="${gwt.tools.lib}/tomcat/commons-collections-3.1.jar" /> + <!-- HtmlUnit dependencies not already included: END --> </gwt.jar> </target> ======================================= --- /branches/crawlability/user/src/com/google/gwt/user/client/History.java Fri Sep 25 09:28:36 2009 +++ /branches/crawlability/user/src/com/google/gwt/user/client/History.java Thu Oct 1 06:38:59 2009 @@ -138,7 +138,7 @@ public static String getToken() { return impl != null ? HistoryImpl.getToken() : ""; } - + /** * Adds a new browser history entry. In hosted mode, the 'back' and 'forward' * actions are accessible via the standard Alt-Left and Alt-Right keystrokes. ======================================= --- /branches/crawlability/user/src/com/google/gwt/user/client/ui/IndexableHyperlink.java Wed Sep 30 06:05:59 2009 +++ /branches/crawlability/user/src/com/google/gwt/user/client/ui/IndexableHyperlink.java Thu Oct 1 06:38:59 2009 @@ -15,43 +15,55 @@ */ package com.google.gwt.user.client.ui; -import com.google.gwt.user.client.Element; - /** - * Indexable version of Hyperlink class. - * This class will produce hyperlinks that contain the special - * "indexable" token. - * + * Indexable version of Hyperlink class. This class will produce hyperlinks that + * contain the special "indexable" token. */ public class IndexableHyperlink extends Hyperlink { + /** + * Creates an empty hyperlink. + */ public IndexableHyperlink() { - // TODO Auto-generated constructor stub + super(); } + /** + * Creates an indexable hyperlink with its text and target history token + * specified. The target history token will be preceded by a special "!" token + * to indicate that this state should be indexed. + * + * @param text the hyperlink's text + * @param asHTML <code>true</code> to treat the specified text as html + * @param targetHistoryToken the history token to which it will link + * @see #setTargetHistoryToken + */ public IndexableHyperlink(String text, boolean asHTML, String targetHistoryToken) { - super(text, asHTML, targetHistoryToken); - // TODO Auto-generated constructor stub + super(text, asHTML, "!" + targetHistoryToken); } + /** + * Creates an indexable hyperlink with its text and target history token + * specified. specified. The target history token will be preceded by a + * special "!" token to indicate that this state should be indexed. + * + * @param text the hyperlink's text + * @param targetHistoryToken the history token to which it will link, which + * may not be null (use {...@link Anchor} instead if you don't need + * history processing) + */ public IndexableHyperlink(String text, String targetHistoryToken) { - super(text, targetHistoryToken); - // TODO Auto-generated constructor stub + super(text, "!" + targetHistoryToken); } - public IndexableHyperlink(Element elem) { - super(elem); - // TODO Auto-generated constructor stub - } - /** * Sets the history token referenced by this hyperlink. This is the history * token that will be passed to {...@link History#newItem} when this link is * clicked. * * @param targetHistoryToken the new history token, which may not be null (use - * {...@link Anchor} instead if you don't need history processing) + * {...@link Anchor} instead if you don't need history processing) */ @Override public void setTargetHistoryToken(String targetHistoryToken) { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
