Skip to content

Instantly share code, notes, and snippets.

@chrismrgn
chrismrgn / web.xml
Last active Oct 27, 2016
DD4T 2 Java - web.xml
View web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>DD4T 2</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
@chrismrgn
chrismrgn / dispatcher-servlet.xml
Created Jul 14, 2016
Fragment from dispatcher-servlet.xml to wire up Sitemap in DD4T 2 Java
View dispatcher-servlet.xml
<!-- Sitemap -->
<bean id="sitemap" class="com.xxx.xxx.navigation.SitemapImpl">
</bean>
<bean id="navigationController" class="com.xxx.xxx.controller.NavigationController">
<property name="navigationViewPath" value="navigation/"/>
<property name="publicationResolver" ref="publicationResolver" />
<property name="sitemapFactory" ref="sitemapFactory"/>
<property name="sitemap" ref="sitemap"/>
</bean>
@chrismrgn
chrismrgn / main-navigation.jsp
Created Jul 14, 2016
Navigation View using the Sitemap classes for DD4T 2 Java
View main-navigation.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- View Models -->
<jsp:useBean id="navigationModel" type="com.xxx.xxx.xxx.Sitemap" scope="request"/>
<ul>
<c:forEach items="${navigationModel.getTopNavigation()}" var="item">
<li class="nav-cols">
<a href="#">${item.title}</a>
@chrismrgn
chrismrgn / header.jsp
Created Jul 14, 2016
Including the Navigation via JSP include
View header.jsp
<jsp:include page="/mainNavigation" />
@chrismrgn
chrismrgn / NavigationController.java
Created Jul 14, 2016
Controller to handle Navigation in DD4T 2 Java
View NavigationController.java
@Controller
public class NavigationController {
private static final Logger LOG = LoggerFactory.getLogger(NavigationController.class);
private SitemapFactory sitemapFactory;
private PublicationResolver publicationResolver;
private Sitemap sitemap;
private String navigationViewPath = "";
@RequestMapping(value = "/mainNavigation", method = { GET })
@chrismrgn
chrismrgn / SitemapFactory.java
Created Jul 14, 2016
Factory interface and class to integrate the CustomDataBind (Sitemap) functionality into DD4T 2 Java
View SitemapFactory.java
public interface SitemapFactory extends Factory {
<T extends Sitemap> T findSitemapByUrl(String url, int publicationId, final Class<? extends T> aClass) throws FactoryException;
<T extends Sitemap> T deserialize(String source, final Class<? extends T> aClass) throws FactoryException;
}
public class SitemapFactoryImpl extends BaseFactory implements SitemapFactory {
private static final Logger LOG = LoggerFactory.getLogger(PageFactoryImpl.class);
private static final SitemapFactoryImpl INSTANCE = new SitemapFactoryImpl();
@chrismrgn
chrismrgn / CustomDataBindFactory.java
Created Jul 14, 2016
Custom data bind factory to plumb in the custom data binder to a DD4T 2 Java project
View CustomDataBindFactory.java
public class CustomDataBindFactory {
private static final Logger LOG = LoggerFactory.getLogger(DataBindFactory.class);
private static final CustomDataBindFactory INSTANCE = new CustomDataBindFactory();
private CustomDataBinder customDataBinder;
private CustomDataBindFactory () {
LOG.info("CustomDataBindFactory init.");
}
@chrismrgn
chrismrgn / CustomDataBinder.java
Last active Jul 14, 2016
DataBinder, based on the DD4T 2 Java pattern, to get other types of pages from SDL
View CustomDataBinder.java
public interface CustomDataBinder {
<T extends Sitemap> T buildSitemap(String source, final Class<T> aClass) throws SerializationException;
}
public class CustomDataBinderImpl implements CustomDataBinder {
private static final Logger LOG = LoggerFactory.getLogger(CustomDataBinderImpl.class);
private static final ObjectMapper GENERIC_MAPPER = new ObjectMapper();
static {
GENERIC_MAPPER.configure(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS,true);
@chrismrgn
chrismrgn / Sitemap.java
Last active Jul 14, 2016
Sitemap interface and classes for DD4T 2 Java
View Sitemap.java
public interface Sitemap {
//Always one root Folder
Folder getFolder();
void setFolder(Folder folder);
//Example
List<BaseItem> getTopNavigation();
}
@JsonIgnoreProperties(ignoreUnknown = true)
@chrismrgn
chrismrgn / sitemap.json
Created Jul 14, 2016
Very rough test sitemap json file
View sitemap.json
{
"folder": {
"id": "tcm:1-2-3",
"title": "root",
"topnav": "false",
"level": "0",
"pages": [{
"id": "tcm:1-2-4",
"title": "homepage",
"topnav": "false",