Ara Correct I'll fix that. Vincent
> -----Original Message----- > From: Ara Abrahamian [mailto:[EMAIL PROTECTED]] > Sent: dimanche 7 avril 2002 21:32 > To: 'Vincent Harcq'; [EMAIL PROTECTED] > Subject: RE: [Xdoclet-devel] CVS update: > xdoclet/core/src/xdoclet/tags MergeTagsHandler.java > > > Vicent, > FileManager does this caching automatically. Or maybe > something have changed? > > Ara. > > > -----Original Message----- > > From: [EMAIL PROTECTED] > [mailto:xdoclet-devel- > > [EMAIL PROTECTED]] On Behalf Of Vincent Harcq > > Sent: Sunday, April 07, 2002 6:23 PM > > To: [EMAIL PROTECTED] > > Subject: [Xdoclet-devel] CVS update: xdoclet/core/src/xdoclet/tags > > MergeTagsHandler.java > > > > User: vharcq > > Date: 02/04/07 06:53:17 > > > > Modified: core/src/xdoclet/tags MergeTagsHandler.java > > Log: > > Cache merg files content when possible (global merge files) > > > > Revision Changes Path > > 1.19 +199 -138 > xdoclet/core/src/xdoclet/tags/MergeTagsHandler.java > > > > Index: MergeTagsHandler.java > > > =================================================================== > > RCS file: > > > /cvsroot/xdoclet/xdoclet/core/src/xdoclet/tags/MergeTagsHandler.java,v > > retrieving revision 1.18 > > retrieving revision 1.19 > > diff -u -w -r1.18 -r1.19 > > --- MergeTagsHandler.java 4 Apr 2002 01:03:05 -0000 1.18 > > +++ MergeTagsHandler.java 7 Apr 2002 13:53:17 -0000 1.19 > > @@ -23,15 +23,20 @@ > > import java.io.IOException; > > import java.text.MessageFormat; > > import java.util.Properties; > > +import java.util.HashMap; > > import java.net.MalformedURLException; > > import java.net.URL; > > > > /** > > * @author Ara Abrahamian ([EMAIL PROTECTED]) > > * @created Oct 15, 2001 > > - * @version $Revision: 1.18 $ > > + * @version $Revision: 1.19 $ > > */ > > -public class MergeTagsHandler extends XDocletTagSupport { > > +public class MergeTagsHandler extends XDocletTagSupport > > +{ > > + > > + private static HashMap fileCache; > > + > > /** > > * Merge contents of the file designated by the file parameter > and > > evaluates > > * the body if the file is not found. It searches for the file > in > > the directory > > @@ -41,47 +46,55 @@ > > * @param attributes The attributes of the template tag > > * @exception XDocletException XDocletException if something > goes > > wrong > > * @doc:tag type="block" > > - * @doc:param name="file" optional="false" description="The path > to > > the file to > > - * be merged. The value of this parameter can have {0} in > it, > > if so {0} is > > - * replaced with the current class name and system searches > for > > the file > > - * in in mergeDir+packageName directory. {0} is for cases > where > > you want > > - * to define and merge a file per each class." > > - * @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="file" optional="false" > > description="The > > + * path to the file to be merged. The value of this > parameter > > can have {0} > > + * in it, if so {0} is replaced with the current class name > and > > system > > + * searches for the file in in mergeDir+packageName > directory. > > {0} is for > > + * cases where you want to define and merge a file per each > > class." > > + * @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." > > */ > > - public void merge(String template, Properties attributes) throws > > XDocletException { > > + public void merge( String template, Properties attributes ) > throws > > XDocletException > > + { > > + > > Category cat = Log.getCategory(MergeTagsHandler.class, > > "merge"); > > String merge_file_pattern = > attributes.getProperty("file"); > > > > - if (cat.isDebugEnabled()) { > > + if( cat.isDebugEnabled() ) > > + { > > cat.debug("Pattern = " + merge_file_pattern); > > } > > - > > - if (merge_file_pattern != null) { > > + if( merge_file_pattern != null ) > > + { > > String contents = > getMergeFileContents(merge_file_pattern); > > > > - if (contents != null) { > > + if( contents != null ) > > + { > > String generate_merged_file = > > attributes.getProperty("generateMergedFile"); > > > > - if (generate_merged_file != null && > > !generate_merged_file.equalsIgnoreCase("true") && > > !generate_merged_file.equalsIgnoreCase("yes")) { > > + if( generate_merged_file != null && > > !generate_merged_file.equalsIgnoreCase( "true" ) && > > !generate_merged_file.equalsIgnoreCase( "yes" ) ) > > + { > > getEngine().print(contents); > > } > > - else { > > + else > > + { > > > generateUsingMergedFile(merge_file_pattern, > > contents); > > } > > } > > - else { > > + else > > + { > > //use body of <XDtMerge:merge> > > > > > generateUsingMergedFile(((TemplateSubTask)getDocletContext().getActi > > veSubTask()).getTemplateURL().toString(), template); > > } > > } > > - else { > > + else > > + { > > cat.error("<XDtMerge:merge/> file parameter > missing from > > template file, ignoring merge command."); > > generate(template); > > } > > - } > > > > + } > > > > /** > > * A utility method used for merging a file used by > > <XDtMerge:merge/>tag. If > > @@ -102,65 +115,99 @@ > > * @see ClassTagsHandler#symbolicClassName() > > * @see xdoclet.util.FileManager > > */ > > - protected String getMergeFileContents(String merge_file_pattern) > { > > + protected String getMergeFileContents( String merge_file_pattern > ) > > + { > > Category cat = Log.getCategory(MergeTagsHandler.class, > > "merge"); > > > > - try { > > - if (merge_file_pattern.indexOf("{0}") != -1) { > > - if (getParser() != null) { > > + if( fileCache == null ) > > + fileCache = new HashMap(); > > + > > + String cacheFile = null; > > + > > + if( merge_file_pattern.indexOf( "{0}" ) == -1 && > > fileCache.containsKey( merge_file_pattern ) ) > > + { > > + cacheFile = ( String ) fileCache.get( > merge_file_pattern > > ); > > + return cacheFile; > > + } > > + else > > + { > > + if( cat.isDebugEnabled() ) > > + cat.debug( "not cached " + > merge_file_pattern ); > > + try > > + { > > + if( merge_file_pattern.indexOf( "{0}" ) > != -1 ) > > + { > > + if( getParser() != null ) > > + { > > > > getParser().addMergeFile(merge_file_pattern); > > } > > - else { > > + else > > + { > > String ejb_name = > MessageFormat.format(merge_file_pattern, new > > > Object[]{AbstractProgramElementTagsHandler.getClassNameFor(get > CurrentCla > ss > > ())}); > > String merge_file_name = > > > PackageTagsHandler.packageNameAsPathFor(getCurrentClass().cont > ainingPack > ag > > e()) + File.separator + ejb_name; > > File merge_file = new > > File(getDocletContext().getActiveSubTask().getMergeDir(), > > merge_file_name); > > > > - if (cat.isDebugEnabled()) { > > + if( cat.isDebugEnabled() > ) > > + { > > cat.debug("Search for > File " + > > merge_file); > > } > > > > - if (merge_file.exists()) { > > - if > (cat.isDebugEnabled()) { > > + if( merge_file.exists() > ) > > + { > > + if( > cat.isDebugEnabled() ) > > + { > > > cat.debug("Search for File OK"); > > } > > > > - return > > FileManager.getURLContent(merge_file.toURL()); > > + cacheFile = > > FileManager.getURLContent( merge_file.toURL() ); > > } > > - else { > > - if > (cat.isDebugEnabled()) { > > + else > > + { > > + if( > cat.isDebugEnabled() ) > > + { > > > cat.debug("Search for File not > > OK"); > > } > > } > > } > > } > > - else { > > + else > > + { > > File merge_file = new > > File(getDocletContext().getActiveSubTask().getMergeDir(), > > merge_file_pattern); > > > > - if (getParser() != null) { > > + if( getParser() != null ) > > + { > > > > getParser().addMergeFile(merge_file_pattern); > > } > > > > - if (merge_file.exists()) { > > - return > > FileManager.getURLContent(merge_file.toURL()); > > + if( merge_file.exists() ) > > + { > > + cacheFile = > FileManager.getURLContent( > > merge_file.toURL() ); > > } > > } > > > > //was not found in mergedir, try the jar > > - URL jarResource = getClass().getResource("/" + > > merge_file_pattern); > > + URL jarResource = > getClass().getResource( '/' + > > merge_file_pattern ); > > > > - if (jarResource != null) { > > - return > FileManager.getURLContent(jarResource); > > + if( jarResource != null ) > > + { > > + cacheFile = > FileManager.getURLContent( > > jarResource ); > > } > > - else { > > + else > > + { > > // not found on file system or in jar. > > - return null; > > + cacheFile = null; > > } > > - } catch (MalformedURLException e) { > > + } > > + catch( MalformedURLException e ) > > + { > > cat.error(e.getMessage()); > > return null; > > } > > } > > - > > + if( merge_file_pattern.indexOf( "{0}" ) == -1 ) > > + fileCache.put( merge_file_pattern, cacheFile ); > > + return cacheFile; > > + } > > > > /** > > * Processes the file specified in merge_file_pattern that has > the > > text content > > @@ -172,8 +219,10 @@ > > * @exception XDocletException Description of Exception > > * @see > xdoclet.template.TemplateEngine#setTemplateURL(java.net.URL) > > */ > > - protected void generateUsingMergedFile(String merge_file, String > > contents) throws XDocletException { > > - try { > > + protected void generateUsingMergedFile( String merge_file, > String > > contents ) throws XDocletException > > + { > > + try > > + { > > int line_num = getEngine().getCurrentLineNum(); > > URL prev_template_url = > > > ((TemplateSubTask)getDocletContext().getActiveSubTask()).getTe > mplateURL( > ); > > > > @@ -184,28 +233,33 @@ > > > > getEngine().setTemplateURL(prev_template_url); > > getEngine().setCurrentLineNum(line_num); > > - } catch (MalformedURLException e) { > > + } > > + catch( MalformedURLException e ) > > + { > > throw new XDocletException(e.getMessage()); > > } > > } > > > > - > > /** > > * A utility method used for generating the dest_file based on > > template_file > > * template file. > > * > > - * @param dest_file the path to the destination file prepended > by > > value of the > > - * destDir configuration parameter. > > + * @param dest_file the path to the destination file > > prepended by > > + * value of the destDir configuration parameter. > > * @param template_file_name the template file name > > * @exception XDocletException Description of Exception > > */ > > - protected void generateFileUsingTemplate(String dest_file, > String > > template_file_name) throws XDocletException { > > + protected void generateFileUsingTemplate( String dest_file, > String > > template_file_name ) throws XDocletException > > + { > > Category cat = Log.getCategory(MergeTagsHandler.class, > > "generateFileUsingTemplate"); > > XClass[] classes = null; > > > > - try { > > + try > > + { > > XJavaDoc.getInstance().sourceClasses(); > > - } catch (XJavaDocException e) { > > + } > > + catch( XJavaDocException e ) > > + { > > throw new XDocletException(e, e.getMessage()); > > } > > > > @@ -224,24 +278,31 @@ > > */ > > file.getParentFile().mkdirs(); > > > > - try { > > + try > > + { > > getEngine().setTemplateURL(new > > File(template_file_name).toURL()); > > > > String content = > > > FileManager.getURLContent(((TemplateSubTask)getDocletContext() > .getActive > Su > > bTask()).getTemplateURL()); > > > > - if (content != null) { > > - try { > > + if( content != null ) > > + { > > + try > > + { > > PrettyPrintWriter out = new > > PrettyPrintWriter(new BufferedWriter(new FileWriter(file))); > > > > getEngine().setWriter(out); > > > getEngine().setCurrentLineNum(0); > > generate(content); > > out.close(); > > - } catch (IOException ex) { > > + } > > + catch( IOException ex ) > > + { > > cat.error("An error occured > while writing > > output to file " + file, ex); > > } > > } > > - } catch (MalformedURLException e) { > > + } > > + catch( MalformedURLException e ) > > + { > > throw new XDocletException(e.getMessage()); > > } > > } > > > > > > > > > > _______________________________________________ > > Xdoclet-devel mailing list [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/xdoclet-devel > > > > _________________________________________________________ > > Do You Yahoo!? > > Get your free @yahoo.com address at http://mail.yahoo.com > > > > _______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel Sponsored by http://www.ThinkGeek.com/
