1 package org.apache.maven.artifact.manager;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.Map;
25
26 import org.apache.maven.wagon.AbstractWagon;
27 import org.apache.maven.wagon.ConnectionException;
28 import org.apache.maven.wagon.ResourceDoesNotExistException;
29 import org.apache.maven.wagon.TransferFailedException;
30 import org.apache.maven.wagon.authentication.AuthenticationException;
31 import org.apache.maven.wagon.authorization.AuthorizationException;
32 import org.apache.maven.wagon.events.TransferEvent;
33 import org.apache.maven.wagon.resource.Resource;
34 import org.codehaus.plexus.util.FileUtils;
35
36
37
38
39 public class WagonString
40 extends AbstractWagon
41 {
42
43
44
45
46
47
48
49 private Map resourceStrings;
50
51 public void closeConnection()
52 {
53
54 }
55
56 public void get( String resourceName, File destination )
57 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
58 {
59 getIfNewer( resourceName, destination, 0 );
60 }
61
62 public boolean getIfNewer( String resourceName, File destination, long timestamp )
63 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
64 {
65 Resource resource = new Resource( resourceName );
66 fireGetInitiated( resource, destination );
67
68 String data = (String) this.resourceStrings.get( resourceName );
69 if ( data == null )
70 {
71 throw new ResourceDoesNotExistException( "Unexistent resource: " + resourceName );
72 }
73
74 fireGetStarted( resource, destination );
75 try
76 {
77 byte[] bytes = data.getBytes( "UTF-8" );
78 FileUtils.fileWrite( destination.getPath(), "UTF-8", data );
79 fireTransferProgress( new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS,
80 TransferEvent.REQUEST_GET ), bytes, bytes.length );
81 }
82 catch ( IOException e )
83 {
84 return false;
85 }
86 fireGetCompleted( resource, destination );
87
88 return true;
89 }
90
91 public void openConnectionInternal()
92 {
93
94 }
95
96 public void put( File source, String destination )
97 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
98 {
99 Resource resource = new Resource( destination );
100 firePutInitiated( resource, source );
101 firePutStarted( resource, source );
102 firePutCompleted( resource, source );
103 }
104
105 public String[] getSupportedProtocols()
106 {
107 return new String[] { "string" };
108 }
109
110 public void openConnection() throws ConnectionException,
111 AuthenticationException {
112
113
114 }
115 }