Search in sources :

Example 1 with Comment

use of de.janrufmonitor.service.comment.impl.Comment in project janrufmonitor by tbrandt77.

the class CommentCallerHandler method createComment.

private IComment createComment(File commentFile) {
    IComment comment = new Comment();
    String commentID = commentFile.getName();
    commentID = commentID.substring(0, commentID.indexOf(this.getCommentFilenameExtension()));
    comment.setID(commentID);
    comment.setDate(new Date(commentFile.lastModified()));
    try {
        FileReader commentReader = new FileReader(commentFile);
        BufferedReader bufReader = new BufferedReader(commentReader);
        StringBuffer text = new StringBuffer();
        while (bufReader.ready()) {
            text.append(bufReader.readLine());
            text.append(IJAMConst.CRLF);
        }
        bufReader.close();
        commentReader.close();
        comment.setText(text.substring(0));
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find comment file " + commentFile);
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + commentFile);
    }
    File commentAttributesFile = new File(commentFile.getAbsolutePath() + ".attributes");
    if (commentAttributesFile.exists() && commentAttributesFile.isFile()) {
        Properties commentAttributes = new Properties();
        try {
            FileInputStream in = new FileInputStream(commentAttributesFile);
            commentAttributes.load(in);
            in.close();
            Iterator it = commentAttributes.keySet().iterator();
            IAttribute a = null;
            String key = null;
            while (it.hasNext()) {
                key = (String) it.next();
                a = PIMRuntime.getInstance().getCallerFactory().createAttribute(key, commentAttributes.getProperty(key));
                comment.addAttribute(a);
            }
        } catch (FileNotFoundException ex) {
            this.m_logger.severe("File not found: " + commentAttributesFile.getAbsolutePath());
        } catch (IOException ex) {
            this.m_logger.severe("IOException on file " + commentAttributesFile.getAbsolutePath());
        }
    }
    return comment;
}
Also used : IComment(de.janrufmonitor.service.comment.api.IComment) Comment(de.janrufmonitor.service.comment.impl.Comment) IComment(de.janrufmonitor.service.comment.api.IComment) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) FileInputStream(java.io.FileInputStream) BufferedReader(java.io.BufferedReader) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)1 IComment (de.janrufmonitor.service.comment.api.IComment)1 Comment (de.janrufmonitor.service.comment.impl.Comment)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1