Author: ltheussl
Date: Thu Feb 7 05:01:52 2008
New Revision: 619392
URL: http://svn.apache.org/viewvc?rev=619392&view=rev
Log:
[DOXIA-210] Snippet macro should include whole file if no id is given
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/AbstractMacro.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/AbstractMacro.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/AbstractMacro.java?rev=619392&r1=619391&r2=619392&view=diff
==============================================================================
---
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/AbstractMacro.java
(original)
+++
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/AbstractMacro.java
Thu Feb 7 05:01:52 2008
@@ -29,5 +29,19 @@
public abstract class AbstractMacro
implements Macro
{
- // nop
+ /**
+ * Check if the given parameter is required. Throws an
+ * IllegalArgumentException if paramValue is null or empty.
+ *
+ * @param paramName The name of the parameter to check.
+ * @param paramValue The parameter value.
+ * @since 1.0-beta-1
+ */
+ protected void required( String paramName, String paramValue )
+ {
+ if ( paramValue == null || "".equals( paramValue.trim() ) )
+ {
+ throw new IllegalArgumentException( paramName + " is a required
parameter!" );
+ }
+ }
}
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java?rev=619392&r1=619391&r2=619392&view=diff
==============================================================================
---
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
(original)
+++
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
Thu Feb 7 05:01:52 2008
@@ -61,8 +61,6 @@
{
String id = (String) request.getParameter( "id" );
- required( id, "id" );
-
String urlParam = (String) request.getParameter( "url" );
String fileParam = (String) request.getParameter( "file" );
@@ -250,30 +248,23 @@
*
* @param url The URL to parse.
* @param id The id of the snippet.
- * @return An identifier, concatenated url and id.
+ * @return An identifier, concatenated url and id,
+ * or just url.toString() if id is empty or null.
*/
private String globalSnippetId( URL url, String id )
{
- return url + " " + id;
- }
-
- /**
- * Check if the given parameter is required. Throws an
- * IllegalArgumentException if id is null or empty.
- *
- * @param id The id of the snippet.
- * @param param The parameter to check.
- */
- private void required( String id, String param )
- {
- if ( id == null || "".equals( id ) )
+ if ( StringUtils.isEmpty( id ) )
+ {
+ return url.toString();
+ }
+ else
{
- throw new IllegalArgumentException( param + " is a required
parameter" );
+ return url + " " + id;
}
}
/**
- *Puts the given snippet into the cache.
+ * Puts the given snippet into the cache.
*
* @param url The URL to parse.
* @param id The id of the snippet.
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java?rev=619392&r1=619391&r2=619392&view=diff
==============================================================================
---
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
(original)
+++
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
Thu Feb 7 05:01:52 2008
@@ -123,17 +123,24 @@
String line;
while ( ( line = reader.readLine() ) != null )
{
- if ( isStart( snippetId, line ) )
+ if ( snippetId == null || "".equals( snippetId.trim() ) )
{
- capture = true;
- }
- else if ( isEnd( snippetId, line ) )
- {
- break;
+ lines.add( line );
}
- else if ( capture )
+ else
{
- lines.add( line );
+ if ( isStart( snippetId, line ) )
+ {
+ capture = true;
+ }
+ else if ( isEnd( snippetId, line ) )
+ {
+ break;
+ }
+ else if ( capture )
+ {
+ lines.add( line );
+ }
}
}
}