A bunch of questions about Jease.

74 views
Skip to first unread message

Dymytry

unread,
Jan 30, 2011, 7:51:44 AM1/30/11
to Jease - Java with Ease
Hello everyone!

Gentlemen, at the moment I browse web for choosing a simple Java-based
CMS. What I want is to create a simple e-commerce site basing on CMS.
Please provide me with some explanations about Jease architecture.

First thing I need to do while building a site is to set a default
page and place links to my content on it. How can I do this with
Jease? I.e.:

1) How can I reach the content I have created from the web? For
example, I have created a Text-content-typed item named 'Item' with a
table inside. How can I view it not from admin's console, but from
outer space?

2) Where are the settings for the default page? How can I modify it?
If I want to create my own start page, what should I do?

3) What is a content instance physically? Can a content instance be a
physical HTML file to be referenced directly?

Errors:

4) Periodically I receive some erros with Serialization. When stopping
server I see:

WARNING: Cannot serialize session attribute JEASE_ROOTS for session
AE2A32DC206B4FCE43CBB88F81EC2198
java.io.NotSerializableException: jease.cms.domain.Folder
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at
org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:
1517)
at
org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:
959)
at
org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:
517)
at
org.apache.catalina.session.StandardManager.unload(StandardManager.java:
463)
at
org.apache.catalina.session.StandardManager.stop(StandardManager.java:
667)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4573)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1098)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1098)
at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:
448)
at org.apache.catalina.core.StandardService.stop(StandardService.java:
584)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:
744)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:633)
at org.apache.catalina.startup.Catalina.start(Catalina.java:608)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

When starting server I get:

used by: java.io.NotSerializableException: jease.cms.domain.Folder
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at
org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:
1517)
at
org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:
959)
at
org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:
517)
at
org.apache.catalina.session.StandardManager.unload(StandardManager.java:
463)
at
org.apache.catalina.session.StandardManager.stop(StandardManager.java:
667)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4573)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1098)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1098)
at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:
448)
at org.apache.catalina.core.StandardService.stop(StandardService.java:
584)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:
744)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:633)
at org.apache.catalina.startup.Catalina.start(Catalina.java:608)
... 6 more

The only thing I have changed is the creation of new Content type from
tutorial. I use included build.xml to build a project: right click on
build.xml->run as->run Ant.
This error do not halts the application, but probably I can fix it
some how.

?

Dymytry

unread,
Jan 30, 2011, 4:27:01 PM1/30/11
to Jease - Java with Ease
OK,
first question is solved. Others remain. New arrive!

5) What is the meaning of Visibility checkbox? I see the unchecked
items anyway..

6) What do I see when I open a folder content-type? Sometimes it looks
like I see the first item in the folder, ia it correct? What I need is
to show some small presentations of my content instances when I click
on the folder. Is it possible? Can a content type have two
presentations (e.g. two views)? Can I show all the contents of a
folder in one page (and add a pagination if possible)?

7) Is it possible to deploy Jease NOT on root context path? Yes, I
have read a article about deploying several instances of Jease on
single server, but a problem is that I have a hosting which is remote,
and I cannot change folders higher than webapps.

8) What is a Node from this scratch of code: (Content)
request.getAttribute("Node")?

Maik Jablonski

unread,
Jan 30, 2011, 4:53:05 PM1/30/11
to je...@googlegroups.com
Hi Dymytry,

welcome to Jease...:-)

I'm going to use http://demo.jease.org/ to explain your questions...

> 1) How can I reach the content I have created from the web? For
> example, I have created a Text-content-typed item named 'Item' with a
> table inside. How can I view it not from admin's console, but from
> outer space?

You can create and edit content via the admin-interface (use
http://demo.jease.org/cms). Now if you want to view content directly
in the browser (e.g. the content stored in
/coffeeklatsch/export_files), you simply call
http://demo.jease.org/coffeeklatsch/export_files and so on.

> 2) Where are the settings for the default page? How can I modify it?
> If I want to create my own start page, what should I do?

The design of the default page is stored in
/ROOT/site/web/default/Page.jsp. You can modify it or use it as
example for your own layout which you can store in a folder of its
own. There are other designs as well (see footer on jease.org and
according folders in /ROOT/site/web).

> 3) What is a content instance physically? Can a content instance be a
> physical HTML file to be referenced directly?

The content is stored within an object-database in a folder called
"db4o/jease" which is stored in the home-directory of the user running
Jease. You can configure another location via ROOT/WEB-INF/web.xml.

> Errors:
>
> 4) Periodically I receive some erros with Serialization. When stopping
> server I see:
>
> WARNING: Cannot serialize session attribute JEASE_ROOTS for session
> AE2A32DC206B4FCE43CBB88F81EC2198

You can simply ignore this warnings or re-configure Tomcat not to
serialize sessions. Just edit tomcat/conf/context.xml and uncomment
the following line:

<Manager pathname="" />

Cheers, Maik

Maik Jablonski

unread,
Jan 30, 2011, 5:02:58 PM1/30/11
to je...@googlegroups.com
Hi,

> 5) What is the meaning of Visibility checkbox? I see the unchecked
> items anyway..

