[prev in list] [next in list] [prev in thread] [next in thread] 

List:       calligra-devel
Subject:    [calligra] libs/kotext: Do not create rdf objects if the xml:id
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2011-12-14 15:51:14
Message-ID: 20111214155114.50028A60B9 () git ! kde ! org
[Download RAW message or body]

Git commit c8277fb5d062a50e1c3654d35c808bb7dccff42f by Boudewijn Rempt.
Committed on 14/12/2011 at 16:48.
Pushed by rempt into branch 'master'.

Do not create rdf objects if the xml:id doesn't start with rdfid-

Following the deprecation of draw:id and text:id, elements that used to
just save draw:id and text:id now also save these id's as xml:id.

Calligra's rdf support thinks that every xml:id is a reference to some
rdf metadata. This breaks because there _is_ no rdf data associated.

Until I've found a proper solution to shared xml:id's between various
parts of calligra, check whether the xml:id starts with rdfid- and only
then load the metadata.

Yes, this probably means we can no longer load documents with rdf saved
by other applications like abiword. I'm working on a "proper" solution.

CCMAIL:calligra-devel@kde.org

M  +4    -0    libs/kotext/KoBookmark.cpp
M  +3    -0    libs/kotext/KoTextInlineRdf.cpp
M  +34   -13   libs/kotext/opendocument/KoTextLoader.cpp

http://commits.kde.org/calligra/c8277fb5d062a50e1c3654d35c808bb7dccff42f

