Package org.jostraca.util

Examples of org.jostraca.util.RegExpMatch


    if( pRecursionCount > MAX_RECURSION_COUNT_performIncludes ) {
      throw new TemplateException( TemplateException.CODE_infinite_recursion, pRecursionCount+" > "+MAX_RECURSION_COUNT_performIncludes );
    }

    String        source           = pSource;
    RegExpMatch   includeMatch     = null;
    String        includeText      = null;
    String        includeFile      = null;
    String        includeModifier  = null;
    int           numIncludes      = 0;
    int           numIncludeBlocks = 0;


    // normal includes
   
    String includeFilePath = Standard.EMPTY;
    try {
      RegExpMatch[] allincludes      = iIncludeRegExp.matchAll( source );
      numIncludes = allincludes.length;

      for( int includeI = 0; includeI < numIncludes; includeI++ ) {
        includeMatch = allincludes[ includeI ];
        includeText  = includeMatch.match();

        includeFile = includeMatch.matchFirstSub();
        includeFile = ( null == includeFile ? Standard.EMPTY : includeFile );
        includeFile    
          = ( includeFile.startsWith( Standard.QUOTE ) && includeFile.endsWith( Standard.QUOTE ) )
          ? includeFile.substring( 1, includeFile.length()-1 ) : includeFile;

        includeModifier = includeMatch.matchSecondSub();
        includeModifier = ( null == includeModifier ? Standard.EMPTY : includeModifier.trim() );

        // REVIEW: TemplatePath interaction with Template needs refactoring

        // include the file
        String includeBase = pIncludeBase;
        if( -1 != includeModifier.indexOf( INCLUDE_MOD_template_relative ) ) {
          includeBase = iTemplatePath.getTemplateFolder();
        }
        else if( -1 != includeModifier.indexOf( INCLUDE_MOD_output_relative ) ) {
          includeBase = getMergedPropertySet().get( Property.main_OutputFolder );
        }

        // another HACK
        File includeF = new File( includeFile );
        if( includeF.isAbsolute() || includeFile.startsWith("/") || includeFile.startsWith("\\") ) {
          includeFilePath = includeFile;
        }
        else {
          // REVIEW: possible user info message that include file does not exist when "if-exists" used?
          includeFilePath = includeBase + File.separatorChar + includeFile;
        }

        boolean onlyifexists = -1 != includeModifier.indexOf( INCLUDE_MOD_if_exists );

        String includeContent = Standard.EMPTY;

        try {
          includeContent = FileUtil.readFile( includeFilePath, ( onlyifexists ? FileUtil.EMPTY_IF_IO_ERROR : FileUtil.FAIL_ON_IO_ERROR ) );
        }

        // HACK
        // try to load from template path
        catch( Throwable t ) {
          BasicTemplatePath includeRef = new BasicTemplatePath( includeFile );
          //includeRef.resolve( iParameters.getList( Property.main_TemplatePath, Standard.COMMA  ));
          includeRef.resolve( getMergedPropertySet().getList( Property.main_TemplatePath, Standard.COMMA  ));
          includeFilePath = includeRef.getTemplatePath();
          includeContent = FileUtil.readFile( includeFilePath, ( onlyifexists ? FileUtil.EMPTY_IF_IO_ERROR : FileUtil.FAIL_ON_IO_ERROR ) );
        }

        int    startOfInclude = source.indexOf( includeText );
        if( 0 > startOfInclude ) { // paranoia ;)
          continue;
        }
        int   lengthOfInclude = includeText.length();
        source
          = source.substring( 0, startOfInclude )
          + includeContent
          + source.substring( startOfInclude + lengthOfInclude, source.length() )
          ;

        FileRefBuildResource includeBuildResource = new FileRefBuildResource( new FileRef( new File( includeFilePath ) ), iCodeWriterRef );
        iBuildResource.add( includeBuildResource );
      }
    }
    catch( IOException ioe ) {
      //ioe.printStackTrace();
      throw new TemplateException( TemplateException.CODE_include,
                                   new String[] { ValueCode.FILE, includeFilePath, ValueCode.TEMPLATE, iPath }, ioe );
    }
    catch( Exception e ) {
      e.printStackTrace();
      throw new TemplateException( TemplateException.CODE_include,
                                   new String[] { ValueCode.FILE, includeFilePath, ValueCode.TEMPLATE, iPath }, e );
    }


    // block includes

    RegExpMatch includeBlockMatch = null;
    String      includeBlockText  = null;
    String      includeBlockFile  = null;
    String      includeBlockMark = null;

    try {
      RegExpMatch[] allincludeblocks = iIncludeBlockRegExp.matchAll( source );
      numIncludeBlocks = allincludeblocks.length;

      for( int includeBlockI = 0; includeBlockI < numIncludeBlocks; includeBlockI++ ) {
        includeBlockMatch = allincludeblocks[ includeBlockI ];
        includeBlockText  = includeBlockMatch.match();
        includeBlockFile  = includeBlockMatch.matchFirstSub();
        includeBlockMark  = includeBlockMatch.matchSecondSub();

        RegExp markRegExp = RegExp.make( includeBlockMark, RegExp.ModeSet.DotMatchesNewline );

        // include the file block
        String  includeFileContent  = FileUtil.readFile( pIncludeBase + File.separatorChar + includeBlockFile );       
View Full Code Here


        throw new TemplateException( TemplateException.CODE_no_conf, new ValueSet( ValueCode.TEMPLATE, iPath ) );
      }
      else {
        PropertySet ps        = new PropertySet();
        boolean     foundConf = false;
        RegExpMatch conf      = null;
        String      props     = null;
        PropertySet propSet   = null;
        for( int confI = 0; confI < numConfs; confI++ ) {
          conf    = allconfs[ confI ];
          props   = conf.matchFirstSub();
          propSet = new PropertySet();
          propSet.parse( props );
          ps.overrideWith( propSet );
          foundConf = true;
        }
View Full Code Here

      pTemplateActionHandler.setDefaultSection( Section.NAME_body );
    }

    // set default section to first argument, and put everything else into that section
    else {
      RegExpMatch match = doRegExpMatchArguments( pArguments );

      if( match.hasMatch() ) {
        String sectionName = match.matchFirstSub();
        String content     = match.matchSecondSub();

        pTemplateActionHandler.setDefaultSection( sectionName );

        // REVIEW: this is deprecated
        pTemplateActionHandler.append( content );
View Full Code Here


  /** perform reg exp */
  private RegExpMatch doRegExpMatchArguments( String pContent ) throws DirectiveException {
    try {
      RegExpMatch match = iRegExpMatchArguments.matchFirst( pContent );
      return match;
    }
    catch( RegExpException e ) {
      throw new DirectiveException
        ( DirectiveException.CODE_regexp_mismatch, e.getMessage(),
View Full Code Here

    try {
      RegExp        savedFileRE = RegExp.make( "Saved\\s+file:\\s*(.*?)\r?\n" );
      RegExpMatch[] mA          = savedFileRE.matchAll( pOutResult );
      int           numM        = mA.length;
      for( int mI = 0; mI < numM; mI++ ) {
        RegExpMatch m = mA[mI];
        String      savedFile = m.matchSub(1);
        savedFilesV.addElement( savedFile );
      }
    }
    catch( Exception e ) {
      ErrorUtil.nonFatalMsg( e.getMessage() );
View Full Code Here

  }


  public void doMatchAllTests( RegExpProvider pREP ) throws Exception {
    RegExp      re01 = pREP.make( "a(.)\n" );
    RegExpMatch m[]  = re01.matchAll( "x\naa\nab\nac\ny\n" );
    assertEquals( 3, m.length );
    assertEquals( "aa\n", m[0].match() );
    assertEquals( "ab\n", m[1].match() );
    assertEquals( "ac\n", m[2].match() );
    assertEquals( "a", m[0].matchSub(1) );
View Full Code Here

    return NAME;
  }

 
  protected String parseArguments( List pArgs, String pArguments ) {
    RegExpMatch match = sIncludeArgsRegExp.matchFirst( pArguments );
    String path = match.matchFirstSub();

    String arg = match.matchSecondSub();
    String[] args = arg.split("\\s");
    pArgs.addAll(Arrays.asList(args));
   
    return path;
  }
View Full Code Here

  /** Remove extra white space
   */
  private String removeExtraWhiteSpace( String pText ) throws RegExpException {
    String newText = pText;

    RegExpMatch prefix = sRemoveExtraWhiteSpacePrefixRegExp.matchFirst( newText );
    if( prefix.hasMatch() ) {
      newText = prefix.matchFirstSub();
    }

    RegExpMatch suffix = sRemoveExtraWhiteSpaceSuffixRegExp.matchFirst( newText );
    if( suffix.hasMatch() ) {
      newText = suffix.matchFirstSub();
    }

    return newText;
  }
View Full Code Here

    try {
      RegExp        savedFileRE = RegExp.make( "Saved\\s+file:\\s*(.*?)\r?\n" );
      RegExpMatch[] mA          = savedFileRE.matchAll( pOutResult );
      int           numM        = mA.length;
      for( int mI = 0; mI < numM; mI++ ) {
        RegExpMatch m = mA[mI];
        String      savedFile = m.matchSub(1);
        savedFilesV.addElement( savedFile );
      }
    }
    catch( Exception e ) {
      ErrorUtil.nonFatalMsg( e.getMessage() );
View Full Code Here

        throw new TemplateException( TemplateException.CODE_no_conf, new ValueSet( ValueCode.TEMPLATE, iPath ) );
      }
      else {
        PropertySet ps        = new PropertySet();
        boolean     foundConf = false;
        RegExpMatch conf      = null;
        String      props     = null;
        PropertySet propSet   = null;
        for( int confI = 0; confI < numConfs; confI++ ) {
          conf    = allconfs[ confI ];
          props   = conf.matchFirstSub();
          propSet = new PropertySet();
          propSet.parse( props );
          ps.overrideWith( propSet );
          foundConf = true;
        }
View Full Code Here

TOP

Related Classes of org.jostraca.util.RegExpMatch

Copyright © 2018 www.massapicom. 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.