This sound to me like you're not saving the newly crated node. Here's
a piece of code we're using to create a folder in the dms:
// assume we have the parent node -> in your case that would be the root
try {
Content ct =
node.createContent("foldername");
node.save();
previewFolder = new Document(ct);
} catch (PathNotFoundException pnfe) {
// take care of that
} catch (RepositoryException re) {
// or that ;-)
}
HTH
-Will
On 08.02.2008, at 20:34, McMains, Sean A wrote:
Hi Folks,
We're planning to add the DMS functionality to our Magnolia
installation
before too long. Since we manage a bunch of sites within a single
instance
of Magnolia, we have a single top-level item for each site in the
Website
repository. We plan to mirror this structure in the DMS, so that
each site
will have an associated folder at the root level of the DMS tree.
I've been working on a script to automate the creation of these
folders in
the DMS repository, but haven't been able to get it totally working
yet.
When I run the script, it claims that it has created the folders. And
indeed, if you run it again, it sees the folders and doesn't try to
create
them again.
However, in both the Documents tab in AdminCentral and the JCR browser
(which I tweaked to look in the dms tree), there's no evidence of the
folders to be seen. I expect I'm probably just missing some small
but vital
step in creating them, but I sure haven't been able to figure out
what that
step is.
So, if anyone has sample code for creating folders in the DMS, or
can tell
me what I'm missing in the following script, I'd sure appreciate
the help.
Thanks,
Sean
-----
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:cms="urn:jsptld:cms-taglib"
xmlns:cmsu="urn:jsptld:cms-util-taglib"
xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core">
<jsp:directive.page contentType="text/html; charset=UTF-8"
session="false" />
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd"
/>
<html>
<head>
<title>Add 404 Pages</title>
</head>
<body>
<jsp:directive.page import="info.magnolia.cms.core.Content" />
<jsp:directive.page
import="info.magnolia.cms.beans.config.ContentRepository" />
<jsp:directive.page
import="info.magnolia.cms.core.HierarchyManager" />
<jsp:directive.page import="info.magnolia.context.MgnlContext" />
<jsp:directive.page import="java.util.Iterator" />
<jsp:directive.page import="info.magnolia.cms.core.ItemType" />
<jsp:directive.page import="info.magnolia.cms.core.MetaData" />
<jsp:directive.page
import="info.magnolia.cms.security.Authenticator" />
<jsp:directive.page import="javax.jcr.ValueFactory" />
<jsp:directive.page import="javax.jcr.RepositoryException" />
<jsp:declaration>
<![CDATA[
public void createPage( Content c, HttpServletRequest request,
HttpServletResponse response ) throws Exception {
response.getWriter().println("<br/>Processing Site:
" +
c.getHandle() + "<br/>");
HierarchyManager
dmsHierarchyManager=MgnlContext.getHierarchyManager( "dms" );
ValueFactory valueFactory =
dmsHierarchyManager.getWorkspace().getSession().getValueFactory();
String folderName = c.getName();
if ( !dmsHierarchyManager.isExist( c.getHandle() ) ) {
response.getWriter().println( folderName + "
needs to be
created.<br/>");
Content dmsRoot = dmsHierarchyManager.getRoot();
Content newFolder = dmsRoot.createContent
( folderName,
ItemType.FOLDER.getSystemName() );
response.getWriter().println("Created new
folder at " +
newFolder.getHandle() + "<br/>" ) ;
dmsRoot.save();
} else {
response.getWriter().println( c.getHandle() + "
already
exists<br/>" );
}
}
public void processSites( Content c, HttpServletRequest
request,
HttpServletResponse response ) {
try {
Iterator childContentNodesIterator = c.getChildren(
ItemType.CONTENT ).iterator();
while ( childContentNodesIterator.hasNext() ) {
Content childNode =
(Content)childContentNodesIterator.next();
createPage( childNode, request, response );
response.flushBuffer();
}
} catch (Exception e) {
e.printStackTrace();
}
}
]]>
</jsp:declaration>
<jsp:scriptlet>
<![CDATA[
HierarchyManager
websiteHierarchyManager=MgnlContext.getHierarchyManager
(ContentRepository.WE
BSITE);
MgnlContext.initAsWebContext( request, response );
Content rootNode = websiteHierarchyManager.getContent("/");
response.getWriter().println("Processing sites...<br/>");
processSites( rootNode, request, response );
response.getWriter().println("**** ADDING 404s COMPLETE ****
<br/>");
]]>
</jsp:scriptlet>
</body>
</html>
</jsp:root>
----------------------------------------------------------------
for list details see
http://documentation.magnolia.info/docs/en/editor/stayupdated.html
----------------------------------------------------------------
----------------------------------------------------------------
for list details see
http://documentation.magnolia.info/docs/en/editor/stayupdated.html
----------------------------------------------------------------