Renamed GoogleExtension* classes/files to GoogleImage*
This commit is contained in:
+15
-15
@@ -8,10 +8,10 @@ import java.net.URL;
|
||||
* Builds an extended sitemap with google support for google extensions. To configure options use {@link #builder(URL, File)}
|
||||
* @see <a href="https://support.google.com/webmasters/answer/183668">Manage your sitemaps</a>
|
||||
* */
|
||||
public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExtensionSitemapUrl, GoogleExtensionSitemapGenerator> {
|
||||
public class GoogleImageSitemapGenerator extends SitemapGenerator<GoogleImageSitemapUrl, GoogleImageSitemapGenerator> {
|
||||
|
||||
GoogleExtensionSitemapGenerator(AbstractSitemapGeneratorOptions<?> options) {
|
||||
super(options, new GoogleExtensionSitemapGenerator.Renderer());
|
||||
GoogleImageSitemapGenerator(AbstractSitemapGeneratorOptions<?> options) {
|
||||
super(options, new GoogleImageSitemapGenerator.Renderer());
|
||||
}
|
||||
|
||||
/** Configures the generator with a base URL and directory to write the sitemap files.
|
||||
@@ -20,7 +20,7 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
* @param baseDir Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
public GoogleExtensionSitemapGenerator(String baseUrl, File baseDir)
|
||||
public GoogleImageSitemapGenerator(String baseUrl, File baseDir)
|
||||
throws MalformedURLException {
|
||||
this(new SitemapGeneratorOptions(baseUrl, baseDir));
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
* @param baseUrl All URLs in the generated sitemap(s) should appear under this base URL
|
||||
* @param baseDir Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
|
||||
*/
|
||||
public GoogleExtensionSitemapGenerator(URL baseUrl, File baseDir) {
|
||||
public GoogleImageSitemapGenerator(URL baseUrl, File baseDir) {
|
||||
this(new SitemapGeneratorOptions(baseUrl, baseDir));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
*
|
||||
* @param baseUrl All URLs in the generated sitemap(s) should appear under this base URL
|
||||
*/
|
||||
public GoogleExtensionSitemapGenerator(String baseUrl) throws MalformedURLException {
|
||||
public GoogleImageSitemapGenerator(String baseUrl) throws MalformedURLException {
|
||||
this(new SitemapGeneratorOptions(new URL(baseUrl)));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
*
|
||||
* @param baseUrl All URLs in the generated sitemap(s) should appear under this base URL
|
||||
*/
|
||||
public GoogleExtensionSitemapGenerator(URL baseUrl) {
|
||||
public GoogleImageSitemapGenerator(URL baseUrl) {
|
||||
this(new SitemapGeneratorOptions(baseUrl));
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
* @param baseDir Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
|
||||
* @return a builder; call .build() on it to make a sitemap generator
|
||||
*/
|
||||
public static SitemapGeneratorBuilder<GoogleExtensionSitemapGenerator> builder(URL baseUrl, File baseDir) {
|
||||
return new SitemapGeneratorBuilder<GoogleExtensionSitemapGenerator>(baseUrl, baseDir, GoogleExtensionSitemapGenerator.class);
|
||||
public static SitemapGeneratorBuilder<GoogleImageSitemapGenerator> builder(URL baseUrl, File baseDir) {
|
||||
return new SitemapGeneratorBuilder<GoogleImageSitemapGenerator>(baseUrl, baseDir, GoogleImageSitemapGenerator.class);
|
||||
}
|
||||
|
||||
/** Configures a builder so you can specify sitemap generator options
|
||||
@@ -71,21 +71,21 @@ public class GoogleExtensionSitemapGenerator extends SitemapGenerator<GoogleExte
|
||||
* @return a builder; call .build() on it to make a sitemap generator
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
public static SitemapGeneratorBuilder<GoogleExtensionSitemapGenerator> builder(String baseUrl, File baseDir) throws MalformedURLException {
|
||||
return new SitemapGeneratorBuilder<GoogleExtensionSitemapGenerator>(baseUrl, baseDir, GoogleExtensionSitemapGenerator.class);
|
||||
public static SitemapGeneratorBuilder<GoogleImageSitemapGenerator> builder(String baseUrl, File baseDir) throws MalformedURLException {
|
||||
return new SitemapGeneratorBuilder<GoogleImageSitemapGenerator>(baseUrl, baseDir, GoogleImageSitemapGenerator.class);
|
||||
}
|
||||
|
||||
private static class Renderer extends AbstractSitemapUrlRenderer<GoogleExtensionSitemapUrl> implements ISitemapUrlRenderer<GoogleExtensionSitemapUrl> {
|
||||
private static class Renderer extends AbstractSitemapUrlRenderer<GoogleImageSitemapUrl> implements ISitemapUrlRenderer<GoogleImageSitemapUrl> {
|
||||
|
||||
public Class<GoogleExtensionSitemapUrl> getUrlClass() {
|
||||
return GoogleExtensionSitemapUrl.class;
|
||||
public Class<GoogleImageSitemapUrl> getUrlClass() {
|
||||
return GoogleImageSitemapUrl.class;
|
||||
}
|
||||
|
||||
public String getXmlNamespaces() {
|
||||
return "xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"";
|
||||
}
|
||||
|
||||
public void render(GoogleExtensionSitemapUrl url, StringBuilder sb, W3CDateFormat dateFormat) {
|
||||
public void render(GoogleImageSitemapUrl url, StringBuilder sb, W3CDateFormat dateFormat) {
|
||||
StringBuilder tagSb = new StringBuilder();
|
||||
|
||||
for(Image image : url.getImages()) {
|
||||
+7
-7
@@ -9,19 +9,19 @@ import java.util.List;
|
||||
/** Configurable sitemap url with support for Google extensions
|
||||
* @see <a href="https://support.google.com/webmasters/answer/183668">Manage your sitemaps</a>
|
||||
*/
|
||||
public class GoogleExtensionSitemapUrl extends WebSitemapUrl {
|
||||
public class GoogleImageSitemapUrl extends WebSitemapUrl {
|
||||
|
||||
private final List<Image> images;
|
||||
|
||||
public GoogleExtensionSitemapUrl(String url) throws MalformedURLException {
|
||||
public GoogleImageSitemapUrl(String url) throws MalformedURLException {
|
||||
this(new Options(url));
|
||||
}
|
||||
|
||||
public GoogleExtensionSitemapUrl(URL url) {
|
||||
public GoogleImageSitemapUrl(URL url) {
|
||||
this(new Options(url));
|
||||
}
|
||||
|
||||
public GoogleExtensionSitemapUrl(Options options) {
|
||||
public GoogleImageSitemapUrl(Options options) {
|
||||
super(options);
|
||||
this.images = options.images;
|
||||
}
|
||||
@@ -34,17 +34,17 @@ public class GoogleExtensionSitemapUrl extends WebSitemapUrl {
|
||||
}
|
||||
|
||||
/** Options to configure Google Extension URLs */
|
||||
public static class Options extends AbstractSitemapUrlOptions<GoogleExtensionSitemapUrl, GoogleExtensionSitemapUrl.Options> {
|
||||
public static class Options extends AbstractSitemapUrlOptions<GoogleImageSitemapUrl, GoogleImageSitemapUrl.Options> {
|
||||
private List<Image> images;
|
||||
|
||||
|
||||
public Options(URL url) {
|
||||
super(url, GoogleExtensionSitemapUrl.class);
|
||||
super(url, GoogleImageSitemapUrl.class);
|
||||
images = new ArrayList<Image>();
|
||||
}
|
||||
|
||||
public Options(String url) throws MalformedURLException {
|
||||
super(url, GoogleExtensionSitemapUrl.class);
|
||||
super(url, GoogleImageSitemapUrl.class);
|
||||
images = new ArrayList<Image>();
|
||||
}
|
||||
|
||||
+11
-11
@@ -9,12 +9,12 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
public class GoogleImageSitemapUrlTest extends TestCase {
|
||||
|
||||
private static final URL LANDING_URL = newURL("http://www.example.com/index.html");
|
||||
private static final URL CONTENT_URL = newURL("http://www.example.com/index.flv");
|
||||
File dir;
|
||||
GoogleExtensionSitemapGenerator wsg;
|
||||
GoogleImageSitemapGenerator wsg;
|
||||
|
||||
private static URL newURL(String url) {
|
||||
try {
|
||||
@@ -41,8 +41,8 @@ public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testSimpleUrl() throws Exception {
|
||||
wsg = new GoogleExtensionSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleExtensionSitemapUrl url = new GoogleExtensionSitemapUrl(LANDING_URL);
|
||||
wsg = new GoogleImageSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleImageSitemapUrl url = new GoogleImageSitemapUrl(LANDING_URL);
|
||||
url.addImage(new Image("http://cdn.example.com/image1.jpg"));
|
||||
url.addImage(new Image("http://cdn.example.com/image2.jpg"));
|
||||
wsg.addUrl(url);
|
||||
@@ -63,8 +63,8 @@ public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testBaseOptions() throws Exception {
|
||||
wsg = new GoogleExtensionSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleExtensionSitemapUrl url = new GoogleExtensionSitemapUrl.Options(LANDING_URL)
|
||||
wsg = new GoogleImageSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleImageSitemapUrl url = new GoogleImageSitemapUrl.Options(LANDING_URL)
|
||||
.images(new Image("http://cdn.example.com/image1.jpg"), new Image("http://cdn.example.com/image2.jpg"))
|
||||
.priority(0.5)
|
||||
.changeFreq(ChangeFreq.WEEKLY)
|
||||
@@ -93,8 +93,8 @@ public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testImageOptions() throws Exception {
|
||||
wsg = new GoogleExtensionSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleExtensionSitemapUrl url = new GoogleExtensionSitemapUrl.Options(LANDING_URL)
|
||||
wsg = new GoogleImageSitemapGenerator("http://www.example.com", dir);
|
||||
GoogleImageSitemapUrl url = new GoogleImageSitemapUrl.Options(LANDING_URL)
|
||||
.images(new Image.ImageBuilder("http://cdn.example.com/image1.jpg")
|
||||
.title("image1.jpg")
|
||||
.caption("An image of the number 1")
|
||||
@@ -142,13 +142,13 @@ public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testTooManyImages() throws Exception {
|
||||
wsg = new GoogleExtensionSitemapGenerator("http://www.example.com", dir);
|
||||
wsg = new GoogleImageSitemapGenerator("http://www.example.com", dir);
|
||||
List<Image> images = new ArrayList<Image>();
|
||||
for(int i = 0; i <= 1000; i++) {
|
||||
images.add(new Image("http://cdn.example.com/image" + i + ".jpg"));
|
||||
}
|
||||
try {
|
||||
GoogleExtensionSitemapUrl url = new GoogleExtensionSitemapUrl.Options(LANDING_URL)
|
||||
GoogleImageSitemapUrl url = new GoogleImageSitemapUrl.Options(LANDING_URL)
|
||||
.images(images)
|
||||
.priority(0.5)
|
||||
.changeFreq(ChangeFreq.WEEKLY)
|
||||
@@ -160,7 +160,7 @@ public class GoogleExtensionSitemapUrlTest extends TestCase {
|
||||
|
||||
|
||||
|
||||
private String writeSingleSiteMap(GoogleExtensionSitemapGenerator wsg) {
|
||||
private String writeSingleSiteMap(GoogleImageSitemapGenerator wsg) {
|
||||
List<File> files = wsg.write();
|
||||
assertEquals("Too many files: " + files.toString(), 1, files.size());
|
||||
assertEquals("Sitemap misnamed", "sitemap.xml", files.get(0).getName());
|
||||
Reference in New Issue
Block a user