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 @Deprecated
40 public class SkinResourceLoader
41 extends ResourceLoader
42 {
43 public void init( ExtendedProperties configuration )
44 {
45 }
46
47 public synchronized InputStream getResourceStream( String name )
48 throws ResourceNotFoundException
49 {
50 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
51
52 if ( name.startsWith( "/" ) )
53 {
54 name = name.substring( 1 );
55 }
56
57 return normalizeNewline( classLoader.getResourceAsStream( name ) );
58 }
59
60 InputStream normalizeNewline( InputStream in )
61 throws ResourceNotFoundException
62 {
63 if ( in == null )
64 {
65 return null;
66 }
67
68 try
69 {
70 byte[] content = IOUtil.toByteArray( in );
71
72
73
74 byte[] eol = System.getProperty( "line.separator" ).getBytes();
75
76 final int size = content.length;
77
78 ByteArrayOutputStream out = new ByteArrayOutputStream( size );
79
80 for ( int i = 0; i < size; i++ )
81 {
82 byte b = content[i];
83
84 if ( b == '\r' )
85 {
86 if ( ( i + 1 ) < size && content[i + 1] == '\n' )
87 {
88 i++;
89 }
90
91 out.write( eol );
92 }
93 else if ( b == '\n' )
94 {
95 out.write( eol );
96 }
97 else
98 {
99 out.write( b );
100 }
101 }
102
103 return new ByteArrayInputStream( out.toByteArray() );
104 }
105 catch ( IOException ioe )
106 {
107 throw new ResourceNotFoundException( "cannot read resource", ioe );
108 }
109 finally
110 {
111 IOUtil.close( in );
112 }
113 }
114
115 public boolean isSourceModified( Resource resource )
116 {
117 return false;
118 }
119
120 public long getLastModified( Resource resource )
121 {
122 return 0;
123 }
124 }