Tutorials

Task-driven tutorials and recipes for PageSeeder

How to create document collections from a template

Skills requiredXML
Time required (minutes)30
Intended audienceDeveloper
DifficultyEasy
CategoryDocument

Objective

Document templates can be used to create single documents but this tutorial will show how to write a process script that will create a document collection from a template containing multiple linked documents.

Prerequisites

To complete this tutorial requires:

  • Administrator access to a PageSeeder server.
  • Knowledge of how to create projects, groups, folders and documents in PageSeeder.

Tutorial

Step 1: Setup projects, groups and documents

  1. In PageSeeder create a project called 'example'.
  2. In this project create groups 'template' and 'publication'.
  3. In the 'example-template' group create a 'templates' folder.
  4. In the 'templates' folder create a 'publication1' folder.
  5. In the 'publication1' folder create a references type document and some default type documents linked to it (these will form the template for one document collection).
  6. Repeat the last 2 actions for a 'publication2' folder.

Step 2: Setup process script

  1. In PageSeeder go the the 'example' project and select the Developer perspective (top left).
  2. Select Document config from the Dev menu and then click Publish scripts (top right).
  3. Click Configure scripts for group/folder/document.
  4. Replace the content with the following XML and click Save at the bottom (the <value> elements define your list of templates, so would need to be updated if you add or rename template folders).
    <publishing>
      <action type="process">
        <source type="folder" />
        <target name="create-collection">
          <description>Create document collection</description>
          <param name="template-name" label="Template" type="select">
            <!-- THIS LIST SHOULD BE MODIFIED FOR SPECIFIC PROJECT --> 
            <value>publication1</value>
            <value>publication2</value>
          </param>
          <param name="collection-name" label="New collection name" type="text" />
        </target>
      </action>
    </publishing>
    
  5. Click Publish scripts (top right).
  6. Click create next to the 'create-collection' target.
  7. Replace the content with the following XML and click Save at the bottom (the template-folder property would need to be modified to setup this in a different project).
<project name="folder-process"
    xmlns:ps="antlib:com.pageseeder.publishapi.ant">

  <target name="create-collection" description="Create document collection">

    <!-- Folder containing the templates (SHOULD BE MODIFIED FOR SPECIFIC PROJECT) -->
    <property name="template-folder" value="/ps/example/template/templates" />

    <!-- load PageSeeder config properties -->
    <ps:config />
    
    <!-- create working folders -->
    <property name="download" value="${ps.config.default.working}/download" />
    <property name="process" value="${ps.config.default.working}/process" />
    <mkdir dir="${download}"/>
    <mkdir dir="${process}"/>

    <!-- export template documents -->
    <ps:export  src="${template-folder}/${ps.param.template-name}"
               dest="${download}" />

    <!-- remove docids to avoid clashes -->
    <ps:process src="${download}"
               dest="${process}"
          processed="false"
        preservesrc="true">
      <strip documentinfo="docid" />
    </ps:process>
    
    <!-- zip files to preserve folder structure on upload -->
    <zip destfile="${ps.config.default.working}/upload.zip"
          basedir="${process}" />
    
    <!-- upload template documents to new location -->
    <script language="javascript">
      var name = project.getProperty("ps.param.collection-name");
      project.setProperty("foldername", name.toLowerCase().replaceAll(" ", "_"));
    </script>
    <ps:upload group="${ps.config.default.group.name}"
              folder="${ps.config.default.uri.path.no.group}/${foldername}"
               unzip="true">
      <fileset file="${ps.config.default.working}/upload.zip" />
    </ps:upload>
    <echo>Creation successful!</echo>
  </target>

</project>

Step 3: Create a collection

  1. In PageSeeder go to the 'example-publication' group and click on Documents.
  2. Next to the 'documents' folder select Process  by mousing over the actions icon at right (this is where the document collection will be created, so you could select any folder).
  3. Select a Template from the drop down list and type a New collection name (e.g. My new publication)
  4. Click the Process button and wait until 'Creation successful!' appears.
  5. Click Close, then click on the documents folder and you should see the folder for your new collection with the documents from the template inside it.

process-folder.png

Created on , last edited on