as a rule of thumb: "visibility" decides if content is displayed in
navigations or not. Just visit http://demo.jease.org/cms and login and
uncheck visible for "download". If you now visit
http://demo.jease.org/ you'll see, that all automatic generated links
(tab / navigation) for "download" are not shown.

> 6) What do I see when I open a folder content-type? Sometimes it looks
> like I see the first item in the folder, ia it correct?

Yes, that's the default. The first item stored in a folder (regardless
if visible or not) is the default view of the folder.

> What I need is
> to show some small presentations of my content instances when I click
> on the folder. Is it possible? Can a content type have two
> presentations (e.g. two views)?

Sorry, I don't understand your requirement. Can you give me an example?

> Can I show all the contents of a
> folder in one page (and add a pagination if possible)?

You can use a Composite for this purpose. Up to Jease 1.6 a Composite
doesn't allow to store "folderish" contents within it, with upcoming
Jease 1.7 this limitation will be dropped. Pagination for a Composite
is not implemented (never thought about it), but it maybe a good idea.

> 7) Is it possible to deploy Jease NOT on root context path? Yes, I
> have read a article about deploying several instances of Jease on
> single server, but a problem is that I have a hosting which is remote,
> and I cannot change folders higher than webapps.

Yes, no problem. The only thing you have to keep in mind is to set the
id of the Root-Node to the context path of your site. So simply log in
into the CMS and click on "/" above the left navigation. This opens
the editor for the root node. Now you should enter the context-path as
id, so all automatic generated links will be correct.

> 8) What is a Node  from this scratch of code: (Content)
> request.getAttribute("Node")?

This is simply the current content object. If you call
http://demo.jease.org/coffeeklatsch/export_files,
request.getAttribute("Node") will return the content object (in this
case a Wiki-Object) which is stored in /coffeeklatsch/export_files.

Cheers, Maik

Dymytry

unread,
Feb 1, 2011, 4:23:48 AM2/1/11
to Jease - Java with Ease
Maik,
thank you for the replies!

Please clarify:

1) "The only thing you have to keep in mind is to set the id of the
Root-Node to the context path of your site." - what is a Root-Node?
How can I set it?

Which "Welcome" Node is opened when I enter root URL (by root URL I
mean "localhost:8080/" if jease is deployed with "/" context path on
server running on port 8080)? How can I set that "Welcome" Node?
Is "Welcome" Node is a "Root-Node"?

2) For example, I am creating a site of some company. I need to make a
catalog of its products. Products relate to different categories. All
items of one category are stored in special folder. If there are
subcategies - we use subfolders. Finally, if user clicks the category
(i.e. clicks on folder named "Category #4") - he sees all the items
inside among with subfolders.

This is a classic scheme of catalog. Just like standart files catalog.
How can I do it with jease? Composite do not allows subfolders. So,
this question can be translated to: can I adjust Folder in a way it
enables to show not the first item, but show subfolders and items in
some way I can adjust.

* * *

I can try one work-around for second question. I can create a script-
content-typed JSP which runs somehow on all Nodes that relate to some
category and constructs JSP body of their names and links to them.
Each folder will have only one item inside: that script-typed JSP item
which takes folder name as a parameter and calculates its contents.
But here a question arises: how can I search for a Node with some
parameters? No SQL here...

Maik Jablonski

unread,
Feb 1, 2011, 5:11:48 AM2/1/11
to je...@googlegroups.com
Hi,

> 1) "The only thing you have to keep in mind is to set the id of the
> Root-Node to the context path of your site." - what is a Root-Node?
> How can I set it?

the root node is the top-level node in your CMS. Its content-type is
"Folder". If you want to edit it, you need to enter the CMS and click
on the "/" above the left navigation. Then an editor opens with fields
for id and title. Id needs to be edited according to your
context-path. E.g. if you deploy your Jease as
http://yourhost.com/mysite, you'll need to set id=mysite.

> Which "Welcome" Node is opened when I enter root URL (by root URL I
> mean "localhost:8080/" if jease is deployed with "/" context path on
> server running on port 8080)? How can I set that "Welcome" Node?
> Is "Welcome" Node is a "Root-Node"?

If you enter localhost:8080, Jease resolves the Root-Node which is a
folder. A Folder doesn't have a view on its own, but "forwards" the
request to the first item stored within this folder.

> 2) For example, I am creating a site of some company. I need to make a
> catalog of its products. Products relate to different categories. All
> items of one category are stored in special folder. If there are
> subcategies - we use subfolders. Finally, if user clicks the category
> (i.e. clicks on folder named "Category #4") - he sees all the items
> inside among with subfolders.
>
> This is a classic scheme of catalog. Just like standart files catalog.
> How can I do it with jease?
> Composite do not allows subfolders.

This restriction will be dropped with the next release in a few days.
If you're still in the evaluation (and not production) phase of your
project, you can try the nightly build:

http://jease.org/download/ROOT.war

All you have to do is to adapt the rendering of the Composite
(/site/domain/Composite.jsp) to your need.

>So,
> this question can be translated to: can I adjust Folder in a way it
> enables to show not the first item, but show subfolders and items in
> some way I can adjust.

