Creating New Entries with CTR
As shown, editing existing entries was straightforward. Creating new content in Plone based on external XML files is more problematic. Namely, what content type should we use for the new resource?
As this isn't a one-size-fits-all situation, Marshall approaches this with configurability in mind. For mortals like me, choice means confusion. So this first example shows the simplest possible way to make it work, albeit in a clumsy-to-use fashion.
For this example, we will set a policy that any XML file ending in .atxmlpage will be used to create a Page resource. The id of that resource will come from the rest of the filename.
The CMF's Content Type Registry is responsible for policies related to file extensions. This tool can be reached via the ZMI in the portal root under the name "content_type_registry".
- Click on content_type_registry tool in ZMI.
- Scroll to the bottom.
- Add a predicate with a name such as atxmlpage, using
Extensionas the predicate type in the drop down, and click Add.
- After saving, change the settings. Set the extensions value to
atxmlpage and the content type in the drop-down to Page, then click
The content type registry is now setup. On your local disk, create a file somewhere named
mynewxmlpage.atxmlpage and give it contents as shown below:
<?xml version="1.0" ?>
My first page from XML
Congratulations! You have successfully installed Plone.
<p>This content came from an XML file on disk.</p>
Save this file, then return to cadaver. In the top folder of your Plone site, use cadaver to add the file:
cadaver uploads the file to Plone. The CTR sees the extension and knows to create a Page (Document) using the ATXML marshaller, which reads the XML file for all the initial settings.
In Plone you can now go to the URL
http://localhost:8080/atxml/mynewxmlpage.atxmlpage and see your new page.
Sure, there are a bunch of caveats to note:
- Be very careful to ensure you don't have a field with id="id" in your upload, nor a uid entry.
- Would be nice if the .atxmlpage extension disappeared.
- If you want to see all the settings, such as dc:subject and workflow state, that you can serialize to XML, go change some things on an existing Page and open it via cadaver. There's lots there! Sidnei's XML format was meant to capture lots of semantics.
- In a potential future addition to this how-to, I'll cover how to use cmf:type in the XML to create different types without the use of crazy file extensions.