8 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.attributes;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.Iterator;
16 import java.util.List;
18 import javax.persistence.DiscriminatorValue;
19 import javax.persistence.Entity;
20 import javax.persistence.NamedQueries;
21 import javax.persistence.NamedQuery;
35 @DiscriminatorValue(
"Entity")
37 @NamedQuery(name =
"SuggestionAttribute.findByEntityName", query =
"SELECT a FROM SuggestionAttribute a WHERE a.stringValue = :name"),
38 @NamedQuery(name =
"SuggestionAttribute.findByEntityType", query =
"SELECT a FROM SuggestionAttribute a WHERE a.entityType = :type"),
39 @NamedQuery(name =
"SuggestionAttribute.findByEntityUri", query =
"SELECT a FROM SuggestionAttribute a WHERE a.uri = :uri")
58 public SugEntityAttribute(String name, String type, String URI, String visualRepresentation, String description){
59 this.entityType = type;
60 this.stringValue = name;
61 this.simpleType =
"Entity";
63 this.entityVisualURI = visualRepresentation;
64 this.textValue = description;
74 return this.entityAdditionalAttributes;
83 this.entityAdditionalAttributes = EntityAdditionalAttributes;
92 this.textValue = textValue;
110 this.stringValue = name;
120 StringBuilder result =
new StringBuilder(
"<entity");
122 if(this.stringValue != null && !this.stringValue.isEmpty()){
123 result.append(
" name=\"");
124 result.append(escapeHTML(this.stringValue));
128 if(this.uri != null && !this.uri.isEmpty()){
129 result.append(
" uri=\"");
130 result.append(escapeHTML(this.uri));
134 if(this.entityType != null && !this.entityType.isEmpty()){
135 result.append(
" type=\"");
136 result.append(this.entityType);
140 if(this.entityVisualURI != null && !this.entityVisualURI.isEmpty()){
141 result.append(
" visualRepresentation=\"");
142 result.append(escapeHTML(this.entityVisualURI));
146 if(this.textValue != null && !this.textValue.isEmpty()){
147 result.append(
"><![CDATA[");
148 result.append(this.textValue);
149 result.append(
"]]></entity>");
154 return result.toString();
163 StringBuilder result =
new StringBuilder(
"<entity");
165 if(this.stringValue != null && !this.stringValue.isEmpty()){
166 result.append(
" name=\"");
167 result.append(escapeHTML(this.stringValue));
171 if(this.uri != null && !this.uri.isEmpty()){
172 result.append(
" uri=\"");
173 result.append(escapeHTML(this.uri));
177 if(this.entityType != null && !this.entityType.isEmpty()){
178 result.append(
" type=\"");
179 result.append(this.entityType);
183 if(this.entityVisualURI != null && !this.entityVisualURI.isEmpty()){
184 result.append(
" visualRepresentation=\"");
185 if (this.entityVisualURI != null && !this.entityVisualURI.startsWith(
"http")) {
186 result.append(AppBean.getKBImagePrefix());
188 result.append(escapeHTML(this.entityVisualURI));
192 if(this.textValue != null && !this.textValue.isEmpty()){
193 result.append(
"><![CDATA[");
194 result.append(this.textValue);
195 result.append(
"]]></entity>");
200 return result.toString();
211 StringBuilder result =
new StringBuilder();
213 if(this.uri == null){
215 result.append(
"<trix:uri>");
216 result.append(
"http://knot.fit.vutbr.cz/annotations/knotOAExtension#anyEntity");
217 result.append(
"</trix:uri></trix:triple>");
218 return result.toString();
221 result.append(
"<trix:uri>");
222 result.append(escapeHTML(this.uri));
223 result.append(
"</trix:uri></trix:triple>");
226 result.append(
"<trix:triple><trix:uri>");
227 result.append(escapeHTML(this.uri));
228 result.append(
"</trix:uri><trix:uri>rdf:type</trix:uri><trix:name>");
229 result.append(entityType);
230 result.append(
"</trix:name></trix:triple>");
233 if(stringValue != null && !stringValue.isEmpty()){
234 result.append(
"<trix:triple><trix:uri>");
235 result.append(escapeHTML(this.uri));
236 result.append(
"</trix:uri><trix:name>name</trix:name><trix:typedLiteral datatype=\"http://www.w3.org/2001/XMLSchema#string\">");
237 result.append(escapeHTML(stringValue));
238 result.append(
"</trix:typedLiteral></trix:triple>");
242 if(textValue != null && !textValue.isEmpty()){
243 result.append(
"<trix:triple><trix:uri>");
244 result.append(escapeHTML(this.uri));
245 result.append(
"</trix:uri><trix:name>description</trix:name><trix:typedLiteral datatype=\"http://www.w3.org/2001/XMLSchema#string\">");
246 result.append(escapeHTML(textValue));
247 result.append(
"</trix:typedLiteral></trix:triple>");
251 if(entityVisualURI != null && !entityVisualURI.isEmpty()){
252 result.append(
"<trix:triple><trix:uri>");
253 result.append(escapeHTML(this.uri));
254 result.append(
"</trix:uri><trix:name>image</trix:name><trix:typedLiteral datatype=\"http://knot.fit.vutbr.cz/annotations/knotOAExtension#imageUri\">");
255 result.append(escapeHTML(entityVisualURI));
256 result.append(
"</trix:typedLiteral></trix:triple>");
259 if(entityAdditionalAttributes != null && !entityAdditionalAttributes.isEmpty()){
260 Collections.sort(entityAdditionalAttributes);
261 Iterator<SugEntityAdditionalAttribute> additionalAttrIt = entityAdditionalAttributes.iterator();
262 while(additionalAttrIt.hasNext()){
264 result.append(actualAttr.toString());
268 return result.toString();
278 public void setRawValues(Object values)
throws IllegalArgumentException {
279 @SuppressWarnings(
"unchecked") ArrayList<Object> valuesArray = (ArrayList<Object>)values;
280 @SuppressWarnings(
"unchecked") Map<String,String> parameters = (Map<String,String>)valuesArray.get(1);
281 String value = (String)valuesArray.get(2);
283 if(parameters.get(
"name") != null){
284 this.stringValue = parameters.get(
"name");
287 if(parameters.get(
"type") != null){
288 this.entityType = parameters.get(
"type");
291 if(parameters.get(
"uri") != null){
292 this.uri = parameters.get(
"uri");
295 if(parameters.get(
"visualRepresentation") != null){
296 this.entityVisualURI = parameters.get(
"visualRepresentation");
300 this.textValue = value;
312 StringBuilder sb =
new StringBuilder();
314 for (
int i = 0; i < n; i++) {
315 char c = s.charAt(i);
317 case '<': sb.append(
"<");
break;
318 case '>': sb.append(
">");
break;
319 case '&': sb.append(
"&");
break;
320 case '"': sb.append(
""");
break;
321 case '\'': sb.append(
"'");
break;
322 default: sb.append(c);
break;
325 return sb.toString();
345 return new EntityAttribute.Entity(this.entityType,this.stringValue,this.uri,this.entityVisualURI, this.textValue);
355 this.entityType = ((EntityAttribute.Entity)value).getType();
356 this.stringValue = ((EntityAttribute.Entity)value).getName();
357 this.uri = ((EntityAttribute.Entity)value).getURI();
358 this.entityVisualURI = ((EntityAttribute.Entity)value).getVisualRepresentation();
359 this.textValue = ((EntityAttribute.Entity)value).getDescription();
368 EntityAttribute.Entity ent =
new EntityAttribute.Entity();
369 ent.fromJSONString(value);
Additional attribute of entity in suggestion attribute.
SugEntityAttribute(String name, String type, String URI, String visualRepresentation, String description)
Singleton for storing global variables.
Class representing vocabulary entity attribute for prupose of suggestion.
List< SugEntityAdditionalAttribute > getEntityAdditionalAttributes()
Class representing vocabulary entity attribute.
void setDescription(String textValue)
void setRawValues(Object values)
void setEntityAdditionalAttributes(ArrayList< SugEntityAdditionalAttribute > EntityAdditionalAttributes)
void setValue(Object value)
String escapeHTML(String s)
String getXmlAttributeName()
Abstract class representing more complex attribute of suggestion.
void setStringValue(String value)
String getTypeOntologyUri()
void setEntityName(String name)
static final String ENTITY_URI