1 2 3 4 package net.nutch.parse.rtf; 5 6 import com.etranslate.tm.processing.rtf.RTFParserDelegate; 7 8 import java.util.Arrays ; 9 import java.util.List ; 10 import java.util.Properties ; 11 12 16 public class RTFParserDelegateImpl implements RTFParserDelegate { 17 18 String tabs = ""; 19 Properties metadata = new Properties (); 20 21 String [] META_NAMES_TEXT = {"title", "subject", "author", "manager", 22 "company", "operator", "category", "keywords", 23 "comment", "doccomm", "hlinkbase"}; 24 String [] META_NAMES_DATE = {"creatim", "creatim", "printim", "buptim"}; 25 26 String metaName = ""; 27 List metaNamesText = Arrays.asList(META_NAMES_TEXT); 28 List metaNamesDate = Arrays.asList(META_NAMES_DATE); 29 boolean isMetaTextValue = false; 30 boolean isMetaDateValue = false; 31 String content = ""; 32 boolean justOpenedGroup = false; 33 boolean ignoreMode = false; 34 35 public void text(String text, String style, int context) { 36 justOpenedGroup = false; 37 if (isMetaTextValue && context == IN_INFO) { 38 metadata.setProperty(metaName, text); 39 isMetaTextValue = false; 40 } else if (context == IN_DOCUMENT && !ignoreMode) { 41 content += text; 42 } 43 } 44 45 public void controlSymbol(String controlSymbol, int context) { 46 if("\\*".equals(controlSymbol) && justOpenedGroup){ 47 ignoreMode = true; 48 } 49 justOpenedGroup = false; 50 } 51 52 public void controlWord(String controlWord, int value, int context) { 53 justOpenedGroup = false; 54 controlWord = controlWord.substring(1); 55 switch (context) { 56 case IN_INFO: 57 if (metaNamesText.contains(controlWord)) { 58 isMetaTextValue = true; 59 metaName = controlWord; 60 } else if (metaNamesDate.contains(controlWord)) { 61 } 63 break; 64 case IN_DOCUMENT: 65 break; 67 } 68 } 69 70 public void openGroup(int depth) { 71 justOpenedGroup = true; 72 } 73 74 public void closeGroup(int depth) { 75 justOpenedGroup = false; 76 ignoreMode = false; 77 } 78 79 public void styleList(List styles) { 80 } 81 82 public void startDocument() { 83 } 84 85 public void endDocument() { 86 } 87 88 public String getText() { 89 return content; 90 } 91 92 public Properties getMetaData() { 93 return metadata; 94 } 95 } 96 | Popular Tags |