1 package org.alfresco.repo.exporter; 17 18 import java.io.File ; 19 import java.io.FileOutputStream ; 20 import java.io.InputStream ; 21 import java.io.InputStreamReader ; 22 import java.io.OutputStream ; 23 import java.util.Collection ; 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 55 protected void onSetUpInTransaction() throws Exception 56 { 57 nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName()); 58 exporterService = (ExporterService)applicationContext.getBean("exporterComponent"); 59 importerService = (ImporterService)applicationContext.getBean("importerComponent"); 60 61 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 76 protected void onTearDownInTransaction() throws Exception 77 { 78 authenticationComponent.clearCurrentSecurityContext(); 79 super.onTearDownInTransaction(); 80 } 81 82 public void testExport() 83 throws Exception 84 { 85 TestProgress testProgress = new TestProgress(); 86 Location location = new Location(storeRef); 87 88 InputStream test = getClass().getClassLoader().getResourceAsStream("org/alfresco/repo/importer/importercomponent_test.xml"); 90 InputStreamReader testReader = new InputStreamReader (test, "UTF-8"); 91 importerService.importView(testReader, location, null, null); 92 System.out.println(NodeStoreInspector.dumpNodeStore((NodeService)applicationContext.getBean("NodeService"), storeRef)); 93 94 location.setPath("/system"); 96 File tempFile = TempFileProvider.createTempFile("xmlexporttest", ".xml"); 97 OutputStream output = new FileOutputStream (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 prefix, String uri) 115 { 116 System.out.println("TestProgress: start namespace prefix = " + prefix + " uri = " + uri); 117 } 118 119 public void endNamespace(String prefix) 120 { 121 System.out.println("TestProgress: end namespace prefix = " + prefix); 122 } 123 124 public void startNode(NodeRef nodeRef) 125 { 126 } 128 129 public void endNode(NodeRef nodeRef) 130 { 131 } 133 134 public void startAspect(NodeRef nodeRef, QName aspect) 135 { 136 } 138 139 public void endAspect(NodeRef nodeRef, QName aspect) 140 { 141 } 143 144 public void startProperty(NodeRef nodeRef, QName property) 145 { 146 } 148 149 public void endProperty(NodeRef nodeRef, QName property) 150 { 151 } 153 154 public void value(NodeRef nodeRef, QName property, Object value) 155 { 156 } 158 159 public void value(NodeRef nodeRef, QName property, Collection values) 160 { 161 } 163 164 public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData) 165 { 166 } 168 169 public void startAssoc(NodeRef nodeRef, QName assoc) 170 { 171 } 173 174 public void endAssoc(NodeRef nodeRef, QName assoc) 175 { 176 } 178 179 public void warning(String 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 } 193 194 public void endProperties(NodeRef nodeRef) 195 { 196 } 198 199 public void startAspects(NodeRef nodeRef) 200 { 201 } 203 204 public void endAspects(NodeRef nodeRef) 205 { 206 } 208 209 public void startAssocs(NodeRef nodeRef) 210 { 211 } 213 214 public void endAssocs(NodeRef nodeRef) 215 { 216 } 218 219 public void startACL(NodeRef nodeRef) 220 { 221 } 223 224 public void permission(NodeRef nodeRef, AccessPermission permission) 225 { 226 } 228 229 public void endACL(NodeRef nodeRef) 230 { 231 } 233 234 public void startReference(NodeRef nodeRef, QName childName) 235 { 236 } 238 239 public void endReference(NodeRef nodeRef) 240 { 241 } 243 244 } 245 246 } 247 | Popular Tags |