Commit 601e15c1 authored by Ard Schrijvers's avatar Ard Schrijvers

HIPPLUG-1357 Remove the unused (since broken) SitemapFeedBasedOnHstSitemap and...

HIPPLUG-1357 Remove the unused (since broken) SitemapFeedBasedOnHstSitemap and SiteMapBasedOnHstSiteMapResource sitemap generators

As a result, quite some other code was unused, which in turn triggered other code to be possible to be removed.

Note I also do a content delete for

/hst:hst/hst:configurations/hst:default/hst:components/forge-sitemap-based-on-hst-configuration-feed

since this component refers to SitemapFeedBasedOnHstSitemap.

I've tested that after a restart (with existing repository), that 'forge-sitemap-based-on-hst-configuration-feed'
component is gone, basic sitemap and NewsSitemapFeed still work as expected
parent e80b956a
/*
* Copyright 2010-2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.sitemap.components;
import org.hippoecm.hst.configuration.hosting.Mount;
import org.hippoecm.hst.content.beans.manager.ObjectConverter;
import org.hippoecm.hst.core.request.HstRequestContext;
import org.hippoecm.hst.jaxrs.services.AbstractResource;
import org.onehippo.forge.sitemap.components.model.Urlset;
import org.onehippo.forge.sitemap.components.splitter.SitemapSplitter;
import org.onehippo.forge.sitemap.components.splitter.TarGzipSitemapSplitter;
import org.onehippo.forge.sitemap.generator.DefaultUrlInformationProvider;
import org.onehippo.forge.sitemap.generator.SitemapGenerator;
import org.springframework.beans.factory.annotation.Required;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayOutputStream;
import java.util.Collections;
import java.util.List;
/**
* This is a JAX-RS resource to be used in the Hippo REST-interface. It outputs a site map in different formats,
* including a tar.gz archive.
*/
@Path("sitemap")
public class SiteMapBasedOnHstSiteMapResource extends AbstractResource {
private List<String> exclusionsByRefId = Collections.emptyList();
private List<String> exclusionsByComponentConfigurationId = Collections.emptyList();
private List<String> exclusionsBySiteMapPath = Collections.emptyList();
private UrlInformationProvider urlInformationProvider = DefaultUrlInformationProvider.INSTANCE;
private int amountOfWorkers = -1;
private String mountAlias;
@GET
@Path("sitemap-archive.tar.gz")
@Produces({"application/zip", "application/x-gzip", "application/octet-stream", MediaType.APPLICATION_XML})
public Response createSiteMapTarGzArchive(@Context HttpServletRequest request,
@Context HttpServletResponse response) {
Urlset siteMap = obtainSiteMap(request);
final ByteArrayOutputStream siteMapArchiveStream = new ByteArrayOutputStream();
SitemapSplitter splitter = new TarGzipSitemapSplitter(siteMap, siteMapArchiveStream);
boolean splittingExecuted = splitter.split();
if (!splittingExecuted) {
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
response.setHeader("Content-Disposition", "attachment; filename=sitemap-archive.tar.gz");
response.setContentType("application/x-gzip");
final Response.ResponseBuilder okResponse = Response.ok(siteMapArchiveStream.toByteArray(), MediaType.APPLICATION_OCTET_STREAM_TYPE);
return okResponse.build();
}
private Urlset obtainSiteMap(final HttpServletRequest request) {
HstRequestContext requestContext = getRequestContext(request);
ObjectConverter objectConverter = getObjectConverter(requestContext);
Mount mount = requestContext.getMount(mountAlias);
SitemapGenerator generator =
new SitemapGenerator(requestContext, objectConverter, urlInformationProvider, mount);
generator.addSitemapRefIdExclusions(exclusionsByRefId);
generator.addComponentConfigurationIdExclusions(exclusionsByComponentConfigurationId);
generator.addSitemapPathExclusions(exclusionsBySiteMapPath);
if (amountOfWorkers > 0) {
generator.setAmountOfWorkers(amountOfWorkers);
}
return generator.createUrlSetBasedOnHstSiteMap();
}
public void setExclusionsByRefId(final List<String> exclusionsByRefId) {
this.exclusionsByRefId = exclusionsByRefId != null ? exclusionsByRefId : Collections.<String>emptyList();
}
public void setExclusionsByComponentConfigurationId(final List<String> exclusionsByComponentConfigurationId) {
this.exclusionsByComponentConfigurationId = exclusionsByComponentConfigurationId != null ?
exclusionsByComponentConfigurationId : Collections.<String>emptyList();
}
public void setExclusionsBySiteMapPath(List<String> exclusionsBySiteMapPath) {
this.exclusionsBySiteMapPath = exclusionsBySiteMapPath != null ?
exclusionsBySiteMapPath : Collections.<String>emptyList();
}
public void setUrlInformationProvider(UrlInformationProvider urlInformationProvider) {
this.urlInformationProvider = urlInformationProvider;
}
public void setAmountOfWorkers(int amountOfWorkers) {
this.amountOfWorkers = amountOfWorkers;
}
@Required
public void setMountAlias(String mountAlias) {
this.mountAlias = mountAlias;
}
}
/*
* 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.
......@@ -16,7 +16,6 @@
package org.onehippo.forge.sitemap.components;
import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.container.RequestContextProvider;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.sitemenu.HstSiteMenus;
......@@ -26,16 +25,16 @@ import org.onehippo.forge.sitemap.generator.SitemapGenerator;
public class SitemapFeed extends BaseHstComponent {
public static final int DEFAULT_DEPTH = 2;
public void doBeforeRender(HstRequest request, HstResponse response) {
String depthStr =getComponentParameter("depth");
int maxdepth = DEFAULT_DEPTH;
if (depthStr != null){
maxdepth = Integer.valueOf(depthStr);
String depthStr = getComponentParameter("depth");
int maxDepth = DEFAULT_DEPTH;
if (depthStr != null) {
maxDepth = Integer.valueOf(depthStr);
}
HstSiteMenus siteMenus = request.getRequestContext().getHstSiteMenus();
request.setAttribute("sitemap", new SitemapGenerator(request.getRequestContext(), RequestContextProvider.get().getContentBeansTool().getObjectConverter())
.createSitemap(siteMenus, maxdepth));
request.setAttribute("sitemap", new SitemapGenerator(request.getRequestContext())
.createSitemap(siteMenus, maxDepth));
}
}
......@@ -28,12 +28,12 @@ public class SitemapView extends BaseHstComponent {
public void doBeforeRender(HstRequest request, HstResponse response) {
String depthStr = getComponentParameter("depth");
int maxdepth = DEFAULT_DEPTH;
int maxDepth = DEFAULT_DEPTH;
if (depthStr != null){
maxdepth = Integer.valueOf(depthStr);
maxDepth = Integer.valueOf(depthStr);
}
HstSiteMenus siteMenus = request.getRequestContext().getHstSiteMenus();
request.setAttribute("sitemap", SitemapGenerator.getSitemapView(siteMenus, maxdepth));
request.setAttribute("sitemap", SitemapGenerator.getSitemapView(siteMenus, maxDepth));
}
}
/*
* 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.
......@@ -66,22 +66,4 @@ public interface UrlInformationProvider {
*/
String getLoc(HippoBean hippoBean, HstRequestContext requestContext, Mount mount);
/**
* Indicates whether this document should be included in the site map
*
* @param hippoBean the document
* @return <code>true</code> if the document should be included, <code>false</code> otherwise
*/
boolean includeDocumentInSiteMap(HippoBean hippoBean);
/**
* Indicates whether the child site map items for this document should be included in the site map.
* This happens when a default/any matcher site map item has child site map items. This method indicates whether
* those child site map items should also be processed.
*
* @param hippoBean the document
* @return <code>true</code> if the child site map items of this document should be included, <code>false</code>
* otherwise
*/
boolean includeChildrenInSiteMap(HippoBean hippoBean);
}
/*
* Copyright 2010-2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1-b02-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.05.05 at 01:46:58 PM CEST
//
package org.onehippo.forge.sitemap.components.model;
import java.math.BigDecimal;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the org.hippoecm.hst.components.sitemap.model package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private static final String SITEMAP_SCHEMA_URI = "http://www.sitemaps.org/schemas/sitemap/0.9";
private static final QName _Lastmod_QNAME = new QName(SITEMAP_SCHEMA_URI, "lastmod");
private static final QName _Loc_QNAME = new QName(SITEMAP_SCHEMA_URI, "loc");
private static final QName _Changefreq_QNAME = new QName(SITEMAP_SCHEMA_URI, "changefreq");
private static final QName _Priority_QNAME = new QName(SITEMAP_SCHEMA_URI, "priority");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.hippoecm.hst.components.sitemap.model
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Urlset }
*
*/
public Urlset createUrlset() {
return new Urlset();
}
/**
* Create an instance of {@link Url }
*
*/
public Url createUrl() {
return new Url();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
*
*/
@XmlElementDecl(namespace = SITEMAP_SCHEMA_URI, name = "lastmod")
public JAXBElement<String> createLastmod(String value) {
return new JAXBElement<String>(_Lastmod_QNAME, String.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
*
*/
@XmlElementDecl(namespace = SITEMAP_SCHEMA_URI, name = "loc")
public JAXBElement<String> createLoc(String value) {
return new JAXBElement<String>(_Loc_QNAME, String.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
*
*/
@XmlElementDecl(namespace = SITEMAP_SCHEMA_URI, name = "changefreq")
public JAXBElement<String> createChangefreq(String value) {
return new JAXBElement<String>(_Changefreq_QNAME, String.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link BigDecimal }{@code >}}
*
*/
@XmlElementDecl(namespace = SITEMAP_SCHEMA_URI, name = "priority")
public JAXBElement<BigDecimal> createPriority(BigDecimal value) {
return new JAXBElement<BigDecimal>(_Priority_QNAME, BigDecimal.class, null, value);
}
}
......@@ -60,8 +60,6 @@ import static java.util.Collections.synchronizedList;
@XmlRootElement(name = "urlset")
public class Urlset {
public static final int MAX_SUPPORTED_URLS_PER_FILE = 50000;
private List<Url> urls;
public Urlset() {
......@@ -100,15 +98,4 @@ public class Urlset {
return this.urls;
}
/**
* 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) {
if (!urls.contains(url)) {
urls.add(url);
}
}
}
/*
* Copyright 2012-2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.sitemap.components.model.sitemapindex;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the sitemapindex package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package:
* sitemapindex
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link TSitemap }
* @return Return a new TSitemap. An item of the SitemapIndex.
*/
public TSitemap createTSitemap() {
return new TSitemap();
}
/**
* Create an instance of {@link SitemapIndex }
* @return Return a new SitemapIndex.
*/
public SitemapIndex createSitemapindex() {
return new SitemapIndex();
}
}
/*
* Copyright 2012-2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.sitemap.components.splitter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.onehippo.forge.sitemap.components.model.Urlset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.commons.io.IOUtils.closeQuietly;
/**
* {@link SitemapSplitter} The splitted sitemap files are written to the filesystem.
*/
public class FileSystemSitemapSplitter extends FolderBasedSitemapSplitter {
private static final Logger LOG = LoggerFactory.getLogger(FileSystemSitemapSplitter.class);
private String sitemapDestinationFolder;
/**
* The SitemapSplitter will split the sitemap that is provided.
*
* @param urlset UrlSet - contains the set of urls which reflects the sitemap.
* @param sitemapDestinationFolder The destination folder where the splitted sitemap files must be stored.
*/
public FileSystemSitemapSplitter(final Urlset urlset, final String sitemapDestinationFolder) {
super(urlset.getUrls());
if (StringUtils.isEmpty(sitemapDestinationFolder)) {
throw new IllegalArgumentException("Destination Folder Path needs to be defined and cannot be empty");
}
this.sitemapDestinationFolder = stripTailingSlashOffFolderPath(sitemapDestinationFolder);
if (sitemapDestinationFolder == null) {
LOG.error("Error while obtaining the sitemap folder from the filesystem. "
+ "No sitemap index files will be created.");
throw new IllegalStateException("Error while obtaing the sitemap folder from the filesystem.");
}
if (!prepareFileSystemSiteMapFolder(this.sitemapDestinationFolder)) {
throw new IllegalArgumentException("Failed to prepare the destination folder on the file system");
}
}
/**
* Take care that the folder is correctly formatted.
*
* @param folderName the initial folder path
* @return The correctly formatted foldername.
*/
private static String stripTailingSlashOffFolderPath(final String folderName) {
String formattedFolderName = folderName;
if (folderName.endsWith("/") || folderName.endsWith("\\")) {
formattedFolderName = folderName.substring(0, folderName.length() - 1);
}
return formattedFolderName;
}
/**
* Prepare the sitemap folder on the filesystem, where the sitemap files will be written to.
*
* @param siteMapFolderPath the folder where to write.
* @return true if the sitemap folder has been prepared.
*/
private static boolean prepareFileSystemSiteMapFolder(final String siteMapFolderPath) {
// If the folder exists it will be deleted.
// After deletion it will be recreated, so we are sure it is an empty folder.
File siteMapFolder = new File(siteMapFolderPath);
boolean exists = siteMapFolder.exists();
if (exists) {
boolean success = true;
if (siteMapFolder.isDirectory()) {
File[] files = siteMapFolder.listFiles();
if (files != null) {
for (File fileToDelete : files) {
if (!fileToDelete.delete()) {
success = false;
}
}
}
}
if (!success) {
// Deletion failed
throw new IllegalStateException("Cannot clean up sitemap folder.");
}
}
return new File(siteMapFolderPath).mkdirs();
}
/**
* Write the generated sitemap to an XML Document somewhere on a filesystem. It must be configured where the
* location of the file will be stored.
*
* @param content the xml content to write to the file
* @param filename the path (including) file name to write the xml content to
*/
protected void writeToFolder(final String content, final String filename) {
BufferedWriter out = null;
String path = sitemapDestinationFolder + File.separator + filename;
try {
out = new BufferedWriter(new FileWriter(path));
out.write(content);
} catch (IOException e) {
LOG.error("Error occurred while writing the sitemap to a file", e);
} finally {
closeQuietly(out);
}
}
}
/*
* Copyright 2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.sitemap.components.splitter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.onehippo.forge.sitemap.components.model.Url;
import org.onehippo.forge.sitemap.components.model.Urlset;
import org.onehippo.forge.sitemap.components.model.sitemapindex.SitemapIndex;
import org.onehippo.forge.sitemap.components.model.sitemapindex.TSitemap;
import org.onehippo.forge.sitemap.generator.SitemapGenerator;
import org.onehippo.forge.sitemap.generator.SitemapIndexGenerator;
/**
* A site map splitter that writes the files to a folder. The implementing class should implement the writeToFolder()
* method to write the files to an actual folder.
*/
public abstract class FolderBasedSitemapSplitter extends SitemapSplitter {
private static final String SITEMAP_FILENAME = "sitemap-index-";
/**
* The sitemap splitter accepts a list of {@link org.onehippo.forge.sitemap.components.model.Url}.
*
* @param urls This list of {@link org.onehippo.forge.sitemap.components.model.Url} will be split.
*/
protected FolderBasedSitemapSplitter(final List<Url> urls) {
super(urls);
}
@Override
public void writeSiteMapFilesToDestination() {
// We must write the sub sitemaps to different files.
// A sitemap index file must be created via a separate process and will not be created
// at this moment.
SitemapIndex sitemapIndexFile = new SitemapIndex();
for (Urlset urlset : getListOfSiteMaps()) {
String sitemapFileName = SITEMAP_FILENAME + getListOfSiteMaps().indexOf(urlset) + ".xml";
writeToFolder(SitemapGenerator.toString(urlset),
sitemapFileName);
sitemapIndexFile.getSitemap().add(createSitemapIndexItem(sitemapFileName));
}
if (!sitemapIndexFile.getSitemap().isEmpty()) {
writeToFolder(SitemapIndexGenerator.toString(sitemapIndexFile), "sitemapindex.xml");
}
}
/**
* Create an item in the Sitemap Index file.
*
* @param sitemapFile The name of the file which will be converted into the sitemap index file.
* @return The Sitemap Index file item.
*/
private static TSitemap createSitemapIndexItem(final String sitemapFile) {
TSitemap tSitemap = new TSitemap();
Calendar now = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
tSitemap.setLoc(sitemapFile);
tSitemap.setLastmod(getCurrentDateTime(now));
return tSitemap;
}
private static String getCurrentDateTime(final Calendar calendar) {
FastDateFormat dateFormatter = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT;
return dateFormatter.format(calendar);
}
protected abstract void writeToFolder(String content, String filename);
}
/*
* Copyright 2012-2013 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.
* 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 License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.sitemap.components.splitter;
import org.apache.commons.lang.StringUtils;
import org.onehippo.forge.sitemap.generator.SitemapGenerator;
import org.onehippo.forge.sitemap.components.model.Urlset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.util.Date;
/**
* {@link SitemapSplitter}
* The splitted sitemap files are written to the repository.
*/
public class RepositorySitemapSplitter extends SitemapSplitter {