16 February 2014

Invalid Dates and Formatting your ExpPrint HTML Listings with Cascading Style Sheets (CSS)

A curious mix of topics you might think – but one lead to the other a few days ago, so in explaining a minor enhancement as a result of a customer reporting an issue, I thought I’d explain how I resolved the situation in more detail…

A customer reported a warning notification occurring when they loaded their listing in the ExpPrint Listing Viewer:

image

You can probably see from the information there that there’s something odd with the DatePrinted property – it’s reporting a date of 18-07-28950. Short of time travel that’s clearly invalid, and ExpPrint identified it because the XML date format is only valid for 4 digit years (whereas the underlying Windows timestamp caters for dates to the year 30827).

At this stage, it’ll be useful to know a little bit about how ExpPrint works, so if you’ve not read the previous article, it might be worth reading it before proceeding.

By opening the .xplisting file in a text editor such as Notepad and searching for the illegal year value, the file with the invalid date was found to be an old Word 6 document dating from 1997. Incidentally, printing and resaving the document in a newer version of Word fixed the incorrect date in the document.

Knowing that the problem was due to the invalid date in the originating document, I modified ExpPrint to check for dates with the year greater than 9999 and replace them with a fixed date of 09-09-9999 which is a valid year for the XML date format standard, but clearly not one most of us are likely to encounter.

Although 09-09-9999 is an obvious incorrect date, in a non-trivial listing I felt that it would easily get overlooked. Since its something you may want to be aware of, I decided to use that value to indicate in the HTML listing that there is an invalid date property, which brings us to the next part of this post…

Enhancing the Listing Presentation of Invalid Dates with Cascading Style Sheets (CSS)

Note that all the dates shows here are in English UK format. The dates you’ll see on your system will follow your locale format.

By checking the date fields in the xplisting data for the special year value 9999, ExpPrint now adds a new class name to the HTML listing – “Invalid”. Here’s an example of the generated HTML listing:

   1:  <td class="DName" style="padding-left:1em;">Old Word6 Document.DOC</td>
   2:  <td class="Size">28.50 KB</td>
   3:  <td class="System.ItemTypeText">Microsoft Word 97 - 2003 Document</td>
   4:  <td class="System.DateModified">07/02/2014 15:40:17</td>
   5:  <td class="System.Document.DatePrinted Invalid">09/09/9999 10:09:09</td>
   6:  <td class="System.Document.DateSaved">04/03/1997 14:06:00</td>



 

You can see that the date values for lines 4 & 6 have a single class name (which is the name of the property), while the invalid date in line 5 is also marked with the class name “Invalid”.


One of the beauties of CSS is the degree of control that you can have with well structured HTML document data. Because the invalid date is now marked with the class name “Invalid”, a CSS style can change how it’s displayed. I experimented with several approaches:


1. Colouring of the invalid data


I initially added the following CSS style to ExpPrint’s DefaultTableBaseCss.csd file – this is the default CSS file applied to any ExpPrint HTML listing without you having to choose it. If you’re creating your own styles, add them to your own .CSS file so that you don’t lose them with any updates to ExpPrint.

.Invalid
{
color:Red;
}



This results in anything in a listing with the class name “Invalid” showing as red text. Here’s the effect it has on the problematic file:


image


Having already used bold red text for the size field when the file size is greater than the configured limit, I felt this ought to be something different, so I tried…


2. Pre & post fixing the value with some text or symbols


In newer browsers, CSS allows you to add text content before and/or after the underlying value. This facility is used elsewhere in ExpPrint’s HTML output for the “No Access” unexpanded directory indication “[+]/[limited]”, symbolic link “{/}” and zip “[/]” file size indicators. You can find those uses in ExpPrint’s DefaultTableBaseCss.csd file. Here’s one of the options I tried for the “Invalid” style:

.Invalid:before
{
content:"Invalid ";
color:red;
}
.Invalid:after
{
content:" ◄";
color:red;
}



Which results in this:


image


One drawback of this technique however, is that you might rightly assume that you can use the browser’s Find facility to find the injected text – but you can’t as the text is a presentation addition, it’s not in the HTML document. Also, the additional text affects the width of the column.


I eventually settled on…


3. Strikethrough with a background colour


I opted for the following style because it stands out without introducing any additional texts that would extend the width of the listing column:


.Invalid
{
background-color:Yellow;
text-decoration:line-through;
}

image


If you’d prefer to see a different presentation, feel free to add your own custom CSS file for the .Invalid style, as any custom style files will override the default.


Other Invalid Properties


In investigating the invalid dates, the only occurrences I've discovered have been in old Word documents (circa Word V6), but the remedy applies to any date property. I’ve also discovered that some old Word documents also had negative values for numeric properties that you would not expect to be negative values, such as the word and page counts. Unfortunately the Windows property system defines these to be signed values, so there's no universal way of detecting them as invalid values. Consequently I've modified ExpPrint's XSD schema (from V6.1.1.2) to accept these as signed values (they were previously unsigned) to match the Windows property definitions and prevent ExpPrint reporting them as errors.


Summary


From ExpPrint V6.1.1.2, it will no longer create listings with invalid dates in them, and if you see dates with the year 9999 in them, ExpPrint is indicating that the date in the underlying file is invalid – in which case you may be able to see what the invalid date is from the offending file’s property pages in Windows Explorer.


I hope I’ve managed to illustrate some of the power and flexibility that you can apply to the presentation of the HTML output in ExpPrint using CSS. I aim to do a more detailed document on how to target your CSS for ExpPrint listings in a future post. Feel free to create your own CSS files to experiment with the possibilities. If you need any guidance, don’t hesitate to ask.


If you’d like to learn more about CSS, there’s a wealth of good information freely available from sites like http://www.w3schools.com/


As always, if you do encounter any problems with ExpPrint or any of our software, please email us and let us know; we’ll do our utmost to fix any reproducible problem and get an update released to resolve it as soon as possible.

No comments:

Post a Comment