📜 ⬆️ ⬇️

Apache Lenya - an unusual opensource CMS in Java

In the comments to the topic of Spring in action - we are trying to open the CMS in Java, I mentioned Apache Lenya, one of the opensource CMS in Java, and I was asked to write more about it.
Apache Lenya Logo

Why Apache Lenya

“Why is CMS in Java?” - the first question I had when I received requests from the customer. The answer turned out to be simple: the customer, a large corporation, had experience in developing projects in Java, so he trusted her the most. “Java EE” sounds more serious and reliable for a businessman’s ear than, say, PHP. How things are with reliability and seriousness is not really important, but still it should be borne in mind that large corporations trust the products of other large corporations.

So, we in the company began to search for CMS Java. It turned out that there are not so few of them, both paid and freely distributed. More details can be found here on Wikipedia.
After analyzing the licenses, and we needed to seriously “finish” the CMS for the needs of the customer, the choice was made by several candidates: Nuxeo EP, Daisy, Hippo CMS, Alfresco and Apache Lenya itself. All have been tested. After analyzing the source code and assessing the complexity of the revision, we decided to stop at Apache Lenya. This CMS provided the most extensive source code modification options that were easily accessible. Benefit Apache License allowed to change the code and then use the product for commercial purposes. The problems that arose at the beginning were solved with the help of a small but rather active community.

Main manu bar

Apache Lenya features

Apache Lenya provides standard CMS features (I only have Joomla experience, so most of the comparisons with it):

And also not the most common:


This concept allows you to reuse the already created site structure (or structure and data of one publication) for a new publication. Different publications may use the general structure of the site, but contain different information. For example, there is a default publication, default, which already contains XSLT templates, user data, user groups, and other service information. Production publication is inherited from default. Then the publication of production has the same appearance (thanks to the general XSLT), access to all users and groups. However, it can override some user rights, page rendering, or even the whole thing. In general, a fairly convenient option if you need to maintain several similar sites.

About this web framework it is worth talking separately a little more detail. He is the heart of Apache Lenya.

Apache cocoon

Apache Cocoon ( official site ) - a framework for web development. It has common features with the Spring Framework, when it was still version 2 or even younger. Among other things, it is worth noting, in my opinion, two main features of Cocoon: the presence of an IoC container and the concept of “channels” (pipelines). It has many other remarkable features, but I needed these two when finalizing Apache Lenya. What is Inversion of Control, I think, is not worth describing, but about the “channels” you should say a few words.
Channels are a kind of implementation of the MVC pattern. The XML configuration looks like this:
<? xml version ="1.0" encoding ="iso-8859-1" ? >
< map:sitemap xmlns:map ="http://apache.org/cocoon/sitemap/1.0" >

<!-- define the Cocoon processing pipelines -->
< map:pipelines >
< map:pipeline >
<!-- respond to *.html requests with
our docs processed by doc2html.xsl -->
< map:match pattern ="*.html" >
< map:generate src ="{1}.xml" />
< map:transform src ="doc2html.xsl" />
< map:serialize type ="html" />
</ map:match >

<!-- later, respond to *.pdf requests with
our docs processed by doc2pdf.xsl -->
< map:match pattern ="*.pdf" >
< map:generate src ="{1}.xml" />
< map:transform src ="doc2pdf.xsl" />
< map:serialize type ="fo2pdf" />
</ map:match >
</ map:pipeline >
</ map:pipelines >
</ map:sitemap >

* This source code was highlighted with Source Code Highlighter .

As you can see, mapping has three main steps for creating pages:
  1. Generation
  2. Transformation
  3. Serialization

In braces are passed parameters for the generator.
Thus, flexibility and a high level of component reuse are achieved: using the same generator and different transformations and serializations, you can get a wide range of output formats from the banal html to pdf or csv.

To implement the IoC container, Apache Cocoon uses the currently closed Apache Avalon framework. All configuration is in the file cocoon.xconf. Almost everything is collected here: components, data sources, module declarations (Cocoon has a flexible plug-in system) and so on.
There is not a lot of documentation on all this on the Internet, therefore it is a little more detailed about components.
The concept of components looks like this: several components (components) are combined on the basis of a role (role), implementation of a default role is declared, and in a Java class it is already possible to use a role and its specific implementation. Roles are interfaces, and components are concrete classes. I will not give specific file listings, they are very large. The details of Apache Cocoon and Avalon require a separate article.

