Package org.jostraca.directive

Source Code of org.jostraca.directive.CollapseWhiteSpaceDirective

/*
* Name:    CollapseWhiteSpaceDirective
* 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.TemplateActionHandler;

import org.jostraca.unit.BasicUnitList;

import org.jostraca.transform.TextualTransformManager;
import org.jostraca.transform.TextualTransformManagerTable;
import org.jostraca.transform.CollapseWhiteSpaceTransform;
import org.jostraca.transform.TextualTransform;

import org.jostraca.util.PropertySet;


/** Remove new lines in text elements.
*  Usage:<br />
*  &nbsp;&nbsp;&lt;% @collapseWhiteSpace %&gt;
*  &nbsp;&nbsp;&lt;% @| %&gt;
*/
public class CollapseWhiteSpaceDirective implements Directive {

  // private static
  private static final String   NAME    = "collapseWhiteSpace";
  private static final String[] ALIASES = new String[] { NAME, "|" };



  // private instance
  private TextualTransform iCollapseWhiteSpaceTransform = new CollapseWhiteSpaceTransform();



  // public methods

  public CollapseWhiteSpaceDirective() throws DirectiveException {
    // does nothing
  }


  // interface Directive

  public void perform( String                       pDirectiveName,
                       String                       pArguments,

                       BasicUnitList                pUnitList,
                       TemplateActionHandler        pTemplateActionHandler,

                       PropertySet                  pPropertySet,
                       TextualTransformManagerTable pTextualTransformManagerTable
                       ) throws DirectiveException
  {
    try {
      // toggle
      TextualTransformManager textTTM = pTextualTransformManagerTable.getTextTTM();
      if( textTTM.contains( iCollapseWhiteSpaceTransform ) ) {
        textTTM.remove( iCollapseWhiteSpaceTransform );
      }
      else {
        textTTM.prepend( iCollapseWhiteSpaceTransform );
      }

      // 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() );
    }
  }


  public String getName() {
    return NAME;
  }

  /** Should include value of getName() */
  public String[] getAliases() {
    return ALIASES;
  }

}
TOP

Related Classes of org.jostraca.directive.CollapseWhiteSpaceDirective

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.