~ubuntu-branches/ubuntu/vivid/herold/vivid

« back to all changes in this revision

Viewing changes to java/org/dbdoclet/trafo/html/docbook/editor/SpanEditor.java

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2012-09-20 10:00:14 UTC
  • Revision ID: package-import@ubuntu.com-20120920100014-5pcwbw2err6on8yg
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (C) 2001-2012 Michael Fuchs
 
3
 *
 
4
 * This file is part of herold.
 
5
 * 
 
6
 * herold is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * herold is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with herold.  If not, see <http://www.gnu.org/licenses/>.  
 
18
 */
 
19
package org.dbdoclet.trafo.html.docbook.editor;
 
20
 
 
21
import org.dbdoclet.service.StringServices;
 
22
import org.dbdoclet.trafo.html.docbook.DocBookTransformer;
 
23
import org.dbdoclet.trafo.tag.docbook.Anchor;
 
24
import org.dbdoclet.trafo.tag.docbook.DocBookElement;
 
25
import org.dbdoclet.trafo.tag.docbook.DocBookTagFactory;
 
26
import org.dbdoclet.trafo.tag.docbook.IndexTerm;
 
27
import org.dbdoclet.trafo.tag.docbook.Primary;
 
28
import org.dbdoclet.trafo.tag.docbook.Secondary;
 
29
import org.dbdoclet.trafo.tag.html.Span;
 
30
 
 
31
public class SpanEditor extends Editor {
 
32
 
 
33
    @Override
 
34
    public EditorInstruction edit(EditorInstruction values) throws EditorException {
 
35
 
 
36
        setValues(super.edit(values));
 
37
        DocBookTagFactory dbfactory = values.getTagFactory();
 
38
 
 
39
        Span span = (Span) getHtmlElement();
 
40
        DocBookElement parent = getParent();
 
41
 
 
42
        String title = span.getTitle();
 
43
 
 
44
        String border1 = ":primary=";
 
45
        String border2 = ":secondary=";
 
46
 
 
47
        if ((title != null) && title.startsWith("indexterm:")) {
 
48
 
 
49
            String buffer = StringServices.cutPrefix(title, "indexterm");
 
50
 
 
51
            if (buffer.startsWith(border1)) {
 
52
 
 
53
                String primaryText = StringServices.cutPrefix(buffer, border1);
 
54
                String secondaryText = null;
 
55
 
 
56
                int indexSecondary = primaryText.indexOf(border2);
 
57
 
 
58
                if (indexSecondary != -1) {
 
59
 
 
60
                    int index = indexSecondary + border2.length();
 
61
 
 
62
                    if (index < primaryText.length()) {
 
63
 
 
64
                        secondaryText = primaryText.substring(indexSecondary + border2.length());
 
65
                    }
 
66
 
 
67
                    primaryText = primaryText.substring(0, indexSecondary);
 
68
                }
 
69
 
 
70
                IndexTerm indexTerm = dbfactory.createIndexTerm();
 
71
                indexTerm.setParentNode(getParent());
 
72
 
 
73
                Primary primary = dbfactory.createPrimary(primaryText);
 
74
                indexTerm.appendChild(primary);
 
75
 
 
76
                if ((secondaryText != null) && (secondaryText.length() > 0)) {
 
77
 
 
78
                    Secondary secondary = dbfactory.createSecondary(secondaryText);
 
79
                    indexTerm.appendChild(secondary);
 
80
                }
 
81
 
 
82
                parent.appendChild(indexTerm);
 
83
            }
 
84
        }
 
85
 
 
86
        String id = span.getId();
 
87
 
 
88
        if (id != null) {
 
89
 
 
90
            DocBookTransformer transformer = getTransformer();
 
91
            Anchor anchor = dbfactory.createAnchor();
 
92
            anchor.setId(transformer.createUniqueId(id));
 
93
            parent.appendChild(anchor);
 
94
        }
 
95
 
 
96
        traverse(true);
 
97
 
 
98
        return finalizeValues();
 
99
    }
 
100
}