1   package org.apache.maven.artifact.manager;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.maven.wagon.ConnectionException;
26  import org.apache.maven.wagon.InputData;
27  import org.apache.maven.wagon.OutputData;
28  import org.apache.maven.wagon.ResourceDoesNotExistException;
29  import org.apache.maven.wagon.StreamWagon;
30  import org.apache.maven.wagon.TransferFailedException;
31  import org.apache.maven.wagon.authentication.AuthenticationException;
32  import org.apache.maven.wagon.resource.Resource;
33  import org.codehaus.plexus.util.StringInputStream;
34  import org.codehaus.plexus.util.StringOutputStream;
35  
36  public class StringWagon
37      extends StreamWagon
38  {
39      private Map expectedContent = new HashMap();
40      
41      public void addExpectedContent( String resourceName, String expectedContent )
42      {
43          this.expectedContent.put( resourceName, expectedContent );
44      }
45  
46      public String[] getSupportedProtocols()
47      {
48          return new String[] { "string" };
49      }
50  
51      public void closeConnection()
52          throws ConnectionException
53      {
54      }
55  
56      public void fillInputData( InputData inputData )
57          throws TransferFailedException, ResourceDoesNotExistException
58      {
59          Resource resource = inputData.getResource();
60  
61          String content = (String) expectedContent.get( resource.getName() );
62          
63          if ( content != null )
64          {
65              resource.setContentLength( content.length() );
66              resource.setLastModified( System.currentTimeMillis() );
67  
68              inputData.setInputStream( new StringInputStream( content ) );
69          }
70          else
71          {
72              throw new ResourceDoesNotExistException( "No content provided for " + resource.getName() );
73          }
74      }
75  
76      public void fillOutputData( OutputData outputData )
77          throws TransferFailedException
78      {
79          outputData.setOutputStream( new StringOutputStream() );
80      }
81  
82      protected void openConnectionInternal()
83          throws ConnectionException, AuthenticationException
84      {
85      }
86  
87      public void clearExpectedContent()
88      {
89          expectedContent.clear();        
90      }
91  
92  	public void openConnection() throws ConnectionException,
93  			AuthenticationException {
94  		// TODO Auto-generated method stub
95  		
96  	}
97  }