Revision: 6723 Author: [email protected] Date: Thu Nov 5 20:02:18 2009 Log: Merges tr...@6718 into releases/2.0 Move xhtml.ent to its new home svn merge --ignore-ancestry -c 6720 https://google-web-toolkit.googlecode.com/svn/trunk .
http://code.google.com/p/google-web-toolkit/source/detail?r=6723 Modified: /releases/2.0/branch-info.txt /releases/2.0/user/src/com/google/gwt/uibinder/rebind/GwtResourceEntityResolver.java /releases/2.0/user/src/com/google/gwt/uibinder/resources/xhtml.ent /releases/2.0/user/test/com/google/gwt/uibinder/rebind/GwtResourceEntityResolverTest.java /releases/2.0/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml ======================================= --- /releases/2.0/branch-info.txt Thu Nov 5 17:34:45 2009 +++ /releases/2.0/branch-info.txt Thu Nov 5 20:02:18 2009 @@ -392,3 +392,7 @@ tr...@6718 was merged into this branch Don't log UnableToCompleteException stack traces svn merge --ignore-ancestry -c 6718 https://google-web-toolkit.googlecode.com/svn/trunk . + +tr...@6718 was merged into this branch + Move xhtml.ent to its new home + svn merge --ignore-ancestry -c 6720 https://google-web-toolkit.googlecode.com/svn/trunk . ======================================= --- /releases/2.0/user/src/com/google/gwt/uibinder/rebind/GwtResourceEntityResolver.java Mon Nov 2 12:44:54 2009 +++ /releases/2.0/user/src/com/google/gwt/uibinder/rebind/GwtResourceEntityResolver.java Thu Nov 5 20:02:18 2009 @@ -1,12 +1,12 @@ /* * Copyright 2009 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -15,32 +15,40 @@ */ package com.google.gwt.uibinder.rebind; +import com.google.gwt.dev.util.collect.Sets; + import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; +import java.util.Collections; +import java.util.Set; /** * Does special handling of external entities encountered by sax xml parser, * e.g. the uri in - * + * * <pre> * <!DOCTYPE gwt:UiBinder SYSTEM "http://google-web-toolkit.googlecode.com/files/xhtml.ent"></pre> * <p> * Specifically, if the requested uri starts with - * <code>http://google-web-toolkit.googlecode.com/files</code>, provide - * the contents from a built in resource rather than allowing sax to make a - * network request. + * <code>http://google-web-toolkit.googlecode.com/files</code>, provide the + * contents from a built in resource rather than allowing sax to make a network + * request. */ class GwtResourceEntityResolver implements EntityResolver { interface ResourceLoader { InputStream fetch(String name); } - private static final String EXTERNAL_ENTITY_PREFIX = "http://google-web-toolkit.googlecode.com/files/"; + private static final Set<String> EXTERNAL_PREFIXES = Collections.unmodifiableSet(Sets.create(new String[] { + "http://google-web-toolkit.googlecode.com/files/", + "http://dl.google.com/gwt/DTD/", + "https://dl-ssl.google.com/gwt/DTD/" + })); private static final String RESOURCES = "com/google/gwt/uibinder/resources/"; @@ -64,20 +72,20 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - if (!systemId.startsWith(EXTERNAL_ENTITY_PREFIX)) { + String matchingPrefix = findMatchingPrefix(systemId); + if (matchingPrefix == null) { // Not our problem, return null and sax will find it return null; } String name = RESOURCES - + systemId.substring(EXTERNAL_ENTITY_PREFIX.length()); + + systemId.substring(matchingPrefix.length()); InputStream resourceStream = resourceLoader.fetch(name); if (resourceStream == null) { /* - * Maybe, just maybe they're asking for something that has been added to - * svn but hasn't reached their local gwt install yet. Return null to - * allow sax to try to fetch it. + * They're asking for another DTD resource that we don't short circuit, + * Return null and let Sax find it on the interweb. */ return null; } @@ -87,4 +95,13 @@ inputSource.setSystemId(systemId); return inputSource; } -} + + private String findMatchingPrefix(String systemId) { + for (String prefix : EXTERNAL_PREFIXES) { + if (systemId.startsWith(prefix)) { + return prefix; + } + } + return null; + } +} ======================================= --- /releases/2.0/user/src/com/google/gwt/uibinder/resources/xhtml.ent Fri Sep 25 13:56:23 2009 +++ /releases/2.0/user/src/com/google/gwt/uibinder/resources/xhtml.ent Thu Nov 5 20:02:18 2009 @@ -17,11 +17,13 @@ Sample usage: <!DOCTYPE ui:UiBinder - SYSTEM "http://google-web-toolkit.googlecode.com/files/xhtml.ent"> + SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> This file is maintained at - <http://google-web-toolkit.googlecode.com/svn/trunk/user/src/com/google/gwt/uibinder/resources/xhtml.ent>. Changes - made to it must be propagated to the URL in the sample above. + http://google-web-toolkit.googlecode.com/svn/trunk/user/src/com/google/gwt/uibinder/resources/xhtml.ent + Changes made to it must be propagated to the URLs above. + It is also available as https://dl-ssl.google.com/gwt/DTD/xhtml.ent + --> <!-- Latin-1 characters --> ======================================= --- /releases/2.0/user/test/com/google/gwt/uibinder/rebind/GwtResourceEntityResolverTest.java Fri Sep 25 13:56:23 2009 +++ /releases/2.0/user/test/com/google/gwt/uibinder/rebind/GwtResourceEntityResolverTest.java Thu Nov 5 20:02:18 2009 @@ -27,17 +27,19 @@ * Text of GwtResourceEntityResolver. */ public class GwtResourceEntityResolverTest extends TestCase { - private static final String SYSTEM_ID = "http://google-web-toolkit.googlecode.com/files/xhtml.ent"; - private static class MockResourceLoader implements GwtResourceEntityResolver.ResourceLoader { - String fetched; InputStream stream; public InputStream fetch(String name) { return stream; } } + private static final String LEGACY_SYSTEM_ID = "http://google-web-toolkit.googlecode.com/files/xhtml.ent"; + private static final String VERSIONED_SYSTEM_ID = "http://dl.google.com/gwt/DTD/2.0.0/xhtml.ent"; + private static final String REDIRECT_SYSTEM_ID = "http://dl.google.com/gwt/DTD/xhtml.ent"; + private static final String SSL_VERSIONED_SYSTEM_ID = "https://dl-ssl.google.com/gwt/DTD/2.0.0/xhtml.ent"; + private static final String SSL_REDIRECT_SYSTEM_ID = "https://dl-ssl.google.com/gwt/DTD/xhtml.ent"; private GwtResourceEntityResolver resolver; private MockResourceLoader loader; @@ -56,22 +58,33 @@ }; } + public void testAlmostCorrectAndOnceWorked() throws SAXException, IOException { + doBad(LEGACY_SYSTEM_ID.replace("files", "filesss")); + doBad(VERSIONED_SYSTEM_ID.replace("DTD", "DTDdddd")); + doBad(REDIRECT_SYSTEM_ID.replace("DTD", "DTDdddd")); + } + public void testNotOurProblem() throws SAXException, IOException { - assertNull(resolver.resolveEntity(null, "http://arbitrary")); - assertNull(resolver.resolveEntity("meaningless", "http://arbitrary")); - assertNull(resolver.resolveEntity(null, "arbitrary/relative")); - - String almostCorrectAndOnceWorked = SYSTEM_ID.replace("files", "filesss"); - assertNull(resolver.resolveEntity("meaningless", almostCorrectAndOnceWorked)); - assertNull(resolver.resolveEntity(null, almostCorrectAndOnceWorked)); + doBad("http://arbitrary"); + } + + public void testVersionedGood() throws SAXException, IOException { + doGood(VERSIONED_SYSTEM_ID); + doGood(REDIRECT_SYSTEM_ID); + doGood(SSL_VERSIONED_SYSTEM_ID); + doGood(SSL_REDIRECT_SYSTEM_ID); + doGood(LEGACY_SYSTEM_ID); } - public void testOursGood() throws SAXException, IOException { - String publicId = "some old public thing"; - - InputSource s = resolver.resolveEntity(publicId, SYSTEM_ID); + private void doBad(String url) throws SAXException, IOException { + assertNull(resolver.resolveEntity(null, url)); + assertNull(resolver.resolveEntity("meaningless", url)); + } + + private void doGood(String url) throws SAXException, IOException { + String publicId = "some old public thing"; + InputSource s = resolver.resolveEntity(publicId, url); + assertNotNull(s); assertEquals(publicId, s.getPublicId()); - assertEquals(SYSTEM_ID, s.getSystemId()); - assertEquals(loader.stream, s.getByteStream()); - } -} + } + } ======================================= --- /releases/2.0/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Wed Nov 4 11:35:50 2009 +++ /releases/2.0/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Thu Nov 5 20:02:18 2009 @@ -14,7 +14,7 @@ --> <!DOCTYPE ui:UiBinder - SYSTEM "http://google-web-toolkit.googlecode.com/files/xhtml.ent" + SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent" [ <!ENTITY % MyEntities SYSTEM "MyEntities.ent"> %MyEntities; @@ -26,10 +26,12 @@ First, this bit: - SYSTEM "http://google-web-toolkit.googlecode.com/files/xhtml.ent" - - allows you to use familiar HTML entities like %nbsp; and •, - which are not part of XML. + SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent" + + allows you to use familiar HTML entities like and •, + which are not part of XML. (The file is also available as + https://dl-ssl.google.com/gwt/DTD/xhtml.ent.) + Next, the bit in square brackets is even more optional. It shows how to add your own entities, in this case pulling in additional --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
