Skip to main content

Posts

Showing posts from 2016

Toolkit - Tricks with Memory Byte Buffer

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. In previous post Writing My Own Database Engine , I quickly mentioned the use of Memory Byte Buffer from Jana NIO that provides fast access to a file by mapping its content to memory. This post goes into more detail over some tricks that occurred with that implementation. There is an issue with Memory Byte Buffer. Namely, once it is created by calling FileChannel.map method, it cannot be unmapped, closed or discarded. The byte buffer will exist until it is garbage collected. From the JavaDoc: A mapping, once established, is not dependent upon the file channel that was used to create it. Closing the channel, in particular, has no effect upon the validity of the mapping. A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected. The issue is affects Windows OS Java implementations, in the sense that it keep

Toolkit - Writing My Own Database Engine

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. In the previous post  Criteria for Dynamic Queries , I presented index classes that allow us to execute performant lookups for keys in indexes on the file system. This post presents the logic behind these indexes. The requirement for the Toolkit API was not to use a database or a third party product such as search engines or indexers. In order to do searches for content on a file system where we had JSON files filled with properties we want to search on, we need to have indexes of those properties. It would be impossible to do performant searches without such indexes. This meant creating my own indexes and indexing logic (put, get) backed by a fast searching algorithm. In other words, it meant writing my own simple database engine. The rationale looks like this: Each query must be as fast as possible. The fastest way to query would be to lookup a key in a dictionary an

Toolkit - Criteria for Dynamic Queries

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. In the previous post  Dynamic Content Queries , I presented a Query class that performs CustomMeta queries on JSON models published to the file system. This post presents the logic that actually queries for results and applies different boolean operators for different Criteria. The base class for each criteria is Criterion, which defines the base methods each criteria must implement: public abstract class Criterion { public Set < String > executeQuery () { return executeQuery ( FilterImpl . EMPTY_FILTER ); } public abstract Set < String > executeQuery ( Filter filter ); } The Filter class contains a set of allowed Publication ids, the item type and whether to include the range boundaries or not. The Filter is used in modifying the results retrieved for each criteria from the indexes. Each criteria uses an index to l

Toolkit - Dynamic Query Sorting and Pagination

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. In the previous post Dynamic Content Queries , I presented a Query class that performs CustomMeta queries on JSON models published to the file system. This post presents the logic that sorts and paginates the result set. The Query class defines four members that help the pagination and sorting logic: Sorter -- the Comparator that perform the actual sorting of two ItemMeta objects (it returns an order between two ItemMeta instances); page -- the page index to return out of all pages; pageSize -- the number of items on a page; totalItemCount -- the total number of items before pagination was applied; Sorting Sorting can be specified on different columns and can use different directions for each column (ascending, descending). A sort column is a predefined metadata of a model (title, last publish date) or a CustomMeta. An association between a sort column and sort di

Toolkit - Dynamic Content Queries

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the Dynamic Content Query capability. The requirements for the Toolkit API are that it should be able to provide CustomMeta queries, pagination, and sorting -- all on the file system, without the use third party tools (database, search engines, indexers, etc). Therefore I had to implement a simple database engine and indexer -- which is described in more detail in post Writing My Own Database Engine . The querying logic does not make use of cache. This means the query logic is executed every time. When models are requested, the models are however retrieved using the ModelFactory and those are cached. Query Class This is the main class for dynamic content queries. It is the entry point into the execution logic of a query. The class takes as parameter a Criterion (presented below) which triggers the execution of query in all sub-criteria of a Criterio

Toolkit - Custom Tags Execution while Assembling

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the TagFactory in charge with execution of custom tags for the Toolkit Component Presentations. The content of Dynamic Component Presentations can contain custom tags in the form of <mytag>some body</mytag> . These XML-like nodes are backed by a Java class that is executed when the tag is rendered. The configuration of tag names and Java class name is done in file toolkit.properties. More information is available in post Installation and Configuration . The custom tag support uses the following concepts: TagFactory -- the entry point into execution of tags for a piece of content; TagSupport -- class that associates a tag name with a tag implementation class; TagRenderer -- interface that a tag implementation class must implement; TagRenderer Interface This is the interface that any tag class must implement. It contains only one me

Toolkit - Component Presentation Assembler

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post describes a Component Presentation Assembler factory. Its role is to retrieve a Dynamic Component Presentation and to trigger the execution of its content. Then the resolved content is returned. The only method the assembler has is getContent(int, int, int), which takes parameters Publication id, Component id and Component Template id. It uses the ComponentPresentationFactory to retrieve the DCP. Next, it triggers the execution of any custom tags might be in the DCP's content. The content can contain XML-like tags (e.g. <mytag>some body</mytag> ). The tag support engine will execute all custom tags it finds in the content. Finally, the resolved content is returned by the assembler and it is ready to be displayed on the response. public String getContent ( int publicationId , int componentId , int templateId ) { ComponentPresenta

Tookit - Component Presentation Factory

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the Component Presentation Factory in the Toolkit. Its role is to retrieve a Dynamic ComponentPresentationMeta models based on several criteria. The factory implements lookup methods by ids - Publication id, Component id, Component Template id and another one for getting a DCP based on the highest linking priority. Method getComponentPresentation(int, int, int) The three parameters, Publication id, Component id and Component Template id identify uniquely a Dynamic Component Presentation. If such a DCP is exists (i.e. is published), it id returned. This method retrieves the Component model and then iterates over its DCP collection, returning the DCP with the given Component Template id, if available. public ComponentPresentationMeta getComponentPresentation ( int publicationId , int componentId , int templateId ) { TcmUri componentUri

Toolkit - Dynamic Linking

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. In this post I describe the dynamic link resolving logic as part of the Link Factory. There are three types of links: Component, Page and Binary links. Each of these links can be resolved using the Link Factory. Component Link Resolving a Component link implies finding the URL of the Page the target Component appears on. Using the current Toolkit models, it is quite straight forward to retrieve the URL, because the link information is contained within the Component model. However, there might be several potential links available when performing Component link resolving. Namely, there can be several cases possible: there is no linking information available in the Component model -- this means the link cannot be resolved (i.e. there is no Page published that contains the given Component); there is exactly one Page available that contains the Component -- this means