01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.cms.impl.jcr.command;
23:
24: import org.jboss.portal.cms.impl.ContentImpl;
25: import org.jboss.portal.cms.impl.FileImpl;
26: import org.jboss.portal.cms.impl.jcr.JCRCommand;
27: import org.jboss.portal.cms.model.Content;
28: import org.jboss.portal.cms.model.File;
29:
30: import javax.jcr.Node;
31: import javax.jcr.NodeIterator;
32: import javax.jcr.nodetype.NodeType;
33: import java.util.ArrayList;
34: import java.util.List;
35: import java.util.Locale;
36:
37: /**
38: * Returns a list of content nodes under a filenode, but ignores versioning labels.
39: *
40: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
41: */
42: public class FileGetListCommand extends JCRCommand {
43: /** The serialVersionUID */
44: private static final long serialVersionUID = 7601421931789710938L;
45: String sFilePath;
46:
47: public FileGetListCommand(String sFilePath) {
48: this .sFilePath = sFilePath;
49: }
50:
51: public Object execute() {
52: List contents = new ArrayList();
53: try {
54: File file = new FileImpl();
55:
56: Node fileNode = (Node) context.getSession().getItem(
57: sFilePath);
58: file.setName(fileNode.getName());
59: file.setBasePath(sFilePath);
60:
61: // get child content objects
62: NodeIterator ni = fileNode.getNodes();
63: while (ni.hasNext()) {
64: Node contentNode = ni.nextNode();
65: NodeType nt = contentNode.getPrimaryNodeType();
66: if (nt.getName().equals("portalcms:content")) {
67: Content content = new ContentImpl();
68: content.setCreationDate(contentNode.getProperty(
69: "jcr:created").getDate().getTime());
70: content.setLastModified(contentNode.getProperty(
71: "jcr:lastModified").getDate().getTime());
72: content.setBasePath(contentNode.getPath());
73: content.setDescription(contentNode.getProperty(
74: "portalcms:description").getString());
75: content.setTitle(contentNode.getProperty(
76: "portalcms:title").getString());
77: content.setMimeType(contentNode.getProperty(
78: "jcr:mimeType").getString());
79: content.setName(contentNode.getName());
80: content.setEncoding(contentNode.getProperty(
81: "jcr:encoding").getString());
82: content.setStream(contentNode.getProperty(
83: "jcr:data").getStream());
84: content.setLocale(new Locale(contentNode
85: .getProperty("portalcms:language")
86: .getString()));
87: contents.add(content);
88: }
89: }
90: return contents;
91: } catch (Exception e) {
92: e.printStackTrace();
93: }
94: return null;
95: }
96: }
|