Update of /cvsroot/xdoclet/xdoclet/core/src/xdoclet/tagshandler
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23570/src/xdoclet/tagshandler

Modified Files:
        MergeTagsHandler.java 
Log Message:
Add support to specify a parent ID when merging a new template, which can then 
be verified from the child merge template to implement custom behaviour 
depending on the id of the parent template.

Index: MergeTagsHandler.java
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/core/src/xdoclet/tagshandler/MergeTagsHandler.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** MergeTagsHandler.java       19 Sep 2004 09:52:52 -0000      1.13
--- MergeTagsHandler.java       12 Jul 2005 17:16:45 -0000      1.14
***************
*** 14,17 ****
--- 14,18 ----
  import java.util.Properties;
  
+ import org.apache.commons.collections.ArrayStack;
  import org.apache.commons.logging.Log;
  
***************
*** 33,36 ****
--- 34,39 ----
  {
  
+     private ArrayStack mergeStack = new ArrayStack();
+ 
      /**
       * Evaluates the body if the file exists specified by the "file" 
attribute.
***************
*** 89,92 ****
--- 92,97 ----
       * @doc.param                   name="generateMergedFile" 
values="true,false" description="If true then process the
       *      merged file also, otherwise only merge it and do not process it. 
True if the default."
+      * @doc.param                   name="parent-id" optional="true" 
description="An identifier that can be checked in
+      *      the merge file to see what parent initiated the merge, using the 
XDtIfParentIdEquals tag."
       */
      public void merge(String template, Properties attributes) throws 
XDocletException
***************
*** 96,138 ****
          String merge_file_pattern = attributes.getProperty("file");
  
          if (log.isDebugEnabled()) {
              log.debug("Pattern = " + merge_file_pattern);
          }
-         if (merge_file_pattern != null) {
-             // .j is deprecated as the template file extension
-             if (merge_file_pattern.endsWith(".j")) {
-                 log.warn("Deprecated template file extension used for merge 
file, .j should now be .xdt");
-                 merge_file_pattern = merge_file_pattern.substring(0, 
merge_file_pattern.length() - 2) + ".xdt";
-             }
  
!             String contents = getMergeFileContents(merge_file_pattern);
  
!             if (contents != null) {
!                 if (log.isDebugEnabled())
!                     log.debug("Merge File found");
  
!                 String generate_merged_file = 
attributes.getProperty("generateMergedFile");
  
!                 if (generate_merged_file != null && 
!generate_merged_file.equalsIgnoreCase("true") && 
!generate_merged_file.equalsIgnoreCase("yes")) {
!                     getEngine().print(contents);
                  }
                  else {
!                     generateUsingMergedFile(merge_file_pattern, contents);
                  }
              }
              else {
!                 if (log.isDebugEnabled()) {
!                     log.debug("Merge File NOT found");
!                 }
  
!                 // use body of <XDtMerge:merge>
!                 generateUsingMergedFile(((TemplateSubTask) 
getDocletContext().getActiveSubTask()).getTemplateURL().toString(), template);
              }
          }
!         else {
!             log.error("<XDtMerge:merge/> file parameter missing from template 
file, ignoring merge command.");
!             generate(template);
          }
  
      }
  
--- 101,193 ----
          String merge_file_pattern = attributes.getProperty("file");
  
+         String parentId = attributes.getProperty("parent-id");
+ 
+         if (log.isDebugEnabled()) {
+             log.debug("specified parent id [" + parentId + "]");
+         }
+ 
+         if (parentId == null || parentId.length() == 0) {
+             parentId = "__UNSPECIFIED__";
+         }
+ 
+         if (log.isDebugEnabled()) {
+             log.debug("pushing id [" + parentId + "] onto the merge stack");
+         }
+         mergeStack.push(parentId);
+ 
          if (log.isDebugEnabled()) {
              log.debug("Pattern = " + merge_file_pattern);
          }
  
!         try {
!             if (merge_file_pattern != null) {
!                 // .j is deprecated as the template file extension
!                 if (merge_file_pattern.endsWith(".j")) {
!                     log.warn("Deprecated template file extension used for 
merge file, .j should now be .xdt");
!                     merge_file_pattern = merge_file_pattern.substring(0, 
merge_file_pattern.length() - 2) + ".xdt";
!                 }
  
!                 String contents = getMergeFileContents(merge_file_pattern);
  
!                 if (contents != null) {
!                     if (log.isDebugEnabled())
!                         log.debug("Merge File found");
  
!                     String generate_merged_file = 
attributes.getProperty("generateMergedFile");
! 
!                     if (generate_merged_file != null && 
!generate_merged_file.equalsIgnoreCase("true") && 
!generate_merged_file.equalsIgnoreCase("yes")) {
!                         getEngine().print(contents);
!                     }
!                     else {
!                         generateUsingMergedFile(merge_file_pattern, contents);
!                     }
                  }
                  else {
!                     if (log.isDebugEnabled()) {
!                         log.debug("Merge File NOT found");
!                     }
! 
!                     // use body of <XDtMerge:merge>
!                     generateUsingMergedFile(((TemplateSubTask) 
getDocletContext().getActiveSubTask()).getTemplateURL().toString(), template);
                  }
              }
              else {
!                 log.error("<XDtMerge:merge/> file parameter missing from 
template file, ignoring merge command.");
!                 generate(template);
!             }
!         }
!         finally {
!             String poppedId = (String) mergeStack.pop();
  
!             if (log.isDebugEnabled()) {
!                 log.debug("popped id [" + poppedId + "] off the merge stack");
              }
          }
! 
!     }
! 
!     /**
!      * The contents of this tag are evaluated if: (1) No id is specified (2) 
The specified id is equal to the parent id
!      * specified in the template that merged in the current file.
!      *
!      * @param template              The body of the block tag
!      * @param attributes            The attributes of the template tag
!      * @exception XDocletException  XDocletException if something goes wrong
!      * @doc.tag                     type="block"
!      * @doc.param                   name="id" optional="true" 
description="The id to compare to the id of the current
!      *      merge parent."
!      */
!     public void ifParentIdEquals(String template, Properties attributes) 
throws XDocletException
!     {
!         Log log = LogUtil.getLog(MergeTagsHandler.class, "ifParentIdEquals");
!         String id = attributes.getProperty("id");
! 
!         if (log.isDebugEnabled()) {
!             log.debug("comparing specified id [" + id + "] to merge parent id 
[" + mergeStack.peek() + "]");
          }
  
+         if (id == null || id.length() == 0 || mergeStack.peek().equals(id)) {
+             generate(template);
+         }
      }
  



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
xdoclet-devel mailing list
xdoclet-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to