Commit 8213a63b authored by Marijan Milicevic's avatar Marijan Milicevic

HIPPLUG-1308 Sitemap plugin allowes duplicate URL entries (thread synch issue)

* synchronize contains block to avoid duplicate entries
parent 334cc4aa
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; ...@@ -26,6 +26,7 @@ package org.onehippo.forge.sitemap.components.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
...@@ -37,9 +38,9 @@ import static java.util.Collections.synchronizedList; ...@@ -37,9 +38,9 @@ import static java.util.Collections.synchronizedList;
/** /**
* <p>Java class for anonymous complex type. * <p>Java class for anonymous complex type.
* * <p>
* <p>The following schema fragment specifies the expected content contained within this class. * <p>The following schema fragment specifies the expected content contained within this class.
* * <p>
* <pre> * <pre>
* &lt;complexType> * &lt;complexType>
* &lt;complexContent> * &lt;complexContent>
...@@ -51,8 +52,6 @@ import static java.util.Collections.synchronizedList; ...@@ -51,8 +52,6 @@ import static java.util.Collections.synchronizedList;
* &lt;/complexContent> * &lt;/complexContent>
* &lt;/complexType> * &lt;/complexType>
* </pre> * </pre>
*
*
*/ */
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(name = "", propOrder = { @XmlType(name = "", propOrder = {
...@@ -63,6 +62,8 @@ public class Urlset { ...@@ -63,6 +62,8 @@ public class Urlset {
public static final int MAX_SUPPORTED_URLS_PER_FILE = 50000; public static final int MAX_SUPPORTED_URLS_PER_FILE = 50000;
private final Object lock = new Object();
private List<Url> urls; private List<Url> urls;
public Urlset() { public Urlset() {
...@@ -76,26 +77,25 @@ public class Urlset { ...@@ -76,26 +77,25 @@ public class Urlset {
/** /**
* Gets the value of the url property. * Gets the value of the url property.
* * <p>
* <p> * <p>
* This accessor method returns a reference to the live list, * This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the * not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object. * returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the url property. * This is why there is not a <CODE>set</CODE> method for the url property.
* * <p>
* <p> * <p>
* For example, to add a new item, do as follows: * For example, to add a new item, do as follows:
* <pre> * <pre>
* getUrls().add(newItem); * getUrls().add(newItem);
* </pre> * </pre>
* * <p>
* * <p>
* <p> * <p>
* Objects of the following type(s) are allowed in the list * Objects of the following type(s) are allowed in the list
* {@link Url } * {@link Url }
* *
* @return the list containing all the {@link Url}s in this set. * @return the list containing all the {@link Url}s in this set.
*
*/ */
@XmlElement(name = "url", required = true) @XmlElement(name = "url", required = true)
public List<Url> getUrls() { public List<Url> getUrls() {
...@@ -104,12 +104,15 @@ public class Urlset { ...@@ -104,12 +104,15 @@ public class Urlset {
/** /**
* Adds the specified url to the Urlset if this Url isn't already in the Urlset * Adds the specified url to the Urlset if this Url isn't already in the Urlset
*
* @param url the Url to add * @param url the Url to add
*/ */
public void addUrlThatDoesntExistInTheListYet(Url url) { public void addUrlThatDoesntExistInTheListYet(Url url) {
synchronized (lock) {
if (!urls.contains(url)) { if (!urls.contains(url)) {
urls.add(url); urls.add(url);
} }
} }
}
} }
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