OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 Rev 182
Line 47... Line 47...
47
import org.jdom.Element;
47
import org.jdom.Element;
48
import org.jdom.JDOMException;
48
import org.jdom.JDOMException;
49
import org.jdom.Namespace;
49
import org.jdom.Namespace;
50
import org.jdom.Parent;
50
import org.jdom.Parent;
51
import org.jdom.Text;
51
import org.jdom.Text;
-
 
52
import org.jdom.Verifier;
52
import org.jdom.xpath.XPath;
53
import org.jdom.xpath.XPath;
53
import org.xml.sax.SAXException;
54
import org.xml.sax.SAXException;
54
 
55
 
55
import net.jcip.annotations.GuardedBy;
56
import net.jcip.annotations.GuardedBy;
56
import net.jcip.annotations.Immutable;
57
import net.jcip.annotations.Immutable;
Line 342... Line 343...
342
     */
343
     */
343
    public final Element encodeWS(final String s) {
344
    public final Element encodeWS(final String s) {
344
        return Span.createEmpty(getFormatVersion()).setContent(encodeWSasList(s));
345
        return Span.createEmpty(getFormatVersion()).setContent(encodeWSasList(s));
345
    }
346
    }
346
 
347
 
-
 
348
    public final String replaceInvalidChars(final String s) {
-
 
349
        return replaceInvalidChars(s, false);
-
 
350
    }
-
 
351
 
-
 
352
    public final String replaceInvalidChars(final String s, final boolean keepVT) {
-
 
353
        final int len = s.length();
-
 
354
        StringBuilder sb = null;
-
 
355
        for (int i = 0; i < len; i++) {
-
 
356
            char c = s.charAt(i);
-
 
357
            if (!Verifier.isXMLCharacter(c) && (!keepVT || c != TextNode.VERTICAL_TAB_CHAR)) {
-
 
358
                if (sb == null) {
-
 
359
                    sb = new StringBuilder(len);
-
 
360
                    sb.append(s.substring(0, i));
-
 
361
                }
-
 
362
                c = '�';
-
 
363
            }
-
 
364
            if (sb != null)
-
 
365
                sb.append(c);
-
 
366
        }
-
 
367
        return sb == null ? s : sb.toString();
-
 
368
    }
-
 
369
 
347
    public final List<Content> encodeWSasList(final String s) {
370
    public final List<Content> encodeWSasList(String s) {
-
 
371
        s = replaceInvalidChars(s, true);
348
        final List<Content> res = new ArrayList<Content>();
372
        final List<Content> res = new ArrayList<Content>();
349
        final Matcher m = WHITE_SPACE_TO_ENCODE.matcher(s);
373
        final Matcher m = WHITE_SPACE_TO_ENCODE.matcher(s);
350
        int last = 0;
374
        int last = 0;
351
        while (m.find()) {
375
        while (m.find()) {
352
            res.add(new Text(s.substring(last, m.start())));
376
            res.add(new Text(s.substring(last, m.start())));
353
            switch (m.group().charAt(0)) {
377
            switch (m.group().charAt(0)) {
354
            case '\n':
378
            case '\n':
355
                // Vertical Tab, see TextNode#VERTICAL_TAB_CHAR
379
            case TextNode.VERTICAL_TAB_CHAR:
356
            case '\u000B':
-
 
357
                res.add(getLineBreak());
380
                res.add(getLineBreak());
358
                break;
381
                break;
359
            case '\t':
382
            case '\t':
360
                res.add(getTab());
383
                res.add(getTab());
361
                break;
384
                break;