BrightSide Workbench Full Report + Source Code
org.turro.action.ContentService Class Reference
Inheritance diagram for org.turro.action.ContentService:
Collaboration diagram for org.turro.action.ContentService:

Public Member Functions

boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 

Static Public Member Functions

static String createURL (IConstructor constructor, KeyValueMap values)
 
static String createURL (IConstructor constructor, String values)
 
static String createEntryPoint (IConstructor constructor, String entryPoint, String valueStr)
 
static String createEntryPoint (IConstructor constructor, String entryPoint, KeyValueMap values)
 
static String getIdentifier ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 57 of file ContentService.java.

Member Function Documentation

◆ createEntryPoint() [1/2]

static String org.turro.action.ContentService.createEntryPoint ( IConstructor  constructor,
String  entryPoint,
KeyValueMap  values 
)
static

Definition at line 82 of file ContentService.java.

82  {
83  values.put("type", "entry-point");
84  values.put("entry-point", entryPoint);
85  String exrino = Actions.createRightNowAction(values);
86  return ElephantContext.getRootWebPath() +
87  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
88  "?" + exrino;
89  }

◆ createEntryPoint() [2/2]

static String org.turro.action.ContentService.createEntryPoint ( IConstructor  constructor,
String  entryPoint,
String  valueStr 
)
static

Definition at line 73 of file ContentService.java.

73  {
74  try {
75  return createEntryPoint(constructor, entryPoint, new KeyValueMap(valueStr));
76  } catch (ParserException ex) {
77  Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, null, ex);
78  }
79  return null;
80  }
static String createEntryPoint(IConstructor constructor, String entryPoint, String valueStr)
Here is the caller graph for this function:

◆ createURL() [1/2]

static String org.turro.action.ContentService.createURL ( IConstructor  constructor,
KeyValueMap  values 
)
static

Definition at line 59 of file ContentService.java.

59  {
60  String exrino = Actions.createRightNowAction(values);
61  return ElephantContext.getRootWebPath() +
62  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
63  "?" + exrino;
64  }
Here is the caller graph for this function:

◆ createURL() [2/2]

static String org.turro.action.ContentService.createURL ( IConstructor  constructor,
String  values 
)
static

Definition at line 66 of file ContentService.java.

66  {
67  String exrino = Actions.createRightNowAction(values);
68  return ElephantContext.getRootWebPath() +
69  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
70  "?" + exrino;
71  }

◆ execute()

void org.turro.action.ContentService.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 106 of file ContentService.java.

106  {
107  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
108  if(isMultipart) {
109  try {
110  ServletFileUpload upload = new ServletFileUpload();
111  upload.setHeaderEncoding(ElephantContext.getEncoding());
112  FileItemIterator iter = upload.getItemIterator(request);
113  File file = null;
114  String redirect = null;
115  Double fixWidth = null, fixHeight = null;
116  while(iter.hasNext()) {
117  FileItemStream item = iter.next();
118  String name = item.getFieldName();
119  InputStream stream = item.openStream();
120  if(item.isFormField()) {
121  switch(name) {
122  case "fileName":
123  file = new File(ElephantContext.getRealPath(Streams.asString(stream, ElephantContext.getEncoding())));
124  break;
125  case "redirect":
126  redirect = Streams.asString(stream, ElephantContext.getEncoding());
127  break;
128  case "fixWidth":
129  fixWidth = Double.valueOf(Streams.asString(stream, ElephantContext.getEncoding()));
130  break;
131  case "fixHeight":
132  fixHeight = Double.valueOf(Streams.asString(stream, ElephantContext.getEncoding()));
133  break;
134  }
135  } else if(file != null) {
136  file.getParentFile().mkdirs();
137  FileOutputStream fos = new FileOutputStream(file);
138  Streams.copy(item.openStream(), fos, true);
139  }
140  }
141  if(file != null && fixWidth != null && fixHeight != null) {
142  ImageUtil.smart(file, file, fixWidth, fixHeight);
143  }
144  if(!Strings.isBlank(redirect)) {
145  Application.getApplication().sendRedirect(redirect);
146  }
147  } catch (FileUploadException | IOException ex) {
148  Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg("Multipart"), ex);
149  }
150  } else {
151  KeyValueMap map = Actions.getRightNowAction(ElephantContext.getConstructor(request, response));
152  if(map != null) {
153  String type = map.get("type");
154  if("qrcode".equals(type)) {
155  try {
156  response.setContentType("image/png");
157  Barcode qr = new Barcode();
158  qr.writeImageCode(
159  response.getOutputStream(),
160  qr.encodeQrCode(map.get("data"), 300),
161  "png");
162  } catch (IOException ex) {
163  Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg("QRCode"), ex);
164  }
165  } else if("image".equals(type)) {
166  try {
167  response.setContentType("image/png");
168  ImageIO.write(ImageIO.read(new File(map.get("data"))), "png", response.getOutputStream());
169  } catch (IOException ex) {
170  Logger.getLogger(ContentService.class.getName()).log(Level.SEVERE, ElephantContext.logMsg("Image"), ex);
171  }
172  } else if("cookie".equals(type)) {
173  if(map.containsKey("remove")) {
174  CookieUtil.deleteCookie(response, map.get("name"), map.getOrDefault("path", "/"));
175  } else {
176  Application.setCookie(map.get("name"), map.get("value"),
177  map.getOrDefault("path", "/"),
178  map.get(Integer.class, "age", 60 * 60 * 24 * 365 * 10));
179  }
180  } else if("entry-point".equals(type)) {
181  if(map.containsKey("entry-point")) {
182  getEntryPoint(map.get("entry-point")).execute(map);
183  }
184  }
185  }
186  }
187  }
default void execute(KeyValueMap kvm)
Here is the call graph for this function:

◆ getIdentifier()

static String org.turro.action.ContentService.getIdentifier ( )
static

Definition at line 91 of file ContentService.java.

91  {
92  return ContentService.class.getAnnotation(DirectContent.class).identifier();
93  }

◆ itsMe()

boolean org.turro.action.ContentService.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 96 of file ContentService.java.

96  {
97  return getIdentifier().equals(id);
98  }

◆ myTurn()

boolean org.turro.action.ContentService.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 101 of file ContentService.java.

101  {
102  return DirectContents.isYourTurn(request, getIdentifier());
103  }
Here is the call graph for this function:

The documentation for this class was generated from the following file: