Hi Sean,
Below is a piece of code I use which should do the page creation part.
It's designed for a servlet environment, so will need some work if you
need to run from the command line. It may also need a bit of tweaking
depending on the magnolia version you're using.
Haven't tried populating content via the APIs so can't offer anything
useful on that at the moment. It will be in APIs somewhere, so trawl
through the Javadoc and Magnolia sources and you will find it
eventually.
Hope this helps,
Simon
String mgnlRepository = request.getParameter("mgnlRepository");
if( mgnlRepository == null )
{
mgnlRepository = "website";
}
String mgnlPath = request.getParameter("mgnlPath");
String label = request.getParameter("label");
String title = request.getParameter("title");
String template = request.getParameter("template");
String name = "/"; //default in case something goes wrong
if( mgnlPath != null && mgnlPath.length() > 0 )
{
MgnlContext.initWebContext(request);
HierarchyManager hm = MgnlContext.getHierarchyManager(mgnlRepository);
ValueFactory valueFactory =
hm.getWorkspace().getSession().getValueFactory();
name = label;
if( label == null || label.trim().length() < 1 )
{
name = "untitled";
}
try {
Content parentNode = hm.getContent(mgnlPath);
String slash = "/";
boolean isRoot = false;
if (mgnlPath.equals("/")) {
isRoot = true;
slash = StringUtils.EMPTY;
}
if (hm.isExist(mgnlPath + slash + label)) {
if (!isRoot) {
name = Path.getUniqueLabel(hm, mgnlPath, label);
}
else {
name = Path.getUniqueLabel(hm,
StringUtils.EMPTY, label);
}
}
Content newNode;
newNode = parentNode.createContent(name,
ItemType.CONTENT.getSystemName());
newNode.getMetaData().setAuthorId(Authenticator.getUserId(request));
newNode.getMetaData().setCreationDate();
newNode.getMetaData().setModificationDate();
newNode.getMetaData().setTemplate(template);
newNode.setNodeData("title", valueFactory.createValue(title));
parentNode.save();
}
catch (Exception e) {
System.out.println("error creating page: " + name);
}
}
On 02/03/07, Sean McMains <[email protected]> wrote:
Hi Folks,
I'm wanting to add a specific page to each of the sites that we're running
under Magnolia. I've got the code to iterate through the WEBSITE repository
working fine, but am not having any luck figuring out what I need to do to
create a new page and populate it with a bit of data. (I've tried a couple
different things that look like they ought to work, and run without error,
but don't actually produce any results.)
Does anybody have any sample page-creation code they'd be willing to share?
Or if there's something relevant in the Magnolia source, I'd love to know
where to look.
Thanks for any help!
Sean
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------