alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Ralph Krueger. 
 */

package org.netbeans.modules.changelog;


import java.util.*;
import org.openide.windows.*;
import org.openide.*;
import java.io.*;
import java.text.SimpleDateFormat;

import org.netbeans.modules.changelog.html.*;

/**
 * prints the processed groups to xml file.. (based on LogPrinter_Text)
 * @author  rbalada
 * @author  ralph
 */
public class LogPrinter_XML implements LogPrinter {
    
    private java.io.PrintWriter writer;
    private boolean includeSummary;
    
    public LogPrinter_XML(File file) {
        if (!file.exists()) {
            try {
                if (file.getParentFile() != null) {
                    file.getParentFile().mkdirs();
                }
                file.createNewFile();
            } catch (IOException exc) {
                 org.openide.ErrorManager.getDefault().notify(exc);
                 System.out.println("error while creating file..");
            }
        }
        writer = null;
        try {
            writer = new PrintWriter(new FileOutputStream(file));
        } catch (IOException exc) {
                 org.openide.ErrorManager.getDefault().notify(exc);
                 System.out.println("error while opening file..");
        }
    }
    
    public void printHeader(ChangeLogProcessor processor) {
        if (writer == null) {
            return;
        }
        writer.println("");
        writer.println();
        writer.println("");
        includeSummary = processor.isIncludeSummary();
        if (processor.isIncludeQueryDescription()) {
            writer.println();
            writer.println("");
            if (processor.getDateRange() != null) {
                writer.println("" + ChangeLogUtils.xmlescapeString(processor.getDateRange()) + "");
            }
            if (processor.getRevisionRange() != null) {
                writer.println("" + ChangeLogUtils.xmlescapeString(processor.getRevisionRange()) + "");
            }
            if (processor.getMessageFilter() != null) {
                String messageType = "";
                if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SUBSTRING) {
                    messageType = "substring";
                } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SOME_WORDS) {
                    messageType = "anywords";
                } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_ALL_WORDS) {
                    messageType = "allwords";
                } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_REGEXP) {
                    messageType = "regexp";
                }
                writer.println("" + ChangeLogUtils.xmlescapeString(processor.getMessageFilter()) + "");
            }
            if (processor.getFileFilter() != null) {
                String fileType = "";
                if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_SUBSTRING) {
                    fileType = "substring";
                } else if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_REGEXP) {
                    fileType = "regexp";
                }
                writer.println("" + ChangeLogUtils.xmlescapeString(processor.getFileFilter()) + "");
            }
            if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_DATE) {
                writer.print("");
            } else {
                writer.println(" direction=\"ascending\"/>");
            }
            writer.println("");
            writer.println();
        }
    }
    
    public void printGroupHeader(RevisionsGroup group) {
        if (writer == null) {
            return;
        } 
        writer.println("");
        writer.println("" + ChangeLogUtils.xmlescapeString(group.getUser()) + "");
        final String sdate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(group.getStartingDate());
        final String stime = (new java.text.SimpleDateFormat("hh:mm:ss")).format(group.getStartingDate());
        writer.println("" + ChangeLogUtils.xmlescapeString(sdate) + "");
        writer.println("");
        if ( group.getCommonBranch() != null) {
            writer.println("" + ChangeLogUtils.xmlescapeString(group.getCommonBranch()) + "");
        }
        writer.println("" + ChangeLogUtils.xmlescapeString(group.getMessage()).trim() + "");
    }
    
    public void printSingleRevision(LogInfoRevision revision) {
        if (writer == null ) {
            return;
        }
        String repoFileName = revision.getLogInfoHeader().getRepositoryFilename();
        repoFileName = repoFileName.substring(0, repoFileName.length() - 2);
        writer.println("");
        writer.println("" + ChangeLogUtils.xmlescapeString(repoFileName) + "");
        writer.println("" + ChangeLogUtils.xmlescapeString(revision.getNumber()) + "");
        if ( revision.getBranch() != "" ) {
            writer.println("" + ChangeLogUtils.xmlescapeString(revision.getBranch()) + "");
        }
        writer.println("");
    }
    
    public void printGroupFooter(RevisionsGroup group) {
        if (writer == null) {
            return;
        } 
        writer.println("");
        writer.println();
    }
    
    public void printSummary(SummaryProcessor processor) {
        if (writer == null) {
            return;
        }
        if (includeSummary) {
            writer.println("");
            writer.println("" + ChangeLogUtils.xmlescapeString(String.valueOf(processor.getCommitCount())) + "");
            writer.println("");
            String[] users = processor.getUserList();
            for (int i = 0; i < users.length; i++) {
                writer.println("" + ChangeLogUtils.xmlescapeString(users[i]) + "");
            }
            writer.println("");
            String[] mostChanged = processor.getMostChangedFiles();
            writer.println("");
            for (int j = 0; j < mostChanged.length; j++) {
                writer.println("" + ChangeLogUtils.xmlescapeString(mostChanged[j]) + "");
            }
            writer.println("");
            writer.println("");
            String[] mostActive= processor.getMostActiveUsers();
            for (int k = 0; k < mostActive.length; k++) {
                writer.println("" + ChangeLogUtils.xmlescapeString(mostActive[k]) + "");
            }
            writer.println("");
            writer.println("");
            writer.println();
        }
    }
    
    public void printFooter(ChangeLogProcessor processor) {
        //do nothing
        if (writer != null) {
            writer.println("");
            writer.println();
            writer.flush();
            writer.close();
        }
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.