buildframework/helium/sf/java/quality/src/com/nokia/helium/quality/ant/taskdefs/CMTSummaryTask.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     1
/*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     3
 * All rights reserved.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     8
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    11
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    12
 * Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    13
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    14
 * Description:  
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    15
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    16
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    17
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    18
package com.nokia.helium.quality.ant.taskdefs;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    19
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    20
import java.io.BufferedReader;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
import java.io.BufferedWriter;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import java.io.FileNotFoundException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import java.io.FileOutputStream;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    24
import java.io.FileReader;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    25
import java.io.IOException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    26
import java.io.OutputStreamWriter;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    27
import java.io.UnsupportedEncodingException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    28
import java.util.regex.Matcher;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    29
import java.util.regex.Pattern;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    30
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    31
import org.apache.tools.ant.Project;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    32
import org.apache.tools.ant.Task;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    33
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    34
/**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    35
 * This Task searches the index.html files created by CMT and looks for the summary values at the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    36
 * end of the file e.g. Files: 12 LOCphy: 137. and takes the info and places it in an XMl file ready
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    37
 * to be sent to diamonds. The Xml file is placed in the diamonds folder in the output folder and
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    38
 * these files are then sent to diamonds when the build is finished soall we have to do is create
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
 * the file in the correct folder.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    40
 * 
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    41
 * <pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    42
 * &lt;hlm:cmtmetadatainput   
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    43
 *             diamondsHeaderFileName="C:\brtaylor\1\diamonds_header.xml" 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    44
 *             diamondsFooterFileName="C:\brtaylor\1\diamonds_footer.xml"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    45
 *             outptuFile="Z:\output\diamonds/cmt_summary_componentName_1.xml/" 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    46
 *             inputFile="Z:\output\logs/minibuild_ido_0.0.03_test_cmt_componentName1_cmt/CMTHTML/index.html/&gt;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    47
 * </pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    48
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    49
 * @ant.task name="cmtsummarytask" category="Quality"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    50
 */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    51
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    52
public class CMTSummaryTask extends Task {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    53
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    54
    // The following 2 variables are indexes to the SEARCH_TERMS_ARRAY
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    55
    /** Index to the searched for text */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    56
    private static final int INPUT_TEXT_INDEX = 0;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    57
    /** Index to the text to write to the xml file */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    58
    private static final int OUTPUT_ELEMENT_INDEX = 1;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    59
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    60
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    61
     * this array contains the text to be searched for in the inputFile (1st element) and the text
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    62
     * to be written to the .xml output file (2nd element)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    63
     */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    64
    private static final String[][] SEARCH_TERMS_ARRAY = {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    65
        // 1st elem 2nd elem
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    66
        { "Files:", "files" }, { "LOCphy:", "locphy" }, { "LOCbl:", "locbl" },
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    67
        { "LOCpro:", "locpro" }, { "LOCcom:", "loccom" }, { "v(G) :", "vg" },
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    68
        { "MI without comments  :", "mi_wo_comments" },
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    69
        { "MI comment weight    :", "mi_comment_weight" }, { "MI:", "mi" } };
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    70
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    71
    /** always accesses the 1st group of the matcher */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    72
    private static int matcherGroupNum; // default init is 0
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    73
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
    /** indexes to the SEARCH_TERMS_ARRAY */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    75
    private int arrayIndex;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    76
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    77
    private int sizeArray = SEARCH_TERMS_ARRAY.length;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    78
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    79
    /** the file containing the CMT summary data */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    80
    private String inputFile;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    81
    /** name of file to write the output to */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    82
    private String outputFile;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    83
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    84
    /** each line of the input file is read into this */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    85
    private String line;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    86
    /** the regex for a string of digits */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    87
    private Pattern digitPattern = Pattern.compile("\\d+");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    88
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    89
    /** file descriptor for the input file */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    90
    private BufferedReader inputFileReader;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    91
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    92
    /** file handler used to write the summary numbers to the output file **/
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    93
    private BufferedWriter output; // default init = null
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    94
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
    /** tells the main method whether it should be looking for digist or text */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    96
    private boolean lineStartsWithDigits; // default init = false
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    97
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    98
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    99
     * file name of the default diamonds XML file header part (1st few lines) used so not writing
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   100
     * the XML text here
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   101
     */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   102
    private String diamondsHeaderFileName;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   103
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   104
     * file name of the default diamonds XML file footer part (last line) used so not writing the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   105
     * XML text here
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
     */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   107
    private String diamondsFooterFileName;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   108
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   109
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   110
     * @param outputFile set the output file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   111
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   112
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   113
    public void setOutputFile(String outputFile) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   114
        this.outputFile = outputFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   115
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   116
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   117
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
     * @return the outputFile the output file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   119
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   120
    public String getOutputFile() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   121
        return outputFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   122
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   123
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   124
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   125
     * @return the inputFile
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   126
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   127
    public String getinputFile() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   128
        return inputFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   129
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   130
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   131
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
     * @param inputFile the name of file to scan and extract data from
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   133
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   134
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   135
    public void setinputFile(String inputFile) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   136
        this.inputFile = inputFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   137
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   138
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   139
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   140
     * @param diamondsFooterFileName set the diamonds footer file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   141
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   142
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   143
    public void setdiamondsFooterFileName(String diamondsFooterFileName) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   144
        this.diamondsFooterFileName = diamondsFooterFileName;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   145
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   146
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   147
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   148
     * @return the diamondsFooterFileName the diamonds footer file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   149
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   150
    public String getdiamondsFooterFileName() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   151
        return diamondsFooterFileName;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   152
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   153
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   154
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   155
     * @param diamondsHeaderFileName set the diamonds header file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   156
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   157
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   158
    public void setdiamondsHeaderFileName(String diamondsHeaderFileName) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   159
        this.diamondsHeaderFileName = diamondsHeaderFileName;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   160
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   161
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   162
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   163
     * @return the diamondsFooterFileName the diamonds footer file name
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   164
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   165
    public String getdiamondsHeaderFileName() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   166
        return diamondsHeaderFileName;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   167
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   168
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   169
    /** the main part of the code - the method that is called */
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   170
    public void execute() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   171
        log("CMTSummaryTask execute method with input file : " + inputFile, Project.MSG_ERR);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   172
        boolean inputFileFound = true;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   173
        BufferedReader diamondsHeaderFile;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   174
        BufferedReader diamondsFooterFile;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   175
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   176
        log("output File is " + getOutputFile(), Project.MSG_ERR);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   177
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   178
        try {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   179
            // open the file with the CMT results init
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   180
            inputFileReader = new BufferedReader(new FileReader(inputFile));
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   181
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   182
        catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   183
            log("FileNotFoundException while getting the input file.  : " + inputFile + "  "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   184
                + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   185
            inputFileFound = false; // stops an empty output file being created.
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   186
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   187
        if (inputFileFound) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   188
            try {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   189
                // write the title stuff for the XML diamonds schema
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   190
                output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(getOutputFile()), "UTF8"));
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   191
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   192
            catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   193
                log("FileNotFoundException while getting the output file.  : " + getOutputFile()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   194
                    + "   " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   195
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   196
            catch (UnsupportedEncodingException exc) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   197
                // We are Ignoring the errors as no need to fail the build.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   198
                log("UnsupportedEncodingException while creating the output file : "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   199
                    + getOutputFile() + "   " + exc.getMessage(), Project.MSG_ERR);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   200
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   201
            catch (SecurityException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   202
                // We are Ignoring the errors as no need to fail the build.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   203
                log("SecurityException while creating the output file : " + getOutputFile() + "   "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   204
                    + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   205
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   206
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   207
            if (output != null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   208
                // managed to open the output file
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   209
                try {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   210
                    // write the initial XML text to the file
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   211
                    String tempLine;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   212
                    diamondsHeaderFile = null;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   213
                    diamondsHeaderFile = new BufferedReader(new FileReader(getdiamondsHeaderFileName()));
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   214
                    while ((tempLine = diamondsHeaderFile.readLine()) != null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   215
                        output.write(tempLine);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   216
                        output.newLine();
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   217
                    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   218
                    diamondsHeaderFile.close();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   219
                    output.write("    <cmt>\r\n");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   220
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   221
                    // CheckStyle:InnerAssignment OFF
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   222
                    // process each of the searchterms
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   223
                    while ((arrayIndex < sizeArray)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   224
                        && ((line = inputFileReader.readLine()) != null)) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   225
                        findTextAndOutput(); // read finput file and write the output
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   226
                    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   227
                    // CheckStyle:InnerAssignment ON
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   228
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   229
                    // write the end of file text
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   230
                    output.write("    </cmt>");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   231
                    output.newLine();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   232
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   233
                    diamondsFooterFile = null;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   234
                    diamondsFooterFile = new BufferedReader(new FileReader(getdiamondsFooterFileName()));
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   235
                    while ((tempLine = diamondsFooterFile.readLine()) != null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   236
                        output.write(tempLine);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   237
                        output.newLine();
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   238
                    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   239
                    output.close(); // close the output file
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   240
                    diamondsFooterFile.close();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   241
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   242
                catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   243
                    log("FileNotFoundException while getting the diamonds header file : "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   244
                        + getdiamondsHeaderFileName() + "   " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   245
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   246
                catch (IOException exc) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   247
                    // We are Ignoring the errors as no need to fail the build.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   248
                    log("IOException : " + getdiamondsHeaderFileName() + " output file =  "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   249
                        + getOutputFile() + "  " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   250
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   251
                catch (IllegalArgumentException exc) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   252
                    // We are Ignoring the errors as no need to fail the build.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   253
                    log("IllegalArgumentException : " + getdiamondsHeaderFileName()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   254
                        + " output file =  " + getOutputFile() + "  " + exc.getMessage(), Project.MSG_ERR);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   255
                }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   256
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   257
            else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   258
                log("Error: no output File available ", Project.MSG_ERR);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   259
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   260
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   261
        else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   262
            log("Error: no input File available ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   263
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   264
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   265
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   266
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   267
     * This is the function that performs the actual file searches and writes the number following
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   268
     * the searched for text to the output XML file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   269
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   270
    private void findTextAndOutput() {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   271
        final int colonSkip = 2;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   272
        byte[] lineBytes = null;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   273
        int buffLen;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   274
        int lineLen;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   275
        int serchTermTextLen;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   276
        int spacesLen;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   277
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   278
        try {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   279
            lineLen = line.length();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   280
            while ((lineLen > 0) && (arrayIndex < sizeArray)) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   281
                // Process each of the groups of chars in a line
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   282
                if (line.startsWith(SEARCH_TERMS_ARRAY[arrayIndex][INPUT_TEXT_INDEX])) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   283
                    // Found the CMT data type we are looking for so look fo r the digits now
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   284
                    serchTermTextLen = SEARCH_TERMS_ARRAY[arrayIndex][INPUT_TEXT_INDEX].length();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   285
                    buffLen = writeToOutput();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   286
                    if ((buffLen > 0) && (arrayIndex < sizeArray)) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   287
                        // Skip over the digits so can get the next searchterm near start of line
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   288
                        line = line.substring(line.indexOf(':') + colonSkip + buffLen);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   289
                        spacesLen = removeAnySpaces();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   290
                        // Decrease line length for the while loop
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   291
                        lineLen = lineLen - (buffLen + serchTermTextLen + spacesLen);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   292
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   293
                    else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   294
                        // Didn't find the digits so probably at the end of the line and the digits
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   295
                        // are on the next line
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   296
                        // Convert the line to bytes so we can check for a specific Character
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   297
                        lineBytes = line.getBytes("UTF-8");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   298
                        int sbLen = lineBytes.length;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   299
                        // The last real char (i.e. not the EOL) should be '=' if the digits are on
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   300
                        // the next line
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   301
                        if (lineBytes[sbLen - 1] == '=') {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   302
                            // found the '=' so read the next line in
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   303
                            lineStartsWithDigits = true;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   304
                            lineLen = 0;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   305
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   306
                        else {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   307
                            log("can't find the '=' at end of line  ", Project.MSG_ERR);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   308
                            lineLen = 0;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   309
                        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   310
                    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   311
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   312
                else if (lineStartsWithDigits) { // probably got a line with digits on
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   313
                    buffLen = writeToOutput(); // definitely got a line with digits on
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   314
                    lineStartsWithDigits = false;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   315
                    if ((buffLen > 0) && (arrayIndex < sizeArray)) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   316
                        // Now need to get rid of the digits and get to the next
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   317
                        // none digits char
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   318
                        line = line.substring(buffLen);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   319
                        spacesLen = removeAnySpaces();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   320
                        // decrease line length for the while loop
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   321
                        lineLen = lineLen - (buffLen + spacesLen);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   322
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   323
                    else {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   324
                        lineLen = 0;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   325
                        log("can't find the digits at beg of line ", Project.MSG_ERR);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   326
                    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   327
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   328
                else {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   329
                    lineLen = 0;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   330
                }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   331
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   332
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   333
        catch (IOException exc) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   334
            log("IOException Error searching : " + exc.getMessage(), Project.MSG_ERR);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   335
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   336
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   337
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   338
    private int writeToOutput() throws IOException {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   339
        String buffer;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   340
        int buffLen;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   341
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   342
        Matcher componentMatch = digitPattern.matcher(line);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   343
        if (componentMatch.find()) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   344
            // Found the digits after the search term
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   345
            buffer = componentMatch.group(matcherGroupNum);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   346
            // Write the XML formated <files>nn</files> to the output file (plus the other)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   347
            output.write("        <" + SEARCH_TERMS_ARRAY[arrayIndex][OUTPUT_ELEMENT_INDEX] + ">");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   348
            output.write(buffer);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   349
            output.write("</" + SEARCH_TERMS_ARRAY[arrayIndex++][OUTPUT_ELEMENT_INDEX] + ">");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   350
            output.newLine();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   351
            buffLen = buffer.length();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   352
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   353
        else {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   354
            buffLen = 0;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   355
            log("can't find digits may be '=' at end of line ", Project.MSG_ERR);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   356
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   357
        return buffLen;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   358
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   359
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   360
    private int removeAnySpaces() throws UnsupportedEncodingException {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   361
        byte[] lineBytes;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   362
        int num = 0;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   363
        int len = line.length();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   364
        // Convert the line to bytes so we can check for a specific Character
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   365
        lineBytes = line.getBytes("UTF-8");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   366
        // While there are still spaces at the front of the line shuffle the line along to get rid
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   367
        // of them
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   368
        while ((lineBytes[num++] == ' ') && (len > 0)) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   369
            // Remove 1 space at front of line
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   370
            line = line.substring(1);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   371
            len--;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   372
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   373
        return num;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   374
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   375
}