⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loganalyser.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    url = value;                }                if (key.equals("host.name"))                {                    name = value;                }            }        }        // close the inputs        br.close();        fr.close();                return;    }        /**     * increment the value of the given map at the given key by one.     *      * @param   map     the map whose value we want to increase     * @param   key     the key of the map whose value to increase     *     * @return          an integer object containing the new value     */    public static Integer increment(Map map, String key)    {        Integer newValue = null;        if (map.containsKey(key))        {            // FIXME: this seems like a ridiculous way to add Integers            newValue = new Integer(((Integer) map.get(key)).intValue() + 1);        }        else        {            newValue = new Integer(1);        }        return newValue;    }        /**     * Take the standard date string requested at the command line and convert     * it into a Date object.  Throws and error and exits if the date does     * not parse     *     * @param   date    the string representation of the date     *     * @return          a date object containing the date, with the time set to     *                  00:00:00     */    public static Date parseDate(String date)    {        SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd");        Date parsedDate = null;                try         {             parsedDate = sdf.parse(date);        }        catch (ParseException e)        {            System.out.println("The date is not in the correct format");            System.exit(0);        }        return parsedDate;    }            /**     * Take the date object and convert it into a string of the form YYYY-MM-DD     *     * @param   date    the date to be converted     *     * @return          A string of the form YYYY-MM-DD     */    public static String unParseDate(Date date)    {        // Use SimpleDateFormat        SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd");        return sdf.format(date);    }            /**     * Take a search query string and pull out all of the meaningful information     * from it, giving the results in the form of a String array, a single word     * to each element     *      * @param   query   the search query to be analysed     *     * @return          the string array containing meaningful search terms     */    public static String[] analyseQuery(String query)    {        // register our standard loop counter        int i = 0;                // make the query string totally lower case, to ensure we don't miss out        // on matches due to capitalisation        query = query.toLowerCase();                // now perform successive find and replace operations using pre-defined        // global regular expressions        Matcher matchQuery = queryRX.matcher(query);        query = matchQuery.replaceAll(" ");                Matcher matchCollection = collectionRX.matcher(query);        query = matchCollection.replaceAll(" ");                Matcher matchCommunity = communityRX.matcher(query);        query = matchCommunity.replaceAll(" ");                Matcher matchResults = resultsRX.matcher(query);        query = matchResults.replaceAll(" ");        Matcher matchTypes = typeRX.matcher(query);        query = matchTypes.replaceAll(" ");                Matcher matchChars = excludeCharRX.matcher(query);        query = matchChars.replaceAll(" ");               Matcher matchWords = wordRX.matcher(query);        query = matchWords.replaceAll(" ");                Matcher single = singleRX.matcher(query);        query = single.replaceAll(" ");                // split the remaining string by whitespace, trim and stuff into an        // array to be returned        StringTokenizer st = new StringTokenizer(query);        String[] words = new String[st.countTokens()];        for (i = 0; i < words.length; i++)        {            words[i] = st.nextToken().trim();        }        // FIXME: some single characters are still slipping through the net;        // why? and how do we fix it?        return words;    }            /**     * split the given line into it's relevant segments if applicable (i.e. the     * line matches the required regular expression.     *     * @param   line    the line to be segmented     *     * @return          a Log Line object for the given line     */    public static LogLine getLogLine(String line)    {        // FIXME: consider moving this code into the LogLine class.  To do this        // we need to much more carefully define the structure and behaviour        // of the LogLine class        Matcher match = valid.matcher(line);                if (match.matches())        {            // set up a new log line object            LogLine logLine = new LogLine(parseDate(match.group(1).trim()),                                          match.group(2).trim(),                                          match.group(3).trim(),                                          match.group(4).trim(),                                          match.group(5).trim());                        return logLine;        }        else        {            return null;        }    }         /**     * get the number of items in the archive which were accessioned between      * the provided start and end dates, with the given value for the DC field     * 'type' (unqualified)     *     * @param   context     the DSpace context for the action     * @param   type        value for DC field 'type' (unqualified)     *     * @return              an integer containing the relevant count     */    public static Integer getNumItems(Context context, String type)        throws SQLException    {        // FIXME: this method is clearly not optimised                // FIXME: we don't yet collect total statistics, such as number of items        // withdrawn, number in process of submission etc.  We should probably do        // that                // start the type constraint        String typeQuery = null;                if (type != null)        {            typeQuery = "SELECT item_id " +                        "FROM metadatavalue " +                        "WHERE text_value LIKE '%" + type + "%' " +                        "AND metadata_field_id = (" +                        " SELECT metadata_field_id " +                        " FROM metadatafieldregistry " +                        " WHERE element = 'type' " +                        " AND qualifier IS NULL) ";        }                // start the date constraint query buffer        StringBuffer dateQuery = new StringBuffer();        dateQuery.append("SELECT item_id " +                          "FROM metadatavalue " +                          "WHERE metadata_field_id = (" +                          " SELECT metadata_field_id " +                          " FROM metadatafieldregistry " +                          " WHERE element = 'date' " +                          " AND qualifier = 'accessioned') ");              if (startDate != null)        {           dateQuery.append(" AND text_value::timestamp > '" +                          unParseDate(startDate) + "'::timestamp ");        }                if (endDate != null)        {            dateQuery.append(" AND text_value::timestamp < ' " +                          unParseDate(endDate) + "'::timestamp ");        }                // build the final query        StringBuffer query = new StringBuffer();                query.append("SELECT COUNT(*) AS number " +                  "FROM item " +                  "WHERE in_archive = true " +                   "AND withdrawn = false ");                if (startDate != null || endDate != null)        {            query.append(" AND item_id IN ( " +                         dateQuery.toString() + ") ");        }        if (type != null)        {            query.append(" AND item_id IN ( " +                         typeQuery + ") ");        }                TableRow row = DatabaseManager.querySingle(context, query.toString());        // for some reason the number column is of "long" data type!        Long count = new Long(row.getLongColumn("number"));        return new Integer(count.intValue());    }            /**     * get the total number of items in the archive at time of execution,     * ignoring all other constraints     *     * @param   context     the DSpace context the action is being performed in     *     * @return              an Integer containing the number of items in the     *                      archive     */    public static Integer getNumItems(Context context)        throws SQLException    {        return getNumItems(context, null);    }            /**     * print out the usage information for this class to the standard out     */    public static void usage()    {        String usage = "Usage Information:\n" +                        "LogAnalyser [options [parameters]]\n" +                        "-log [log directory]\n" +                            "\tOptional\n" +                            "\tSpecify a directory containing log files\n" +                            "\tDefault uses [dspace.dir]/log from dspace.cfg\n" +                        "-file [file name regex]\n" +                            "\tOptional\n" +                            "\tSpecify a regular expression as the file name template.\n" +                            "\tCurrently this needs to be correctly escaped for Java string handling (FIXME)\n" +                            "\tDefault uses dspace.log*\n" +                        "-cfg [config file path]\n" +                            "\tOptional\n" +                            "\tSpecify a config file to be used\n" +                            "\tDefault uses dstat.cfg in dspace config directory\n" +                        "-out [output file path]\n" +                            "\tOptional\n" +                            "\tSpecify an output file to write results into\n" +                            "\tDefault uses dstat.dat in dspace log directory\n" +                        "-start [YYYY-MM-DD]\n" +                            "\tOptional\n" +                            "\tSpecify the start date of the analysis\n" +                            "\tIf a start date is specified then no attempt to gather \n" +                            "\tcurrent database statistics will be made unless -lookup is\n" +                            "\talso passed\n" +                            "\tDefault is to start from the earliest date records exist for\n" +                        "-end [YYYY-MM-DD]\n" +                            "\tOptional\n" +                            "\tSpecify the end date of the analysis\n" +                            "\tIf an end date is specified then no attempt to gather \n" +                            "\tcurrent database statistics will be made unless -lookup is\n" +                            "\talso passed\n" +                            "\tDefault is to work up to the last date records exist for\n" +                        "-lookup\n" +                            "\tOptional\n" +                            "\tForce a lookup of the current database statistics\n" +                            "\tOnly needs to be used if date constraints are also in place\n" +                        "-help\n" +                            "\tdisplay this usage information\n";                System.out.println(usage);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -