/* * [Repository.java] * * Summary: Generate link to a file in the Subversion repository. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-06-03 initial release. */ package com.mindprod.htmlmacros.macro; import com.mindprod.fastcat.FastCat; import static java.lang.System.*; /** * Generate link to a file in the Subversion repository. *

* browse(with browser), look(anonymous browse), access(with Tortoise) * * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-06-03 initial release. * @since 2009-06-03 */ public final class Repository extends Macro { /** * how to use the macro */ private static final String USAGE = "\nRepository macro needs access|browse|look|view com/mindprod/amper/ "; /** * access the Wush.net repository. For advanced skill users with a Tortoise Subversion client. * * @param filename fully qualified name file in the repository, using slashes. * * @return expand html for the link to repository. */ private static String access( String filename ) { final String humanName = calcHumanName( filename ); final FastCat sb = new FastCat( 7 ); // e.g. http://wush.net/svn/mindprod/com/mindprod/amper/ sb.append( "access " ); sb.append( humanName ); sb.append( " source in repository with [Tortoise] Subversion client on wush" + ".net/svn/mindprod/" ); sb.append( filename ); sb.append( "" ); return sb.toString(); } /** * browse the Wush.net repository. For intermediate skill users. Uses a browser. Generates same link as Look, * just different text. * browse displays name of the file in the repository, look does not. * * @param filename fully qualified name file in the repository, using slashes. Has trailing / * * @return expand html for the link to repository. */ private static String browse( String filename ) { final String humanName = calcHumanName( filename ); final FastCat sb = new FastCat( 5 ); // e.g.https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Famper%2F sb.append( "browse " ); sb.append( humanName ); sb.append( " source in repository" ); return sb.toString(); } /** * get name that will display for give fully qualified name * * @param filename fully qualified dir or filename, with trailing / * * @return name to display */ private static String calcHumanName( final String filename ) { if ( filename.endsWith( "/" ) ) { // we have just a package // extract just the last leg of the package name String leg = filename.substring( 0, filename.length() - 1 ); int place = leg.lastIndexOf( '/' ); return leg.substring( place + 1 ); } else { // extract just the filename int place = filename.lastIndexOf( '/' ); return filename.substring( place + 1 ); } } /** * look (browse without naming the package) the Wush.net repository. For intermediate skill users. * Used by prices, which puts name of package elsewhere. * browse displays name of the file in the repository, look does not. * * @param filename fully qualified name file in the repository, using slashes. * * @return expand html for the link to repository. */ private static String look( String filename ) { final FastCat sb = new FastCat( 3 ); sb.append( "browse source repository" ); return sb.toString(); } /** * @param parms command filename. filename. with slashes. Package alone ends in / * @param quiet true if want output suppressed. * @param verbose @return expanded macro HTML */ public String expandMacro( String[] parms, final boolean quiet, final boolean verbose ) { if ( !quiet ) { out.print( "R" ); } if ( parms.length != 2 ) { throw new IllegalArgumentException( USAGE ); } final String command = parms[ 0 ]; // filename has no lead / but a trailing / final String fileName = parms[ 1 ]; if ( command.equals( "access" ) ) { return access( fileName ); } else if ( command.equals( "browse" ) ) { return browse( fileName ); } else if ( command.equals( "look" ) ) { return look( fileName ); } else { throw new IllegalArgumentException( USAGE ); } } }