• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

pd_DocumentRDF.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiWord
00004  * Copyright (c) 2010 GPL. V2+ copyright to AbiSource B.V.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 #ifndef PD_DOCUMENTRDF_H
00023 #define PD_DOCUMENTRDF_H
00024 
00025 #include <string>
00026 #include <list>
00027 #include <map>
00028 #include <memory>
00029 #include <set>
00030 #include "ut_types.h"
00031 #include "pt_Types.h"
00032 
00033 
00034 class PD_Document;
00035 class pt_PieceTable;
00036 class PP_AttrProp;
00037 class RDFModel_SPARQLLimited;
00038 class pf_Frag;
00039 class pf_Frag_Object;
00040 class PD_RDFSemanticItem;
00041 class FV_View;
00042 
00043 class   PD_DocumentRDFMutation;
00044 typedef std::shared_ptr<PD_DocumentRDFMutation> PD_DocumentRDFMutationHandle;
00045 class   PD_RDFModel;
00046 typedef std::shared_ptr<PD_RDFModel> PD_RDFModelHandle;
00047 class   PD_DocumentRDF;
00048 typedef std::shared_ptr<PD_DocumentRDF> PD_DocumentRDFHandle;
00049 
00050 
00058 class ABI_EXPORT PD_URI
00059 {
00060   protected:
00061     std::string m_value;
00062 
00063   public:
00064     PD_URI( const std::string& v = "" );
00065     virtual ~PD_URI() {}
00066     virtual std::string toString() const;
00067     int  length() const
00068     {
00069         return m_value.length();
00070     }
00071     bool isValid() const;
00072     bool operator==(const PD_URI& b) const;
00073     bool operator==(const std::string& b) const;
00074     bool operator<(const PD_URI& b) const;
00075 
00076     virtual bool read( std::istream& ss );
00077     virtual bool write( std::ostream& ss ) const;
00078 
00079     PD_URI prefixedToURI(const PD_RDFModelHandle & model) const;
00080 
00081     bool empty() const        { return m_value.empty(); }
00082     const char* c_str() const { return m_value.c_str(); }
00083 
00084 };
00085 
00086 template <class ostream>
00087 ostream& operator<<( ostream& ss, PD_URI& uri )
00088 {
00089     ss << uri.toString();
00090     return ss;
00091 }
00092 
00093 
00094 
00112 class ABI_EXPORT PD_Object : public PD_URI
00113 {
00114   public:
00115     enum
00116     {
00117         OBJECT_TYPE_URI = 1,
00118         OBJECT_TYPE_LITERAL,
00119         OBJECT_TYPE_BNODE
00120     };
00121 
00122     PD_Object( const std::string& v = "" );
00123     PD_Object( const PD_URI& u );
00124     PD_Object( const std::string& v, int objectType, const std::string& xsdtype = "" );
00125 
00126     std::string getXSDType() const;
00127     bool hasXSDType() const;
00128     int  getObjectType() const;
00129     bool isLiteral() const;
00130     bool isURI() const;
00131     bool isBNode() const;
00132 
00133     virtual bool read( std::istream& ss );
00134     virtual bool write( std::ostream& ss ) const;
00135 
00136   protected:
00137     std::string m_xsdType;
00138     std::string m_context;
00139     int m_objectType;
00140 };
00147 class ABI_EXPORT PD_Literal : public PD_Object
00148 {
00149   public:
00150     PD_Literal( const std::string& v = "", const std::string& xsdtype = "" );
00151 };
00152 
00153 typedef std::list< PD_URI > PD_URIList;
00154 // REQUIRES: ordered, same key can -> many different values
00155 typedef std::multimap< PD_URI, PD_Object > POCol;
00156 typedef std::list< PD_Object > PD_ObjectList;
00157 
00158 struct PD_URIListCompare : public std::binary_function<PD_URI, PD_URI, bool> {
00159     bool operator()(PD_URI x, PD_URI y) { return x.toString() < y.toString(); }
00160 };
00161 
00162 
00167 class ABI_EXPORT PD_RDFStatement
00168 {
00169     PD_URI    m_subject;
00170     PD_URI    m_predicate;
00171     PD_Object m_object;
00172     bool      m_isValid;
00173   public:
00174     PD_RDFStatement();
00175     PD_RDFStatement( PD_RDFModelHandle model, const PD_URI& s, const PD_URI& p, const PD_Object& o );
00176     PD_RDFStatement( const PD_URI& s, const PD_URI& p, const PD_Object& o );
00177     PD_RDFStatement( const std::string& s, const std::string& p, const PD_Object& o );
00178     PD_RDFStatement( const std::string& s, const std::string& p, const PD_Literal& o );
00179     const PD_URI&    getSubject() const;
00180     const PD_URI&    getPredicate() const;
00181     const PD_Object& getObject() const;
00182     bool             isValid() const;
00183     std::string      toString() const;
00184 
00185     PD_RDFStatement uriToPrefixed( PD_RDFModelHandle model ) const;
00186     PD_RDFStatement prefixedToURI( PD_RDFModelHandle model ) const;
00187 
00188     bool operator==(const PD_RDFStatement& b) const;
00189 
00190 };
00191 
00192 template <class ostream>
00193 ostream& operator<<( ostream& ss, const PD_RDFStatement& st )
00194 {
00195     ss << st.toString();
00196     return ss;
00197 }
00198 
00199 
00200 
00201 
00202 class ABI_EXPORT PD_RDFModelIterator
00203     :
00204     public std::iterator< std::forward_iterator_tag, PD_RDFStatement >
00205 {
00206     PD_RDFModelHandle   m_model;
00207     const PP_AttrProp*  m_AP;
00208     bool                m_end;
00209     size_t              m_apPropertyNumber;
00210     std::string         m_subject;
00211     POCol               m_pocol;
00212     POCol::iterator     m_pocoliter;
00213     PD_RDFStatement     m_current;
00214 
00215     void setup_pocol();
00216 
00217   public:
00218     typedef const PD_RDFModelIterator& self_constref;
00219     typedef PD_RDFModelIterator& self_reference;
00220     typedef PD_RDFModelIterator  self_type;
00221 
00222     PD_RDFModelIterator();
00223     ~PD_RDFModelIterator();
00224     PD_RDFModelIterator( PD_RDFModelHandle model, const PP_AttrProp* AP );
00225 
00226     self_reference operator++();
00227     bool operator==( self_constref other );
00228     PD_RDFModelIterator& operator=( const PD_RDFModelIterator& other );
00229 
00230     self_type operator++(int)
00231     {
00232         self_type result( *this );
00233         ++( *this );
00234         return result;
00235     }
00236     bool operator!=( self_constref other )
00237     {
00238         return !operator==(other);
00239     }
00240     reference operator*()
00241     {
00242         return m_current;
00243     }
00244 
00245     self_reference moveToNextSubject();
00246     void moveToNextSubjectReadPO();
00247     bool moveToNextSubjectHavePOCol();
00248 };
00249 
00250 
00276 class ABI_EXPORT PD_RDFModel
00277 {
00278   protected:
00279     long m_version;
00280     PD_URI    front( const PD_URIList& l    ) const;
00281     PD_Object front( const PD_ObjectList& l ) const;
00282     PD_RDFModel();
00283     void incremenetVersion();
00284 
00285   public:
00286     virtual ~PD_RDFModel() {}
00287     virtual PD_ObjectList getObjects( const PD_URI& s, const PD_URI& p );
00288     virtual PD_Object     getObject( const PD_URI& s, const PD_URI& p );
00289     virtual PD_URIList getSubjects( const PD_URI& p, const PD_Object& o );
00290     virtual PD_URI     getSubject( const PD_URI& p, const PD_Object& o );
00291     virtual PD_URIList getAllSubjects();
00292     virtual POCol      getArcsOut( const PD_URI& s );
00293     virtual bool       contains( const PD_URI& s, const PD_URI& p, const PD_Object& o );
00294     virtual bool       contains( const PD_URI& s, const PD_URI& p );
00295     virtual bool       contains( const PD_RDFStatement& st );
00296     virtual long       getTripleCount();
00297 
00298     virtual PD_RDFModelIterator begin() = 0;
00299     virtual PD_RDFModelIterator end() = 0;
00300 
00301     typedef std::map< std::string, std::string > stringmap_t;
00302     typedef stringmap_t uriToPrefix_t;
00303     virtual uriToPrefix_t& getUriToPrefix();
00304 
00305 
00306     virtual void dumpModel( const std::string& headerMsg = "dumpModel()" );
00307 
00308     virtual PD_DocumentRDFMutationHandle createMutation() = 0;
00309     virtual std::string uriToPrefixed( const std::string& uri );
00310     virtual std::string prefixedToURI( const std::string& prefixed );
00311 
00312     inline long size()  { return getTripleCount(); }
00313     inline bool empty() { return size() == 0; }
00314 
00315     long getVersion() const { return m_version; }
00316 
00317 };
00318 
00319 class   PD_RDFSemanticItem;
00320 typedef std::shared_ptr<PD_RDFSemanticItem> PD_RDFSemanticItemHandle;
00321 typedef std::list< PD_RDFSemanticItemHandle > PD_RDFSemanticItems;
00322 class   PD_RDFContact;
00323 typedef std::shared_ptr<PD_RDFContact >     PD_RDFContactHandle;
00324 typedef std::list< PD_RDFContactHandle      > PD_RDFContacts;
00325 class   PD_RDFEvent;
00326 typedef std::shared_ptr<PD_RDFEvent >       PD_RDFEventHandle;
00327 typedef std::list< PD_RDFEventHandle      >   PD_RDFEvents;
00328 class   PD_RDFLocation;
00329 typedef std::shared_ptr<PD_RDFLocation >       PD_RDFLocationHandle;
00330 typedef std::list< PD_RDFLocationHandle      >   PD_RDFLocations;
00331 class   PD_RDFSemanticStylesheet;
00332 typedef std::shared_ptr<PD_RDFSemanticStylesheet > PD_RDFSemanticStylesheetHandle;
00333 typedef std::list< PD_RDFSemanticStylesheetHandle  > PD_RDFSemanticStylesheets;
00334 class   PD_RDFSemanticItemViewSite;
00335 typedef std::shared_ptr<PD_RDFSemanticItemViewSite> PD_RDFSemanticItemViewSiteHandle;
00336 typedef std::list< PD_RDFSemanticItemViewSiteHandle > PD_RDFSemanticItemViewSites;
00337 
00338 // semantic stylesheets
00339 #define RDF_SEMANTIC_STYLESHEET_NAME                         "name"
00340 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME                 RDF_SEMANTIC_STYLESHEET_NAME
00341 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NICK                 "nick"
00342 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME_PHONE           "name, phone"
00343 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NICK_PHONE           "nick, phone"
00344 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME_HOMEPAGE_PHONE  "name, (homepage), phone"
00345 #define RDF_SEMANTIC_STYLESHEET_EVENT_NAME                   RDF_SEMANTIC_STYLESHEET_NAME
00346 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY                "summary"
00347 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_LOCATION       "summary, location"
00348 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_LOCATION_TIMES "summary, location, start date/time"
00349 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_TIMES          "summary, start date/time"
00350 #define RDF_SEMANTIC_STYLESHEET_LOCATION_NAME                RDF_SEMANTIC_STYLESHEET_NAME
00351 #define RDF_SEMANTIC_STYLESHEET_LOCATION_NAME_LATLONG        "name, digital latitude, digital longitude"
00352 
00358 class ABI_EXPORT PD_RDFSemanticItem
00359 {
00360     PD_DocumentRDFHandle m_rdf;
00361     PD_URI               m_context;
00362   protected:
00363     std::string          m_name;
00364     PD_URI               m_linkingSubject;
00365     typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00366 
00367     virtual std::string getImportFromFileName( const std::string& filename_const,
00368                                                std::list< std::pair< std::string, std::string> > types ) const;
00369     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00370 
00371     virtual std::string getExportToFileName( const std::string& filename_const,
00372                                              std::string defaultExtension,
00373                                              std::list< std::pair< std::string, std::string> > types ) const;
00374     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00375     virtual std::string getDefaultExtension() const;
00376     std::string getProperty( std::string subj, std::string pred, std::string defVal ) const;
00377 
00378   public:
00379     PD_RDFSemanticItem( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00380     virtual ~PD_RDFSemanticItem();
00381 
00382     PD_DocumentRDFHandle getRDF() const;
00383     PD_DocumentRDFMutationHandle createMutation();
00384 
00385     std::string requestExportFileNameByDialog();
00386 
00387 
00398     virtual PD_URI linkingSubject() const;
00399 
00400 
00408     static std::set< std::string > getXMLIDsForLinkingSubject( PD_DocumentRDFHandle rdf, const std::string& linkingSubj );
00409 
00410 
00414     virtual std::string name() const;
00415     virtual void        setName( const std::string& n );
00416 
00421     virtual std::string getDisplayLabel() const;
00422 
00423 
00435     virtual std::set< std::string > getXMLIDs() const;
00436 
00448      virtual void* createEditor() = 0;
00449 
00453      virtual void showEditorWindow( const PD_RDFSemanticItemHandle & c );
00454      virtual void showEditorWindow( const PD_RDFSemanticItems & cl );
00455 
00462      void updateFromEditorData();
00463      virtual void updateFromEditorData( PD_DocumentRDFMutationHandle m ) = 0;
00464 
00465 
00476      virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 ) = 0;
00477 
00482      virtual void exportToFile( const std::string& filename = "" ) const = 0;
00483 
00490      virtual void importFromFile( const std::string& filename = "" );
00491 
00492 
00498      static PD_RDFSemanticItemHandle createSemanticItem( PD_DocumentRDFHandle rdf, const std::string& semanticClass );
00499      static PD_RDFSemanticItemHandle createSemanticItem( PD_DocumentRDFHandle rdf,
00500                                                          PD_ResultBindings_t::iterator it,
00501                                                          const std::string& semanticClass );
00502 
00510      static std::list< std::string > getClassNames();
00511 
00512 
00519      std::pair< PT_DocPosition, PT_DocPosition > insert( PD_DocumentRDFMutationHandle m, FV_View* pView );
00520      std::pair< PT_DocPosition, PT_DocPosition > insert( FV_View* pView );
00521 
00522 
00523      virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00524 
00525 
00530      PD_RDFSemanticStylesheetHandle findStylesheetByUuid(const std::string &uuid) const;
00531 
00537     PD_RDFSemanticStylesheetHandle findStylesheetByName(const std::string &sheetType, const std::string &n) const;
00543     PD_RDFSemanticStylesheetHandle findStylesheetByName(const PD_RDFSemanticStylesheets& ssl, const std::string &n) const;
00544 
00554     PD_RDFSemanticStylesheetHandle defaultStylesheet() const;
00555 
00560     virtual PD_RDFSemanticStylesheets stylesheets() const = 0;
00561     virtual std::string className() const = 0;
00562 
00563     enum RelationType
00564     {
00565         RELATION_FOAF_KNOWS = 1
00566     };
00567     void relationAdd( PD_RDFSemanticItemHandle si, RelationType rt );
00568     PD_RDFSemanticItems relationFind( RelationType rt );
00569 
00570   protected:
00571 
00572      std::pair< PT_DocPosition, PT_DocPosition > insertTextWithXMLID( const std::string& textconst,
00573                                                                       const std::string& xmlid );
00574 
00594      virtual void importFromDataComplete( std::istream& iss,
00595                                           PD_DocumentRDFHandle rdf,
00596                                           PD_DocumentRDFMutationHandle m,
00597                                           PD_DocumentRange * pDocRange = 0 );
00598 
00599      std::string bindingAsString( PD_ResultBindings_t::iterator& it, const std::string k );
00600      std::string optionalBindingAsString( PD_ResultBindings_t::iterator& it, const std::string k );
00601 
00602     PD_URI& handleSubjectDefaultArgument( PD_URI& subj );
00603 
00609     virtual PD_URI context() const;
00610 
00616     void setRDFType(PD_DocumentRDFMutationHandle m, const std::string& type, PD_URI subj = PD_URI());
00617     void setRDFType(const std::string& type, PD_URI subj = PD_URI());
00618 
00619 
00639     void updateTriple( PD_DocumentRDFMutationHandle m, std::string& toModify, const std::string& newValue, const PD_URI& predString );
00640     void updateTriple( PD_DocumentRDFMutationHandle m, time_t&      toModify, time_t newValue, const PD_URI& predString );
00641     void updateTriple( PD_DocumentRDFMutationHandle m, double&      toModify, double newValue, const PD_URI& predString );
00642     void updateTriple( PD_DocumentRDFMutationHandle m, double&      toModify, double newValue, const PD_URI& predString, PD_URI linkingSubject  );
00643 
00644     void updateTriple( std::string& toModify, const std::string& newValue, const PD_URI& predString );
00645     void updateTriple( time_t&      toModify, time_t newValue, const PD_URI& predString );
00646     void updateTriple( double&      toModify, double newValue, const PD_URI& predString );
00647 
00651     PD_URI createUUIDNode();
00652 
00653 
00654 protected:
00665     void updateTriple_remove( PD_DocumentRDFMutationHandle m,
00666                               const PD_URI& toModify,
00667                               const PD_URI& predString,
00668                               const PD_URI& explicitLinkingSubject );
00669 
00675     void updateTriple_add( PD_DocumentRDFMutationHandle m,
00676                            const PD_URI& toModify,
00677                            const PD_URI& predString,
00678                            const PD_URI& explicitLinkingSubject );
00679 
00680 };
00681 
00682 
00683 
00684 class ABI_EXPORT PD_RDFContact : public PD_RDFSemanticItem
00685 {
00686   protected:
00687     std::string m_nick;
00688     std::string m_email;
00689     std::string m_homePage;
00690     std::string m_imageUrl;
00691     std::string m_phone;
00692     std::string m_jabberID;
00693 
00694     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00695     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00696     virtual std::string getDefaultExtension() const;
00697 
00698   public:
00699     PD_RDFContact( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00700     virtual ~PD_RDFContact();
00701 
00702     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00703     virtual void exportToFile( const std::string& filename = "" ) const;
00704     virtual std::string getDisplayLabel() const;
00705     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00706     virtual PD_RDFSemanticStylesheets stylesheets() const;
00707     virtual std::string className() const;
00708 };
00709 
00710 
00711 class ABI_EXPORT PD_RDFEvent : public PD_RDFSemanticItem
00712 {
00713   protected:
00714     std::string m_uid;
00715     std::string m_summary;
00716     std::string m_location;
00717     std::string m_desc;
00718     time_t      m_dtstart;
00719     time_t      m_dtend;
00720 
00721     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00722     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00723     virtual std::string getDefaultExtension() const;
00724 
00725   public:
00726     PD_RDFEvent( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00727     virtual ~PD_RDFEvent();
00728 
00729     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00730     virtual void exportToFile( const std::string& filename = "" ) const;
00731     virtual std::string getDisplayLabel() const;
00732     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00733     virtual PD_RDFSemanticStylesheets stylesheets() const;
00734     virtual std::string className() const;
00735 };
00736 
00737 
00738 class ABI_EXPORT PD_RDFLocation : public PD_RDFSemanticItem
00739 {
00740   protected:
00741     std::string m_uid;
00742     std::string m_desc;
00743     double      m_dlat;
00744     double      m_dlong;
00745     PD_Object   m_joiner;
00746     bool        m_isGeo84;
00747 
00748     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00749     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00750     virtual std::string getDefaultExtension() const;
00751 
00752   public:
00753     PD_RDFLocation( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it, bool isGeo84 = false );
00754     virtual ~PD_RDFLocation();
00755 
00756     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00757     virtual void exportToFile( const std::string& filename = "" ) const;
00758     virtual std::string getDisplayLabel() const;
00759     virtual std::set< std::string > getXMLIDs() const;
00760     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00761     virtual PD_RDFSemanticStylesheets stylesheets() const;
00762     virtual std::string className() const;
00763 };
00764 
00765 
00779 class ABI_EXPORT PD_RDFSemanticStylesheet
00780 {
00781     std::string m_uuid;
00782     std::string m_name;
00783     std::string m_templateString;
00784     std::string m_type;
00785     bool        m_isMutable;
00786 protected:
00787 
00788     // Restrict who can make us
00789     friend class PD_RDFSemanticItem;
00790     friend class PD_RDFLocation;
00791     friend class PD_RDFContact;
00792     friend class PD_RDFEvent;
00793     friend class PD_RDFSemanticItemViewSite;
00794 
00795     PD_RDFSemanticStylesheet( const std::string &uuid,
00796                               const std::string &name,
00797                               const std::string &templateString,
00798                               const std::string &type = "System",
00799                               bool isMutable = false);
00800 
00806     void format( PD_RDFSemanticItemHandle sob, FV_View* pView, const std::string& xmlid = "" );
00807 
00808 public:
00809 
00810     virtual ~PD_RDFSemanticStylesheet();
00811     static std::string stylesheetTypeSystem();
00812     static std::string stylesheetTypeUser();
00813 
00814     std::string uuid() const;
00815     std::string name() const;
00816     std::string templateString() const;
00817     std::string type() const;
00818     bool isMutable() const;
00819 };
00820 
00821 
00840 class ABI_EXPORT PD_RDFSemanticItemViewSite
00841 {
00842     std::string m_xmlid;
00843     PD_RDFSemanticItemHandle m_semItem;
00844 
00845   public:
00849     PD_RDFSemanticItemViewSite( PD_RDFSemanticItemHandle si, const std::string &xmlid );
00850     PD_RDFSemanticItemViewSite( PD_RDFSemanticItemHandle si, PT_DocPosition pos );
00851     ~PD_RDFSemanticItemViewSite();
00852 
00856     PD_RDFSemanticStylesheetHandle stylesheet() const;
00857 
00862     void disassociateStylesheet();
00863 
00877     void applyStylesheet( FV_View* pView, PD_RDFSemanticStylesheetHandle ss );
00878 
00886     void setStylesheetWithoutReflow( PD_RDFSemanticStylesheetHandle ss );
00887 
00894     void reflowUsingCurrentStylesheet( FV_View* pView );
00895 
00899     void select( FV_View* pView );
00900 
00901 private:
00902 
00919     PD_URI linkingSubject() const;
00920 
00930     std::string getProperty(const std::string &prop, const std::string &defval) const;
00935     void setProperty(const std::string &prop, const std::string &v);
00936 
00940     void selectRange( FV_View* pView, std::pair< PT_DocPosition, PT_DocPosition > range );
00941 
00942 };
00943 
00944 
00945 
00949 ABI_EXPORT std::pair< PT_DocPosition, PT_DocPosition > runInsertReferenceDialog( FV_View* pView );
00950 ABI_EXPORT void runSemanticStylesheetsDialog( FV_View* pView );
00951 
00952 
00953 class ABI_EXPORT PD_SemanticItemFactory
00954 {
00955   public:
00956     typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00957     virtual ~PD_SemanticItemFactory() {}
00958     virtual PD_RDFContact*  createContact( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it ) = 0;
00959     virtual PD_RDFEvent*    createEvent( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it ) = 0;
00960     virtual PD_RDFLocation* createLocation( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it,
00961                                             bool isGeo84 = false ) = 0;
00962 };
00963 
00964 class ABI_EXPORT PD_RDFDialogs
00965 {
00966   public:
00967     virtual ~PD_RDFDialogs() {}
00968     virtual void runSemanticStylesheetsDialog( FV_View* pView ) = 0;
00969     virtual std::pair< PT_DocPosition, PT_DocPosition > runInsertReferenceDialog( FV_View* pView ) = 0;
00970 };
00971 
00972 
00973 
00985 class ABI_EXPORT PD_DocumentRDF : public PD_RDFModel
00986 {
00987     friend class PD_DocumentRDFMutation;
00988     friend class RDFModel_SPARQLLimited;
00989     friend class PD_RDFMutation_XMLIDLimited;
00990     friend class PD_RDFSemanticItem;
00991 
00992   public:
00993     explicit PD_DocumentRDF( PD_Document* doc );
00994     virtual ~PD_DocumentRDF();
00995 
00996     UT_Error setupWithPieceTable();
00997 
01001     bool haveSemItems() const;
01002     
01003     // PD_RDFModel methods...
01004     virtual PD_ObjectList getObjects( const PD_URI& s, const PD_URI& p );
01005     virtual PD_URIList getSubjects( const PD_URI& p, const PD_Object& o );
01006     virtual PD_URIList getAllSubjects();
01007     virtual POCol      getArcsOut( const PD_URI& s );
01008     virtual bool       contains( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01009     virtual bool       contains( const PD_RDFStatement& st );
01010     virtual long       getTripleCount();
01011     virtual PD_RDFModelIterator begin();
01012     virtual PD_RDFModelIterator end();
01013     virtual void dumpModel( const std::string& headerMsg = "dumpModel()" );
01014     virtual PD_DocumentRDFMutationHandle createMutation();
01015 
01016 
01017     void handleCollabEvent(const gchar** szAtts, const gchar** szProps );
01018 
01019     PD_RDFModelHandle getRDFAtPosition( PT_DocPosition pos );
01020     PD_RDFModelHandle getRDFForID( const std::string& xmlid );
01021 
01022     std::list< pf_Frag_Object* > getObjectsInScopeOfTypesForRange(
01023         std::set< PTObjectType > objectTypes,
01024         std::pair< PT_DocPosition, PT_DocPosition > range );
01025     std::set< std::string >& addXMLIDsForObjects( std::set< std::string >& ret, std::list< pf_Frag_Object* > objectList );
01026     PT_DocPosition addXMLIDsForBlockAndTableCellForPosition( std::set< std::string >& col, PT_DocPosition pos );
01027 
01028 
01029     void addRDFForID( const std::string& xmlid, PD_DocumentRDFMutationHandle& m );
01030     std::set< std::string >& addRelevantIDsForPosition( std::set< std::string >& ret,
01031                                                         PT_DocPosition pos );
01032     std::set< std::string >& addRelevantIDsForRange( std::set< std::string >& ret,
01033                                                       PD_DocumentRange* range );
01034     std::set< std::string >& addRelevantIDsForRange( std::set< std::string >& ret,
01035                                                       std::pair< PT_DocPosition, PT_DocPosition > range );
01036 
01037     std::set< std::string >& getAllIDs( std::set< std::string >& ret );
01038     std::pair< PT_DocPosition, PT_DocPosition > getIDRange( const std::string& xmlid ) const;
01039 
01040 
01041     PD_RDFModelHandle createRestrictedModelForXMLIDs( const std::string& writeID,
01042                                                       const std::set< std::string >& xmlids );
01043     PD_RDFModelHandle createRestrictedModelForXMLIDs( const std::set< std::string >& xmlids );
01044 
01045     virtual void maybeSetDocumentDirty();
01046 
01047     // testing methods...
01048     void runMilestone2Test();
01049     void runMilestone2Test2();
01050     void dumpObjectMarkersFromDocument();
01051     void runPlay();
01052 
01053     static std::string getSPARQL_LimitedToXMLIDList( const std::set< std::string >& xmlids,
01054                                                      const std::string& extraPreds = "" );
01055 
01056     std::string makeLegalXMLID( const std::string& s );
01057     void relinkRDFToNewXMLID( const std::string& oldxmlid, const std::string& newxmlid, bool deepCopyRDF = false );
01058 
01059     PD_RDFModelHandle createScratchModel();
01060 
01061     static PD_URI getManifestURI();
01062 
01063     PD_RDFSemanticItems getAllSemanticObjects( const std::string& classRestriction = "" );
01064     PD_RDFSemanticItems getSemanticObjects( const std::set< std::string >& xmlids );
01065     PD_RDFContacts  getContacts( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01066     PD_RDFEvents    getEvents( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01067     PD_RDFLocations getLocations( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01068     void selectXMLIDs( const std::set< std::string >& xmlids, FV_View* pView = 0 ) const;
01069 
01070 
01071     void showEditorWindow( const PD_RDFSemanticItems& cl );
01072 
01073 
01074     // GTK, win32, osx, whatever backends can call this method to allow the correct
01075     // subclasses to be made for the runtime environment.
01076     static void setSemanticItemFactory( PD_SemanticItemFactory* f );
01077     static void setRDFDialogs( PD_RDFDialogs* d );
01078 
01079     static PD_SemanticItemFactory *getSemanticItemFactory();
01080     static PD_RDFDialogs *getRDFDialogs();
01081 
01082   protected:
01083     PD_Document* m_doc;
01084   private:
01085     static PD_SemanticItemFactory *s_SemanticItemFactory;
01086     static PD_RDFDialogs *s_RDFDialogs;
01087     PT_AttrPropIndex m_indexAP;
01088     bool m_haveSemItems;
01089     
01090     PD_Document*   getDocument(void) const;
01091     pt_PieceTable* getPieceTable(void) const;
01092     void setIndexAP( PT_AttrPropIndex idx );
01093     PT_AttrPropIndex getIndexAP(void) const;
01094     virtual const PP_AttrProp* getAP(void);
01095     virtual UT_Error setAP( PP_AttrProp* newAP );
01096     virtual bool isStandAlone() const;
01097 
01098     std::set< std::string >& priv_addRelevantIDsForPosition( std::set< std::string >& ret,
01099                                                              PT_DocPosition pos,
01100                                                              PT_DocPosition searchBackThisFar = 0 );
01101 
01102   protected:
01103     PD_ObjectList& apGetObjects(     const PP_AttrProp* AP, PD_ObjectList& ret, const PD_URI& s, const PD_URI& p );
01104     PD_URIList&    apGetSubjects(    const PP_AttrProp* AP, PD_URIList& ret,    const PD_URI& p, const PD_Object& o );
01105     PD_URIList&    apGetAllSubjects( const PP_AttrProp* AP, PD_URIList& ret );
01106     POCol&         apGetArcsOut(     const PP_AttrProp* AP, POCol& ret, const PD_URI& s );
01107     bool           apContains(       const PP_AttrProp* AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01108     void           apDumpModel(      const PP_AttrProp* AP, const std::string& headerMsg );
01109 
01110     void updateHaveSemItemsCache();
01111     
01112   private:
01113     PD_RDFLocations& addLocations( PD_RDFLocations& ret,
01114                                    bool isGeo84,
01115                                    const std::string sparql,
01116                                    PD_RDFModelHandle alternateModel );
01117 };
01118 
01119 
01161 class ABI_EXPORT PD_DocumentRDFMutation
01162 {
01163     friend class PD_DocumentRDF;
01164     friend class RDFModel_XMLIDLimited;
01165 
01166   protected:
01167     PD_DocumentRDF* m_rdf; 
01168     bool m_rolledback;     
01169     bool m_committed;      
01170     bool m_handlingAbiCollabNotification; 
01171     PP_AttrProp* m_pAP;        
01172     PP_AttrProp* m_crRemoveAP; 
01173     PP_AttrProp* m_crAddAP;    
01174 
01175 
01176 
01177     bool apAdd( PP_AttrProp* AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01178     void apRemove( PP_AttrProp*& AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01179     UT_Error handleAddAndRemove( PP_AttrProp* add, PP_AttrProp* remove );
01180 
01181     PD_DocumentRDFMutation( PD_DocumentRDF* rdf );
01182 
01183   public:
01184 
01185     virtual ~PD_DocumentRDFMutation();
01186     virtual void handleCollabEvent(const gchar** szAtts, const gchar** szProps );
01187 
01191     virtual bool add( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01192     virtual bool add( const PD_URI& s, const PD_URI& p, const PD_Object& o, const PD_URI& context );
01193     virtual void remove( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01194     void remove( const PD_URI& s, const PD_URI& p, const PD_URI& o );
01195     bool add( const PD_RDFStatement& st );
01196     void remove( const PD_RDFStatement& st );
01197     int add( PD_RDFModelHandle model );
01198     void remove( const std::list< PD_RDFStatement >& sl );
01199     void remove( const PD_URI& s, const PD_URI& p );
01200 
01201     PD_URI createBNode();
01202 
01203     virtual UT_Error commit();
01204     virtual void rollback();
01205 };
01206 
01207 
01208 
01209 class ABI_EXPORT RDFAnchor
01210 {
01211     bool m_isEnd;
01212     std::string m_xmlid;
01213 
01214     void setup( const PP_AttrProp* pAP );
01215 
01216 public:
01217     RDFAnchor( const PP_AttrProp* pAP );
01218     RDFAnchor( PD_Document* pDoc, PT_AttrPropIndex api );
01219     RDFAnchor( PD_Document* doc, pf_Frag* pf );
01220     bool isEnd();
01221     std::string getID();
01222 };
01223 
01224 
01225 #endif

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1