1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.common;
|
10
|
|
11
|
/**
|
12
|
* Utility class to handle {@link IntextReference}s
|
13
|
*
|
14
|
* @author a.mueller
|
15
|
* @since 10.03.2017
|
16
|
*
|
17
|
*/
|
18
|
public final class IntextReferenceHelper {
|
19
|
|
20
|
public static IntextReference addIntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, String start, String inner, String end){
|
21
|
IntextReference intextReference = IntextReference.NewInstance(target, referencedEntity, 0, 0);
|
22
|
referencedEntity.setText(start + intextReference.toInlineString(inner) + end);
|
23
|
referencedEntity.getIntextReferences().add(intextReference);
|
24
|
return intextReference;
|
25
|
}
|
26
|
public static IntextReference addIntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, int start, int end){
|
27
|
String text = referencedEntity.getText();
|
28
|
if (start < 0 || end < 0 || start > end || end > text.length()){
|
29
|
throw new IndexOutOfBoundsException("Start and end must be within bounds");
|
30
|
}
|
31
|
IntextReference intextReference = IntextReference.NewInstance(target, referencedEntity, 0, 0);
|
32
|
referencedEntity.setText(text.substring(0, start) + intextReference.toInlineString(text.substring(start,end))
|
33
|
+ text.substring(end));
|
34
|
referencedEntity.getIntextReferences().add(intextReference);
|
35
|
return intextReference;
|
36
|
}
|
37
|
}
|