I would recommend to use the Composite as it is meant for this purpose.

> I can try one work-around for second question. I can create a script-
> content-typed JSP which runs somehow on all Nodes that relate to some
> category and constructs JSP body of their names and links to them.
> Each folder will have only one item inside: that script-typed JSP item
> which takes folder name as a parameter and calculates its contents.
> But here a question arises: how can I search for a Node with some
> parameters? No SQL here...

Queries against the content are done via the Java-API. Here's an
simple example. Just create a Script with id=test.jsp within the CMS
and put in the following code which is an example and needs to be
adapted to your requirements.

HTH, Maik

<%@page import="jease.cmf.service.*,jease.cms.domain.*"%>
<%
// Get handle for Root-Node
Content root = (Content) Nodes.getRoot();

// Now traverse from Root to "download"-Folder
Folder download = (Folder) root.getChild("/download");

// Now get all children (and children of children) which are File
from below download
for(File file : download.getDescendants(File.class)) { %>

// Output files which are visible and ending with .zip
<% if(file.isVisible() && file.getId().endsWith(".zip")) { %>
<li><%= file.getTitle() %></li>
<% } %>
<% } %>

Maik Jablonski

unread,
Feb 1, 2011, 5:15:18 AM2/1/11
to je...@googlegroups.com
Hi,

just forgot:

On Tue, Feb 1, 2011 at 11:11, Maik Jablonski <maik.ja...@gmail.com> wrote:
> This restriction will be dropped with the next release in a few days.
> If you're still in the evaluation (and not production) phase of your
> project, you can try the nightly build:
>
> http://jease.org/download/ROOT.war

If you're going to use the nightly build, you have to call
http://localhost:8008/cms/setup once if you want to work with an
existing database. This performs a minor update operation (creating
default configuration parameters which are stored within the database
from 1.7 on).

Cheers, Maik

Dymytry

unread,
Feb 2, 2011, 8:00:17 AM2/2/11
to Jease - Java with Ease
Maik,

1) what can I do if one content instance is related to two or more
folders or composites?
For example, I need to handle a BMW Car item. It relates to Germany
folder and to Cars folder (or Composite). How can I show it in two
folders?

2) What is the jfix library? It contains classes for Zkoss and db4o,
do they have something in common?

What if I want to add some functionality to editors: for example I
need an input for Integer or Double values? I see the Integer input
box when I add an Integer property but I cannot find it in the list of
zkoss components available in jfix library.

Maik Jablonski

unread,
Feb 2, 2011, 8:38:16 AM2/2/11
to je...@googlegroups.com
Hi Dimitry,

> 1) what can I do if one content instance is related to two or more
> folders or composites?
> For example, I need to handle a BMW Car item. It relates to Germany
> folder and to Cars folder (or Composite). How can I show it in two
> folders?

you can use a Reference-Object. This way you can store the cars
belonging to a manufacturer in one folder and use references for
displaying cars according to countries:

- Manufacturer
- BMW
- Z3
- VW
- Polo

- Countries
- Germany
- Reference -> Z3
- Reference -> Polo
- England
- Reference -> Z3

> 2) What is the jfix library? It contains classes for Zkoss and db4o,
> do they have something in common?

The JFix-Library is the power-horse "below" Jease. It is a library
which contains basic common stuff I've developed over the years.
Classes in jfix.zk and jfix.db4o have nothing in common (besides
living in the same library).

> What if I want to add some functionality to editors: for example I
> need an input for Integer or Double values? I see the Integer input
> box when I add an Integer property but I cannot find it in the list of
> zkoss components available in jfix library.

You can use vanilla ZK-components (see demo for availabe components:
http://www.zkoss.org/zkdemo/layout). I've wrapped most of them in
jfix.zk to add some more convenience methods and so on. The component
for the integer box is called Spinner and is used in
jease.cms.web.content.editor.property.IntegerPropertyEditor.

You can define your own properties at source level and register them
via the registry. This way you can build more advanced properties.

In regard to double values/properties/editor: good idea, I'll create a
feature request for it and maybe I can ship it with the upcoming
release.

If you're going to build more complex stuff (and need more control
(e.g. validation)), you should implement your content object and an
corresponding editor at soruce level. Have a look at the tutorial
which shows how to create a simple custom object called "Meeting":

http://www.jease.org/documentation/meeting

Cheers, Maik

Dymytry

unread,
Feb 2, 2011, 9:03:18 AM2/2/11
to Jease - Java with Ease
Maik, thanks for quick reply!

Sorry for a big number of questions :)

Could you explain me how I can handle a Listbox object in ContentItem-
Editor java file? What I want is to create my own content type with a
Listbox inside. To create listbox I need to set a selection list. I
can do it programatically inside MyItemEditor class, but I suppose its
better to create a Lines Property and take the selections from it. But
If I had created a Lines item in my new content-type template which is
placed in my Factory, how would I reach my selection list from
MyItemEditor.java file?

public class MyItemEditor extends ContentEditor<MyItem> {

Listbox category = new Listbox();

public void init() {
add("Category", category);
}

public void load() {

// what should i write here to get the selection list
from template located in Factory?

// Property categoryNames = getNode().getProperty("CategoryNames"); //
but this property is set in the template item in Factory. Is it
available in any item? // How can I translate it to
selection list?

// category.setSelection( ??? , getNode().getCategory() );

Maik Jablonski

unread,
Feb 2, 2011, 9:28:26 AM2/2/11
to je...@googlegroups.com
Hi agian,

> Sorry for a big number of questions :)

no problem...:-)

> Could you explain me how I can handle a Listbox object in ContentItem-
> Editor java file? What I want is to create my own content type with a
> Listbox inside.

...

I guess you want to store several categories within a single MyItem,
right? So I'm going to call it categories instead of category below.

Best is to have a look how it is done in
jease.cms.web.content.editor.property.ChoiceProperty... at least this
is the way I do it...;-)

Here's some code which should give you the idea (untested, although it
should work).

public void load() {
LinesProperty property = (LinesProperty)
Properties.getByPath("/path/to/factory/ID_of_your_LinesProperty");
String[] choices = property.getValue();
categories.setSelection(choices, getNode().getCategories());
}

public void save() {
...
getNode().setCategories(Arrays.cast(categories.getSelected(), String.class);
...
}

HTH, Maik

Dymytry

unread,
Feb 2, 2011, 10:53:52 AM2/2/11
to Jease - Java with Ease
Maik,

it looks like me, as the site developer, have to hardcode the id of a
property, that was entered by the site manager. Probably it was a bad
idea and its better to create new Lisboxes via factory.

But anyway, how can I know the ID of a property? I see only the ID of
the item.

Maik Jablonski

unread,
Feb 2, 2011, 11:06:20 AM2/2/11
to je...@googlegroups.com
Hi,

> it looks like me, as the site developer, have to hardcode the id of a
> property, that was entered by the site manager. Probably it was a bad
> idea and its better to create new Lisboxes via factory.

yes, that might be a problem with this approach... Jease 1.7 will
support "persistent parameters" stored in the database (best compared
to items in Java property files), this might be another solution for
such editable reference lists. You'll still need to hardcode the
parameter-id in your sources, but this is far more maintainable. Jease
makes use of this parameters on its own.

> But anyway, how can I know the ID of a property? I see only the ID of
> the item.

the ID is just the name of the property. Sorry, did use the wrong
notion in my last mail.

Cheers, Maik

Dymytry

unread,
Feb 2, 2011, 3:18:02 PM2/2/11
to Jease - Java with Ease
Maik,
what about dynamic types is Jease?

A best option is to make creation of new types of content possible
without coding. I can use the Item content-type combined with factory,
but it can be used only once! If I need one more new type created by
cms admin - what can I do while item is "busy"?

Also, as far as I understand, second Factory instance is completely of
no use - all items created inside cannot have properties different
from the items of that type in the first Factory.

Dymytry

unread,
Feb 2, 2011, 3:22:14 PM2/2/11
to Jease - Java with Ease
Probably a good idea is to make it possible to specify a Factory with
a template while creating a new content instance.

Maik Jablonski

unread,
Feb 2, 2011, 3:32:30 PM2/2/11
to je...@googlegroups.com
Hi,

you can use the following structure to create different "items" in
different sub-folders:

- CarsFolder
- CarsFactory
- CarItem
- BikesFolder
- BikesFactory
- BikesItem

If you need more than one Item globally, you'll have to provide new
derived "dummy" Items at source level. You can simply extend Item
(e.g. as class Car extends Item) and register it via the registry.
This allows you also to define custom (and separate) templates for
your derived Items.

I'm already spent some thoughts about creating dynamic content types
at runtime, but this isn't as (j)easy as it seems to be. The property
stuff is quite new and the combination of Factory/Item is a first
draft which is meant to allow the simple "enrichment" of existing
content-types.

Cheers, Maik

Dymytry

unread,
Feb 8, 2011, 10:12:04 AM2/8/11
to Jease - Java with Ease
Maik,
could you advice, what is the best way to store images in Jease?

I know about image content type, but what I need is to create my own
content type with an image connected with it. That image should be
showed to user in two ways: fullsized and thumbnail sized.

First way is to store images separately in some folder and link them
to the content type to be shown to user. But this is not quite
convenient because its always easier to manage one content entry
instead of several connected entries.

Another way is to attach image to content as a file property. But how
can I show an image located in File-typed property? If I write
content.getProperty("propertyName") I will get only image name.

Any other suggestions?

Maik Jablonski

unread,
Feb 8, 2011, 6:20:10 PM2/8/11
to je...@googlegroups.com
Hi Dymytry,

> could you advice, what is the best way to store images in Jease?

this depends on your use-case...:-)

> Another way is to attach image to content as a file property. But how
> can I show an image located in File-typed property? If I write
> content.getProperty("propertyName") I will get only image name.

I'm attaching an example for an advanced Item-Renderer below. Just
replace it against the default /site/domain/Item.jsp (you can use a
Transit-object to edit files in the file-system directly through the
CMS, so no need to fire up your IDE), then create an Item and attach a
File-Property to it. Then upload an image. Then see how it works.

The renderer below creates an thumbnail image and displays the image
in fullsize when clicked on it. The trick is that the Item-renderer
runs in two modes:

1) The first call (in "page"-rendering mode") returns the HTML for
creating the link with the reference to the image.
2) The browser now loads the image which also calls the Item-Renderer,
but this time with the parameter "file" which has a special meaning
and turns Jease into "file-mode", meaning: all content is streamed
directly to the browser.

Something you should implement on your own is some kind of caching for
the thumbnails.

HTH, Maik

/site/domain/Item.jsp:

<%@page import="java.awt.*,org.apache.commons.io.FileUtils,jfix.util.*,jfix.servlet.*,jease.cms.domain.*,jease.cms.domain.property.*"%>
<%
Item item = (Item) request.getAttribute("Node");

if (request.getParameter("file") != null) {
FileProperty file = (FileProperty)
item.getProperty(request.getParameter("file"));
if(request.getParameter("thumb") != null) {
int size = Integer.parseInt(request.getParameter("thumb"));
Dimension sourceDimension = Images.getSize(file.getFile());
Dimension targetDimension = Images.scaleDimension(sourceDimension,
new Dimension(size, size));
java.io.File thumbImage = Images.scale(file.getFile(),targetDimension);
Servlets.write(thumbImage, file.getContentType(), response);
} else {
Servlets.write(file.getFile(), file.getContentType(), response);
}
return;
}
%>
<div class="Item">
<h1><%=item.getTitle()%></h1>
<dl>
<% for (Property property : item.getProperties()) { %>
<dt><%=property.getName() %></dt>
<dd>
<% if (property instanceof FileProperty) { %>
<% if(((FileProperty) property).getContentType().startsWith("image")) { %>
<a class="Image" href="?file=<%= property.getName() %>"><img
src="?file=<%= property.getName() %>&thumb=100" /></a>
<% } else { %>
<a href="?file=<%= property.getName()%>"><%=property.toString()%></a>
<% } %>
<% } else { %>
<%=property.toString()%>
<% } %>
</dd>
<% } %>
</dl>
</div>

Maik Jablonski

unread,
Feb 9, 2011, 3:54:05 AM2/9/11
to je...@googlegroups.com
Hi again,

I've just created a utility-method in jfix.util.Images which does the
thumbnailing & caching of scaled images. This method will be available
for Jease with the next release.

In the meanwhile you can simply update your jfix.jar with the latest
one from SVN which includes the update:

http://jease.googlecode.com/svn/Jease/WEB-INF/lib/jfix.jar

Just put it into ROOT/WEB-INF/lib and you're done.

Now you can use the following simplified code e.g. for Item.jsp.

Cheers, Maik

<%@page import="java.awt.*,org.apache.commons.io.FileUtils,jfix.util.*,jfix.servlet.*,jease.cms.domain.*,jease.cms.domain.property.*"%>
<%
Item item = (Item) request.getAttribute("Node");

if (request.getParameter("file") != null) {
FileProperty file = (FileProperty)
item.getProperty(request.getParameter("file"));

if(request.getParameter("size") != null) {
int size = Integer.parseInt(request.getParameter("size"));
Servlets.write(Images.scale(file.getFile(), size),


file.getContentType(), response);
} else {
Servlets.write(file.getFile(), file.getContentType(), response);
}
return;
}
%>
<div class="Item">
<h1><%=item.getTitle()%></h1>
<dl>
<% for (Property property : item.getProperties()) { %>
<dt><%=property.getName() %></dt>
<dd>
<% if (property instanceof FileProperty) { %>
<% if(((FileProperty) property).getContentType().startsWith("image")) { %>
<a class="Image" href="?file=<%= property.getName() %>"><img

src="?file=<%= property.getName() %>&size=250" /></a>

Dymytry

unread,
Feb 11, 2011, 8:35:15 AM2/11/11
to Jease - Java with Ease
Maik,
is it possible to know whether this content was opened by Reference,
and find that Reference content?

Maik Jablonski

unread,
Feb 11, 2011, 8:45:33 AM2/11/11
to je...@googlegroups.com
Hi,

> is it possible to know whether this content was opened by Reference,
> and find that Reference content?

the Controller.jsp saves the "original" node in an attribute called
"Context". So you can use something like

<% if (request.getAttribute("Context") instanceof Reference) { %>
This content was brought to you by a Reference...
<% } %>

To clarify things:

request.getAttribute("Node") returns the Node which is currently
rendered by the JSP and this is in most cases equal to
request.getAttribute("Context"). But in some cases (Folders,
References, Composites) the "Node"-Attribute is exchanged on the fly,
while the "Context" points to the original request Node.

HTH, Maik

Dymytry

unread,
Feb 11, 2011, 9:51:23 AM2/11/11
to Jease - Java with Ease
Maik, thanks!

1) Is there any methods for filtering Node collections and arrays by
properties?

2) As far as I understand, equals/hashcode are not implemented for
Property class?

Maik Jablonski

unread,
Feb 11, 2011, 11:21:59 AM2/11/11
to je...@googlegroups.com
Hi,

> 1) Is there any methods for filtering Node collections and arrays by
> properties?

here's an simple example (use it as Script) which filters all Nodes in
the Root folder with a property called "Test" which evaluates to true
(= BooleanProperty). It uses jfix.functor.* which provides means for
filtering/transforming arrays in a functional programming style.

<%@page import="jfix.functor.*,jease.cms.domain.*,jease.cmf.service.*" %>
<%
// Get some nodes into an array...
Content[] input = Nodes.getRoot().getChildren(Content.class);

// Filter contents with a predicate
Content[] output = Functors.filter(input, new Predicate<Content>() {
public boolean test(Content content) {
return "true".equals(String.valueOf(content.getProperty("Test")));
}
});

// Print the result
for(Content content : output) {
out.print(content.getId());
out.print("<br />");
}
%>

> 2) As far as I understand, equals/hashcode are not implemented for
> Property class?

No, do you have any good idea how it should be implemented? If so,
please let me know...:-)

Cheers, Maik

Dymytry

unread,
Feb 12, 2011, 11:05:45 AM2/12/11
to Jease - Java with Ease
Maik,
what should I do if I want to include some additional Node in the
page, which renders another Node? I.e. I want to show some ads or
menus or news in complete form (using corresponding jsp file), not
just title.

I have used the following scratch but it looks a bit ugly. May be you
can suggest something beautiful? :)

Node old_node = (Node)request.getAttribute("Node");
Node menuScript = Nodes.getByPath("menu/menuScript");
request.setAttribute("Node", menuScript);
pageContext.include(Registry.getView(menuScript));
request.setAttribute("Node", old_node);
* * *

As for properties, I suppose it can be useful to implement equals and
hashcode to be able to compare them. Properties can be compared by
name and value. For Date property equals should compare inner date
field and name of property, for example. This can simplify the writing
of test methods for filtering the arrays of Nodes by Properties if the
filter criteria is also a Property.

How I encountered this: I was thinking how to place one item in
several categories (folders). Solution with Reference works, but its a
bit hard to maintain: if I have a number of items I'll have to create
several duplicate entries for each of them. Now I am trying another
solution: I create a Composite with some Property and place a Script
and a ReferenceToFolder inside. Script finds folder by
ReferenceToFolder and runs through all elements from there filtering
them by Property from Composite. Thats how I can show one item in
multiple categories.
This method is a bit complicated in deploying, but saves me from
creating numerous References.

But I was not testing the performance of Jease yet..

Maik Jablonski

unread,
Feb 13, 2011, 5:27:14 AM2/13/11
to je...@googlegroups.com
Hi,

> what should I do if I want to include some additional Node in the
> page, which renders another Node?

...


> I have used the following scratch but it looks a bit ugly. May be you
> can suggest something beautiful? :)

that's the same pattern I'm using to include nodes within nodes... so
it looks fine to me... but I'm thinking about introducing a helper
method which reduces this slightly ugly code to a single line.

> As for properties, I suppose it can be useful to implement equals and
> hashcode to be able to compare them. Properties can be compared by
> name and value. For Date property  equals should compare inner date
> field and name of property, for example. This can simplify the writing
> of test methods for filtering the arrays of Nodes by Properties if the
> filter criteria is also a Property.

Sounds very good, maybe you can provide the implementations for the
existing Properties? Just post a patch against current SVN.

> How I encountered this: I was thinking how to place one item in
> several categories (folders). Solution with Reference works, but its a
> bit hard to maintain: if I have a number of items I'll have to create
> several duplicate entries for each of them. Now I am trying another
> solution: I create a Composite with some Property and place a Script
> and a ReferenceToFolder inside. Script finds folder by
> ReferenceToFolder and runs through all elements from there filtering
> them by Property from Composite. Thats how I can show one item in
> multiple categories.
> This method is a bit complicated in deploying, but saves me from
> creating numerous References.

Can you describe your use-case? I know that you're trying to create
something like a catalog... but I'm not quite sure what is the exact
problem you're running into. If you're trying to create something like
a category based listing of contents, I'm eager to help because this
would make a nice coffee-klatsch, too...:-)

> But I was not testing the performance of Jease yet..

Just keep in mind: Jease keeps the "fabric" of a web-site (so all
metadata and so on) in memory which makes direct access very fast
(orders of magnitudes faster than talking to a disk). This should be
fast enough for nearly all most use-cases. But there's even an very
elegant and effective data-caching implemented which done with so
called Suppliers. Have a look at jease.site.Fulltexts to see how it is
used.

Cheers, Maik

Dymytry

unread,
Feb 14, 2011, 9:28:54 AM2/14/11
to Jease - The Java CMS with Ease
> Can you describe your use-case? I know that you're trying to create
> something like a catalog... but I'm not quite sure what is the exact
> problem you're running into. If you're trying to create something like
> a category based listing of contents, I'm eager to help because this
> would make a nice coffee-klatsch, too...:-)

Yes, actually I am creating a simple e-commerse site. Each site of
that kind has a catalog, of course. In my case I want to make a
catalog where one item can be found in several categories. For
example, I sell cars:

Cars
--cars by country
----German cars
------>BMW
----French cars

