Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Refactored code.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1713101 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
khmarbaise committed Nov 7, 2015
1 parent 0d14276 commit 06f1758
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 160 deletions.
@@ -0,0 +1,114 @@
package org.apache.maven.shared.filtering;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.FilterReader;
import java.io.Reader;
import java.util.LinkedHashSet;

import org.codehaus.plexus.interpolation.multi.DelimiterSpecification;

/**
* @author Karl Heinz Marbaise <khmarbaise@apache.org>
*/
public abstract class AbstractFilterReaderLineEnding
extends FilterReader
{

private String escapeString;

/**
* using escape or not.
*/
protected boolean useEscape = false;

/**
* if true escapeString will be preserved \{foo} -> \{foo}
*/
private boolean preserveEscapeString = false;

protected LinkedHashSet<DelimiterSpecification> delimiters = new LinkedHashSet<DelimiterSpecification>();

/**
* must always be bigger than escape string plus delimiters, but doesn't need to be exact
*/
protected int markLength = 128;

protected AbstractFilterReaderLineEnding( Reader in )
{
super( in );
}

/**
* @return the escapce string.
*/
public String getEscapeString()
{
return escapeString;
}

/**
* @param escapeString Set the value of the escape string.
*/
public void setEscapeString( String escapeString )
{
// TODO NPE if escapeString is null ?
if ( escapeString != null && escapeString.length() >= 1 )
{
this.escapeString = escapeString;
this.useEscape = escapeString != null && escapeString.length() >= 1;
calculateMarkLength();
}
}

/**
* @return state of preserve escape string.
*/
public boolean isPreserveEscapeString()
{
return preserveEscapeString;
}

/**
* @param preserveEscapeString preserve escape string {@code true} or {@code false}.
*/
public void setPreserveEscapeString( boolean preserveEscapeString )
{
this.preserveEscapeString = preserveEscapeString;
}

protected void calculateMarkLength()
{
markLength = 128;

if ( escapeString != null )
{

markLength += escapeString.length();

}
for ( DelimiterSpecification spec : delimiters )
{
markLength += spec.getBegin().length();
markLength += spec.getEnd().length();

}
}
}
Expand Up @@ -20,7 +20,6 @@
*/

import java.io.BufferedReader;
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;

Expand All @@ -38,7 +37,7 @@
* @since 1.0
*/
public class InterpolatorFilterReaderLineEnding
extends FilterReader
extends AbstractFilterReaderLineEnding
{

/**
Expand Down Expand Up @@ -77,22 +76,8 @@ public class InterpolatorFilterReaderLineEnding
*/
private boolean interpolateWithPrefixPattern = true;

private String escapeString;

private boolean useEscape = false;

/**
* if true escapeString will be preserved \{foo} -> \{foo}
*/
private boolean preserveEscapeString = false;

private boolean supportMultiLineFiltering;

/**
* must always be bigger than escape string plus delimiters, but doesn't need to be exact
*/
private int markLength = 16;

private boolean eof = false;

/**
Expand Down Expand Up @@ -221,18 +206,18 @@ public int read()
return ch;
}

boolean inEscape = ( useEscape && ch == escapeString.charAt( 0 ) );
boolean inEscape = ( useEscape && ch == getEscapeString().charAt( 0 ) );

StringBuilder key = new StringBuilder();

// have we found an escape string?
if ( inEscape )
{
for ( int i = 0; i < escapeString.length(); i++ )
for ( int i = 0; i < getEscapeString().length(); i++ )
{
key.append( (char) ch );

if ( ch != escapeString.charAt( i ) || ch == -1 || ( ch == '\n' && !supportMultiLineFiltering ) )
if ( ch != getEscapeString().charAt( i ) || ch == -1 || ( ch == '\n' && !supportMultiLineFiltering ) )
{
// mismatch, EOF or EOL, no escape string here
in.reset();
Expand Down Expand Up @@ -278,7 +263,7 @@ public int read()

if ( beginToken != null )
{
if ( !preserveEscapeString )
if ( !isPreserveEscapeString() )
{
key.setLength( 0 );
}
Expand Down Expand Up @@ -403,44 +388,6 @@ public void setInterpolateWithPrefixPattern( boolean interpolateWithPrefixPatter
this.interpolateWithPrefixPattern = interpolateWithPrefixPattern;
}

/**
* @return The current value of escapeString.
*/
public String getEscapeString()
{
return escapeString;
}

/**
* @param escapeString Set the value for escapeString.
*/
public void setEscapeString( String escapeString )
{
// TODO NPE if escapeString is null ?
if ( escapeString != null && escapeString.length() >= 1 )
{
this.escapeString = escapeString;
this.useEscape = escapeString != null && escapeString.length() >= 1;
calculateMarkLength();
}
}

/**
* @return state of preserve escape string.
*/
public boolean isPreserveEscapeString()
{
return preserveEscapeString;
}

/**
* @param preserveEscapeString {@link #preserveEscapeString}
*/
public void setPreserveEscapeString( boolean preserveEscapeString )
{
this.preserveEscapeString = preserveEscapeString;
}

/**
* @return {@link #recursionInterceptor}
*/
Expand All @@ -459,25 +406,4 @@ public InterpolatorFilterReaderLineEnding setRecursionInterceptor( RecursionInte
return this;
}

private void calculateMarkLength()
{
markLength = 16;

if ( escapeString != null )
{
markLength += escapeString.length();
}

if ( beginToken != null )
{
markLength += beginToken.length();
}

if ( endToken != null )
{
markLength += endToken.length();
}

}

}

0 comments on commit 06f1758

Please sign in to comment.