/* * [CoSection.java] * * Summary: Produce the header for a Cherokee Obama Chapter section. * * Copyright: (c) 2010-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 2010-01-23 initial version, cloned from Living Love Head.. */ package com.mindprod.htmlmacros.macro; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.support.ConfigurationForCherokeeObama; import com.mindprod.htmlmacros.support.GoogleAdSense; import com.mindprod.htmlmacros.support.Indexing; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Produce the header for a Cherokee Obama Chapter section. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2010-01-23 initial version, cloned from Living Love Head. * @since 2010-01-23 */ public final class CoSection extends Head { // declarations private static final String[] LOW_ROMANS = { "0", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV" }; private static final String SYNOPSIS = ConfigurationForCherokeeObama.getSynopsis(); /** * how to use the macro */ private static final String USAGE = "\nCoChapter macro needs {chapter#} {chapterName} {section#} {sectionName} " + "[keywords]"; // /declarations // methods /** * build description for head meta description * * @param chapterNumber chapter number * @param chapterName description of what chapter is about * @param sectionNumberRoman section number Roman numerals * @param sectionName description of what section is about * * @return concatenation as an html table */ private static String buildDescriptionForMetaHead( final int chapterNumber, final String chapterName, final String sectionNumberRoman, final String sectionName ) { final FastCat sb = new FastCat( 8 ); sb.append( "Dreaming Gods of Gaia : Chapter " ); sb.append( chapterNumber ); sb.append( " : " ); sb.append( chapterName ); sb.append( " : Section " ); sb.append( sectionNumberRoman ); sb.append( " : " ); sb.append( sectionName ); return sb.toString(); } // method /** * build title html for top -of page * * @param chapterNumber chapter number * @param chapterName description of what chapter is about * @param sectionNumberRoman section number Roman numerals * @param sectionName description of what section is about * * @return concatenation as an html table */ private static String buildLongTitle( final int chapterNumber, final String chapterName, final String sectionNumberRoman, final String sectionName ) { final FastCat sb = new FastCat( 14 ); sb.append( "" ); sb.append( "" ); sb.append( "" ); sb.append( "
multiline title
Dreaming " + "Gods of Gaia
Chapter " ); sb.append( chapterNumber ); sb.append( "" ); sb.append( chapterName ); sb.append( "
" ); sb.append( SYNOPSIS ); sb.append( "
Section " ); sb.append( sectionNumberRoman ); sb.append( "" ); sb.append( sectionName ); sb.append( "
" ); return sb.toString(); } // method /** * build a simplified header used by kindle * * @param sectionNumberRoman section as a Roman numeral String * @param sectionName title for section * @param keywords indexing keywords. * @param description long description, (might contain entities and tags). not null. for head meta * Description. * @param icon16 for title bar * * @return HTML for header and simplified title. */ private String buildKindleHead( final String sectionNumberRoman, final String sectionName, final String keywords, final String description, final String icon16 ) { final String sectionTitle = "Section " + sectionNumberRoman + " : " + sectionName; final FastCat sb = new FastCat( 5 ); // header sb.append( configuration.getDoctypeDefault( fileBeingDistributed ) ); final int firstCopyrightYear = configuration.getFirstCopyrightYear( fileBeingDistributed ); final String copyrightHolderForPage = configuration.getCopyrightHolderForPage( fileBeingDistributed ); if ( configuration.isUsingXHTML() ) { sb.append( buildInvisHead( "— " + sectionTitle, sectionTitle, description, keywords, icon16, firstCopyrightYear, copyrightHolderForPage ) ); } // append body, TOP anchor, CONFIG sb.append( "

" ); sb.append( sectionTitle ); sb.append( "

\n" ); return sb.toString(); } // method /** * Produce the header for an Produce the header for a Cherokee Obama Chapter * * @param parms parameters from macro command line. parms[0] = title description of fragment. parms[1] * = description parms[2] = keywords * @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( "S" ); } if ( !( 4 <= parms.length && parms.length <= 5 ) ) { throw new IllegalArgumentException( USAGE ); } final int chapterNumber = Integer.parseInt( parms[ 0 ] ); final int totalChapters = ConfigurationForCherokeeObama.SECTIONS_IN_CHAPTER.length - 1; if ( !( 1 <= chapterNumber && chapterNumber <= totalChapters ) ) { throw new IllegalArgumentException( "macro CoSection chapter number " + chapterNumber + " must be in " + "range 1.." + totalChapters ); } final String chapterName = parms[ 1 ]; final int sectionNumber = Integer.parseInt( parms[ 2 ] ); final int sectionsInChapter = ConfigurationForCherokeeObama.SECTIONS_IN_CHAPTER[ chapterNumber ]; if ( !( 1 <= sectionNumber && sectionNumber <= sectionsInChapter ) ) { throw new IllegalArgumentException( "macro CoSection section number " + sectionNumber + " must be in " + "range 1.." + sectionsInChapter ); } final String sectionNumberRoman = LOW_ROMANS[ sectionNumber ]; final String sectionName = parms[ 3 ]; // don't pad chapterNumber to 2 digits. final String hereBreadcrumbTitle = "Section " + sectionNumberRoman; final String longTitle = buildLongTitle( chapterNumber, chapterName, sectionNumberRoman, sectionName ); // make sure macro matches file name. // should be in dgg/dgg99/dgg99.html final String chapterNN = ST.toLZ( chapterNumber, 2 ); final String sectionNN = ST.toLZ( sectionNumber, 2 ); if ( !EIO.getCanOrAbsPath( fileBeingDistributed ).replace( '\\', '/' ).endsWith( "dgg/dgg" + chapterNN + "/dgg" + chapterNN + sectionNN + ".html" ) ) { throw new IllegalArgumentException( "CoSection chapter/section number does not match implied filename chapter/section." ); } final String keywords = "science fiction, Cherokee O’Bama, Dreaming Gods of Gaia, " + "witchcraft" + ( parms.length > 4 ? "," + parms[ 4 ] : "" ); final String description = buildDescriptionForMetaHead( chapterNumber, chapterName, sectionNumberRoman, sectionName ); final String icon16 = "icon16/seagull.png"; final String sectionBreadcrumbFile = "dgg/dgg" + chapterNN + "/dgg" + chapterNN + ".html"; final String sectionBreadcrumbTitle = "Chapter " + chapterNumber; final String relUpLink = "dgg" + chapterNN + ".html"; if ( configuration.isKindle() ) { return buildKindleHead( sectionNumberRoman, sectionName, keywords, description, icon16 ); } else { return generalHead( longTitle, description /* use also as shortTitle */, description, hereBreadcrumbTitle, "cosection", keywords, icon16, null, null, null, null, sectionBreadcrumbFile, sectionBreadcrumbTitle, null, null, null, null, relUpLink, "chapter page", Indexing.NONE, GoogleAdSense.NONE, null, null ); } } // method // /methods }