KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > parser > rules > MSOfficeDocumentPropertiesRule


1 package com.opensymphony.module.sitemesh.parser.rules;
2
3 import com.opensymphony.module.sitemesh.HTMLPage;
4 import com.opensymphony.module.sitemesh.html.BasicRule;
5 import com.opensymphony.module.sitemesh.html.Tag;
6 import com.opensymphony.module.sitemesh.html.BlockExtractingRule;
7
8 /**
9  * Extracts the extra properties saved in HTML from MS Office applications (Word and Excel),
10  * such as Author, Company, Version, etc.
11  *
12  * @author Joe Walnes
13  */

14 public class MSOfficeDocumentPropertiesRule extends BlockExtractingRule {
15
16     private final HTMLPage page;
17     private boolean inDocumentProperties;
18
19     public MSOfficeDocumentPropertiesRule(HTMLPage page) {
20         super(true);
21         this.page = page;
22     }
23
24     public boolean shouldProcess(String JavaDoc name) {
25         return (inDocumentProperties && name.startsWith("o:")) || name.equals("o:DocumentProperties");
26     }
27
28     public void process(Tag tag) {
29         if (tag.getName().equals("o:DocumentProperties")) {
30             inDocumentProperties = (tag.getType() == Tag.OPEN);
31             tag.writeTo(context.currentBuffer());
32         } else {
33             super.process(tag);
34         }
35     }
36
37     protected void start(Tag tag) {
38     }
39
40     protected void end(Tag tag) {
41         String JavaDoc name = tag.getName().substring(2);
42         page.addProperty("office.DocumentProperties." + name, context.currentBuffer().toString());
43         context.mergeBuffer();
44     }
45
46 }
47
Popular Tags