1 package org.apache.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 org.apache.commons.lang.StringUtils;
23 import org.slf4j.LoggerFactory;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
35 private static final String eol = System.getProperty("line.separator");
37 public static String encode( String raw )
39 // Canonicalize line ends to make them easier to process
40 raw = raw.replace("\r\n", "\n").replace("\r", "\n");
42 StringBuilder encoded = new StringBuilder();
43 int rawlen = raw.length();
45 for ( int i = 0; i < rawlen; i++ )
47 char c = raw.charAt( i );
50 encoded.append( "$." );
54 encoded.append( "$$" );
58 encoded.append( "$n" );
60 else if ( Character.isDigit( c ) )
64 else if ( Character.isLetter( c ) )
66 encoded.append( rot13( c ) );
68 else if ( i < raw.length() - 1 )
73 for ( int n = i; !done; n++ )
97 encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
107 return encoded.toString();
110 public static String decode( String encoded )
112 StringBuilder decoded = new StringBuilder();
113 int enlen = encoded.length();
114 for ( int i = 0; i < enlen; i++ )
116 char c = encoded.charAt( i );
119 char nc = encoded.charAt( i + 1 );
122 decoded.append( '$' );
125 else if ( nc == '.' )
127 decoded.append( '\\' );
130 else if ( nc == 'n' )
132 decoded.append( eol );
135 else if ( Character.isDigit( nc ) )
139 while ( Character.isDigit( nc ) )
141 count = ( count * 10 );
142 count += ( nc - '0' );
143 nc = encoded.charAt( ++nn );
145 for ( int d = 0; d < count; d++ )
147 decoded.append( nc );
152 else if ( Character.isLetter( c ) )
154 decoded.append( rot13( c ) );
162 return decoded.toString();
165 private static char rot13( char c )
167 if ( ( c >= 'a' ) && ( c <= 'z' ) )
176 else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
191 public static String injectVersion( String text, String version )
193 Pattern pat = Pattern.compile( "#{2,}" );
194 Matcher mat = pat.matcher( text );
195 StringBuilder ret = new StringBuilder();
198 while ( mat.find( off ) )
200 ret.append( text.substring( off, mat.start() ) );
201 String repl = mat.group();
202 ret.append( StringUtils.center( version, repl.length() ) );
206 ret.append( text.substring( off ) );
208 return ret.toString();
211 public static String getBanner( String version )
213 String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 | Ba" +
214 " orunys bs nyy bs gur nycnpnf |$n$14 | (~' __| gbvyvat njnl ba " +
215 "gur Ncnpur Nepuvin |$n$6 _,--.$3_/ |$4 $.$5 cebwrpg grnz, V jbhyq y" +
216 "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5 jrypbzr lbh gb Nepuvin$6 |$" +
217 "n$4 | ($6 $. /$6 | $32# |$n$5 $. )$._/ ,_/$7 |$36 |$n$5 / /$3 " +
218 "( |/$9 | uggc://nepuvin.ncnpur.bet/ |$n$4 ( |$4 ( |$10 | hf" +
219 "ref@nepuvin.ncnpur.bet$7 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
221 return injectVersion( decode( encodedBanner ), version );
224 public static void display( String version )
226 String banner = getBanner( version );
227 LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + eol + banner );