01: package com.opensymphony.module.sitemesh.html.rules;
02:
03: import com.opensymphony.module.sitemesh.html.BlockExtractingRule;
04: import com.opensymphony.module.sitemesh.html.Tag;
05:
06: /**
07: * Extracts the extra properties saved in HTML from MS Office applications (Word and Excel),
08: * such as Author, Company, Version, etc.
09: *
10: * @author Joe Walnes
11: */
12: public class MSOfficeDocumentPropertiesRule extends BlockExtractingRule {
13:
14: private final PageBuilder page;
15: private boolean inDocumentProperties;
16:
17: public MSOfficeDocumentPropertiesRule(PageBuilder page) {
18: super (true);
19: this .page = page;
20: }
21:
22: public boolean shouldProcess(String name) {
23: return (inDocumentProperties && name.startsWith("o:"))
24: || name.equals("o:documentproperties");
25: }
26:
27: public void process(Tag tag) {
28: if (tag.getName().equals("o:DocumentProperties")) {
29: inDocumentProperties = (tag.getType() == Tag.OPEN);
30: tag.writeTo(currentBuffer());
31: } else {
32: super .process(tag);
33: }
34: }
35:
36: protected void start(Tag tag) {
37: }
38:
39: protected void end(Tag tag) {
40: String name = tag.getName().substring(2);
41: page.addProperty("office.DocumentProperties." + name,
42: currentBuffer().toString());
43: context.mergeBuffer();
44: }
45:
46: }
|