diff --git a/libs/kotext/KoBookmark.cpp b/libs/kotext/KoBookmark.cpp
index 8a40d02..7fb07ba 100644
--- a/libs/kotext/KoBookmark.cpp
+++ b/libs/kotext/KoBookmark.cpp
@@ -169,6 +169,10 @@ bool KoBookmark::loadOdf(const KoXmlElement &element, \
KoShapeLoadingContext &con  if (inlineRdf->loadOdf(element)) {
                     setInlineRdf(inlineRdf);
                 }
+                else {
+                    delete inlineRdf;
+                    inlineRdf = 0;
+                }
             }
         }
         else if (localName == "bookmark-end") {
diff --git a/libs/kotext/KoTextInlineRdf.cpp \
b/libs/kotext/KoTextInlineRdf.cpp index 6328d11..f449426 100644
--- a/libs/kotext/KoTextInlineRdf.cpp
+++ b/libs/kotext/KoTextInlineRdf.cpp
@@ -145,6 +145,9 @@ KoTextInlineRdf::~KoTextInlineRdf()
 bool KoTextInlineRdf::loadOdf(const KoXmlElement &e)
 {
     d->id = e.attribute("id", QString());
+    if (!d->id.startsWith("rdfid-")) {
+        return false;
+    }
     d->subject = e.attributeNS(KoXmlNS::xhtml, "about");
     d->predicate = e.attributeNS(KoXmlNS::xhtml, "property");
     d->dt = e.attributeNS(KoXmlNS::xhtml, "datatype");
diff --git a/libs/kotext/opendocument/KoTextLoader.cpp \
b/libs/kotext/opendocument/KoTextLoader.cpp index 397ab54..db9f6b1 100644
--- a/libs/kotext/opendocument/KoTextLoader.cpp
+++ b/libs/kotext/opendocument/KoTextLoader.cpp
@@ -1080,8 +1080,13 @@ void KoTextLoader::loadParagraph(const KoXmlElement \
&element, QTextCursor &curso  QTextBlock block = cursor.block();
         KoTextInlineRdf* inlineRdf =
                 new KoTextInlineRdf((QTextDocument*)block.document(), \
                block);
-        inlineRdf->loadOdf(element);
-        KoTextInlineRdf::attach(inlineRdf, cursor);
+        if (inlineRdf->loadOdf(element)) {
+                KoTextInlineRdf::attach(inlineRdf, cursor);
+        }
+        else {
+            delete inlineRdf;
+            inlineRdf = 0;
+        }
     }
 
 #ifdef KOOPENDOCUMENTLOADER_DEBUG
@@ -1147,8 +1152,13 @@ void KoTextLoader::loadHeading(const KoXmlElement \
&element, QTextCursor &cursor)  QTextBlock block = cursor.block();
         KoTextInlineRdf* inlineRdf =
                 new KoTextInlineRdf((QTextDocument*)block.document(), \
                block);
-        inlineRdf->loadOdf(element);
-        KoTextInlineRdf::attach(inlineRdf, cursor);
+        if (inlineRdf->loadOdf(element)) {
+            KoTextInlineRdf::attach(inlineRdf, cursor);
+        }
+        else {
+            delete inlineRdf;
+            inlineRdf = 0;
+        }
     }
 
 #ifdef KOOPENDOCUMENTLOADER_DEBUG
@@ -1715,7 +1725,7 @@ void KoTextLoader::loadSpan(const KoXmlElement \
&element, QTextCursor &cursor, bo  QString target = \
                ts.attributeNS(KoXmlNS::xlink, "href");
             QString styleName = ts.attributeNS(KoXmlNS::text, \
                "style-name", QString());
             QTextCharFormat cf = cursor.charFormat(); // store the current \
                cursor char format
-            
+
             if (!styleName.isEmpty()) {
                 KoCharacterStyle *characterStyle = \
d->textSharedData->characterStyle(styleName, d->stylesDotXml);  if \
(characterStyle) { @@ -1728,10 +1738,10 @@ void \
KoTextLoader::loadSpan(const KoXmlElement &element, QTextCursor &cursor, bo \
newCharFormat.setAnchor(true);  newCharFormat.setAnchorHref(target);
             cursor.setCharFormat(newCharFormat);
-            
+
             loadSpan(ts, cursor, stripLeadingSpace);   // recurse
             cursor.setCharFormat(cf); // restore the cursor char format
-            
+
             if (!ts.attributeNS(KoXmlNS::delta, \
"insertion-type").isEmpty())  d->closeChangeRegion(ts);
         } else if (isTextNS && localName == "line-break") { // \
text:line-break @@ -1759,8 +1769,14 @@ void KoTextLoader::loadSpan(const \
KoXmlElement &element, QTextCursor &cursor, bo  || ts.hasAttribute("id")) {
                     KoTextInlineRdf* inlineRdf =
                             new KoTextInlineRdf((QTextDocument*)document, \
                startmark);
-                    inlineRdf->loadOdf(ts);
-                    startmark->setInlineRdf(inlineRdf);
+                    if (inlineRdf->loadOdf(ts)) {
+                        startmark->setInlineRdf(inlineRdf);
+                    }
+                    else {
+                        delete inlineRdf;
+                        inlineRdf = 0;
+                    }
+
                 }
 
                 loadSpan(ts, cursor, stripLeadingSpace);   // recurse
@@ -2299,10 +2315,15 @@ void KoTextLoader::loadTableCell(KoXmlElement \
&rowTag, QTextTable *tbl, QList<QR  // rowTag is the current table cell.
         if (rowTag.hasAttributeNS(KoXmlNS::xhtml, "property") || \
                rowTag.hasAttribute("id")) {
             KoTextInlineRdf* inlineRdf = new \
                KoTextInlineRdf((QTextDocument*)cursor.block().document(),cell);
                
-            inlineRdf->loadOdf(rowTag);
-            QTextTableCellFormat cellFormat = \
                cell.format().toTableCellFormat();
-            cellFormat.setProperty(KoTableCellStyle::InlineRdf,QVariant::fromValue(inlineRdf));
                
-            cell.setFormat(cellFormat);
+            if (inlineRdf->loadOdf(rowTag)) {
+                QTextTableCellFormat cellFormat = \
cell.format().toTableCellFormat(); +                \
cellFormat.setProperty(KoTableCellStyle::InlineRdf,QVariant::fromValue(inlineRdf));
 +                cell.setFormat(cellFormat);
+            }
+            else {
+                delete inlineRdf;
+                inlineRdf = 0;
+            }
         }
 
         cursor = cell.firstCursorPosition();
_______________________________________________
calligra-devel mailing list
calligra-devel@kde.org
https://mail.kde.org/mailman/listinfo/calligra-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic