Search:

Apache » Lenya
project logo
  • Project
  • Developer
  • Community
  • Version 2.2
  • Version 2.0
  • Version 1.2
  • Version 2.0
    • FAQs
    • Installation
      • Download
      • Subversion Access
      • Install Instructions
    • Tutorials
      • Create a Publication
      • Create a Resource Type
        • Declaration
        • Creation
        • Presentation
        • Editing (One-Form)
        • Editing (BXE)
      • Implement a Usecase
        • Prerequisites
        • The Usecase
      • Setting up Eclipse
      • Proxying
        • Proxying
        • mod_proxy
        • mod_proxy_ajp
      • Best Practises
      • Production Checklist
      • Writing Tests
    • Concepts
      • Publication
      • Working with Documents
      • Authoring and Live mode
      • WYSIWYG
    • Technical Reference
      • Overview of Lenya Sitemaps
      • Repository
      • Access Control Specification
      • Usecase Framework
        • Overview
        • AbstractUsecase
      • Publications
        • Configuration
        • Publication Templating
      • Resource Types
      • Modules
      • Meta data
      • Protocols
        • lenya Protocol
        • lenya-document Protocol
        • site Protocol
        • lenyadoc Protocol
        • fallback Protocol
      • URLs and Links
        • URL Mapping
        • Link Management
    • Core API
    • Core Modules
      • ac
        • Overview
        • API
      • acusecases
        • Overview
        • API
      • administration
        • Overview
        • API
      • cache
        • Overview
        • API
      • janitor
        • Overview
        • API
      • ldap
        • Overview
        • API
      • linking
        • Overview
        • API
      • observation
        • Overview
        • API
      • properties
        • Overview
        • API
      • sitemanagement
        • Overview
        • API
      • templating
        • Overview
        • API
      • usecase
        • Overview
        • API
      • workflow
        • Overview
        • API
    • Standard Modules
      • blog
        • Overview
        • API
      • bxe
        • Overview
      • cforms
        • Overview
        • API
      • collection
        • Overview
        • API
      • contactform
        • Overview
        • API
      • development
        • Overview
        • API
      • editors
        • Overview
        • API
      • export
        • Overview
        • API
      • fckeditor
        • Overview
        • API
      • kupu
        • Overview
        • API
      • languageselector
        • Overview
      • lenyadoc
        • Overview
        • API
      • linkcheck
        • Overview
        • API
      • links
        • Overview
        • API
      • lucene
        • Overview
        • API
      • migration
        • Overview
        • API
      • navigation
      • neutron
        • Overview
      • news
        • Overview
        • API
      • notification
        • Overview
        • API
      • opendocument
        • Overview
        • API
      • prettyprinting
        • Overview
      • profiling
        • Overview
      • resource
        • Overview
        • API
      • simplesite
        • Overview
        • API
      • sitetree
        • Overview
        • API
      • sourcerepository
        • Overview
        • API
      • svg
        • Rounded Corners
        • Resizing Images
        • API
      • tinymce
        • Overview
        • API
      • usecasedocument
        • Overview
        • API
      • webdav
        • Getting started
        • Monitoring
        • WebDAV Servers
        • API
      • xhtml
        • Overview
        • API
      • xopus
        • Overview

Current Event

Meeting Bad Säckingen 2009

Built with Apache Lenya

Working with Documents

Table of Contents
  • The Session
  • The Document Factory
  • Browsing Content and Site Structure

This document shows some simple scenarios to access the Lenya repository. For more information, refer to the repository documentation.

The Session

An o.a.l.cms.repository.Session is a temporary container for repository nodes which you want to work with. If you want to change or remove nodes - for instance in a usecase handler - you have to start a transaction. To avoid overriding or losing someone else's changes, you should lock any nodes which are potentially affected or read during your transaction.

A convenient way to get the session which is attached to the current request is provided by the RepositoryUtil:

Session session = RepositoryUtil.getSession(this.manager, request);

The Document Factory

The o.a.l.cms.publication.DocumentFactory is the main entry point to the content repository. It is tied to a session. You get the document factory which is attached to the current session this way:

DocumentFactory factory = DocumentUtil.getDocumentFactory(this.manager, request);

Browsing Content and Site Structure

From the document factory, you can access a publication:

String webappUrl = ServletHelper.getWebappUrl(request);
URLInformation info = new URLInformation(webappUrl);
Publication pub = factory.getPublication(info.getPublicationId());

The publication provides access to all areas (pun intended). An area object enables you to obtain documents by their UUID.

Area authoring = pub.getArea("authoring");
Document[] docs = authoring.getDocuments();
Document doc = authoring.getDocument(uuid, language);

If you want to obtain a document by its path in the site structure, get the site structure from the area:

SiteStructure site = authoring.getSite();
SiteNode node = site.getNode("/tutorial");
String[] languages = node.getLanguages();
Link link = node.getLink(language);
Document doc = link.getDocument();

You can also browse the document structure in a bottom-up way:

Document doc = ...;
doc.area().getPublication();
String area = doc.getLink().getNode().getStructure().getArea();

The Document class allows to access different language and area versions of the document:

if (doc.existsTranslation("en")) {
    englishVersion = doc.getTranslation("en");
}
if (doc.existsVersion("live", doc.getLanguage()) {
    addInfoMessage("Live version exists!");
    liveVersion = doc.getVersion("live", doc.getLanguage());
}

Copyright © 1999-2009 The Apache Software Foundation. All rights reserved.