Search in sources :

Example 91 with Format

use of java.text.Format in project OpenGrok by OpenGrok.

the class DirectoryListing method listTo.

/**
     * Write a htmlized listing of the given directory to the given destination.
     *
     * @param contextPath path used for link prefixes
     * @param dir the directory to list
     * @param out write destination
     * @param path virtual path of the directory (usually the path name of
     *  <var>dir</var> with the opengrok source directory stripped off).
     * @param files basenames of potential children of the directory to list.
     *  Gets filtered by {@link IgnoredNames}.
     * @return a possible empty list of README files included in the written
     *  listing.
     * @throws org.opensolaris.opengrok.history.HistoryException when we cannot
     * get result from scm
     *
     * @throws java.io.IOException when any I/O problem
     * @throws NullPointerException if a parameter except <var>files</var>
     *  is {@code null}
     */
public List<String> listTo(String contextPath, File dir, Writer out, String path, List<String> files) throws HistoryException, IOException {
    // TODO this belongs to a jsp, not here
    ArrayList<String> readMes = new ArrayList<>();
    int offset = -1;
    EftarFileReader.FNode parentFNode = null;
    if (desc != null) {
        parentFNode = desc.getNode(path);
        if (parentFNode != null) {
            offset = parentFNode.childOffset;
        }
    }
    out.write("<table id=\"dirlist\" class=\"tablesorter tablesorter-default\">\n");
    out.write("<thead>\n");
    out.write("<tr>\n");
    out.write("<th class=\"sorter-false\"></th>\n");
    out.write("<th>Name</th>\n");
    out.write("<th class=\"sorter-false\"></th>\n");
    out.write("<th class=\"sort-dates\">Date</th>\n");
    out.write("<th class=\"sort-groksizes\">Size</th>\n");
    if (offset > 0) {
        out.write("<th><tt>Description</tt></th>\n");
    }
    out.write("</tr>\n</thead>\n<tbody>\n");
    IgnoredNames ignoredNames = RuntimeEnvironment.getInstance().getIgnoredNames();
    Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault());
    // print the '..' entry even for empty directories
    if (path.length() != 0) {
        out.write("<tr><td><p class=\"'r'\"/></td><td>");
        out.write("<b><a href=\"..\">..</a></b></td><td></td>");
        printDateSize(out, dir.getParentFile(), null, dateFormatter);
        out.write("</tr>\n");
    }
    Map<String, Date> modTimes = HistoryGuru.getInstance().getLastModifiedTimes(dir);
    if (files != null) {
        for (String file : files) {
            if (ignoredNames.ignore(file)) {
                continue;
            }
            File child = new File(dir, file);
            if (ignoredNames.ignore(child)) {
                continue;
            }
            if (file.startsWith("README") || file.endsWith("README") || file.startsWith("readme")) {
                readMes.add(file);
            }
            boolean isDir = child.isDirectory();
            out.write("<tr><td>");
            out.write("<p class=\"");
            out.write(isDir ? 'r' : 'p');
            out.write("\"/>");
            out.write("</td><td><a href=\"");
            if (isDir) {
                String longpath = getSimplifiedPath(child);
                out.write(Util.URIEncodePath(longpath));
                out.write("/\"><b>");
                int idx;
                if ((idx = longpath.lastIndexOf('/')) > 0) {
                    out.write("<span class=\"simplified-path\">");
                    out.write(longpath.substring(0, idx + 1));
                    out.write("</span>");
                    out.write(longpath.substring(idx + 1));
                } else {
                    out.write(longpath);
                }
                out.write("</b></a>/");
            } else {
                out.write(Util.URIEncodePath(file));
                out.write("\">");
                out.write(file);
                out.write("</a>");
            }
            out.write("</td>");
            Util.writeHAD(out, contextPath, path + file, isDir);
            printDateSize(out, child, modTimes.get(file), dateFormatter);
            if (offset > 0) {
                String briefDesc = desc.getChildTag(parentFNode, file);
                if (briefDesc == null) {
                    out.write("<td/>");
                } else {
                    out.write("<td>");
                    out.write(briefDesc);
                    out.write("</td>");
                }
            }
            out.write("</tr>\n");
        }
    }
    out.write("</tbody>\n</table>");
    return readMes;
}
Also used : ArrayList(java.util.ArrayList) IgnoredNames(org.opensolaris.opengrok.index.IgnoredNames) Date(java.util.Date) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 92 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_String_parseError.

@Test(expectedExceptions = ParseException.class)
public void test_toFormat_parseObject_String_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX");
    } catch (ParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX"), true);
        assertEquals(ex.getErrorOffset(), 3);
        throw ex;
    }
}
Also used : Format(java.text.Format) ParseException(java.text.ParseException) DateTimeParseException(java.time.format.DateTimeParseException) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 93 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition.

//-----------------------------------------------------------------------
@Test
public void test_toFormat_parseObject_StringParsePosition() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30XXX", pos);
    assertEquals(pos.getIndex(), 5);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
Also used : Format(java.text.Format) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 94 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_String_null.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_parseObject_String_null() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject((String) null);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 95 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_invalidPosition_tooBig.

@Test
public void test_toFormat_parseObject_StringParsePosition_invalidPosition_tooBig() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter dtf = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(6);
    Format test = dtf.toFormat();
    assertNull(test.parseObject("ONE30", pos));
    assertTrue(pos.getErrorIndex() >= 0);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Aggregations

Format (java.text.Format)160 SimpleDateFormat (java.text.SimpleDateFormat)63 DecimalFormat (java.text.DecimalFormat)39 Test (org.junit.Test)38 DateFormat (java.text.DateFormat)34 Date (java.util.Date)32 NumberFormat (java.text.NumberFormat)29 DateTimeFormatter (java.time.format.DateTimeFormatter)27 ChoiceFormat (java.text.ChoiceFormat)24 ParsePosition (java.text.ParsePosition)22 MessageFormat (java.text.MessageFormat)20 FieldPosition (java.text.FieldPosition)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)15 ParseException (java.text.ParseException)11 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)10 AttributedString (java.text.AttributedString)9 TemporalAccessor (java.time.temporal.TemporalAccessor)7 Calendar (java.util.Calendar)7