/*
* Name: OneLineDirective
* Author: 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.directive;
// import
import org.jostraca.Template;
import org.jostraca.TemplateActionHandler;
import org.jostraca.unit.BasicUnitList;
import org.jostraca.transform.TextualTransformManager;
import org.jostraca.transform.TextualTransformManagerTable;
import org.jostraca.transform.OneLineTransform;
import org.jostraca.transform.TextualTransform;
import org.jostraca.util.PropertySet;
/** Remove new lines and compress space in text elements.
* Usage:<br />
* <% @oneLine %>
* <% @_ %>
*/
public class OneLineDirective implements Directive {
// private static
private static final String NAME = "oneLine";
private static final String[] ALIASES = new String[] { NAME, "_" };
// private instance
private TextualTransform iOneLineTransform = new OneLineTransform();
// public methods
public OneLineDirective() throws DirectiveException {
// does nothing
}
// interface Directive
public String perform(
String pDirectiveName,
String pArguments,
BasicUnitList pBasicUnitList,
TemplateActionHandler pTemplateActionHandler,
PropertySet pPropertySet,
TextualTransformManagerTable pTextualTransformManagerTable,
Template pTemplate
) throws DirectiveException
{
try {
// toggle
TextualTransformManager textTTM = pTextualTransformManagerTable.getTextTTM();
if( textTTM.contains( iOneLineTransform ) ) {
textTTM.remove( iOneLineTransform );
}
else {
textTTM.prepend( iOneLineTransform );
}
// REVIEW: this is deprecated
// REVIEW: need a cleaner way to do this - should be handled by
// TemplateScriptProcessor
// arguments can be any script content
pTemplateActionHandler.append( pArguments );
}
catch( Exception e ) {
throw new DirectiveException( e.getMessage() );
}
return null;
}
public String getName() {
return NAME;
}
/** Should include value of getName() */
public String[] getAliases() {
return ALIASES;
}
}