/* * [JglossLetterHead.java] * * Summary: Produce the header on a Java Glossary letter index document. * * 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.8 2009-02-06 include go package in ZIP bundle. */ package com.mindprod.htmlmacros.macro; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.support.BuildImage; import com.mindprod.htmlmacros.support.GoogleAdSense; import com.mindprod.htmlmacros.support.ImageAlignment; import com.mindprod.htmlmacros.support.Indexing; import com.mindprod.htmlmacros.support.Tools; import com.mindprod.qf.JglossCustomiser; import java.io.File; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Produce the header on a Java Glossary letter index document. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * @since 2009 */ public final class JglossLetterHead extends Head { /** how to use the macro */ /** * how to use the macro */ private static final String USAGE = "\nJglossLetterHead macro needs a letterCode."; /** * build a button to go in the Java glossary to link to the Buyer glossary * * @param fileBeingProcessed where we will place this button. */ private String buildBGlossButton( final File fileBeingProcessed ) { String bglossLinkTo = "bgloss/" + Tools.basicNameWithExtension( fileBeingProcessed ); final File linkToFile = Tools.toFileFromUPath( bglossLinkTo ); if ( !linkToFile.exists() ) { // no equivalent file, use base page bglossLinkTo = "bgloss/bgloss.html"; } final String bglossImageRef = BuildImage.buildImgTag( "navigate/bgloss.png", "go to the Computer Buyer’s Glossary", ImageAlignment.middle, "plain", fileBeingDistributed ); return ( Tools.completeLink( bglossLinkTo, bglossImageRef, "plain", fileBeingDistributed ) ); } /** * build code to display and link to the Jgloss home and buyer glossary * * @return genernated html code */ private String buildExtraNavigation() { // If bgloss icon in Java glossary, try to go to similar page in Buyer glossary. // e.g. master -> master, page index -> page index, item -> item // if no match go to bgloss.html // if jgloss icon in Java glossary, goes to jgloss.html. // But icon on jgloss.html itself gots to master index (not handled here). final FastCat sb = new FastCat( 4 ); sb.append( buildJGlossButton( fileBeingProcessed ), "\n" ); sb.append( buildBGlossButton( fileBeingProcessed ), "\n" ); return sb.toString(); } /** * build a button to go in the Java glossary to link to the Java glossary home * * @param fileBeingProcessed where we will place this button. */ private String buildJGlossButton( final File fileBeingProcessed ) { final String jglossImageRef = BuildImage.buildImgTag( "navigate/jgloss.png", "go to the Java Glossary Home", ImageAlignment.middle, "plain", fileBeingDistributed ); return ( Tools.completeLink( "jgloss/jgloss.html", jglossImageRef, "plain", fileBeingDistributed ) ); } /** * Generate the header for a jgloss html document. * * @param letterCode code A-Z 0 * ~ * * @return expanded macro HTML */ private String expand( char letterCode ) { final JglossCustomiser s = new JglossCustomiser(); final String title = s.getTitleForLetterCode( letterCode ) + " : Java Glossary"; final String shortTitle = s.getDescriptionForLetterCode( letterCode ); final String description = configuration.getCompanyName() + " Java & Internet glossary : " + s.getDescriptionForLetterCode( letterCode ); final String keywords = "Java, terminology, glossary, Roedy Green"; final String icon16 = "icon16/jgloss.png"; final String sectionFile = "jgloss/jgloss.html"; final String sectionTitle = "Java Glossary Home"; final String extraNavigation = buildExtraNavigation(); return generalHead( title, shortTitle, description, shortTitle, "titlejglossindex", keywords, icon16, null, null, null, extraNavigation, sectionFile, sectionTitle, null, null, null, null, null, null, Indexing.LETTERINDEX, GoogleAdSense.NONE, null, null ); } /** * Generate the header for a Java Glossary letter index document. * * @param parms parameters from macro command line. parm[0] = letterCode. 0=all numbers *=all * punctuation ~=master index A-Z=letter * @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( "H" ); } if ( parms.length != 1 || parms[ 0 ].length() == 0 ) { throw new IllegalArgumentException( USAGE ); } // already converted to a letter code. char letterCode = Character.toUpperCase( parms[ 0 ].charAt( 0 ) ); return expand( letterCode ); } }