1
|
package eu.etaxonomy.taxeditor.util;
|
2
|
|
3
|
import java.util.regex.Matcher;
|
4
|
import java.util.regex.Pattern;
|
5
|
|
6
|
import org.apache.commons.lang.StringUtils;
|
7
|
|
8
|
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
|
9
|
import eu.etaxonomy.cdm.model.common.IntextReference;
|
10
|
|
11
|
public class RichtextHelper {
|
12
|
private static final String CDM_PREFIX = "cdm:";
|
13
|
public static String createHtml(IntextReference inRef, String innerString){
|
14
|
/*
|
15
|
*
|
16
|
* <span
|
17
|
class="cdm:IntextReference"
|
18
|
data-cdm-referenced-type="reference"
|
19
|
data-cdm-referenced-uuid="38567a90-bcae-4f76-b148-21fcae649a85'"
|
20
|
data-cdm-intext-uuid="'d427802f-ea22-4d10-b90b-fa90aa0092ed">
|
21
|
innerString
|
22
|
</span>
|
23
|
|
24
|
*/
|
25
|
String type = " data-cdm-referenced-type=\"" + inRef.myClass().tag() + "\"";
|
26
|
IIntextReferenceTarget entity = inRef.getTarget();
|
27
|
String intextUuid= " data-cdm-intext-uuid=\"" + inRef.getUuid() + "\"";
|
28
|
String referencedUuid = " data-cdm-referenced-uuid=\"" + entity.getUuid()+ "\"" ;
|
29
|
String result;
|
30
|
if (StringUtils.isNotEmpty(innerString)){
|
31
|
result = "<span class=\"cdm:IntextReference\"" + intextUuid + type + referencedUuid + ">" + innerString + "</" + "span" + ">";
|
32
|
}else{
|
33
|
result ="<span \n class=\"cdm:IntextReference\"" + intextUuid + type + referencedUuid + "/>";
|
34
|
}
|
35
|
return result;
|
36
|
|
37
|
|
38
|
}
|
39
|
|
40
|
public static String findInlineString(String text, String inlineString){
|
41
|
if (text == null){
|
42
|
return null;
|
43
|
}
|
44
|
Pattern pattern = Pattern.compile(inlineString);
|
45
|
Matcher matcher = pattern.matcher(text);
|
46
|
String result = null;
|
47
|
if (matcher.find()){
|
48
|
result = matcher.group();
|
49
|
System.out.println(result);
|
50
|
for (int i = 0; i<matcher.groupCount(); i++){
|
51
|
if (i == 0){
|
52
|
result= matcher.group(i);
|
53
|
}
|
54
|
System.out.println(matcher.group(i));
|
55
|
}
|
56
|
|
57
|
|
58
|
|
59
|
}
|
60
|
return result;
|
61
|
}
|
62
|
|
63
|
public static String findInText(String text, String inlineString){
|
64
|
if (text == null){
|
65
|
return null;
|
66
|
}
|
67
|
|
68
|
Pattern pattern = Pattern.compile(inlineString);
|
69
|
Matcher matcher = pattern.matcher(text);
|
70
|
if (matcher.find())
|
71
|
{
|
72
|
String result = matcher.group(1);
|
73
|
return matcher.group(2);
|
74
|
}
|
75
|
return null;
|
76
|
}
|
77
|
|
78
|
public static String createCdmMarkUp(IntextReference inRef, String innerText){
|
79
|
return inRef.toInlineString(innerText);
|
80
|
|
81
|
}
|
82
|
}
|