BrightSide Workbench Full Report + Source Code
EntitiesInfo.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.action;
20 
21 import java.io.Writer;
22 import java.util.Map;
23 import org.turro.annotation.EntityInfo;
24 import org.turro.elephant.context.Application;
25 import org.turro.entities.Entities;
26 import org.turro.html.HtmlContent;
27 import org.turro.marker.ElephantMarker;
28 import org.turro.path.Path;
29 import org.turro.reflection.Instances;
30 
35 public class EntitiesInfo {
36 
37  public static String getString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link) {
38  return getString(entity, wrapper, label, type, link, null);
39  }
40 
41  public static String getString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link, Map<String, Object> args) {
43  marker.put(label, entity);
44  marker.put("wrapper", wrapper);
45  marker.put("link", link.toString());
46  marker.put("type", type.toString());
47  marker.put("iee", Entities.getController(entity));
48  if(args != null) {
49  marker.putAll(args);
50  }
51  return marker.parse(label, "entityInfo");
52  }
53 
54  public static String getTextString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link) {
55  return getTextString(entity, wrapper, label, type, link, null);
56  }
57 
58  public static String getTextString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link, Map<String, Object> args) {
59  return HtmlContent.text(getString(entity, wrapper, label, type, link, args));
60  }
61 
62  /* Entities info */
63 
64  public static boolean writeEntityInfo(Writer out, String path, EntityInfoType type, LinkType link) {
65  Path entityPath = new Path(path);
66  for(IEntityInfo iEntity : Instances.cached().byAnnotation(EntityInfo.class, IEntityInfo.class)) {
67  if(iEntity.writeEntityInfo(out, entityPath, type, link)) {
68  return true;
69  }
70  }
71  return false;
72  }
73 
74  private EntitiesInfo() {
75  }
76 
77 }
static boolean writeEntityInfo(Writer out, String path, EntityInfoType type, LinkType link)
static String getString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link, Map< String, Object > args)
static String getTextString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link)
static String getTextString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link, Map< String, Object > args)
static String getString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link)
static IElephantEntity getController(String path)
Definition: Entities.java:78
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)