code.onehippo.org is currently readonly. We are migrating to code.bloomreach.com, please continue working there on Monday 14/12. See: https://docs.bloomreach.com/display/engineering/GitLab

Commit 89f41bf3 authored by Jeroen Hoffman's avatar Jeroen Hoffman

HIPPLUG-1522 Reintegrate branch 'Feature/HIPPLUG-1522' into release/13.0

parents 8e3b0bd5 ee30a2e5
......@@ -26,3 +26,5 @@ definitions:
site-title: Site Title
site-title-in-template: Use title-tag provided by page templates
template-page-title: Template Page Title
group.imagesettings: Image settings
document-image-bean-props: Image field(s) in the documents
\ No newline at end of file
/*
* Copyright 2011-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2011-2018 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.
......@@ -86,6 +86,7 @@ public class SEOHelperComponent extends BaseHstComponent {
setDublinCoreLinksRequestAttributes(request, params);
setMetaKeywordsDescriptionRequestAttributes(request, params, document, menu);
setDocumentDatesRequestAttributes(request, document);
setImageAttributes(request, params, document);
}
/**
......@@ -116,6 +117,27 @@ public class SEOHelperComponent extends BaseHstComponent {
}
}
/**
* Sets the {@literal image} request attribute
*
* @param request current {@link HstRequest}
* @param params {@link SEOHelperComponentParamsInfo}
* @param document {@link HippoBean} that is the source for the current page
*/
protected void setImageAttributes(HstRequest request, SEOHelperComponentParamsInfo params, HippoBean document) {
if (document != null) {
try {
request.setAttribute("image", getDocumentImage(document, params));
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Failed to add image head element", e);
} else {
log.warn("Failed to add image head element. {}", e.toString());
}
}
}
}
/**
* Sets {@literal metaKeywords} and {@literal metaDescription} request attributes
*
......@@ -312,8 +334,14 @@ public class SEOHelperComponent extends BaseHstComponent {
}
String documentTitle = getDocumentTitle(document, params);
String sitemapTitle = null;
if (request.getRequestContext().getResolvedSiteMapItem()!=null) {
sitemapTitle = request.getRequestContext().getResolvedSiteMapItem().getPageTitle();
}
if (StringUtils.isNotBlank(documentTitle)) {
values.put("pageTitle", documentTitle);
} else if (sitemapTitle != null) {
values.put("pageTitle", sitemapTitle);
} else if (selectedMenuItem != null) {
values.put("pageTitle", selectedMenuItem.getName());
}
......@@ -363,6 +391,33 @@ public class SEOHelperComponent extends BaseHstComponent {
return null;
}
/**
* Gets the document image from a comma separated list of properties using the first property that returns a value
*
* @param document {@link HippoBean}
* @param params {@link SEOHelperComponentParamsInfo}
* @return image based on the configured properties or {@literal null} if it can't be found
* @throws Exception if something goes wrong
*/
protected Object getDocumentImage(HippoBean document, SEOHelperComponentParamsInfo params) throws Exception {
if (document != null) {
// fall-back to property-based title
final String propertiesString = params.getDocumentImageBeanProperties();
if (propertiesString != null) {
final String[] propertyNames = StringUtils.split(propertiesString, SEPARATOR_CHARACTERS);
for (String propertyName : propertyNames) {
if (PropertyUtils.isReadable(document, propertyName)) {
Object image = PropertyUtils.getProperty(document, propertyName);
return image;
}
}
}
}
return null;
}
/**
* Tries to find the sitemenu item that is an exact match (hit on "Events")
*
......
/*
* Copyright 2011-2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2011-2018 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.
......@@ -35,7 +35,13 @@ import org.hippoecm.hst.core.parameters.Parameter;
titleKey = "group.descriptionsettings",
value = {
"document-description-bean-props",
"default-meta-description"
"default-meta-description",
}
),
@FieldGroup(
titleKey = "group.imagesettings",
value = {
"document-image-bean-props"
}
),
@FieldGroup(
......@@ -90,6 +96,9 @@ public interface SEOHelperComponentParamsInfo {
@Parameter(name="document-description-bean-props", defaultValue="description")
String getDocumentDescriptionBeanProperties();
@Parameter(name="document-image-bean-props", defaultValue="image")
String getDocumentImageBeanProperties();
@Parameter(name="site-title")
String getSiteTitle();
......
/*
* Copyright 2011-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2011-2018 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.
......@@ -313,6 +313,7 @@ public class SEOHelperComponentTest {
private String documentTitleBeanProperties = "title";
private String documentKeywordsBeanProperties = "keywords";
private String documentDescriptionBeanProperties = "description";
private String documentImageBeanProperties = "image";
private String siteTitle;
private String dublinCoreSchemaLink = "http://purl.org/dc/elements/1.1/";
private String dublinCoreTermsLink = "http://purl.org/dc/terms/";
......@@ -383,6 +384,11 @@ public class SEOHelperComponentTest {
return documentDescriptionBeanProperties;
}
@Override
public String getDocumentImageBeanProperties() {
return documentImageBeanProperties;
}
public void setDocumentDescriptionBeanProperties(String documentDescriptionBeanProperties) {
this.documentDescriptionBeanProperties = documentDescriptionBeanProperties;
}
......
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