1 package org.apache.maven.doxia.siterenderer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26
27 import org.apache.velocity.runtime.resource.Resource;
28 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
29 import org.apache.velocity.exception.ResourceNotFoundException;
30 import org.apache.commons.collections.ExtendedProperties;
31 import org.codehaus.plexus.util.IOUtil;
32
33
34
35
36
37
38
39
40 @Deprecated
41 public class SkinResourceLoader
42 extends ResourceLoader
43 {
44 public void init( ExtendedProperties configuration )
45 {
46 }
47
48 public synchronized InputStream getResourceStream( String name )
49 throws ResourceNotFoundException
50 {
51 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
52
53 if ( name.startsWith( "/" ) )
54 {
55 name = name.substring( 1 );
56 }
57
58 return normalizeNewline( classLoader.getResourceAsStream( name ) );
59 }
60
61 InputStream normalizeNewline( InputStream in )
62 throws ResourceNotFoundException
63 {
64 if ( in == null )
65 {
66 return null;
67 }
68
69 try
70 {
71 byte[] content = IOUtil.toByteArray( in );
72
73
74
75 byte[] eol = System.getProperty( "line.separator" ).getBytes();
76
77 final int size = content.length;
78
79 ByteArrayOutputStream out = new ByteArrayOutputStream( size );
80
81 for ( int i = 0; i < size; i++ )
82 {
83 byte b = content[i];
84
85 if ( b == '\r' )
86 {
87 if ( ( i + 1 ) < size && content[i + 1] == '\n' )
88 {
89 i++;
90 }
91
92 out.write( eol );
93 }
94 else if ( b == '\n' )
95 {
96 out.write( eol );
97 }
98 else
99 {
100 out.write( b );
101 }
102 }
103
104 return new ByteArrayInputStream( out.toByteArray() );
105 }
106 catch ( IOException ioe )
107 {
108 throw new ResourceNotFoundException( "cannot read resource", ioe );
109 }
110 finally
111 {
112 IOUtil.close( in );
113 }
114 }
115
116 public boolean isSourceModified( Resource resource )
117 {
118 return false;
119 }
120
121 public long getLastModified( Resource resource )
122 {
123 return 0;
124 }
125 }