/* * [BglossHead.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.BglossCustomiser; 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 BglossHead extends Head { /** * how to use the macro */ private static final String USAGE = "\nBglossHead macro needs description, [lastReviewedDate]."; /** * 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 buildBglossButton( final File fileBeingProcessed ) { final String bglossImageRef = BuildImage.buildImgTag( "navigate/bgloss.png", "go to the Buyer Glossary Home", ImageAlignment.middle, "plain", fileBeingDistributed ); return ( Tools.completeLink( "bgloss/bgloss.html", bglossImageRef, "plain", fileBeingDistributed ) ); } /** * build code to display and link to the Bgloss home and buyer glossary * * @return genernated html code */ private String buildExtraNavigation() { // If jgloss 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 jgloss.html // if bgloss icon in Java glossary, goes to bgloss.html. // But icon on bgloss.html itself gots to master index (not handled here). final FastCat sb = new FastCat( 4 ); sb.append( buildBglossButton( fileBeingProcessed ), "\n" ); sb.append( buildJglossButton( fileBeingProcessed ), "\n" ); return sb.toString(); } /** * build a button to go in the Buyer glossary to link to the Java glossary * * @param fileBeingProcessed where we will place this button. */ private String buildJglossButton( final File fileBeingProcessed ) { String jglossLinkTo = "jgloss/" + Tools.basicNameWithExtension( fileBeingProcessed ); final File linkToFile = Tools.toFileFromUPath( jglossLinkTo ); if ( !linkToFile.exists() ) { // no equivalent file, use base page jglossLinkTo = "jgloss/jgloss.html"; } final String jglossImageRef = BuildImage.buildImgTag( "navigate/jgloss.png", "go to the Java Glossary", ImageAlignment.middle, "plain", fileBeingDistributed ); return ( Tools.completeLink( jglossLinkTo, jglossImageRef, "plain", fileBeingDistributed ) ); } /** * Generate the header for a bgloss 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 ); } final BglossCustomiser s = new BglossCustomiser(); String title = parms[ 0 ]; 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( "BglossHead 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 = title; title = shortTitle + " : Computer Hardware Buyers’ Glossary"; final String description = configuration.getCompanyName() + " Computer Hardware Buyers’ Glossary: " + shortTitle; final String keywords = "Computer Hardware Buyers’ Glossary, Roedy Green, overview, introduction, precis, definition, " + shortTitle; final String icon = "icon16/bgloss.png"; final String sectionFile = "bgloss/bgloss.html"; final String sectionTitle = "Computer Hardware Buyers’ Glossary Home"; final String subSectionFile = "bgloss/" + ancestorFile; final String extraNavigation = buildExtraNavigation(); return generalHead( title, shortTitle, description, shortTitle, "titlebgloss", keywords, icon, null, null, null, extraNavigation, sectionFile, sectionTitle, subSectionFile, ancestor, null, null, null, null, Indexing.LETTERINDEX, GoogleAdSense.MEDIUM_RECTANGLE, lastReviewedDate, null ); } }