• 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., 59 Temple Place - Suite 330, Boston, MA
00019  * 02111-1307, 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 <set>
00029 #include "ut_types.h"
00030 #include "pt_Types.h"
00031 
00032 #include <boost/shared_ptr.hpp>
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 boost::shared_ptr<PD_DocumentRDFMutation> PD_DocumentRDFMutationHandle;
00045 class   PD_RDFModel;
00046 typedef boost::shared_ptr<PD_RDFModel> PD_RDFModelHandle;
00047 class   PD_DocumentRDF;
00048 typedef boost::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     bool isValid() const;
00069     bool operator==(const PD_URI& b) const;
00070     bool operator==(const std::string& b) const;
00071 
00072     virtual bool read( std::istream& ss );
00073     virtual bool write( std::ostream& ss ) const;
00074 
00075     PD_URI prefixedToURI( PD_RDFModelHandle model ) const;
00076 
00077     bool empty() const        { return m_value.empty(); }
00078     const char* c_str() const { return m_value.c_str(); }
00079 
00080 };
00081 
00082 template <class ostream>
00083 ostream& operator<<( ostream& ss, PD_URI& uri )
00084 {
00085     ss << uri.toString();
00086     return ss;
00087 }
00088 
00089 
00090 
00108 class ABI_EXPORT PD_Object : public PD_URI
00109 {
00110   public:
00111     enum
00112     {
00113         OBJECT_TYPE_URI = 1,
00114         OBJECT_TYPE_LITERAL,
00115         OBJECT_TYPE_BNODE
00116     };
00117 
00118     PD_Object( const std::string& v = "" );
00119     PD_Object( const PD_URI& u );
00120     PD_Object( const std::string& v, int objectType, const std::string& xsdtype = "" );
00121 
00122     std::string getXSDType() const;
00123     bool hasXSDType() const;
00124     int  getObjectType() const;
00125     bool isLiteral() const;
00126     bool isURI() const;
00127     bool isBNode() const;
00128 
00129     virtual bool read( std::istream& ss );
00130     virtual bool write( std::ostream& ss ) const;
00131 
00132   protected:
00133     std::string m_xsdType;
00134     std::string m_context;
00135     int m_objectType;
00136 };
00143 class ABI_EXPORT PD_Literal : public PD_Object
00144 {
00145   public:
00146     PD_Literal( const std::string& v = "", const std::string& xsdtype = "" );
00147 };
00148 
00149 typedef std::list< PD_URI > PD_URIList;
00150 // REQUIRES: ordered, same key can -> many different values
00151 typedef std::multimap< PD_URI, PD_Object > POCol;
00152 typedef std::list< PD_Object > PD_ObjectList;
00153 
00154 struct PD_URIListCompare : public std::binary_function<PD_URI, PD_URI, bool> {
00155     bool operator()(PD_URI x, PD_URI y) { return x.toString() < y.toString(); }
00156 };
00157 
00158 
00163 class ABI_EXPORT PD_RDFStatement
00164 {
00165     PD_URI    m_subject;
00166     PD_URI    m_predicate;
00167     PD_Object m_object;
00168     bool      m_isValid;
00169   public:
00170     PD_RDFStatement();
00171     PD_RDFStatement( PD_RDFModelHandle model, const PD_URI& s, const PD_URI& p, const PD_Object& o );
00172     PD_RDFStatement( const PD_URI& s, const PD_URI& p, const PD_Object& o );
00173     PD_RDFStatement( const std::string& s, const std::string& p, const PD_Object& o );
00174     PD_RDFStatement( const std::string& s, const std::string& p, const PD_Literal& o );
00175     const PD_URI&    getSubject() const;
00176     const PD_URI&    getPredicate() const;
00177     const PD_Object& getObject() const;
00178     bool             isValid() const;
00179     std::string      toString() const;
00180 
00181     PD_RDFStatement uriToPrefixed( PD_RDFModelHandle model ) const;
00182     PD_RDFStatement prefixedToURI( PD_RDFModelHandle model ) const;
00183 
00184     bool operator==(const PD_RDFStatement& b) const;
00185 
00186 };
00187 
00188 template <class ostream>
00189 ostream& operator<<( ostream& ss, const PD_RDFStatement& st )
00190 {
00191     ss << st.toString();
00192     return ss;
00193 }
00194 
00195 
00196 
00197 
00198 class ABI_EXPORT PD_RDFModelIterator
00199     :
00200     public std::iterator< std::forward_iterator_tag, PD_RDFStatement >
00201 {
00202     PD_RDFModelHandle   m_model;
00203     const PP_AttrProp*  m_AP;
00204     bool                m_end;
00205     size_t              m_apPropertyNumber;
00206     std::string         m_subject;
00207     POCol               m_pocol;
00208     POCol::iterator     m_pocoliter;
00209     PD_RDFStatement     m_current;
00210 
00211     void setup_pocol();
00212 
00213   public:
00214     typedef const PD_RDFModelIterator& self_constref;
00215     typedef PD_RDFModelIterator& self_reference;
00216     typedef PD_RDFModelIterator  self_type;
00217 
00218     PD_RDFModelIterator();
00219     ~PD_RDFModelIterator();
00220     PD_RDFModelIterator( PD_RDFModelHandle model, const PP_AttrProp* AP );
00221 
00222     self_reference operator++();
00223     bool operator==( self_constref other );
00224     PD_RDFModelIterator& operator=( const PD_RDFModelIterator& other );
00225 
00226     self_type operator++(int)
00227     {
00228         self_type result( *this );
00229         ++( *this );
00230         return result;
00231     }
00232     bool operator!=( self_constref other )
00233     {
00234         return !operator==(other);
00235     }
00236     reference operator*()
00237     {
00238         return m_current;
00239     }
00240 
00241     self_reference moveToNextSubject();
00242     void moveToNextSubjectReadPO();
00243     bool moveToNextSubjectHavePOCol();
00244 };
00245 
00246 
00272 class ABI_EXPORT PD_RDFModel
00273 {
00274   protected:
00275     long m_version;
00276     PD_URI    front( const PD_URIList& l    ) const;
00277     PD_Object front( const PD_ObjectList& l ) const;
00278     PD_RDFModel();
00279     void incremenetVersion();
00280 
00281   public:
00282     virtual ~PD_RDFModel() {}
00283     virtual PD_ObjectList getObjects( const PD_URI& s, const PD_URI& p );
00284     virtual PD_Object     getObject( const PD_URI& s, const PD_URI& p );
00285     virtual PD_URIList getSubjects( const PD_URI& p, const PD_Object& o );
00286     virtual PD_URI     getSubject( const PD_URI& p, const PD_Object& o );
00287     virtual PD_URIList getAllSubjects();
00288     virtual POCol      getArcsOut( const PD_URI& s );
00289     virtual bool       contains( const PD_URI& s, const PD_URI& p, const PD_Object& o );
00290     virtual bool       contains( const PD_URI& s, const PD_URI& p );
00291     virtual bool       contains( const PD_RDFStatement& st );
00292     virtual long       getTripleCount();
00293 
00294     virtual PD_RDFModelIterator begin() = 0;
00295     virtual PD_RDFModelIterator end() = 0;
00296 
00297     typedef std::map< std::string, std::string > stringmap_t;
00298     typedef stringmap_t uriToPrefix_t;
00299     virtual uriToPrefix_t& getUriToPrefix();
00300 
00301 
00302     virtual void dumpModel( const std::string& headerMsg = "dumpModel()" );
00303 
00304     virtual PD_DocumentRDFMutationHandle createMutation() = 0;
00305     virtual std::string uriToPrefixed( const std::string& uri );
00306     virtual std::string prefixedToURI( const std::string& prefixed );
00307 
00308     inline long size()  { return getTripleCount(); }
00309     inline bool empty() { return size() == 0; }
00310 
00311     long getVersion() const { return m_version; }
00312 
00313 };
00314 
00315 class   PD_RDFSemanticItem;
00316 typedef boost::shared_ptr<PD_RDFSemanticItem> PD_RDFSemanticItemHandle;
00317 typedef std::list< PD_RDFSemanticItemHandle > PD_RDFSemanticItems;
00318 class   PD_RDFContact;
00319 typedef boost::shared_ptr<PD_RDFContact >     PD_RDFContactHandle;
00320 typedef std::list< PD_RDFContactHandle      > PD_RDFContacts;
00321 class   PD_RDFEvent;
00322 typedef boost::shared_ptr<PD_RDFEvent >       PD_RDFEventHandle;
00323 typedef std::list< PD_RDFEventHandle      >   PD_RDFEvents;
00324 class   PD_RDFLocation;
00325 typedef boost::shared_ptr<PD_RDFLocation >       PD_RDFLocationHandle;
00326 typedef std::list< PD_RDFLocationHandle      >   PD_RDFLocations;
00327 class   PD_RDFSemanticStylesheet;
00328 typedef boost::shared_ptr<PD_RDFSemanticStylesheet > PD_RDFSemanticStylesheetHandle;
00329 typedef std::list< PD_RDFSemanticStylesheetHandle  > PD_RDFSemanticStylesheets;
00330 class   PD_RDFSemanticItemViewSite;
00331 typedef boost::shared_ptr<PD_RDFSemanticItemViewSite> PD_RDFSemanticItemViewSiteHandle;
00332 typedef std::list< PD_RDFSemanticItemViewSiteHandle > PD_RDFSemanticItemViewSites;
00333 
00334 // semantic stylesheets
00335 #define RDF_SEMANTIC_STYLESHEET_NAME                         "name"
00336 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME                 RDF_SEMANTIC_STYLESHEET_NAME
00337 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NICK                 "nick"
00338 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME_PHONE           "name, phone"
00339 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NICK_PHONE           "nick, phone"
00340 #define RDF_SEMANTIC_STYLESHEET_CONTACT_NAME_HOMEPAGE_PHONE  "name, (homepage), phone"
00341 #define RDF_SEMANTIC_STYLESHEET_EVENT_NAME                   RDF_SEMANTIC_STYLESHEET_NAME
00342 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY                "summary"
00343 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_LOCATION       "summary, location"
00344 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_LOCATION_TIMES "summary, location, start date/time"
00345 #define RDF_SEMANTIC_STYLESHEET_EVENT_SUMMARY_TIMES          "summary, start date/time"
00346 #define RDF_SEMANTIC_STYLESHEET_LOCATION_NAME                RDF_SEMANTIC_STYLESHEET_NAME
00347 #define RDF_SEMANTIC_STYLESHEET_LOCATION_NAME_LATLONG        "name, digital latitude, digital longitude"
00348 
00354 class ABI_EXPORT PD_RDFSemanticItem
00355 {
00356     PD_DocumentRDFHandle m_rdf;
00357     PD_URI               m_context;
00358   protected:
00359     std::string          m_name;
00360     PD_URI               m_linkingSubject;
00361     typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00362 
00363     virtual std::string getImportFromFileName( const std::string& filename_const,
00364                                                std::list< std::pair< std::string, std::string> > types ) const;
00365     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00366 
00367     virtual std::string getExportToFileName( const std::string& filename_const,
00368                                              std::string defaultExtension,
00369                                              std::list< std::pair< std::string, std::string> > types ) const;
00370     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00371     virtual std::string getDefaultExtension() const;
00372     std::string getProperty( std::string subj, std::string pred, std::string defVal ) const;
00373 
00374   public:
00375     PD_RDFSemanticItem( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00376     virtual ~PD_RDFSemanticItem();
00377 
00378     PD_DocumentRDFHandle getRDF() const;
00379     PD_DocumentRDFMutationHandle createMutation();
00380 
00381     std::string requestExportFileNameByDialog();
00382 
00383 
00394     virtual PD_URI linkingSubject() const;
00395 
00396 
00404     static std::set< std::string > getXMLIDsForLinkingSubject( PD_DocumentRDFHandle rdf, const std::string& linkingSubj );
00405 
00406 
00410     virtual std::string name() const;
00411     virtual void        setName( const std::string& n );
00412 
00417     virtual std::string getDisplayLabel() const;
00418 
00419 
00431     virtual std::set< std::string > getXMLIDs() const;
00432 
00444      virtual void* createEditor() = 0;
00445 
00449      virtual void showEditorWindow( const PD_RDFSemanticItemHandle & c );
00450      virtual void showEditorWindow( const PD_RDFSemanticItems & cl );
00451 
00458      void updateFromEditorData();
00459      virtual void updateFromEditorData( PD_DocumentRDFMutationHandle m ) = 0;
00460 
00461 
00472      virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 ) = 0;
00473 
00478      virtual void exportToFile( const std::string& filename = "" ) const = 0;
00479 
00486      virtual void importFromFile( const std::string& filename = "" );
00487 
00488 
00494      static PD_RDFSemanticItemHandle createSemanticItem( PD_DocumentRDFHandle rdf, const std::string& semanticClass );
00495      static PD_RDFSemanticItemHandle createSemanticItem( PD_DocumentRDFHandle rdf,
00496                                                          PD_ResultBindings_t::iterator it,
00497                                                          const std::string& semanticClass );
00498 
00506      static std::list< std::string > getClassNames();
00507 
00508 
00515      std::pair< PT_DocPosition, PT_DocPosition > insert( PD_DocumentRDFMutationHandle m, FV_View* pView );
00516      std::pair< PT_DocPosition, PT_DocPosition > insert( FV_View* pView );
00517 
00518 
00519      virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00520 
00521 
00526      PD_RDFSemanticStylesheetHandle findStylesheetByUuid(const std::string &uuid) const;
00527 
00533     PD_RDFSemanticStylesheetHandle findStylesheetByName(const std::string &sheetType, const std::string &n) const;
00539     PD_RDFSemanticStylesheetHandle findStylesheetByName(const PD_RDFSemanticStylesheets& ssl, const std::string &n) const;
00540 
00550     PD_RDFSemanticStylesheetHandle defaultStylesheet() const;
00551 
00556     virtual PD_RDFSemanticStylesheets stylesheets() const = 0;
00557     virtual std::string className() const = 0;
00558 
00559     enum RelationType
00560     {
00561         RELATION_FOAF_KNOWS = 1
00562     };
00563     void relationAdd( PD_RDFSemanticItemHandle si, RelationType rt );
00564     PD_RDFSemanticItems relationFind( RelationType rt );
00565 
00566   protected:
00567 
00568      std::pair< PT_DocPosition, PT_DocPosition > insertTextWithXMLID( const std::string& textconst,
00569                                                                       const std::string& xmlid );
00570 
00590      virtual void importFromDataComplete( std::istream& iss,
00591                                           PD_DocumentRDFHandle rdf,
00592                                           PD_DocumentRDFMutationHandle m,
00593                                           PD_DocumentRange * pDocRange = 0 );
00594 
00595      std::string bindingAsString( PD_ResultBindings_t::iterator& it, const std::string k );
00596      std::string optionalBindingAsString( PD_ResultBindings_t::iterator& it, const std::string k );
00597 
00598     PD_URI& handleSubjectDefaultArgument( PD_URI& subj );
00599 
00605     virtual PD_URI context() const;
00606 
00612     void setRDFType(PD_DocumentRDFMutationHandle m, const std::string& type, PD_URI subj = PD_URI());
00613     void setRDFType(const std::string& type, PD_URI subj = PD_URI());
00614 
00615 
00635     void updateTriple( PD_DocumentRDFMutationHandle m, std::string& toModify, const std::string& newValue, const PD_URI& predString );
00636     void updateTriple( PD_DocumentRDFMutationHandle m, time_t&      toModify, time_t newValue, const PD_URI& predString );
00637     void updateTriple( PD_DocumentRDFMutationHandle m, double&      toModify, double newValue, const PD_URI& predString );
00638     void updateTriple( PD_DocumentRDFMutationHandle m, double&      toModify, double newValue, const PD_URI& predString, PD_URI linkingSubject  );
00639 
00640     void updateTriple( std::string& toModify, const std::string& newValue, const PD_URI& predString );
00641     void updateTriple( time_t&      toModify, time_t newValue, const PD_URI& predString );
00642     void updateTriple( double&      toModify, double newValue, const PD_URI& predString );
00643 
00647     PD_URI createUUIDNode();
00648 
00649 
00650 protected:
00661     void updateTriple_remove( PD_DocumentRDFMutationHandle m,
00662                               const PD_URI& toModify,
00663                               const PD_URI& predString,
00664                               const PD_URI& explicitLinkingSubject );
00665 
00671     void updateTriple_add( PD_DocumentRDFMutationHandle m,
00672                            const PD_URI& toModify,
00673                            const PD_URI& predString,
00674                            const PD_URI& explicitLinkingSubject );
00675 
00676 };
00677 
00678 
00679 
00680 class ABI_EXPORT PD_RDFContact : public PD_RDFSemanticItem
00681 {
00682   protected:
00683     std::string m_nick;
00684     std::string m_email;
00685     std::string m_homePage;
00686     std::string m_imageUrl;
00687     std::string m_phone;
00688     std::string m_jabberID;
00689 
00690     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00691     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00692     virtual std::string getDefaultExtension() const;
00693 
00694   public:
00695     PD_RDFContact( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00696     virtual ~PD_RDFContact();
00697 
00698     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00699     virtual void exportToFile( const std::string& filename = "" ) const;
00700     virtual std::string getDisplayLabel() const;
00701     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00702     virtual PD_RDFSemanticStylesheets stylesheets() const;
00703     virtual std::string className() const;
00704 };
00705 
00706 
00707 class ABI_EXPORT PD_RDFEvent : public PD_RDFSemanticItem
00708 {
00709   protected:
00710     std::string m_uid;
00711     std::string m_summary;
00712     std::string m_location;
00713     std::string m_desc;
00714     time_t      m_dtstart;
00715     time_t      m_dtend;
00716 
00717     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00718     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00719     virtual std::string getDefaultExtension() const;
00720 
00721   public:
00722     PD_RDFEvent( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it );
00723     virtual ~PD_RDFEvent();
00724 
00725     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00726     virtual void exportToFile( const std::string& filename = "" ) const;
00727     virtual std::string getDisplayLabel() const;
00728     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00729     virtual PD_RDFSemanticStylesheets stylesheets() const;
00730     virtual std::string className() const;
00731 };
00732 
00733 
00734 class ABI_EXPORT PD_RDFLocation : public PD_RDFSemanticItem
00735 {
00736   protected:
00737     std::string m_uid;
00738     std::string m_desc;
00739     double      m_dlat;
00740     double      m_dlong;
00741     PD_Object   m_joiner;
00742     bool        m_isGeo84;
00743 
00744     virtual std::list< std::pair< std::string, std::string> > getImportTypes() const;
00745     virtual std::list< std::pair< std::string, std::string> > getExportTypes() const;
00746     virtual std::string getDefaultExtension() const;
00747 
00748   public:
00749     PD_RDFLocation( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it, bool isGeo84 = false );
00750     virtual ~PD_RDFLocation();
00751 
00752     virtual void importFromData( std::istream& iss, PD_DocumentRDFHandle rdf, PD_DocumentRange * pDocRange = 0 );
00753     virtual void exportToFile( const std::string& filename = "" ) const;
00754     virtual std::string getDisplayLabel() const;
00755     virtual std::set< std::string > getXMLIDs() const;
00756     virtual void setupStylesheetReplacementMapping( std::map< std::string, std::string >& m );
00757     virtual PD_RDFSemanticStylesheets stylesheets() const;
00758     virtual std::string className() const;
00759 };
00760 
00761 
00775 class ABI_EXPORT PD_RDFSemanticStylesheet
00776 {
00777     std::string m_uuid;
00778     std::string m_name;
00779     std::string m_templateString;
00780     std::string m_type;
00781     bool        m_isMutable;
00782 protected:
00783 
00784     // Restrict who can make us
00785     friend class PD_RDFSemanticItem;
00786     friend class PD_RDFLocation;
00787     friend class PD_RDFContact;
00788     friend class PD_RDFEvent;
00789     friend class PD_RDFSemanticItemViewSite;
00790 
00791     PD_RDFSemanticStylesheet( const std::string &uuid,
00792                               const std::string &name,
00793                               const std::string &templateString,
00794                               const std::string &type = "System",
00795                               bool isMutable = false);
00796 
00802     void format( PD_RDFSemanticItemHandle sob, FV_View* pView, const std::string& xmlid = "" );
00803 
00804 public:
00805 
00806     virtual ~PD_RDFSemanticStylesheet();
00807     static std::string stylesheetTypeSystem();
00808     static std::string stylesheetTypeUser();
00809 
00810     std::string uuid() const;
00811     std::string name() const;
00812     std::string templateString() const;
00813     std::string type() const;
00814     bool isMutable() const;
00815 };
00816 
00817 
00836 class ABI_EXPORT PD_RDFSemanticItemViewSite
00837 {
00838     std::string m_xmlid;
00839     PD_RDFSemanticItemHandle m_semItem;
00840 
00841   public:
00845     PD_RDFSemanticItemViewSite( PD_RDFSemanticItemHandle si, const std::string &xmlid );
00846     PD_RDFSemanticItemViewSite( PD_RDFSemanticItemHandle si, PT_DocPosition pos );
00847     ~PD_RDFSemanticItemViewSite();
00848 
00852     PD_RDFSemanticStylesheetHandle stylesheet() const;
00853 
00858     void disassociateStylesheet();
00859 
00873     void applyStylesheet( FV_View* pView, PD_RDFSemanticStylesheetHandle ss );
00874 
00882     void setStylesheetWithoutReflow( PD_RDFSemanticStylesheetHandle ss );
00883 
00890     void reflowUsingCurrentStylesheet( FV_View* pView );
00891 
00895     void select( FV_View* pView );
00896 
00897 private:
00898 
00915     PD_URI linkingSubject() const;
00916 
00926     std::string getProperty(const std::string &prop, const std::string &defval) const;
00931     void setProperty(const std::string &prop, const std::string &v);
00932 
00936     void selectRange( FV_View* pView, std::pair< PT_DocPosition, PT_DocPosition > range );
00937 
00938 };
00939 
00940 
00941 
00945 ABI_EXPORT std::pair< PT_DocPosition, PT_DocPosition > runInsertReferenceDialog( FV_View* pView );
00946 ABI_EXPORT void runSemanticStylesheetsDialog( FV_View* pView );
00947 
00948 
00949 class ABI_EXPORT PD_SemanticItemFactory
00950 {
00951   public:
00952     typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00953     virtual ~PD_SemanticItemFactory() {}
00954     virtual PD_RDFContact*  createContact( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it ) = 0;
00955     virtual PD_RDFEvent*    createEvent( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it ) = 0;
00956     virtual PD_RDFLocation* createLocation( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator it,
00957                                             bool isGeo84 = false ) = 0;
00958 };
00959 
00960 class ABI_EXPORT PD_RDFDialogs
00961 {
00962   public:
00963     virtual ~PD_RDFDialogs() {}
00964     virtual void runSemanticStylesheetsDialog( FV_View* pView ) = 0;
00965     virtual std::pair< PT_DocPosition, PT_DocPosition > runInsertReferenceDialog( FV_View* pView ) = 0;
00966 };
00967 
00968 
00969 
00981 class ABI_EXPORT PD_DocumentRDF : public PD_RDFModel
00982 {
00983     friend class PD_DocumentRDFMutation;
00984     friend class RDFModel_SPARQLLimited;
00985     friend class PD_RDFMutation_XMLIDLimited;
00986     friend class PD_RDFSemanticItem;
00987 
00988   public:
00989     explicit PD_DocumentRDF( PD_Document* doc );
00990     virtual ~PD_DocumentRDF();
00991 
00992     UT_Error setupWithPieceTable();
00993 
00994     // PD_RDFModel methods...
00995     virtual PD_ObjectList getObjects( const PD_URI& s, const PD_URI& p );
00996     virtual PD_URIList getSubjects( const PD_URI& p, const PD_Object& o );
00997     virtual PD_URIList getAllSubjects();
00998     virtual POCol      getArcsOut( const PD_URI& s );
00999     virtual bool       contains( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01000     virtual bool       contains( const PD_RDFStatement& st );
01001     virtual long       getTripleCount();
01002     virtual PD_RDFModelIterator begin();
01003     virtual PD_RDFModelIterator end();
01004     virtual void dumpModel( const std::string& headerMsg = "dumpModel()" );
01005     virtual PD_DocumentRDFMutationHandle createMutation();
01006 
01007 
01008     void handleCollabEvent( gchar** szAtts, gchar** szProps );
01009 
01010     PD_RDFModelHandle getRDFAtPosition( PT_DocPosition pos );
01011     PD_RDFModelHandle getRDFForID( const std::string& xmlid );
01012 
01013     std::list< pf_Frag_Object* > getObjectsInScopeOfTypesForRange(
01014         std::set< PTObjectType > objectTypes,
01015         std::pair< PT_DocPosition, PT_DocPosition > range );
01016     std::set< std::string >& addXMLIDsForObjects( std::set< std::string >& ret, std::list< pf_Frag_Object* > objectList );
01017     PT_DocPosition addXMLIDsForBlockAndTableCellForPosition( std::set< std::string >& col, PT_DocPosition pos );
01018 
01019 
01020     void addRDFForID( const std::string& xmlid, PD_DocumentRDFMutationHandle& m );
01021     std::set< std::string >& addRelevantIDsForPosition( std::set< std::string >& ret,
01022                                                         PT_DocPosition pos );
01023     std::set< std::string >& addRelevantIDsForRange( std::set< std::string >& ret,
01024                                                       PD_DocumentRange* range );
01025     std::set< std::string >& addRelevantIDsForRange( std::set< std::string >& ret,
01026                                                       std::pair< PT_DocPosition, PT_DocPosition > range );
01027 
01028     std::set< std::string >& getAllIDs( std::set< std::string >& ret );
01029     std::pair< PT_DocPosition, PT_DocPosition > getIDRange( const std::string& xmlid ) const;
01030 
01031 
01032     PD_RDFModelHandle createRestrictedModelForXMLIDs( const std::string& writeID,
01033                                                       const std::set< std::string >& xmlids );
01034     PD_RDFModelHandle createRestrictedModelForXMLIDs( const std::set< std::string >& xmlids );
01035 
01036     virtual void maybeSetDocumentDirty();
01037 
01038     // testing methods...
01039     void runMilestone2Test();
01040     void runMilestone2Test2();
01041     void dumpObjectMarkersFromDocument();
01042     void runPlay();
01043 
01044     static std::string getSPARQL_LimitedToXMLIDList( const std::set< std::string >& xmlids,
01045                                                      const std::string& extraPreds = "" );
01046 
01047     std::string makeLegalXMLID( const std::string& s );
01048     void relinkRDFToNewXMLID( const std::string& oldxmlid, const std::string& newxmlid, bool deepCopyRDF = false );
01049 
01050     PD_RDFModelHandle createScratchModel();
01051 
01052     static PD_URI getManifestURI();
01053 
01054     PD_RDFSemanticItems getAllSemanticObjects( const std::string& classRestriction = "" );
01055     PD_RDFSemanticItems getSemanticObjects( const std::set< std::string >& xmlids );
01056     PD_RDFContacts  getContacts( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01057     PD_RDFEvents    getEvents( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01058     PD_RDFLocations getLocations( PD_RDFModelHandle alternateModel = PD_RDFModelHandle((PD_RDFModel*)0) );
01059     void selectXMLIDs( const std::set< std::string >& xmlids, FV_View* pView = 0 ) const;
01060 
01061 
01062     void showEditorWindow( const PD_RDFSemanticItems& cl );
01063 
01064 
01065     // GTK, win32, osx, whatever backends can call this method to allow the correct
01066     // subclasses to be made for the runtime environment.
01067     static void setSemanticItemFactory( PD_SemanticItemFactory* f );
01068     static void setRDFDialogs( PD_RDFDialogs* d );
01069 
01070     static PD_SemanticItemFactory *getSemanticItemFactory();
01071     static PD_RDFDialogs *getRDFDialogs();
01072 
01073   protected:
01074     PD_Document* m_doc;
01075   private:
01076     static PD_SemanticItemFactory *s_SemanticItemFactory;
01077     static PD_RDFDialogs *s_RDFDialogs;
01078     PT_AttrPropIndex m_indexAP;
01079 
01080     PD_Document*   getDocument(void) const;
01081     pt_PieceTable* getPieceTable(void) const;
01082     void setIndexAP( PT_AttrPropIndex idx );
01083     PT_AttrPropIndex getIndexAP(void) const;
01084     virtual const PP_AttrProp* getAP(void);
01085     virtual UT_Error setAP( PP_AttrProp* newAP );
01086     virtual bool isStandAlone() const;
01087 
01088     std::set< std::string >& priv_addRelevantIDsForPosition( std::set< std::string >& ret,
01089                                                              PT_DocPosition pos,
01090                                                              PT_DocPosition searchBackThisFar = 0 );
01091 
01092   protected:
01093     PD_ObjectList& apGetObjects(     const PP_AttrProp* AP, PD_ObjectList& ret, const PD_URI& s, const PD_URI& p );
01094     PD_URIList&    apGetSubjects(    const PP_AttrProp* AP, PD_URIList& ret,    const PD_URI& p, const PD_Object& o );
01095     PD_URIList&    apGetAllSubjects( const PP_AttrProp* AP, PD_URIList& ret );
01096     POCol&         apGetArcsOut(     const PP_AttrProp* AP, POCol& ret, const PD_URI& s );
01097     bool           apContains(       const PP_AttrProp* AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01098     void           apDumpModel(      const PP_AttrProp* AP, const std::string& headerMsg );
01099 
01100   private:
01101     PD_RDFLocations& addLocations( PD_RDFLocations& ret,
01102                                    bool isGeo84,
01103                                    const std::string sparql,
01104                                    PD_RDFModelHandle alternateModel );
01105 };
01106 
01107 
01149 class ABI_EXPORT PD_DocumentRDFMutation
01150 {
01151     friend class PD_DocumentRDF;
01152     friend class RDFModel_XMLIDLimited;
01153 
01154   protected:
01155     PD_DocumentRDF* m_rdf; 
01156     bool m_rolledback;     
01157     bool m_committed;      
01158     bool m_handlingAbiCollabNotification; 
01159     PP_AttrProp* m_pAP;        
01160     PP_AttrProp* m_crRemoveAP; 
01161     PP_AttrProp* m_crAddAP;    
01162 
01163 
01164 
01165     bool apAdd( PP_AttrProp* AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01166     void apRemove( PP_AttrProp*& AP, const PD_URI& s, const PD_URI& p, const PD_Object& o );
01167     UT_Error handleAddAndRemove( PP_AttrProp* add, PP_AttrProp* remove );
01168 
01169     PD_DocumentRDFMutation( PD_DocumentRDF* rdf );
01170 
01171   public:
01172 
01173     virtual ~PD_DocumentRDFMutation();
01174     virtual void handleCollabEvent( gchar** szAtts, gchar** szProps );
01175 
01179     virtual bool add( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01180     virtual bool add( const PD_URI& s, const PD_URI& p, const PD_Object& o, const PD_URI& context );
01181     virtual void remove( const PD_URI& s, const PD_URI& p, const PD_Object& o );
01182     void remove( const PD_URI& s, const PD_URI& p, const PD_URI& o );
01183     bool add( const PD_RDFStatement& st );
01184     void remove( const PD_RDFStatement& st );
01185     int add( PD_RDFModelHandle model );
01186     void remove( const std::list< PD_RDFStatement >& sl );
01187     void remove( const PD_URI& s, const PD_URI& p );
01188 
01189     PD_URI createBNode();
01190 
01191     virtual UT_Error commit();
01192     virtual void rollback();
01193 };
01194 
01195 
01196 
01197 class ABI_EXPORT RDFAnchor
01198 {
01199     bool m_isEnd;
01200     std::string m_xmlid;
01201 
01202     void setup( const PP_AttrProp* pAP );
01203 
01204 public:
01205     RDFAnchor( const PP_AttrProp* pAP );
01206     RDFAnchor( PD_Document* pDoc, PT_AttrPropIndex api );
01207     RDFAnchor( PD_Document* doc, pf_Frag* pf );
01208     bool isEnd();
01209     std::string getID();
01210 };
01211 
01212 
01213 #endif

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1