/*
* Name: BasicTemplateElementProcessor
* Authors: Richard Rodger
*
* Copyright (c) 2001-2004 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
// package
package org.jostraca;
// import
import org.jostraca.util.Internal;
import org.jostraca.util.PropertySet;
import org.jostraca.util.StandardException;
import org.jostraca.unit.UnitList;
import org.jostraca.unit.BasicUnitList;
import org.jostraca.transform.TextualTransformManagerTable;
/** Basic processor for template elements (text,script,etc.)
*/
public class BasicTemplateElementProcessor implements TemplateElementProcessor {
// public static
public static final String CN = BasicTemplateElementProcessor.class.getName();
public static final String REGEXP_PART_any_whitespace = "\\s*";
public static final String REGEXP_PART_any_whitespace_at_start = "^\\s*";
public static final String REGEXP_PART_submatch_any_whitespace_any_chars_at_end = "(\\s*.*)$";
public static final String REGEXP_PART_submatch_section_name = "([a-zA-Z_-][0-9a-zA-Z_-]+)";
public static final String NEWLINE = "\n"; // internal representation
// private instance
private BasicUnitList iUnitList;
private TemplateActionHandler iTemplateActionHandler;
private PropertySet iPropertySet;
private TextualTransformManagerTable iTextualTransformManagerTable;
private Template iTemplate;
private BasicTextElementProcessor iTextElement;
private BasicExpressionElementProcessor iExpressionElement;
private BasicScriptElementProcessor iScriptElement;
private BasicDirectiveElementProcessor iDirectiveElement;
// constructors
/** Constructor. Needs TemplateActionHandler and PropertySet.
* @param pTemplateActionHandler Results of processing operations are sent here.
* @param pPropertySet PropertySet used for parse.
*/
public BasicTemplateElementProcessor
( TemplateActionHandler pTemplateActionHandler,
PropertySet pPropertySet,
Template pTemplate )
{
TemplateActionHandler tah = (TemplateActionHandler) Internal.null_arg( pTemplateActionHandler );
PropertySet ps = (PropertySet) Internal.null_arg( pPropertySet );
Template tm = (Template) Internal.null_arg( pTemplate );
iUnitList = new BasicUnitList();
iTemplateActionHandler = tah;
iPropertySet = ps;
iTextualTransformManagerTable = new TextualTransformManagerTable( iPropertySet );
iTemplate = tm;
// create the specific template element processors.
// these all implement BasicGenericElementProcessor which
// expects non null arguments.
iTextElement = new BasicTextElementProcessor( iUnitList, iTemplateActionHandler, iPropertySet,
iTextualTransformManagerTable );
iExpressionElement = new BasicExpressionElementProcessor( iUnitList, iTemplateActionHandler, iPropertySet,
iTextualTransformManagerTable );
iScriptElement = new BasicScriptElementProcessor( iUnitList, iTemplateActionHandler, iPropertySet,
iTextualTransformManagerTable );
iDirectiveElement = new BasicDirectiveElementProcessor( iUnitList, iTemplateActionHandler, iPropertySet,
iTextualTransformManagerTable, iTemplate );
}
// interface TemplateElementProcessor
/** @see org.jostraca.TemplateElementProcessor */
public String process( Block pBlock ) throws StandardException {
Block b = (Block ) Internal.null_arg( pBlock );
if( iTextElement.isMatch( b ) ) {
return iTextElement.process( b );
}
else if( iExpressionElement.isMatch( b ) ) {
return iExpressionElement.process( b );
}
else if( iDirectiveElement.isMatch( b ) ) {
return iDirectiveElement.process( b );
}
else if( iScriptElement.isMatch( b ) ) {
return iScriptElement.process( b );
}
else {
throw new TemplateElementProcessorException
( TemplateElementProcessorException.CODE_unknown_element, b.toString() );
}
}
public String getContent() {
return iTextElement.getContent();
}
// transitional method
public UnitList getUnitList() {
return iUnitList;
}
public String toString() {
return "BasicTemplateElementProcessor: "+iTextualTransformManagerTable;
}
}