KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > exporter > ExporterComponentTest


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  */
package org.alfresco.repo.exporter;
17
18 import java.io.File JavaDoc;
19 import java.io.FileOutputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import org.alfresco.repo.security.authentication.AuthenticationComponent;
26 import org.alfresco.service.ServiceRegistry;
27 import org.alfresco.service.cmr.repository.ContentData;
28 import org.alfresco.service.cmr.repository.NodeRef;
29 import org.alfresco.service.cmr.repository.NodeService;
30 import org.alfresco.service.cmr.repository.StoreRef;
31 import org.alfresco.service.cmr.security.AccessPermission;
32 import org.alfresco.service.cmr.view.Exporter;
33 import org.alfresco.service.cmr.view.ExporterContext;
34 import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
35 import org.alfresco.service.cmr.view.ExporterService;
36 import org.alfresco.service.cmr.view.ImporterService;
37 import org.alfresco.service.cmr.view.Location;
38 import org.alfresco.service.namespace.QName;
39 import org.alfresco.util.BaseSpringTest;
40 import org.alfresco.util.TempFileProvider;
41 import org.alfresco.util.debug.NodeStoreInspector;
42
43
44 public class ExporterComponentTest extends BaseSpringTest
45 {
46
47     private NodeService nodeService;
48     private ExporterService exporterService;
49     private ImporterService importerService;
50     private StoreRef storeRef;
51     private AuthenticationComponent authenticationComponent;
52
53     
54     @Override JavaDoc
55     protected void onSetUpInTransaction() throws Exception JavaDoc
56     {
57         nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
58         exporterService = (ExporterService)applicationContext.getBean("exporterComponent");
59         importerService = (ImporterService)applicationContext.getBean("importerComponent");
60         
61         // Create the store
62
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
63
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test");
64
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
65

66         
67         
68         this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
69         
70         this.authenticationComponent.setSystemUserAsCurrentUser();
71         
72         this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
73     }
74
75     @Override JavaDoc
76     protected void onTearDownInTransaction() throws Exception JavaDoc
77     {
78         authenticationComponent.clearCurrentSecurityContext();
79         super.onTearDownInTransaction();
80     }
81     
82     public void testExport()
83         throws Exception JavaDoc
84     {
85         TestProgress testProgress = new TestProgress();
86         Location location = new Location(storeRef);
87
88         // import
89
InputStream JavaDoc test = getClass().getClassLoader().getResourceAsStream("org/alfresco/repo/importer/importercomponent_test.xml");
90         InputStreamReader JavaDoc testReader = new InputStreamReader JavaDoc(test, "UTF-8");
91         importerService.importView(testReader, location, null, null);
92         System.out.println(NodeStoreInspector.dumpNodeStore((NodeService)applicationContext.getBean("NodeService"), storeRef));
93         
94         // now export
95
location.setPath("/system");
96         File JavaDoc tempFile = TempFileProvider.createTempFile("xmlexporttest", ".xml");
97         OutputStream JavaDoc output = new FileOutputStream JavaDoc(tempFile);
98         ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
99         parameters.setExportFrom(location);
100         exporterService.exportView(output, parameters, testProgress);
101         output.close();
102     }
103
104     
105     private static class TestProgress
106         implements Exporter
107     {
108
109         public void start(ExporterContext exportNodeRef)
110         {
111             System.out.println("TestProgress: start");
112         }
113
114         public void startNamespace(String JavaDoc prefix, String JavaDoc uri)
115         {
116             System.out.println("TestProgress: start namespace prefix = " + prefix + " uri = " + uri);
117         }
118
119         public void endNamespace(String JavaDoc prefix)
120         {
121             System.out.println("TestProgress: end namespace prefix = " + prefix);
122         }
123
124         public void startNode(NodeRef nodeRef)
125         {
126 // System.out.println("TestProgress: start node " + nodeRef);
127
}
128
129         public void endNode(NodeRef nodeRef)
130         {
131 // System.out.println("TestProgress: end node " + nodeRef);
132
}
133
134         public void startAspect(NodeRef nodeRef, QName aspect)
135         {
136 // System.out.println("TestProgress: start aspect " + aspect);
137
}
138
139         public void endAspect(NodeRef nodeRef, QName aspect)
140         {
141 // System.out.println("TestProgress: end aspect " + aspect);
142
}
143
144         public void startProperty(NodeRef nodeRef, QName property)
145         {
146 // System.out.println("TestProgress: start property " + property);
147
}
148
149         public void endProperty(NodeRef nodeRef, QName property)
150         {
151 // System.out.println("TestProgress: end property " + property);
152
}
153
154         public void value(NodeRef nodeRef, QName property, Object JavaDoc value)
155         {
156 // System.out.println("TestProgress: single value " + value);
157
}
158
159         public void value(NodeRef nodeRef, QName property, Collection JavaDoc values)
160         {
161 // System.out.println("TestProgress: multi value " + value);
162
}
163
164         public void content(NodeRef nodeRef, QName property, InputStream JavaDoc content, ContentData contentData)
165         {
166 // System.out.println("TestProgress: content stream ");
167
}
168
169         public void startAssoc(NodeRef nodeRef, QName assoc)
170         {
171 // System.out.println("TestProgress: start association " + assocDef.getName());
172
}
173
174         public void endAssoc(NodeRef nodeRef, QName assoc)
175         {
176 // System.out.println("TestProgress: end association " + assocDef.getName());
177
}
178
179         public void warning(String JavaDoc warning)
180         {
181             System.out.println("TestProgress: warning " + warning);
182         }
183
184         public void end()
185         {
186             System.out.println("TestProgress: end");
187         }
188
189         public void startProperties(NodeRef nodeRef)
190         {
191 // System.out.println("TestProgress: startProperties: " + nodeRef);
192
}
193
194         public void endProperties(NodeRef nodeRef)
195         {
196 // System.out.println("TestProgress: endProperties: " + nodeRef);
197
}
198
199         public void startAspects(NodeRef nodeRef)
200         {
201 // System.out.println("TestProgress: startAspects: " + nodeRef);
202
}
203
204         public void endAspects(NodeRef nodeRef)
205         {
206 // System.out.println("TestProgress: endAspects: " + nodeRef);
207
}
208
209         public void startAssocs(NodeRef nodeRef)
210         {
211 // System.out.println("TestProgress: startAssocs: " + nodeRef);
212
}
213
214         public void endAssocs(NodeRef nodeRef)
215         {
216 // System.out.println("TestProgress: endAssocs: " + nodeRef);
217
}
218
219         public void startACL(NodeRef nodeRef)
220         {
221 // System.out.println("TestProgress: startACL: " + nodeRef);
222
}
223
224         public void permission(NodeRef nodeRef, AccessPermission permission)
225         {
226 // System.out.println("TestProgress: permission: " + permission);
227
}
228
229         public void endACL(NodeRef nodeRef)
230         {
231 // System.out.println("TestProgress: endACL: " + nodeRef);
232
}
233
234         public void startReference(NodeRef nodeRef, QName childName)
235         {
236 // System.out.println("TestProgress: startReference: " + nodeRef);
237
}
238
239         public void endReference(NodeRef nodeRef)
240         {
241 // System.out.println("TestProgress: endReference: " + nodeRef);
242
}
243
244     }
245     
246 }
247
Popular Tags