KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jsftest > repository > NodeService


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package jsftest.repository;
18
19 import java.util.Date;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * Mock NodeService API
28  *
29  * @author gavinc
30  */

31 public class NodeService
32 {
33    private static Log logger = LogFactory.getLog(NodeService.class);
34    
35    public static NodeRef getNodeRef(String path)
36    {
37       return new NodeRef(path);
38    }
39    
40    public static String getType(NodeRef nodeRef)
41    {
42       String id = nodeRef.getId();
43       String type = null;
44       
45       if (id.equalsIgnoreCase("/gav.doc") ||
46           id.equalsIgnoreCase("/kev.txt"))
47       {
48          type = "base";
49       }
50       else if (id.equalsIgnoreCase("/sop.txt"))
51       {
52          type = "SOP";
53       }
54       
55       return type;
56    }
57    
58    public static Map getProperties(NodeRef nodeRef)
59    {
60       String id = nodeRef.getId();
61       Map properties = null;
62       
63       if (id.equalsIgnoreCase("/gav.doc"))
64       {
65          properties = createProperties("Gav", "Gavs Object",
66                new String[] {"gav", "gadget", "gibbon"}, null);
67       }
68       else if (id.equalsIgnoreCase("/kev.txt"))
69       {
70          properties = createProperties("Kev", "Kevs Object",
71               new String[] {"kev", "monkey"}, null);
72       }
73       else if (id.equalsIgnoreCase("/sop.txt"))
74       {
75          properties = createProperties("SOP", "A manufacturing SOP",
76                new String[] {"sop", "manufacturing"}, "sop1");
77       }
78       
79       return properties;
80    }
81
82    private static Map createProperties(String name, String desc,
83          String[] keywords, String sop)
84    {
85       HashMap props = new HashMap();
86       
87       Date date = new Date();
88       props.put("name", name);
89       props.put("description", desc);
90       props.put("keywords", keywords);
91       props.put("created", date);
92       props.put("modified", date);
93       
94       if (sop != null)
95       {
96          props.put("sopId", sop);
97          props.put("effective", date);
98          props.put("approved", new Boolean(true));
99          props.put("latestversion", "1.6");
100       }
101       
102       return props;
103    }
104 }
105
Popular Tags