1 package org.jahia.services.fileextraction; 2 3 import java.util.ArrayList ; 4 import java.util.Date ; 5 import java.util.HashMap ; 6 ; 7 8 12 public class ExtractedDocumentImpl implements ExtractedDocument { 13 14 private HashMap properties = new HashMap (); 15 private String content; 16 17 public ExtractedDocumentImpl(){ 18 } 19 20 public ExtractedDocumentImpl(String content){ 21 this(content,null); 22 } 23 24 public ExtractedDocumentImpl(String content, HashMap properties){ 25 this.content = content; 26 if ( properties != null ){ 27 this.properties = properties; 28 } 29 } 30 31 public void setContent(String content){ 32 this.content = content; 33 } 34 35 public void setProperties(HashMap properties){ 36 if ( properties != null ){ 37 this.properties = properties; 38 } 39 } 40 41 public void setProperty(String name, Object [] values){ 42 if ( name != null && values != null ){ 43 this.getProperties().put(name,values); 44 } 45 } 46 47 public void setProperty(String name, Object value){ 48 if ( name != null && value != null ){ 49 Object [] values = {value}; 50 this.getProperties().put(name, values); 51 } 52 } 53 54 58 public String getContentAsString(){ 59 return this.content; 60 } 61 62 66 public HashMap getProperties(){ 67 if ( this.properties == null) { 68 this.properties = new HashMap (); 69 } 70 return this.properties; 71 } 72 73 77 public String [] getPropertiesAsStrings(String name){ 78 String [] results = null; 79 ArrayList arrayList = new ArrayList (); 80 Object [] objs = (Object [])this.getProperties().get(name); 81 Object obj = null; 82 String strVal = null; 83 for ( int i=0; i<objs.length; i++){ 84 strVal = null; 85 obj = objs[i]; 86 try { 87 if ( obj instanceof String ){ 88 strVal = (String )obj; 89 } else if ( obj instanceof Date ){ 90 strVal = String.valueOf(((Date )obj).getTime()); 91 } else { 92 strVal = String.valueOf(obj); 93 } 94 } catch ( Throwable t ){ 95 } 96 if ( strVal != null) { 97 arrayList.add(strVal); 98 } 99 } 100 101 results = new String [arrayList.size()]; 102 for ( int i=0; i<arrayList.size(); i++ ){ 103 results[i] = (String )arrayList.get(i); 104 } 105 return results; 106 } 107 108 113 public String getPropertyAsString(String name){ 114 Object [] objs = (Object [])this.getProperties().get(name); 115 Object obj = null; 116 String strVal = null; 117 for ( int i=0; i<objs.length; i++){ 118 strVal = null; 119 obj = objs[i]; 120 try { 121 if ( obj instanceof String ){ 122 strVal = (String )obj; 123 } else if ( obj instanceof Date ){ 124 strVal = String.valueOf(((Date )obj).getTime()); 125 } else { 126 strVal = String.valueOf(obj); 127 } 128 } catch ( Throwable t ){ 129 } 130 break; 131 } 132 return strVal; 133 } 134 135 } 136 | Popular Tags |