/* * [JglossHead.java] * * Summary: Produce the header on a Java Glossary *.html file. * * 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.common18.BigDate; 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 *.html file. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * @since 2009 */ public final class JglossHead extends Head { /** * how to use the macro */ private static final String USAGE = "\nJglossHead macro needs description [lastReviewedDate]"; /** * 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 parms parameters from macro command line. parm[0] = title description of fragment. * @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 ( !( 1 <= parms.length && parms.length <= 2 ) ) { throw new IllegalArgumentException( USAGE ); } // unqualified e.g. sniff.html String title = parms[ 0 ]; JglossCustomiser s = new JglossCustomiser(); final char letterCode = s.getLetterCode( title.charAt( 0 ) ); final String lastReviewedDate; if ( parms.length > 1 ) { lastReviewedDate = parms[ 1 ]; if ( !BigDate.isValid( lastReviewedDate ) ) { throw new IllegalArgumentException( "JglossHead macro lastReviewedDate must have be a valid date of form yyyy-mm-dd." ); } } else { lastReviewedDate = null; } final String ancestorFile = s.getFilenameForLetterCode( letterCode ); // we don't create ancestor, just link to it. final String ancestor = s.getDescriptionForLetterCode( letterCode ); final String shortTitle; switch ( title ) { case "&": shortTitle = "ampersand"; break; case "&&": shortTitle = "McCarthy And"; break; default: shortTitle = title; } title = shortTitle + " : Java Glossary"; final String description = configuration.getCompanyName() + " Java & Internet Glossary : " + shortTitle; final String keywords = "Java, terminology, glossary, Roedy Green, primer, overview, introduction, precis, definition, " + shortTitle; final String icon = "icon16/jgloss.png"; final String image = null; final String sectionFile = "jgloss/jgloss.html"; final String sectionTitle = "Java Glossary"; final String subSectionFile = "jgloss/" + ancestorFile; // webroot relative final String extraNavigation = buildExtraNavigation(); return generalHead( title, shortTitle, description, shortTitle, "titlejgloss", keywords, icon, null, image, null, extraNavigation, sectionFile, sectionTitle, subSectionFile, ancestor, null, null, null, null, /* addendum */ Indexing.LETTERINDEX, GoogleAdSense.MEDIUM_RECTANGLE, lastReviewedDate, null ); } }