~spyzer-abhishek0/+junk/gsoc2011

« back to all changes in this revision

Viewing changes to src/attribute-rel-css.cpp

  • Committer: Abhishek Sharma
  • Date: 2011-08-07 18:56:20 UTC
  • Revision ID: sharma.abhishek.it@gmail.com-20110807185620-1y7o9gp466yuqy55
Modifying approach to check attributes. Inserting more checks. Reading files from inkscape_datadir standard install directories. Fixed some bugs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * mapping indirectly(only reading).
13
13
 */
14
14
 
 
15
#ifdef HAVE_CONFIG_H
 
16
# include <config.h>
 
17
#endif
 
18
 
15
19
#include <fstream>
16
20
#include <sstream>
 
21
#include <string>
17
22
 
18
23
#include "attribute-rel-css.h"
19
24
 
 
25
#include "path-prefix.h"
 
26
 
20
27
SPAttributeRelCSS * SPAttributeRelCSS::instance = NULL;
21
28
 
22
29
bool SPAttributeRelCSS::findIfValid(Glib::ustring property, Glib::ustring element)
24
31
    if (SPAttributeRelCSS::instance == NULL) {
25
32
        SPAttributeRelCSS::instance = new SPAttributeRelCSS();
26
33
    }
 
34
    
 
35
    Glib::ustring temp = element;
 
36
    if ( temp.find("svg:") != std::string::npos ) {
 
37
        temp.erase( temp.find("svg:"), 4 );
 
38
    }
27
39
 
28
40
    if (property[0] == '-'
29
41
        || property.substr(0,4) == "role"
30
42
        || property.substr(0,4) == "aria"
31
 
        || (SPAttributeRelCSS::instance->propertiesOfElements[element].find(property)
32
 
            != SPAttributeRelCSS::instance->propertiesOfElements[element].end()) ) {
 
43
        || property.substr(0,5) == "xmlns"
 
44
        || property.substr(0,8) == "inkscape:"
 
45
        || property.substr(0,9) == "sodipodi:"
 
46
        || property.substr(0,4) == "rdf:"
 
47
        || property.substr(0,3) == "cc:"
 
48
        || (SPAttributeRelCSS::instance->propertiesOfElements[temp].find(property)
 
49
            != SPAttributeRelCSS::instance->propertiesOfElements[temp].end()) ) {
33
50
        return true;
34
51
    } else {
 
52
        g_warning( "Invalid attribute: %s used on <%s>", property.c_str(), element.c_str() );
35
53
        return false;
36
54
    }
37
55
}
47
65
 
48
66
SPAttributeRelCSS::SPAttributeRelCSS()
49
67
{
50
 
    readDataFromFileIn("/home/abhishek/Documents/GSoC2011/inkscape/src/cssprops", SPAttributeRelCSS::prop_element_pair);
51
 
    readDataFromFileIn("/home/abhishek/Documents/GSoC2011/inkscape/src/css_defaults", SPAttributeRelCSS::prop_defValue_pair);
 
68
    std::string filepath = INKSCAPE_ATTRRELDIR;
 
69
    filepath += "/cssprops";
 
70
    readDataFromFileIn(filepath, SPAttributeRelCSS::prop_element_pair);
 
71
    
 
72
    filepath = INKSCAPE_ATTRRELDIR;
 
73
    filepath += "/css_defaults";
 
74
    readDataFromFileIn(filepath, SPAttributeRelCSS::prop_defValue_pair);
52
75
}
53
76
 
54
77
void SPAttributeRelCSS::readDataFromFileIn(Glib::ustring fileName, storageType type)
55
78
{
56
79
    std::fstream file;
57
80
    file.open(fileName.c_str(), std::ios::in);
 
81
    
 
82
    if (!file.is_open()) {
 
83
        g_warning("could not open the data file for CSS attribute-element map construction");
 
84
        file.close();
 
85
        return ;        
 
86
    }
58
87
 
59
88
    while (!file.eof()) {
60
89
        std::stringstream ss;
84
113
        }
85
114
    }
86
115
    
 
116
    file.close();
 
117
    
87
118
}
88
119
 
89
120
/*