Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Xtag |
|
| 2.625;2.625 |
1 | /************************************************************************** | |
2 | OmegaT - Computer Assisted Translation (CAT) tool | |
3 | with fuzzy matching, translation memory, keyword search, | |
4 | glossaries, and translation leveraging into updated projects. | |
5 | ||
6 | Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk | |
7 | 2008 Didier Briel | |
8 | Home page: http://www.omegat.org/ | |
9 | Support center: http://groups.yahoo.com/group/OmegaT/ | |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
15 | ||
16 | This program is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with this program; if not, write to the Free Software | |
23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | **************************************************************************/ | |
25 | ||
26 | package org.omegat.filters2.xtagqxp; | |
27 | ||
28 | import org.omegat.filters3.Element; | |
29 | ||
30 | /** | |
31 | * A Xtag in a CopyFlow Gold for QuarkXPress source text. | |
32 | * | |
33 | * @author Didier Briel | |
34 | */ | |
35 | public class Xtag implements Element { | |
36 | ||
37 | 0 | public Xtag(String tag, int index) { |
38 | 0 | this.tag = tag; |
39 | 0 | this.shortcut = makeShortcut(tag); |
40 | 0 | this.index = index; |
41 | 0 | } |
42 | ||
43 | /** | |
44 | * Makes a shortcut from an Xtag. If the tag contains no letter, uses 'x' | |
45 | * for the shortcut. | |
46 | * | |
47 | * @param tag | |
48 | * The full Xtag | |
49 | * @return The shortcut | |
50 | */ | |
51 | private String makeShortcut(String tag) { | |
52 | 0 | char letter = ' '; |
53 | ||
54 | 0 | for (int i = 0; i < tag.length(); i++) { |
55 | 0 | letter = tag.charAt(i); |
56 | 0 | if (Character.isLetter(letter)) { |
57 | 0 | letter = Character.toLowerCase(letter); |
58 | 0 | return String.valueOf(letter); |
59 | } | |
60 | } | |
61 | 0 | if (letter == '<') |
62 | 0 | return "<"; |
63 | 0 | else if (letter == '>') |
64 | 0 | return ">"; |
65 | else | |
66 | 0 | return "x"; |
67 | } | |
68 | ||
69 | private String tag; | |
70 | ||
71 | /** Returns this tag. */ | |
72 | public String getTag() { | |
73 | 0 | return tag; |
74 | } | |
75 | ||
76 | private String shortcut; | |
77 | ||
78 | /** Returns the short form of this tag, most often -- the first letter. */ | |
79 | public String getShortcut() { | |
80 | 0 | if (shortcut != null) |
81 | 0 | return shortcut; |
82 | else | |
83 | 0 | return Character.toString(getTag().charAt(0)); |
84 | } | |
85 | ||
86 | private int index; | |
87 | ||
88 | /** Returns the index of this tag in the entry. */ | |
89 | public int getIndex() { | |
90 | 0 | return index; |
91 | } | |
92 | ||
93 | /** | |
94 | * Returns shortcut string representation of the element. If the shortcut is | |
95 | * < or >, return the character rather than a tag E.g. for <strong> | |
96 | * tag should return <s3>. | |
97 | */ | |
98 | public String toShortcut() { | |
99 | 0 | StringBuffer buf = new StringBuffer(); |
100 | ||
101 | 0 | if (getShortcut().equals("<")) |
102 | 0 | return "<"; |
103 | 0 | else if (getShortcut().equals(">")) |
104 | 0 | return ">"; |
105 | else | |
106 | 0 | buf.append("<"); |
107 | 0 | buf.append(getShortcut()); |
108 | 0 | buf.append(getIndex()); |
109 | // All Xtags are single tags | |
110 | 0 | buf.append("/"); |
111 | 0 | buf.append(">"); |
112 | ||
113 | 0 | return buf.toString(); |
114 | } | |
115 | ||
116 | /** | |
117 | * Returns the tag in its original form as it was in the original document. | |
118 | * E.g. for <strong> tag should return <strong>. | |
119 | */ | |
120 | public String toOriginal() { | |
121 | 0 | return "<" + getTag() + ">"; |
122 | } | |
123 | ||
124 | /** | |
125 | * Not really implemented | |
126 | * | |
127 | * @return an empty string | |
128 | */ | |
129 | public String toTMX() { | |
130 | 0 | return ""; |
131 | } | |
132 | } |