1 #ifndef LVOPC_H 2 #define LVOPC_H 3 4 #include "lvstream.h" 5 #include "lvhashtable.h" 6 #include "props.h" 7 8 /* 9 * Open Packaging Conventions (OPC) 10 * The OPC is specified in Part 2 of the Office Open XML standards ISO/IEC 29500:2008 and ECMA-376 11 */ 12 13 class OpcPart; 14 typedef LVFastRef<OpcPart> OpcPartRef; 15 class OpcPackage; 16 17 class OpcPart : public LVRefCounter 18 { 19 public: 20 ~OpcPart(); 21 LVStreamRef open(); 22 lString32 getRelatedPartName(const lChar32 * const relationType, const lString32 id = lString32()); 23 OpcPartRef getRelatedPart(const lChar32 * const relationType, const lString32 id = lString32()); 24 protected: OpcPart(OpcPackage * package,lString32 name)25 OpcPart(OpcPackage* package, lString32 name): 26 m_relations(16), m_package(package), m_name(name), m_relationsValid(false) 27 { 28 } 29 void readRelations(); 30 lString32 getTargetPath(const lString32 srcPath, const lString32 targetMode, lString32 target); createPart(OpcPackage * package,lString32 name)31 OpcPart* createPart(OpcPackage* package, lString32 name) { 32 return new OpcPart(package, name); 33 } 34 private: 35 LVHashTable<lString32, LVHashTable<lString32, lString32> *> m_relations; 36 OpcPackage* m_package; 37 lString32 m_name; 38 bool m_relationsValid; 39 private: 40 // non copyable 41 OpcPart(); 42 OpcPart( const OpcPart& ); 43 OpcPart& operator=( const OpcPart& ); 44 }; 45 46 47 class OpcPackage : public OpcPart 48 { 49 private: 50 bool m_contentTypesValid; 51 LVContainerRef m_container; 52 LVHashTable<lString32, lString32> m_contentTypes; 53 private: 54 // non copyable 55 OpcPackage(); 56 OpcPackage( const OpcPackage& ); 57 OpcPackage& operator=( const OpcPart& ); 58 public: OpcPackage(LVContainerRef container)59 OpcPackage(LVContainerRef container) : OpcPart(this, U"/"), 60 m_contentTypesValid(false), m_container(container), 61 m_contentTypes(16) 62 { 63 } open(lString32 partName)64 LVStreamRef open(lString32 partName) { 65 return m_container->OpenStream(partName.c_str(), LVOM_READ); 66 } 67 lString32 getContentPartName(const lChar32* contentType); getContentPart(const lChar32 * contentType)68 OpcPartRef getContentPart(const lChar32* contentType) { 69 return getPart(getContentPartName(contentType)); 70 } openContentPart(const lChar32 * contentType)71 LVStreamRef openContentPart(const lChar32* contentType) { 72 return open(getContentPartName(contentType)); 73 } 74 OpcPartRef getPart(const lString32 partName); 75 bool partExist(const lString32 partName); 76 void readCoreProperties(CRPropRef doc_props); 77 private: 78 void readContentTypes(); 79 }; 80 81 #endif // LVOPC_H 82