Revision: 8929
Author: gwt.mirror...@gmail.com
Date: Mon Oct 4 13:22:55 2010
Log: Making Showcase generate a hidden site map to make it crawlable. Also
ensuring that the select box used to select source code always contains at
least one option to work around an HtmlUnit innerHtml bug that affects
crawlability.
Review at http://gwt-code-reviews.appspot.com/952801
Review by: kpro...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8929
Modified:
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/MainMenuTreeViewModel.java
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java
=======================================
---
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/MainMenuTreeViewModel.java
Mon Sep 13 12:31:36 2010
+++
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/MainMenuTreeViewModel.java
Mon Oct 4 13:22:55 2010
@@ -70,8 +70,10 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* The {...@link TreeViewModel} used by the main menu.
@@ -247,6 +249,21 @@
public boolean isLeaf(Object value) {
return value != null && !(value instanceof Category);
}
+
+ /**
+ * Get the set of all {...@link ContentWidget}s used in the model.
+ *
+ * @return the {...@link ContentWidget}s
+ */
+ Set<ContentWidget> getAllContentWidgets() {
+ Set<ContentWidget> widgets = new HashSet<ContentWidget>();
+ for (Category category : categories.getList()) {
+ for (ContentWidget example : category.examples.getList()) {
+ widgets.add(example);
+ }
+ }
+ return widgets;
+ }
/**
* Initialize the top level categories in the tree.
=======================================
---
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
Mon Sep 13 12:31:36 2010
+++
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/Showcase.java
Mon Oct 4 09:55:53 2010
@@ -26,17 +26,22 @@
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.LocaleInfo;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import
com.google.gwt.sample.showcase.client.MainMenuTreeViewModel.Category;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootLayoutPanel;
+import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@@ -99,6 +104,7 @@
final SingleSelectionModel<ContentWidget> selectionModel = new
SingleSelectionModel<ContentWidget>();
final MainMenuTreeViewModel treeModel = new MainMenuTreeViewModel(
constants, selectionModel);
+ Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets();
shell = new ShowcaseShell(treeModel);
RootLayoutPanel.get().add(shell);
@@ -176,8 +182,30 @@
ContentWidget content = (ContentWidget) category.getChildValue(0);
selectionModel.setSelected(content, true);
}
+
+ // Generate a site map.
+ createSiteMap(contentWidgets);
}
+ /**
+ * Create a hidden site map for crawlability.
+ *
+ * @param contentWidgets the {...@link ContentWidget}s used in Showcase
+ */
+ private void createSiteMap(Set<ContentWidget> contentWidgets) {
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ for (ContentWidget cw : contentWidgets) {
+ String token = getContentWidgetToken(cw);
+ sb.append(SafeHtmlUtils.fromTrustedString("<a href=\"#" + token
+ "\">"
+ + token + "</a>"));
+ }
+
+ // Add the site map to the page.
+ HTML siteMap = new HTML(sb.toSafeHtml());
+ siteMap.setVisible(false);
+ RootPanel.get().add(siteMap, 0, 0);
+ }
+
/**
* Set the content to the {...@link ContentWidget}.
*
=======================================
---
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java
Wed Sep 22 12:58:01 2010
+++
/trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java
Mon Oct 4 09:55:53 2010
@@ -255,7 +255,15 @@
tabStyle.setVisible(content.hasStyle());
tabSource.setVisible(true);
- // Show the list of raw source files if there are any.
+ /*
+ * Show the list of raw source files if there are any. We need to add
at
+ * least one option to the list for crawlability. If we do not,
HtmlUnit
+ * innerHtml will close the select tag in the open tag (ie, use a
forward
+ * slash instead of a separate close tag) which most browsers parse
+ * incorrectly.
+ */
+ tabSourceList.clear();
+ tabSourceList.addItem("Example");
List<String> rawFilenames = content.getRawSourceFilenames();
if (rawFilenames.size() > 0) {
String text = tabSource.getText();
@@ -263,8 +271,6 @@
tabSource.setText(text + ":");
}
tabSourceList.setVisible(true);
- tabSourceList.clear();
- tabSourceList.addItem("Example");
for (String filename : rawFilenames) {
tabSourceList.addItem(filename);
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors