opencms days 2014 - opencms content editor and pdf extensions

20
Georg Westenberger, Alkacon Software Workshop track Content editor and PDF extensions in 9.5 27.11.2014

Upload: alkacon-software-gmbh

Post on 13-Jul-2015

241 views

Category:

Software


2 download

TRANSCRIPT

Georg Westenberger, Alkacon Software

Workshop track

Content editor and PDF

extensions in 9.5

27.11.2014

● PDF extensions

● Generating PDFs from XML contents

● Generating thumbnails for PDFs

● Content editor extensions

● Locale synchronization

● Visibility handlers

● Change handlers

2

Overview

● Generate PDFs from XML contents

● Write a JSP to generate XHTML which is then

converted to PDF using the flying-saucer library

● See code.google.com/p/flying-saucer/ for more

info on the library.

● PDFs are not stored in VFS, but generated on

the fly when a special PDF link is used

3

PDF Generation

● Live Demo

4

PDF Generation

Demo

Demo Demo

Demo

デモ

● Step 1: Write a JSP to generate XHTML from

your XML content

● Step 2: Generate a PDF link with the

<cms:pdf> tag ● <cms:pdf

format='/system/modules/com.alkacon.bootstrap.formatters/pages/blog-pdf.jsp'

content='${content.filename}' locale='en'/>"

5

PDF Generation – how to use

● Generate thumbnails for PDFs in various formats

● <cms:pdfthumbnail format=„png“ file=„/my-

document.pdf“ width=„50“ />

● format: format for the thumbnails, use ‚png‘ or ‚jpg‘

● file: the path of the PDF for which to generate the

thumbnail

● width / height: At least one of these need to be

set, determines dimensions of thumbnail

● PDF thumbnails are cached on the server file

system

6

PDF thumbnails

● Live Demo

7

PDF thumbnails

Demo

Demo Demo

Demo

デモ

● These only work with the XML content editor

introduced in OpenCms 8.5, not with the older

XML content editor or any other way of editing

XML contents

● Example: Type bs-image in the demo

8

Notes on the content editor

enhancements

● Sometimes, no localization is needed for some

values in an XML content

● For example: IDs (product ID,…), images,

configuration data

● Make selected fields locale-independent

● For any change made in the editor, the field

value is updated in all other locales

9

Locale synchronization

● Live Demo

10

Locale synchronization

Demo

Demo Demo

Demo

デモ

● Configure in XSD schema

● Example image.xsd:

<xsd:sequence>

<xsd:element name="Headline" type="OpenCmsString" />

<xsd:element name="Image" type="OpenCmsVfsFile" />

</xsd:sequence>

<synchronizations>

<synchronization element="Image" />

</synchronizations>

11

Locale synchronization

● Hide content fields from the user dynamically

● Visibility is determined by custom Java class

● Example: hide cryptic status / configuration

values from normal users, restrict them to

admins.

12

Field visibility handlers

● Live Demo

13

Field visibility handlers

Demo

Demo Demo

Demo

デモ

● Configure in XSD schema:

<visibilities>

<visibility

element="GalleryTitle" params="ROLE.GALLERY_EDITOR" />

<visibility

element=“OtherField"

class=“my.custom.VisibilityHandler” params=“parameters for my custom class" />

</visibilities>

● element: The field being checked for visibility

● class: The Java class responsible for deciding whether the field isvisible

● params: Configuration string passed to the Java class

14

Field visibility handlers

● Visibility handler class:

class MyVisibilityHandler implementsI_CmsXmlContentVisibilityHandler {

public boolean isValueVisible(

CmsObject cms,

I_CmsXmlSchemaType value,

String elementPath,

String params,

CmsResource resource,

Locale contentLocale) {

return true;

}

}

15

Field visibility handlers

● Basic idea: Automatically update other fields

when a given field is changed

● Example: Updating a content field from a

property of a linked image

16

Dynamic field handlers

<editorchangehandlers>

<editorchangehandler

class="org.opencms.ade.contenteditor.CmsEditorChangeHandlerProperty"

scope="Image" configuration="Copyright|../Copyright" />

</editorchangehandlers>

● class : Custom Java class to process changes

● scope : Path of the field which is watched for changes

● configuration : Configuration string passed to the change handler class

17

Dynamic field handlers

● Extend

A_CmsXmlContentEditorChangeHandler and

implement these methods:

public CmsXmlContent handleChange(

CmsObject cms,

CmsXmlContent content,

Locale locale,

Collection<String> changedPaths)

public void setConfiguration(String configuration)

Note: The return value of handleChange is not used, modify theCmsXmlContent parameter directly instead

18

Dynamic field handlers

● Any Questions?

19

Any Questions?

Fragen?Questions ?

Questiones?

¿Preguntas?質問

Georg Westenberger

Alkacon Software GmbH

http://www.alkacon.com

http://www.opencms.org

Thank you very much for your

attention!20