Commit 447c8d3c authored by Ard Schrijvers's avatar Ard Schrijvers

HIPPLUG-1308 Reintegrate bugfix/HIPPLUG-1308

parents 334cc4aa 031750fa
/*
* Copyright 2010-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2010-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -26,6 +26,7 @@ package org.onehippo.forge.sitemap.components.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
......@@ -37,9 +38,9 @@ import static java.util.Collections.synchronizedList;
/**
* <p>Java class for anonymous complex type.
*
* <p>
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <p>
* <pre>
* &lt;complexType>
* &lt;complexContent>
......@@ -51,12 +52,10 @@ import static java.util.Collections.synchronizedList;
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(name = "", propOrder = {
"urls"
"urls"
})
@XmlRootElement(name = "urlset")
public class Urlset {
......@@ -76,26 +75,25 @@ public class Urlset {
/**
* Gets the value of the url property.
*
* <p>
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the url property.
*
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getUrls().add(newItem);
* </pre>
*
*
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Url }
*
* @return the list containing all the {@link Url}s in this set.
*
*/
@XmlElement(name = "url", required = true)
public List<Url> getUrls() {
......@@ -104,6 +102,7 @@ public class Urlset {
/**
* Adds the specified url to the Urlset if this Url isn't already in the Urlset
*
* @param url the Url to add
*/
public void addUrlThatDoesntExistInTheListYet(Url url) {
......
......@@ -226,9 +226,8 @@ public class SitemapGenerator {
* @return The Urlset containing the urls of the sitemap items
*/
public Urlset createUrlSetBasedOnHstSiteMap() {
Urlset urlset = new Urlset();
createAndStartWorkers(urlset);
createAndStartWorkers();
fillInitialWorkQueue();
......@@ -245,9 +244,22 @@ public class SitemapGenerator {
throw new IllegalStateException("Error occurred while trying to generate the site map", lastWorkerException);
}
Urlset urlset = combineUrlSetsFromWorkers();
return urlset;
}
private Urlset combineUrlSetsFromWorkers() {
final Urlset combinedUrlset = new Urlset();
for (SitemapGeneratorWorker worker : workers) {
for (Url url : worker.getUrlset().getUrls()) {
combinedUrlset.addUrlThatDoesntExistInTheListYet(url);
}
}
return combinedUrlset;
}
private void stopWorkers() {
for (SitemapGeneratorWorker worker : workers) {
worker.interrupt();
......@@ -279,12 +291,12 @@ public class SitemapGenerator {
}
}
private List<SitemapGeneratorWorker> createAndStartWorkers(Urlset urlset) {
private List<SitemapGeneratorWorker> createAndStartWorkers() {
// Initialize the workers
workers = new ArrayList<SitemapGeneratorWorker>();
for (int i = 0 ; i < amountOfWorkers; i++) {
SitemapGeneratorWorker worker = new SitemapGeneratorWorker(
this, mount, urlset, requestContext,
this, mount, requestContext,
objectConverter, urlInformationProvider
);
worker.start();
......
/*
* Copyright 2012-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2012-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -99,12 +99,11 @@ public class SitemapGeneratorWorker extends Thread {
* Constructor.
*
* @param generator the Sitemap generator
* @param urlset the Urlset which contains all the Urls
* @param requestContext the Hst Request context
* @param objectConverter the Object converter converts any kind of beans into JCR nodes & properties
* @param urlInformationProvider the Url information provider
*/
public SitemapGeneratorWorker(final SitemapGenerator generator, final Mount mount, final Urlset urlset,
public SitemapGeneratorWorker(final SitemapGenerator generator, final Mount mount,
final HstRequestContext requestContext, final ObjectConverter objectConverter,
final UrlInformationProvider urlInformationProvider) {
......@@ -116,7 +115,7 @@ public class SitemapGeneratorWorker extends Thread {
this.generator = generator;
this.mount = mount;
this.urlset = urlset;
this.urlset = new Urlset();
this.objectConverter = objectConverter;
this.requestContext = requestContext;
this.urlInformationProvider = urlInformationProvider;
......@@ -131,6 +130,10 @@ public class SitemapGeneratorWorker extends Thread {
}
}
public Urlset getUrlset() {
return urlset;
}
/**
* Run method for Threads.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment