OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 57 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 57 Rev 180
Line 34... Line 34...
34
 
34
 
35
public class Include extends Statement {
35
public class Include extends Statement {
36
 
36
 
37
    private static final String PREFIX = "[IOD";
37
    private static final String PREFIX = "[IOD";
38
 
38
 
-
 
39
    // Cache whole file to avoid disk access since there can be a lot of sections in a single file
39
    private final ICache<File, ODSingleXMLDocument, File> cache;
40
    private final ICache<File, ODSingleXMLDocument, File> cache;
-
 
41
    // Cache the Parsed of just one section in the above file
-
 
42
    // { filePath#sectionName -> Parsed }
40
    private final ICache<String, Parsed<ODSingleXMLDocument>, File> parsedCache;
43
    private final ICache<String, Parsed<ODSingleXMLDocument>, File> parsedCache;
41
 
44
 
42
    public Include() {
45
    public Include() {
43
        super("include");
46
        super("include");
44
        this.cache = new ICache<File, ODSingleXMLDocument, File>(180);
47
        this.cache = new ICache<File, ODSingleXMLDocument, File>(180);
45
        this.parsedCache = new ICache<String, Parsed<ODSingleXMLDocument>, File>(180);
48
        this.parsedCache = new ICache<String, Parsed<ODSingleXMLDocument>, File>(180);
46
    }
49
    }
47
 
50
 
-
 
51
    @Override
-
 
52
    public void destroy() {
-
 
53
        this.cache.getSupp().die();
-
 
54
        this.parsedCache.getSupp().die();
-
 
55
        super.destroy();
-
 
56
    }
-
 
57
 
48
    public boolean matches(Element elem) {
58
    public boolean matches(Element elem) {
49
        if (!elem.getQualifiedName().equals("text:a"))
59
        if (!elem.getQualifiedName().equals("text:a"))
50
            return false;
60
            return false;
51
        final String name = getName(elem);
61
        final String name = getName(elem);
52
        // see 5.1.4 Hyperlinks § Name
62
        // see 5.1.4 Hyperlinks § Name
Line 127... Line 137...
127
    }
137
    }
128
 
138
 
129
    private Parsed<ODSingleXMLDocument> createParsed(final File ref, final String sectionName, final Parsed<?> parsed) throws JDOMException, IOException, TemplateException {
139
    private Parsed<ODSingleXMLDocument> createParsed(final File ref, final String sectionName, final Parsed<?> parsed) throws JDOMException, IOException, TemplateException {
130
        final ODSingleXMLDocument docToAdd = getXMLDocument(ref).clone();
140
        final ODSingleXMLDocument docToAdd = getXMLDocument(ref).clone();
131
 
141
 
-
 
142
        // replace the body with just sectionName
132
        final XPath sectionXP = docToAdd.getXPath("//text:section[@text:name = '" + sectionName + "']");
143
        final XPath sectionXP = docToAdd.getXPath("//text:section[@text:name = '" + sectionName + "']");
133
        final Element section = (Element) sectionXP.selectSingleNode(docToAdd.getDocument());
144
        final Element section = (Element) sectionXP.selectSingleNode(docToAdd.getDocument());
134
        // ajouter la section car souvent des if s'y réfèrent.
145
        // ajouter la section elle-même car souvent des if s'y réfèrent.
135
        docToAdd.getBody().setContent(section.detach());
146
        docToAdd.getBody().setContent(section.detach());
136
 
147
 
137
        final Material<ODSingleXMLDocument> from = Material.from(docToAdd);
148
        final Material<ODSingleXMLDocument> from = Material.from(docToAdd);
138
        from.setBase(ref);
149
        from.setBase(ref);
139
        return new Parsed<ODSingleXMLDocument>(from, parsed);
150
        return new Parsed<ODSingleXMLDocument>(from, parsed);