--cars by price
----cheap cars
----expensive cars
------>BMW

etc

I dont want to create several Reference objects for each Car Content
because if I have hundreds of items in my e-shop this will become a
problem to maintain all this stuff. Thats why I created a solution
described above. Actually I have no problems with it now, but may be
the same task can be implemented more (J)easy :)

Dymytry

unread,
Feb 18, 2011, 5:08:23 AM2/18/11
to Jease - The Java CMS with Ease
Maik,
could you give some advice about my next task, please.

I need to show a Node in two views: first one available to anyone, and
second one can be available only to registered users. I cannot use the
Access modifier because I need to specify a login-password there. What
I want is to create a standart registration procedure and if the user
is logged in - he will see the "full" version of some Node, otherwise
only "short version". What is the ebst way to implement this?

The real task underlying this is to create a Shopping Cart
representation for my e-commerce site, which should make possible to
make an order only if user is registered.

Maik Jablonski

unread,
Feb 18, 2011, 5:17:21 AM2/18/11
to je...@googlegroups.com
Hi Dymytry,

> I need to show a Node in two views: first one available to anyone, and
> second one can be available only to registered users. I cannot use the
> Access modifier because I need to specify a login-password there. What
> I want is to create a standart registration procedure and if the user
> is logged in - he will see the "full" version of some Node, otherwise
> only "short version". What is the ebst way to implement this?

I would recommend the following approach:

- After the user has logged in via your login-form, store the login as
session attribute, e.g. <% session.setAttribute("USER_LOGIN", login);
%>
- When rendering your "Product"-Node-Template test if the "USER_LOGIN"
is present as session-attribute:

...
<% if(session.getAttribute("USER_LOGIN") != null) { %>
... only rendered when a user is logged in...
<% } %>

Does it help?

Maik

Dymytry

unread,
Feb 18, 2011, 9:16:18 AM2/18/11
to Jease - The Java CMS with Ease
Maik,
so currently the only way to prevent anonymous user from accessing
some protected node is programming, am I right?

Prorbably you can modify the Access content type to deal with logged
in user also, not only with some login-password pair.

Dymytry

unread,
Feb 18, 2011, 9:26:50 AM2/18/11
to Jease - The Java CMS with Ease
But how have you protected the cms area with password and where do cms
code reside?

Maik Jablonski

unread,
Feb 18, 2011, 9:26:52 AM2/18/11
to je...@googlegroups.com, Dymytry
Hi,

> so currently the only way to prevent anonymous user from accessing
> some protected node is programming, am I right?

yes, that's right (besides the protection provided by the Access-Object).

> Prorbably you can modify the Access content type to deal with logged
> in user also, not only with some login-password pair.

Very good idea... if a user can access content within the CMS, he
shouldn't be forced to login by the Access-Object. I'll create a
feature request for this.

Cheers, Maik

Maik Jablonski

unread,
Feb 18, 2011, 9:37:05 AM2/18/11
to je...@googlegroups.com, Dymytry
On Fri, Feb 18, 2011 at 15:26, Dymytry <koktebe...@gmail.com> wrote:
> But how have you protected the cms area with password and where do cms
> code reside?

If you have a look at ROOT/cms/index.zul, you'll see:

<zk>
<div use="jease.cms.web.Login" />
</zk>

This means that when calling your CMS via /cms, ZK creates a div tag
and uses the jease.cms.web.Login as component. If the login is
successful, the Login-Component replaces itself with the CMS-desktop
in the ZK-component hierarchy. This way only logged in users can reach
the CMS. for all other users the CMS doesn't simply "exist".

This is a little different than programming traditional
web-applications where you have lots of pages which can simply be
called via an URL. In ZK world you can use a single page approach,
which is well suited for creating application like interfaces.

Cheers, Maik

Dymytry

unread,
Feb 18, 2011, 4:33:43 PM2/18/11
to Jease - The Java CMS with Ease
Maik,
I have implemented my own authorization form. For authorization I just
store a User object (if found by login-password) in the session. This
is the way it is implemented in your Login.java class.

But I have a small concern, because I was not able to run the
JeaseSession.set() or JeaseSession.get() methods from my code. Both
throw a NullPointerException in getSession() method of
jfix.zk.Sessions class:

public static HttpSession getSession() {
return (HttpSession)
Executions.getCurrent().getSession().getNativeSession(); //NULLPOINTER
IS HERE!
}

I wonder why this happens? In your code in Login.java it works ok.
I run JeaseSession.set() in my Filter or JeaseSession.get() in Script
Content.

Code in a Script Content Type:

User user = JeaseSession.get(User.class); // throws NULLPOINTER
if (user != null) { //authorized user: show something for authorized
user
}.


Another example: code inside my Filter constructed from Login.java:

String jeaseUserAuthenticator =
servletContext.getInitParameter("JEASE_USER_AUTHENTICATOR");
Authenticator auth;
if (jeaseUserAuthenticator != null) {
auth = (Authenticator)
Reflections.newInstance(jeaseUserAuthenticator);
} else {
auth = new Authenticator();
}

