1 package org.apache.maven.archiva.web.startup;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
25 import org.apache.commons.lang.StringUtils;
26 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
27 import org.slf4j.LoggerFactory;
32 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 * role="org.apache.maven.archiva.web.startup.Banner"
41 public static String encode( String raw )
43 StringBuffer encoded = new StringBuffer();
44 int rawlen = raw.length();
46 for ( int i = 0; i < rawlen; i++ )
48 char c = raw.charAt( i );
51 encoded.append( "$." );
55 encoded.append( "$$" );
59 encoded.append( "$n" );
61 else if ( Character.isDigit( c ) )
65 else if ( Character.isLetter( c ) )
67 encoded.append( rot13( c ) );
69 else if ( i < raw.length() - 1 )
74 for ( int n = i; !done; n++ )
98 encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
108 return encoded.toString();
111 public static String decode( String encoded )
113 StringBuffer decoded = new StringBuffer();
114 int enlen = encoded.length();
115 for ( int i = 0; i < enlen; i++ )
117 char c = encoded.charAt( i );
120 char nc = encoded.charAt( i + 1 );
123 decoded.append( '$' );
126 else if ( nc == '.' )
128 decoded.append( '\\' );
131 else if ( nc == 'n' )
133 decoded.append( '\n' );
136 else if ( Character.isDigit( nc ) )
140 while ( Character.isDigit( nc ) )
142 count = ( count * 10 );
143 count += ( nc - '0' );
144 nc = encoded.charAt( ++nn );
146 for ( int d = 0; d < count; d++ )
148 decoded.append( nc );
153 else if ( Character.isLetter( c ) )
155 decoded.append( rot13( c ) );
163 return decoded.toString();
166 private static char rot13( char c )
168 if ( ( c >= 'a' ) && ( c <= 'z' ) )
177 else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
192 public static String injectVersion( String text, String version )
194 Pattern pat = Pattern.compile( "#{2,}" );
195 Matcher mat = pat.matcher( text );
196 StringBuffer ret = new StringBuffer();
199 while ( mat.find( off ) )
201 ret.append( text.substring( off, mat.start() ) );
202 String repl = mat.group();
203 ret.append( StringUtils.center( version, repl.length() ) );
207 ret.append( text.substring( off ) );
209 return ret.toString();
212 public static String getBanner( String version )
214 String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 | Ba" +
215 " orunys bs nyy bs gur nycnpn'f |$n$14 | (~' __| gbvyvat njnl ba " +
216 "gur Ncnpur Znira |$n$6 _,--.$3_/ |$4 $.$5 cebwrpg grnzf, V jbhyq y" +
217 "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5 jrypbzr lbh gb Znira Nepuvin$4 |$" +
218 "n$4 | ($6 $. /$6 | $32# |$n$5 $. )$._/ ,_/$7 |$36 |$n$5 / /$3 " +
219 "( |/$9 | uggc://znira.ncnpur.bet/nepuvin/ |$n$4 ( |$4 ( |$10 | ne" +
220 "puvin-hfref@znira.ncnpur.bet$4 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
222 return injectVersion( decode( encodedBanner ), version );
225 public void display()
227 String banner = getBanner( ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) );
228 LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + "\n" + banner );