Install Apache Lenya

After downloading apache-lenya-2.0.3-src.zip and unpacking it, which can take a long time due to the larger number of files, it needs to be compiled. Here begins the biggest "dancing with a tambourine."
Version 2.0.2 I managed to knock off by executing at the root:
>build build-cocoon
>build build-cocoon

This is not a slip of the pen, the first command must be executed twice.
For version 2.0.3, everything was much more complicated.
First, in the externals \ cocoon_2_1_x \ lib \ optional directory , you need to update xalan-2.7.1.jar to contain package org.apache.xpath, and add serializer.jar from the xalan-j_2_7_1-bin.zip distribution. By the way, after updating xalan-2.7.1.jar errors may occur during compilation, then you need to look for another xalan-2.7.1.jar . I took it from the maven repository, and the serializer from the Xalan distribution.
Next, try to hit the Cocoon. To do this, perform at the root:
build.bat build-cocoon -lib externals/cocoon_2_1_x/lib/optional

Times from the 3rd or even from the 4th build must pass successfully.
The -lib externals / cocoon_2_1_x / lib / optional parameter is required, because some libraries with ant tasks are there, and some libraries are needed for compilation.
Then for Windows users, you need to put GnuWin32 ( you can take it from here ), add to PATH from the environment variables the directory where GnuWin32 was installed. It is necessary that the patch command be executed during the build.
In the end, the team
build -lib externals/cocoon_2_1_x/lib/optional

must end with a magical message BUILD SUCCESSFUL.
If something did not work out, you can additionally ask me or look for answers in the mail archive

Run Apache Lenya

The launch did not go smoothly with me either. At first I had to copy jms.jar (javax.jms package) and jta-1.1.jar (javax.transaction package) into build\lenya\webapp\WEB-INF\lib\ (I need to fix this in the main ant build) , and only after that Apache Lenya successfully started:
Lenya homepage

It is launched by Lenya using the lenya.bat or lenya.sh file.
The default is the Jetty servlet container.
It is also possible to run under Tomcat (personally tested). More information about this can be found on the official website .
Apache Lenya is partially translated into Russian. Non-localized labels can be translated by adding the required data in the internationalization files: $ LENYA_HOME $ \ src \ webapp \ lenya \ resources \ i18n

Creating a new publication Apache Lenya

To create your publication you must do the following.
On the main page, click 'Create publication', enter the identifier (future context) and the name of the publication:
Create publication

After creation, click on the link to the publication and get to the page with the properties of the publication:
Publication homepage

Select 'Login for authoring' (allows editing site content and site configuration)
Login as lenya (password levi)
Choose what to do: export the default pages or not create any pages:
Import pages

Then the user lenya can create pages, edit them and send for approval. In the "Edit" menu, you can create pages, and in the "Process" menu, manage the status of pages:
Edit menu
Workflow menu

The user alice (password levi) has the role of a reviewer and has the right to publish pages. After the publication of the page appear on the Live View (or tab "Published")
For help, data about users, groups and roles are stored in \ build \ lenya \ webapp \ lenya \ pubs \ default \ config \ access-control \ passwd \ Of course, you can change them via the web interface, the 'Admin' tab.


Apache Lenya is a flexible Java CMS, based on Apache Cocoon, and therefore its full capabilities, and distributed under the Apache License. This CMS has many features, as they say, "right out of the box", and the functionality can be easily expanded by writing additional modules. There are few documentation and manuals on the Internet, but there is a small active community. Under certain conditions, Lenya can be recommended for use.
This article covers only the basics and part of the capabilities of Apache Lenya. If someone has an interest in this topic, I can continue the description of this unusual CMS.

Resource list
  1. Apache Lenya official website http://lenya.apache.org/
  2. Apache Cocoon official website http://cocoon.apache.org/
  3. Apache Lenya zip archive http://mail-archives.apache.org/mod_mbox/lenya-user/
  4. GnuWin32 http://gnuwin32.sourceforge.net/packages/patch.htm
  5. List of CMS in Java on Wikipedia

Source: https://habr.com/ru/post/101294/

All Articles