2
* Copyright (C) 2001-2012 Michael Fuchs
4
* This file is part of herold.
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.
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.
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/>.
19
package org.dbdoclet.trafo.html.docbook.editor;
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;
31
public class SpanEditor extends Editor {
34
public EditorInstruction edit(EditorInstruction values) throws EditorException {
36
setValues(super.edit(values));
37
DocBookTagFactory dbfactory = values.getTagFactory();
39
Span span = (Span) getHtmlElement();
40
DocBookElement parent = getParent();
42
String title = span.getTitle();
44
String border1 = ":primary=";
45
String border2 = ":secondary=";
47
if ((title != null) && title.startsWith("indexterm:")) {
49
String buffer = StringServices.cutPrefix(title, "indexterm");
51
if (buffer.startsWith(border1)) {
53
String primaryText = StringServices.cutPrefix(buffer, border1);
54
String secondaryText = null;
56
int indexSecondary = primaryText.indexOf(border2);
58
if (indexSecondary != -1) {
60
int index = indexSecondary + border2.length();
62
if (index < primaryText.length()) {
64
secondaryText = primaryText.substring(indexSecondary + border2.length());
67
primaryText = primaryText.substring(0, indexSecondary);
70
IndexTerm indexTerm = dbfactory.createIndexTerm();
71
indexTerm.setParentNode(getParent());
73
Primary primary = dbfactory.createPrimary(primaryText);
74
indexTerm.appendChild(primary);
76
if ((secondaryText != null) && (secondaryText.length() > 0)) {
78
Secondary secondary = dbfactory.createSecondary(secondaryText);
79
indexTerm.appendChild(secondary);
82
parent.appendChild(indexTerm);
86
String id = span.getId();
90
DocBookTransformer transformer = getTransformer();
91
Anchor anchor = dbfactory.createAnchor();
92
anchor.setId(transformer.createUniqueId(id));
93
parent.appendChild(anchor);
98
return finalizeValues();