How to create website (or Berlioz) publish script in PageSeeder
Skills required | XML |
---|---|
Time required (minutes) | 30 |
Intended audience | Developer |
Difficulty | Medium |
Category | Berlioz |
Objective
This tutorial will show how to create a script to publish PageSeeder documents to a website (or Berlioz). It explains how to publish from both the document and folder level.
Pre-requisites
Please make sure you have the following items set up before proceeding:
- PageSeeder (version 5.8 or above) installed, please see Installation guide for setting up PageSeeder;
- Jetty and Berlioz website installed;
- FTP server in target website server;
- Exposure to XML language;
- Experience in programming Apache ANT script (see manual for more information).
Tutorial
Create PageSeeder webapp config
Create publish configuration file:
[template]/publish/publish-config.xml
with the following content:
<?xml version="1.0"?> <publishing> <action type="publish"> <source type="document" extension="psml" /> <target name="ps-publish-website-document"> <description>Publish document to website</description> </target> </action> <action type="publish"> <source type="folder"/> <target name="ps-publish-website-folder"> <description>Publish folder to website</description> </target> </action> </publishing>
To create a publish configuration file for the document type, create a config file:
[template]/psml/[document-type]/document-config.xml
with the following content:
<?xml version="1.0"?> <document-config> <publishing override="true"> <action type="publish"> <source type="document" extension="psml" /> <target name="ps-publish-website-document"> <description>Publish document to website</description> </target> </action> </publishing> </document-config>
Define Publish FTP property file
Create a website properties file:
[template]/publish/config/website.properties
with the following content:
# --------------------------------------------------------------------------- # BERLIOZ PROPERTIES FOR A WEBSITE (Server) # --------------------------------------------------------------------------- # # This file will be copied to the /config directory of your project on the # publisher when your deploy this publish script to the server using FTP # (build.xml > deploy-server). # # This file will ultimately be used by the Publisher on your PageSeeder # production server when you publish your group/document to the Website. It # should therefore specify the properties of your production Berlioz Website. # # --------------------------------------------------------------------------- # FTP properties ftp.server=[Host URL] ftp.userid=[Host User ID] ftp.password=[Host User Password] ftp.dir=[Host Remote Folder]
Publish a document
This is a document-level publish script that uses FTP for transport. In this scenario, only a single document is exported and it will overwrite the file on the target server.
Create the following file and path:
[template]/document/psml/publish/build.xml
with the following content:
<?xml version="1.0" encoding="utf-8" ?> <project name="pageseeder-publish-website-document" xmlns:ps="antlib:com.pageseeder.publishapi.ant"> <!-- Publish config properties --> <property name="pswebsiteconfig.basedir" location="../../publish/config"/> <!-- Document publish --> <target name="ps-publish-website-document"> <!-- Configure PageSeeder --> <ps:config /> <!-- Load Website Properties --> <loadproperties srcFile="${pswebsiteconfig.basedir}/website.properties"/> <!-- Create working folder --> <mkdir dir="${ps.config.default.working}/export" /> <!-- Export --> <ps:export src="${ps.config.default.uri.path}" dest="${ps.config.default.working}/export" context="${ps.config.default.group.folder}"/> <!-- FTP all PSML files to website root --> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" remotedir="${ftp.webapp}/WEB-INF/psml"> <fileset dir="${ps.config.default.working}/export" includes="**/*.psml" excludes="META-INF/**" /> </ftp> <!-- FTP all non-PSML files to website root --> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" remotedir="${ftp.preview.webapp}"> <fileset dir="${ps.config.default.working}/export" excludes="**/*.psml,META-INF/**" /> </ftp> <!-- local working folder clean-up --> <delete dir="${ps.config.default.working}" includes="*,**" includeemptydirs="true" /> <!-- Publish completed --> <echo message="Publishing document ${ps.config.default.uri.path} to Berlioz - Complete"/> </target> </project>
Publish a folder
This folder-level script will export all documents plus images and binary files to a server via FTP. Whatever folders are being published on the source server will delete, and then overwrite, the folders and files on the destination server.
Create the following file and path:
[template]/folder/publish/build.xml
with the following content:
<project name="pageseeder-publish-website-folder" xmlns:ps="antlib:com.pageseeder.publishapi.ant"> <!-- Publish config properties --> <property name="pswebsiteconfig.basedir" location="../../publish/config"/> <target name="ps-publish-website-folder"> <!-- Configure PageSeeder --> <ps:config /> <!-- Load Website Properties --> <loadproperties srcFile="${pswebsiteconfig.basedir}/website-pbs.properties" /> <!-- Cleaning working directory --> <echo message="Cleaning working directories" /> <delete dir="${ps.config.default.working}/export" includes="*,**" includeemptydirs="true" /> <!-- Creating a working directory --> <echo message="Creating working directories" /> <mkdir dir="${ps.config.default.working}/export" /> <!-- Export --> <echo message="Exporting folder ${ps.config.default.uri.path}" /> <ps:export src="${ps.config.default.uri.path}" context="${ps.config.default.group.folder}" dest="${ps.config.default.working}/export" failonerror="false" /> <!-- Delete PSML folder--> <echo message="Create folder ${ftp.webapp}/WEB-INF/psml${ps.config.default.uri.path.no.group} in target folder (if doesn't exists)" /> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" action="mkdir" depends="yes" verbose="yes" passive="yes" remotedir="${ftp.webapp}/WEB-INF/psml${ps.config.default.uri.path.no.group}"> </ftp> <echo message="Delete all PSML files under ${ftp.webapp}/WEB-INF/psml${ps.config.default.uri.path.no.group}" /> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" action="rmdir" depends="yes" verbose="yes" passive="yes" skipFailedTransfers="true" ignoreNoncriticalErrors="true" remotedir="${ftp.webapp}/WEB-INF/psml${ps.config.default.uri.path.no.group}"> <fileset includes="**"/> </ftp> <!-- Delete non-PSML folder--> <echo message="Create folder {ftp.webapp}${ps.config.default.uri.path.no.group} in target folder (if doesn't exists)" /> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" action="mkdir" depends="yes" verbose="yes" passive="yes" remotedir="${ftp.webapp}${ps.config.default.uri.path.no.group}"/> <echo message="Delete all non PSML files under ${ftp.webapp}${ps.config.default.uri.path.no.group}" /> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" action="rmdir" depends="yes" verbose="yes" passive="yes" skipFailedTransfers="true" ignoreNoncriticalErrors="true" remotedir="${ftp.webapp}${ps.config.default.uri.path.no.group}"> <fileset includes="**"/> </ftp> <!-- Publishing PSML folder --> <echo message="Publishing all PSML files to website ${ftp.webapp}/WEB-INF/psml" /> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" depends="yes" verbose="yes" passive="yes" remotedir="${ftp.webapp}/WEB-INF/psml"> <fileset dir="${ps.config.default.working}/export" includes="**/*.psml" excludes="META-INF/**" /> </ftp> <!-- Publishing all non-PSML files to Website --> <echo message="Publishing all non-PSML files to website"/> <ftp server="${ftp.server}" userid="${ftp.userid}" password="${ftp.password}" depends="yes" verbose="yes" passive="yes" remotedir="${ftp.webapp}"> <fileset dir="${ps.config.default.working}/export" excludes="**/*.psml,META-INF/**" /> </ftp> <echo message="Cleaning working directories" /> <delete dir="${ps.config.default.working}" includes="*,**" includeemptydirs="true" /> <echo message="Publishing folder ${ps.config.default.uri.path} to website - Complete"/> </target> </project>
Check configuration
To check that the Publish option is enabled. Go to the document folders page and that check that:
- The Export button at the top is a drop-down with the Publish option
- The drop-down menu for documents and folders include the Publish option