/*
* [BibleHead.java]
*
* Summary: Header for one of KJV bible pages. There are four patterns:
- macro BibleHead Chronologically on.
*
* Copyright: (c) 2004-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.
* kjv/index.html
- macro BibleHead Alphabetically on kjv/alpha.html
- macro BibleHead
* "2
* Kings" on kjv/2_Kings/index.html
- macro BibleHead "2 Kings" on
* kjv/2_Kings/1.html
* Macro expansion depends on file name as well as macro parms.
*/
package com.mindprod.htmlmacros.macro;
import com.mindprod.htmlmacros.support.GoogleAdSense;
import com.mindprod.htmlmacros.support.Indexing;
import java.io.File;
import java.io.IOException;
import static com.mindprod.htmlmacros.macro.Global.configuration;
import static java.lang.System.*;
/**
* Header for one of KJV bible pages. There are four patterns: - macro BibleHead Chronologically on.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.8 2009-02-06 include go package in ZIP bundle.
* kjv/index.html
- macro BibleHead Alphabetically on kjv/alpha.html
- macro BibleHead "2
* Kings" on kjv/2_Kings/index.html
- macro BibleHead "2 Kings" on kjv/2_Kings/1
* html
* Macro expansion depends on file name as well as macro parms.
* @since 2004
*/
public final class BibleHead extends Head
{
/**
* big logo
*/
private static final String ICON128 = "icon128/bible.png";
/**
* small ICON16
*/
private static final String ICON16 = "icon16/bible.png";
/**
* ICON64 logo
*/
private static final String ICON64 = "icon64/bible.png";
/**
* search engine keywords
*/
private static final String KEYWORDS =
"bible, testament, old testament, new testament, King James bible, gospel, Christian";
/**
* how to use the macro
*/
private static final String USAGE = "\nBibleHead macro needs booktitle";
/**
* build header for book e.g. Revelation.
*
* @param bookTitle name of book in bible, e.g. Revelation
*
* @return generated HTML
*/
@SuppressWarnings( { "UnnecessaryLocalVariable" } )
private String buildBookHead( String bookTitle )
{
final String sectionFile = "kjv/index.html";
final String sectionTitle = "King James Bible";
final String title = "King James Bible : " + bookTitle;
final String shortTitle = bookTitle;
final String description = title + " (public domain text)";
final String subSectionTitle = null;
final String subSectionFile = null;
return generalHead( title,
shortTitle,
description,
shortTitle,
"titlesubsection",
KEYWORDS,
ICON16,
null,
ICON128,
null,
null,
sectionFile,
sectionTitle,
subSectionFile,
subSectionTitle,
null,
null,
null,
null,
Indexing.NONE,
GoogleAdSense.MEDIUM_RECTANGLE,
null,
null
);
}
/**
* Build header for an individual chapter of a bookInternalName.
*
* @param bookInternalName bookInternalName file name
* @param chapter number of chapter of this page
* @param bookTitle name of book in bible, e.g. Revelation
*
* @return generated HTML
*/
@SuppressWarnings( { "UnnecessaryLocalVariable" } )
private String buildChapterHead( String bookInternalName,
String bookTitle,
int chapter
)
{
// handle header for jkj/Revelation/1.html
if ( bookInternalName.length() == 0 )
{
throw new IllegalArgumentException(
"BibleHead can't have chapter without a bookInternalName" );
}
final String sectionFile = "kjv/index.html";
final String sectionTitle = "King James Bible";
final String title =
"King James Bible : " + bookTitle + " : Chapter " + chapter;
final String shortTitle = bookTitle + " " + chapter;
final String breadCrumbTitle = "Chapter " + chapter;
final String description = title + " (public domain text)";
final String subSectionTitle = bookTitle;
// breadcrumbs will go back to the Alphabetical root no matter
// how we really got here.
final String subSectionFile = "kjv/" + bookInternalName + "/index.html";
return generalHead( title,
shortTitle,
description,
breadCrumbTitle,
"titlesubsubsection",
KEYWORDS,
ICON16,
null,
ICON64,
null,
null,
sectionFile,
sectionTitle,
subSectionFile,
subSectionTitle,
null,
null,
null,
null,
Indexing.NONE,
GoogleAdSense.MEDIUM_RECTANGLE,
null,
null
);
}
/**
* build header for the root Chronologically or Alphabetically document. root Chronologically or Alphabetically
* doing title for kjv/index.html or kjv/alpha.html bookTitle is actually title for whole bible
*
* @param sortOrder Alphabetically or Chronologically
*
* @return generated HTML
*/
@SuppressWarnings( { "UnnecessaryLocalVariable" } )
private String buildRootDocumentHead( String sortOrder )
{
assert sortOrder.equals( "Chronologically" ) || sortOrder.equals(
"Alphabetically" ) : "unexpected use of BibleHead";
final String title = "King James Bible : " + sortOrder;
final String shortTitle = sortOrder;
final String description = title + " (public domain text)";
final String sectionFile = null;
final String sectionTitle = null;
final String subSectionTitle = null;
final String subSectionFile = null;
return generalHead( title,
null,
description,
shortTitle,
"titlesection",
KEYWORDS,
ICON16,
null,
ICON128,
null,
null,
sectionFile,
sectionTitle,
subSectionFile,
subSectionTitle,
null,
null,
null,
null,
Indexing.NONE,
GoogleAdSense.MEDIUM_RECTANGLE,
null,
null
);
}
/**
* get the internal name used in KVJ macro e.g. 2_Kings for the book. null for root document.
*
* @return e.g. 2_Kings
*/
private String getBookInternalName()
{
try
{
// Its canonical name will be something like:
// E:/mindprod/kjv/Revelation/index.html or
// E:/mindprod/kjv/Revelation/1.html or
// E:/mindprod/kjv/index.html or
// E:/mindprod/kjv/alpha.html
// don't use getCanOrAbsPath
final String canonical = fileBeingDistributed.getCanonicalPath();
// LOCAL_WEBROOT_WITH_BACKSLASHES is E:\\mindprod
final String dirShouldStartWidth = ( configuration.getLocalWebrootWithSlashes() + "/kjv/" ).replace( '/',
File.separatorChar )
.toLowerCase();
if ( !canonical.toLowerCase().startsWith( dirShouldStartWidth ) )
{
throw new IllegalArgumentException( "BibleHead only valid in "
+ dirShouldStartWidth
+ " directory." );
}
// chop off lead E:\mindprod\kjv\
final String headChopped =
canonical.substring( dirShouldStartWidth.length() );
// now chop off the tail filename leaving the book, e.g. Revelation.
final int place = headChopped.lastIndexOf( File.separatorChar );
if ( place >= 0 )
{
return headChopped.substring( 0, place );
}
else
{
//e.g. kjv/index.html or kjv/alpha.html
return null;
}
}
catch ( IOException e )
{
throw new IllegalArgumentException(
"BibleHead getCanonicalPath failed" );
}
}
/**
* Get chapter, 0 for a root document or a book header.
*
* @return 0 or number 1 .. 99
*/
private int getChapter()
{
// unqualified e.g. 1.html or index.html
final String filename = fileBeingDistributed.getName().toLowerCase();
assert filename.endsWith( ".html" ) : "BibleHead being used on non *.html";
// chop trailing .html
final String chapterString =
filename.substring( 0, filename.length() - ".html".length() );
try
{
return Integer.parseInt( chapterString );
}
catch ( NumberFormatException e )
{
return 0;
}
}
/**
* Generate the header for a KJV King James Version bible page document, either root document,
* book index or 1.html page
*
* @param parms parameters from macro command line. - parm[0] = book title e.g. "Song of Songs"
*
*
*
chapter number comes from file name, not from parm.
* @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( "B" );
}
if ( parms.length != 1 )
{
throw new IllegalArgumentException( USAGE );
}
final String bookTitle = parms[ 0 ];
// null for a rootDocument
final String bookInternalName = getBookInternalName();
int chapter = getChapter();
// At this point we have bookInternalName -- the name of the file for a bookInternalName in the bible
// and chapter.
// null 0 indicates a rootDocument.
if ( bookInternalName == null )
{
// Either the Chronologically or Alphabetically root document.
return buildRootDocumentHead( bookTitle );
}
else if ( chapter == 0 )
{
return buildBookHead( bookTitle );
}
else
{
return buildChapterHead( bookInternalName, bookTitle, chapter );
}
}
}