Skip to content

Instantly share code, notes, and snippets.

@chrismrgn
chrismrgn / web.xml
Last active October 27, 2016 20:20
DD4T 2 Java - 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 July 14, 2016 02:51
Fragment from dispatcher-servlet.xml to wire up Sitemap in DD4T 2 Java
<!-- 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 July 14, 2016 02:43
Navigation View using the Sitemap classes for DD4T 2 Java
<%@ 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 July 14, 2016 02:41
Including the Navigation via JSP include
<jsp:include page="/mainNavigation" />
@chrismrgn
chrismrgn / NavigationController.java
Created July 14, 2016 02:39
Controller to handle Navigation in DD4T 2 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 July 14, 2016 02:33
Factory interface and class to integrate the CustomDataBind (Sitemap) functionality into DD4T 2 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 July 14, 2016 02:30
Custom data bind factory to plumb in the custom data binder to a DD4T 2 Java project
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 July 14, 2016 02:50
DataBinder, based on the DD4T 2 Java pattern, to get other types of pages from SDL
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 July 14, 2016 02:35
Sitemap interface and classes for DD4T 2 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 July 14, 2016 02:13
Very rough test sitemap json file
{
"folder": {
"id": "tcm:1-2-3",
"title": "root",
"topnav": "false",
"level": "0",
"pages": [{
"id": "tcm:1-2-4",
"title": "homepage",
"topnav": "false",