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>
37 public static String encode( String raw )
39 StringBuffer encoded = new StringBuffer();
40 int rawlen = raw.length();
42 for ( int i = 0; i < rawlen; i++ )
44 char c = raw.charAt( i );
47 encoded.append( "$." );
51 encoded.append( "$$" );
55 encoded.append( "$n" );
57 else if ( Character.isDigit( c ) )
61 else if ( Character.isLetter( c ) )
63 encoded.append( rot13( c ) );
65 else if ( i < raw.length() - 1 )
70 for ( int n = i; !done; n++ )
94 encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
104 return encoded.toString();
107 public static String decode( String encoded )
109 StringBuffer decoded = new StringBuffer();
110 int enlen = encoded.length();
111 for ( int i = 0; i < enlen; i++ )
113 char c = encoded.charAt( i );
116 char nc = encoded.charAt( i + 1 );
119 decoded.append( '$' );
122 else if ( nc == '.' )
124 decoded.append( '\\' );
127 else if ( nc == 'n' )
129 decoded.append( '\n' );
132 else if ( Character.isDigit( nc ) )
136 while ( Character.isDigit( nc ) )
138 count = ( count * 10 );
139 count += ( nc - '0' );
140 nc = encoded.charAt( ++nn );
142 for ( int d = 0; d < count; d++ )
144 decoded.append( nc );
149 else if ( Character.isLetter( c ) )
151 decoded.append( rot13( c ) );
159 return decoded.toString();
162 private static char rot13( char c )
164 if ( ( c >= 'a' ) && ( c <= 'z' ) )
173 else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
188 public static String injectVersion( String text, String version )
190 Pattern pat = Pattern.compile( "#{2,}" );
191 Matcher mat = pat.matcher( text );
192 StringBuffer ret = new StringBuffer();
195 while ( mat.find( off ) )
197 ret.append( text.substring( off, mat.start() ) );
198 String repl = mat.group();
199 ret.append( StringUtils.center( version, repl.length() ) );
203 ret.append( text.substring( off ) );
205 return ret.toString();
208 public static String getBanner( String version )
210 String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 | Ba" +
211 " orunys bs nyy bs gur nycnpn'f |$n$14 | (~' __| gbvyvat njnl ba " +
212 "gur Ncnpur Nepuvin |$n$6 _,--.$3_/ |$4 $.$5 cebwrpg grnz, V jbhyq y" +
213 "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5 jrypbzr lbh gb Nepuvin$6 |$" +
214 "n$4 | ($6 $. /$6 | $32# |$n$5 $. )$._/ ,_/$7 |$36 |$n$5 / /$3 " +
215 "( |/$9 | uggc://nepuvin.ncnpur.bet/ |$n$4 ( |$4 ( |$10 | hf" +
216 "ref@nepuvin.ncnpur.bet$7 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
218 return injectVersion( decode( encodedBanner ), version );
221 public void display()
223 String banner = getBanner( ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) );
224 LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + "\n" + banner );