Commit a0e4c0da authored by Ate Douma's avatar Ate Douma

TRIVIAL cleanup master

parent 9814a584
* text=auto !eol
/LICENSE -text
/NOTICE -text
component/pom.xml svneol=native#text/plain
component/src/main/appended-resources/META-INF/LICENSE -text
content/pom.xml svneol=native#text/plain
content/src/main/resources/component.xml svneol=native#text/plain
content/src/main/resources/hippoecm-extension.xml svneol=native#text/plain
content/src/main/resources/news-sitemap-component.xml svneol=native#text/plain
content/src/main/resources/sitemap-based-on-hst-sitemap-component.xml svneol=native#text/plain
content/src/main/resources/sitemap-entry.xml svneol=native#text/plain
content/src/main/resources/sitemap-index-component.xml svneol=native#text/plain
content/src/main/resources/template.xml svneol=native#text/plain
/pom.xml svneol=native#text/plain
/*.iml
/.idea
/.project
/.settings
component/*.iml
component/.classpath
component/.project
component/.settings
component/target
content/*.iml
content/.classpath
content/.project
content/.settings
content/target
/target
This diff is collapsed.
Hippo Plugin Sitemap
Copyright 2009-2018 Hippo B.V. (http://www.onehippo.com)
This product includes software developed by:
Hippo B.V., Amsterdam, The Netherlands (http://www.onehippo.com/);
The Apache Software Foundation (http://www.apache.org/).
NOTICE: Only our own original work is licensed under the terms of the
Apache License Version 2.0. The licenses of some libraries might impose
different redistribution or general licensing terms than those stated in the
Apache License. Users and redistributors are hereby requested to verify these
conditions and agree upon them.
# This is not the branch you're looking for...
BloomReach only provides the git trees for the release tags of Hippo CMS, as explained on https://www.onehippo.org/about/open-source-release-policy.html
To checkout the code for a specific release tag, after cloning this repository, use the following:
## to show the available tags
git tag
## to checkout a specific tag
git checkout <tag name>
## to modify a project
If you want to make modifications to a project, for example to create a patch, create a new fork branch from the specific tag like this:
git checkout -b forked-<tag name> <tag name>
For the latter, also see the **Build from Source** documentation at https://www.onehippo.org/library/development/build-hippo-cms-from-scratch.html
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-plugin-sitemap</artifactId>
<version>4.3.0-SNAPSHOT</version>
</parent>
<name>Hippo Plugin Sitemap Component</name>
<description>Hippo Plugin Sitemap Component</description>
<artifactId>hippo-plugin-sitemap-component</artifactId>
<dependencies>
<dependency>
<groupId>org.onehippo.cms7.hst.dependencies</groupId>
<artifactId>hst-client-dependencies</artifactId>
<version>${hippo.hst.version}</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-api</artifactId>
<version>${hippo.hst.version}</version>
<scope>provided</scope>
<!-- <type>pom</type> -->
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-commons</artifactId>
<version>${hippo.hst.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms7-commons</artifactId>
<version>${hippo.commons.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<!-- For HippoNodeType constants -->
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-api</artifactId>
<version>${hippo.repository.version}</version>
<scope>provided</scope>
</dependency>
<!-- For HippoStdNodeType constants -->
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-builtin</artifactId>
<version>${hippo.repository.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>package</defaultGoal>
</build>
</project>
This diff is collapsed.
/*
* 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;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.onehippo.forge.sitemap.components.model.news.info.AccessType;
import org.onehippo.forge.sitemap.components.model.news.info.Genre;
import org.onehippo.forge.sitemap.components.model.news.info.Publication;
import java.util.Calendar;
import java.util.List;
/**
* An interface implemented by classes that can resolve news sitemap item properties for HippoBeans
* Classes that implement this interface can be passed to the SitemapGenerator to be used in creating a news site map.
*
* @author Wouter Danes
*/
public interface NewsInformationProvider extends UrlInformationProvider{
/**
* Returns a comma seperated list of geo locations for this sitemap item, from more to less specific, f.ex:
* Amsterdam, Netherlands, Europe
* @param hippoBean the document to generate the geo locations value for
* @return {@link String} containing a comma seperated list of geo locations
*/
String getGeoLocations(HippoBean hippoBean);
/**
* Returns the title of the document for the google news sitemap
* @param hippoBean the document to generate the title value for
* @return {@link String} containing the Title of this news document
*/
String getTitle(HippoBean hippoBean);
/**
* Returns the access type of this news document. For a list of supported values, check the {@link AccessType} enum.
* @param hippoBean the document to return the {@link AccessType} for
* @return the {@link AccessType} for this news document
*/
AccessType getAccess(HippoBean hippoBean);
/**
* Returns the {@link Publication} for this news document
* @param hippoBean the document to return the {@link Publication} for
* @return the {@link Publication} for this news document
*/
Publication getPublication(HippoBean hippoBean);
/**
* Returns the publication date for the passed {@link HippoBean}.
* @param hippoBean the document to return the publication date for
* @return {@link Calendar} representing the publication date of this news document
*/
Calendar getPublicationDate(HippoBean hippoBean);
/**
* Returns the {@link Genre}s for the passed {@link HippoBean}
* @param hippoBean the document to return the {@link Genre}s for. For possible values check the enum.
* @return {@link List} containing the applicable {@link Genre}s.
*/
List<Genre> getGenres(HippoBean hippoBean);
/**
* Returns a comma seperated list of keywords that are applicable to the passed {@link HippoBean}
* @param hippoBean the document to return the keywords for.
* @return a {@link String} containing a comma seperated list of keywords
*/
List<String> getKeywords(HippoBean hippoBean);
/**
* Returns the publication date property that will be used to resolve the age of documents. documents old than 48
* hours should not be included in the news sitemap
* @return the name of the property of type jcr:date that contains the publication date of a news document
*/
String getPublicationDateProperty();
}
/*
* Copyright 2012-2015 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 static org.onehippo.forge.sitemap.components.util.ReflectionUtils.obtainInstanceForClass;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.lang.StringUtils;
import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.container.RequestContextProvider;
import org.hippoecm.hst.content.beans.query.HstQuery;
import org.hippoecm.hst.content.beans.query.exceptions.QueryException;
import org.hippoecm.hst.content.beans.query.filter.Filter;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.parameters.Parameter;
import org.hippoecm.hst.core.parameters.ParametersInfo;
import org.hippoecm.hst.core.request.HstRequestContext;
import org.onehippo.forge.sitemap.components.model.news.NewsUrlset;
import org.onehippo.forge.sitemap.components.model.news.info.Publication;
import org.onehippo.forge.sitemap.components.util.MatcherUtils;
import org.onehippo.forge.sitemap.generator.DefaultNewsInformationProvider;
import org.onehippo.forge.sitemap.generator.NewsSitemapGenerator;
/**
* This component serves a news sitemap based on configured document types
* The documents in the news sitemap cannot be older than 48 hours
* This class uses deprecated annotations and methods to be compatible with Hippo 7.6
*
* @author Wouter Danes
*/
@SuppressWarnings({"unused"})
@ParametersInfo(type = NewsSitemapFeed.NewsSitemapFeedParametersInformation.class)
public class NewsSitemapFeed extends BaseHstComponent {
private static final int MAX_AGE_IN_HOURS = 48;
public interface NewsSitemapFeedParametersInformation {
@Parameter(
name = "publicationDateProperty",
required = true
)
String getPublicationDateProperty();
@Parameter(
name = "documentTypes",
required = true
)
String getDocumentTypes();
@Parameter(
name = "propertyCriteria",
defaultValue = ""
)
String getPropertyCriteria();
@Parameter(
name = "timezone",
defaultValue = "UTC"
)
String getTimezone();
@Parameter(
name = "publicationName",
defaultValue = ""
)
String getPublicationName();
@Parameter(
name = "publicationLanguage",
defaultValue = ""
)
String getPublicationLanguage();
@Parameter(
name = "newsInformationProvider",
defaultValue = ""
)
String getNewsInformationProviderClassname();
}
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
super.doBeforeRender(request, response);
NewsSitemapFeedParametersInformation parameters = getComponentParametersInfo(request);
verifyRequiredParametersAreFilled(parameters);
NewsInformationProvider newsInformationProvider = createNewsInformationProvider(parameters);
Map<String, String> propertyCriteria = parsePropertyCriteria(parameters.getPropertyCriteria());
String[] documentTypes = parameters.getDocumentTypes().trim().split("[\\s]*,[\\s]*");
HstQuery query = createQuery(
request,
documentTypes,
parameters.getTimezone(),
newsInformationProvider,
propertyCriteria
);
HstRequestContext requestContext = request.getRequestContext();
NewsSitemapGenerator sitemapGenerator =
new NewsSitemapGenerator(requestContext, newsInformationProvider, RequestContextProvider.get().getContentBeansTool().getObjectConverter());
NewsUrlset urlset = sitemapGenerator.createNewsSitemap(query);
String sitemap = NewsSitemapGenerator.toString(urlset);
request.setAttribute("sitemap", sitemap);
}
private HstQuery createQuery(final HstRequest request, final String[] documentTypes, final String timezone,
final NewsInformationProvider newsInformationProvider,
final Map<String, String> propertyCriteria) {
HippoBean siteContentBaseBean = request.getRequestContext().getSiteContentBaseBean();
HstQuery query;
try {
query = RequestContextProvider.get().getQueryManager().createQuery(siteContentBaseBean, documentTypes);
Filter filter = query.createFilter();
Calendar dateToObtainNewsSince = new GregorianCalendar(TimeZone.getTimeZone(timezone));
dateToObtainNewsSince.add(Calendar.HOUR_OF_DAY, -MAX_AGE_IN_HOURS);
filter.addGreaterThan(newsInformationProvider.getPublicationDateProperty(), dateToObtainNewsSince);
if (!propertyCriteria.isEmpty()) {
// Add property criteria
for (Map.Entry<String, String> propertyCriterion : propertyCriteria.entrySet()) {
filter.addEqualTo(propertyCriterion.getKey(), propertyCriterion.getValue());
}
}
query.setFilter(filter);
} catch (QueryException e) {
throw new HstComponentException("Cannot create HstQuery", e);
}
return query;
}
private static void verifyRequiredParametersAreFilled(final NewsSitemapFeedParametersInformation parameters){
if (StringUtils.isEmpty(parameters.getDocumentTypes())) {
throw new HstComponentException("No document types specified, please pass the parameter documentTypes");
}
if (StringUtils.isEmpty(parameters.getPublicationDateProperty())
&& StringUtils.isEmpty(parameters.getNewsInformationProviderClassname())
) {
throw new HstComponentException("No Publication date property specified, please pass the parameter " +
"publicationDateProperty");
}
}
private static NewsInformationProvider createNewsInformationProvider(
final NewsSitemapFeedParametersInformation parameters) {
boolean hasCustomProviderClass = StringUtils.isNotEmpty(parameters.getNewsInformationProviderClassname());
boolean hasPublicationInformation = StringUtils.isNotEmpty(parameters.getPublicationName()) &&
StringUtils.isNotEmpty(parameters.getPublicationLanguage());
if (!hasCustomProviderClass && !hasPublicationInformation) {
throw new HstComponentException("No publication information set and no custom NewsInformationProvider specified");
}
if (hasCustomProviderClass) {
return obtainInstanceForClass(NewsInformationProvider.class,
parameters.getNewsInformationProviderClassname());
} else {
return new DefaultNewsInformationProvider(
new Publication(parameters.getPublicationName(), parameters.getPublicationLanguage()),
parameters.getPublicationDateProperty()
);
}
}
/**
* Takes an input string with comma separated property criteria (in the format prop1=condition1,prop2=condiion2...)
* and returns a map with key = property and value = criterion
*
* @param propertyCriteria comma separated list of property criteria
* @return {@link Map} containing the property criteria
*/
private static Map<String, String> parsePropertyCriteria(final String propertyCriteria) {
if (StringUtils.isEmpty(propertyCriteria)) {
return Collections.emptyMap();
}
final String[] criteria = MatcherUtils.getCommaSeparatedValues(propertyCriteria);
final Map<String, String> propertiesWithCriteria = new HashMap<>();
for (final String criterion : criteria) {
final String[] propertyValuePair = MatcherUtils.parsePropertyValue(criterion);
if (propertyValuePair == null) {
throw new HstComponentException("Criterion '" + criterion + "' doet not have format 'property=value'");
}
propertiesWithCriteria.put(propertyValuePair[0], propertyValuePair[1]);
}
return propertiesWithCriteria;
}
}
/*
* 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.
* 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.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.sitemenu.HstSiteMenus;
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);
}
HstSiteMenus siteMenus = request.getRequestContext().getHstSiteMenus();
request.setAttribute("sitemap", new SitemapGenerator(request.getRequestContext())
.createSitemap(siteMenus, maxDepth));
}
}
/*
* 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;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import org.apache.commons.lang.StringUtils;
import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.parameters.Parameter;
import org.hippoecm.hst.core.parameters.ParametersInfo;
import org.onehippo.forge.sitemap.generator.SitemapIndexGenerator;
/**
* Serves a Sitemap IndexXML.
*
* @author Ricardo Sawirjo
*/
@SuppressWarnings({"unused" })
@ParametersInfo(type = SitemapIndexFeed.SitemapIndexFeedParametersInformation.class)
public class SitemapIndexFeed extends BaseHstComponent {
/**
* A sitemap index file will be created. This file will contain urls which points to the
* assets folder in the Hippo Repository.
* The sitemap-location-foldername must be configured via the console.
* Add a parameter at the following location:
* /hst:hst/hst:configurations/hst:default/hst:components/forge-sitemap-index-feed
* The value of this parameter contains the complete folder path relative to
* content/assets/sitemap/
* The assets-url-prefix: this parameter is used for placing a prefix in front of the url, which is
* linking to the asset. Why? Some sites uses url rewriting or mapping.
* The additional-sitemap-file-url: this parameter is to be able to add manual additional
* sitemap url to the sitemap index file. It can be a list of urls, where the items are separated with a comma.
*/
public interface SitemapIndexFeedParametersInformation {
/**
* The location of the sitemap folder, where the sitemap files are stored.
* These files will be used while generating the sitemap index file.
* @return A string containing the location of the sitemap index files.
*/
@Parameter(
name = "sitemap-location-foldername",
required = true
)
String getSitemapLocationFolderNameProperty();
/**
* For some systems the sitemap index files are stored in the repository asset folder.
* These systems might use url rewriting. With this parameter a prefix can be configured, which
* is placed in front of the asset url.
* @return The prefix which is placed in front of the url.
*/
@Parameter(
name = "assets-url-prefix",
required = false
)
String getAssetUrlPrefix();
/**
* Provide additional urls which must be added to the sitemap index.
* @return A comma delimited list of urls which must be added to the generated site map index file.
*/
@Parameter(
name = "additional-sitemap-file-url",
required = false
)
String getAdditionalSitemapFileUrl();
}
/**
* @param request The incoming request.
* @param response The Response.
* @throws HstComponentException
*/
public void doBeforeRender(final HstRequest request, final HstResponse response) {
super.doBeforeRender(request, response);
SitemapIndexFeedParametersInformation parameters = getComponentParametersInfo(request);
verifyRequiredParametersAreFilled(parameters);
String siteMapFolder = parameters.getSitemapLocationFolderNameProperty();
String urlPrefix = parameters.getAssetUrlPrefix();
String additionalSiteMap = parameters.getAdditionalSitemapFileUrl();
String [] additionalSiteMapUrls = null;
if (isNotEmpty(additionalSiteMap)) {
additionalSiteMapUrls = additionalSiteMap.split(",");
}
HippoBean assetContentRoot = getAssetBaseBean(request);
request.setAttribute("sitemap", new SitemapIndexGenerator(request, assetContentRoot).
createSitemapIndex(siteMapFolder, urlPrefix, additionalSiteMapUrls));
}
/**
* Verify if the required parameters are filled via the CMS Console.
* And that they are correct configured.
*
* @param parameters The parameters which have been configured in the CMS Console.
*/
private static void verifyRequiredParametersAreFilled(final SitemapIndexFeedParametersInformation parameters) {
if (StringUtils.isEmpty(parameters.getSitemapLocationFolderNameProperty())) {
throw new HstComponentException("No sitemap location folder specified, please pass the parameter "
+ "sitemap-location-foldername.");
}
if (isNotEmpty(parameters.getAssetUrlPrefix())) {
String urlPrefix = parameters.getAssetUrlPrefix();
if (isNotEmpty(urlPrefix) && (!urlPrefix.startsWith("/") || !urlPrefix.endsWith("/"))) {
throw new HstComponentException("The assets-url-prefix specified, must start with a / and end with /.");
}
}
}
}
/*
* 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.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.sitemenu.HstSiteMenus;
import org.onehippo.forge.sitemap.generator.SitemapGenerator;
@SuppressWarnings({"unused"})
public class SitemapView 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);
}
HstSiteMenus siteMenus = request.getRequestContext().getHstSiteMenus();
request.setAttribute("sitemap", SitemapGenerator.getSitemapView(siteMenus, maxDepth));
}
}
/*
* 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.