Added panic= arg to find tags

This commit is contained in:
Vhati 2013-09-03 16:19:21 -04:00
parent 3572850586
commit e41a4fdd75
2 changed files with 18 additions and 4 deletions

View file

@ -105,7 +105,7 @@ Advanced XML
They take the form:
<mod:find... reverse="false" start="0" limit="-1">
<mod:find... reverse="false" start="0" limit="-1" panic="false">
<mod:holderForExtraFindArgs />
<mod:someCommand />
<mod:someCommand />
@ -114,8 +114,9 @@ Advanced XML
Some identify existing tags, using each result as context for commands.
Unless stated otherwise, these all accept optional reverse, start,
and limit args: defaulting to search forward, skip 0 matched
candidates, and return up to an unlimited number of results.
limit, and panic args: defaulting to search forward, skip 0 matched
candidates, return up to an unlimited number of results, and not cause
an error when no results are found.
Sometimes the <find...> may have an auxiliary tag just to hold more
args.

View file

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Matcher;
@ -98,6 +99,7 @@ public class XMLPatcher {
boolean searchReverse = getAttributeBooleanValue( node, "reverse", true );
int searchStart = getAttributeIntValue( node, "start", 0 );
int searchLimit = getAttributeIntValue( node, "limit", 1 );
boolean panic = getAttributeBooleanValue( node, "panic", false );
if ( searchName == null || searchName.length() == 0 )
throw new IllegalArgumentException( String.format( "<%s> requires a name attribute (%s).", node.getName(), getPathToRoot(node) ) );
@ -122,7 +124,9 @@ public class XMLPatcher {
matchedNodes = matchedNodes.subList( searchStart, matchedNodes.size() );
}
}
if ( matchedNodes.isEmpty() )
throw new NoSuchElementException( String.format( "<%s> was set to require results but found none (%s).", node.getName(), getPathToRoot(node) ) );
result = matchedNodes;
}
else if ( node.getName().equals( "findLike" ) ) {
@ -131,6 +135,7 @@ public class XMLPatcher {
boolean searchReverse = getAttributeBooleanValue( node, "reverse", false );
int searchStart = getAttributeIntValue( node, "start", 0 );
int searchLimit = getAttributeIntValue( node, "limit", -1 );
boolean panic = getAttributeBooleanValue( node, "panic", false );
if ( searchType != null && searchType.length() == 0 )
throw new IllegalArgumentException( String.format( "<%s> type attribute, when present, can't be empty (%s).", node.getName(), getPathToRoot(node) ) );
@ -170,6 +175,8 @@ public class XMLPatcher {
matchedNodes = matchedNodes.subList( searchStart, matchedNodes.size() );
}
}
if ( matchedNodes.isEmpty() )
throw new NoSuchElementException( String.format( "<%s> was set to require results but found none (%s).", node.getName(), getPathToRoot(node) ) );
result = matchedNodes;
}
@ -180,6 +187,7 @@ public class XMLPatcher {
boolean searchReverse = getAttributeBooleanValue( node, "reverse", false );
int searchStart = getAttributeIntValue( node, "start", 0 );
int searchLimit = getAttributeIntValue( node, "limit", -1 );
boolean panic = getAttributeBooleanValue( node, "panic", false );
if ( searchType != null && searchType.length() == 0 )
throw new IllegalArgumentException( String.format( "<%s> type attribute, when present, can't be empty (%s).", node.getName(), getPathToRoot(node) ) );
@ -218,6 +226,8 @@ public class XMLPatcher {
matchedNodes = matchedNodes.subList( searchStart, matchedNodes.size() );
}
}
if ( matchedNodes.isEmpty() )
throw new NoSuchElementException( String.format( "<%s> was set to require results but found none (%s).", node.getName(), getPathToRoot(node) ) );
result = matchedNodes;
}
@ -226,6 +236,7 @@ public class XMLPatcher {
boolean searchReverse = getAttributeBooleanValue( node, "reverse", false );
int searchStart = getAttributeIntValue( node, "start", 0 );
int searchLimit = getAttributeIntValue( node, "limit", -1 );
boolean panic = getAttributeBooleanValue( node, "panic", false );
if ( searchStart < 0 )
throw new IllegalArgumentException( String.format( "<%s> 'start' attribute is not >= 0 (%s).", node.getName(), getPathToRoot(node) ) );
@ -246,6 +257,8 @@ public class XMLPatcher {
matchedNodes = matchedNodes.subList( searchStart, matchedNodes.size() );
}
}
if ( matchedNodes.isEmpty() )
throw new NoSuchElementException( String.format( "<%s> was set to require results but found none (%s).", node.getName(), getPathToRoot(node) ) );
result = matchedNodes;
}