User user = auth.identify(login, password);
if (user != null) {
//JeaseSession.set(user); - commented because it THROWS
NULLPOINTER!
session.setAttribute(User.class.toString(), user); // this works
ok.
if (Validations.isNotEmpty(user.getRoots())) {
JeaseSession.setRoots(user.getRoots()); //THROWS NULLPOINTER in
the same place! I cannot set the Roots.
if (queryString != null) {
JeaseSession.setContainer(Nodes.getByPath(queryString));
}
if (JeaseSession.getContainer() == null
|| !JeaseSession.getContainer().isDescendant(
user.getRoots())) {
JeaseSession.setContainer(user.getRoots()[0]);
}
JeaseSession.setConfig(new Configuration());
}
//show(new Navigation(user));
//show something protected
here

Please let me know if you have any ideas.

Maik Jablonski

unread,
Feb 18, 2011, 6:21:21 PM2/18/11
to je...@googlegroups.com
Hi Dymytry,

> But I have a small concern, because I was not able to run the
> JeaseSession.set() or JeaseSession.get() methods from my code. Both
> throw a NullPointerException in getSession() method of
> jfix.zk.Sessions class:

jfix.zk.Sessions is bound to be run in context of a ZK/ZUL page. It
can't work when no ZK context is present. So calling jfix.zk.Sessions
in a Script doesn't work, because a Script (as JSP) is executed
completely outside of ZK. If you use a ZUL page, it should work, but
not in a plain JSP.

The whole idea behind jfix.zk.Sessions is to provide a wrapper for ZK,
which stores all attributes in the native session (and not in the
dedicated ZK session). This way you can reach the all attributes
easily via the native session provided by the servlet container.

Hope this helps,
Maik

Marcus Schopen

unread,
Feb 23, 2011, 12:36:15 PM2/23/11
to je...@googlegroups.com
Hi Maik,
hi Dymytry,

Am Freitag, den 18.02.2011, 06:16 -0800 schrieb Dymytry:
>
> Prorbably you can modify the Access content type to deal with logged
> in user also, not only with some login-password pair.

I asekd myself the same todoy. To my mind the access object should
"know" if a user is a) logged in and b) has (write)access to the folder
protected by an access object. If a) and b) is true the access object
shouldn't ask for user/password to view the content. I think this would
make accessing protected content more comfortable.

Ciao,
Marcus

Maik Jablonski

unread,
Feb 23, 2011, 12:50:31 PM2/23/11
to je...@googlegroups.com
Hi,

> I asekd myself the same todoy. To my mind the access object should
> "know" if a user is a) logged in and b) has (write)access to the folder
> protected by an access object. If a) and b) is true the access object
> shouldn't ask for user/password to view the content. I think this would
> make accessing protected content more comfortable.

ok, that sounds very reasonable. And to be honest: I've run into this
issue lately on my own, so we are at least 3 people complaining about
this behaviour...;-)

I'm going to change the Access object accordingly so upcoming Jease
1.8 will behave more user friendly...:-)

Thanks!
Maik

Dymytry

unread,
Mar 4, 2011, 3:18:07 AM3/4/11
to Jease - The Java CMS with Ease
Maik,
I am experiencing a strange issue.

I cannot delete ANY Content items in the database via cms. When I
press "Delete" button an empty message box with "Error" caption arises
and nothing happens. No exceptions are thrown on server console.

From the other hand, I CAN delete content items programmatically via
Nodes.delete(Node).

I thought this is because I changed something in Jease files and
forgotten about this, but I switched to Jease 1.8 having only site
folder and one Servlet class preserved, and the error remains.

?

Maik Jablonski

unread,
Mar 4, 2011, 3:37:30 AM3/4/11
to je...@googlegroups.com
Hi,

> I cannot delete ANY Content items in the database via cms. When I
> press "Delete" button an empty message box with "Error" caption arises
> and nothing happens. No exceptions are thrown on server console.

strange... can you try the following... change
jease.cms.web.content.editor.ContentEditor#doDelete like this:

protected void doDelete() throws Exception {
try {
if (Contents.isDeletable(getNode())) {
super.doDelete();
} else {
Modal.error(Strings.Content_is_not_deletable);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Do you get any stacktrace? If yes, please post it.

Do you use the Trash object (or maybe even "nested" Trash objects)?
Does it work if you remove the Trash object?

Cheers, Maik

Dymytry

unread,
Mar 5, 2011, 3:41:21 AM3/5/11
to Jease - The Java CMS with Ease
Fixed, thanks!

The reason was the following: I have created some users via my own
registration form with no roots set, and this produced an error in
Content.isDeletable method in user.getRoots() call.

Maik Jablonski

unread,
Mar 5, 2011, 8:08:04 AM3/5/11
to je...@googlegroups.com, Dymytry
Hi,

> The reason was the following: I have created some users via my own
> registration form with no roots set, and this produced an error in
> Content.isDeletable method in user.getRoots() call.

very good diagnosis... never thought about users with roots == null...
but as your case shows: never think never...;-)

I've just fixed two possible NullPointerExceptions in
jease.cms.service.Contents which tackles problems with "non rooted"
users and content deletion.

Thanks for reporting!
Maik

Reply all
Reply to author
Forward
0 new messages