BrightSide Workbench Full Report + Source Code
AbstractDirectContentSearch.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.elephant.direct;
20 
21 import java.util.Collections;
22 import javax.servlet.ServletContext;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.turro.action.Actions;
26 import org.turro.collections.KeyValueMap;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.context.IConstructor;
29 
34 public abstract class AbstractDirectContentSearch implements IDirectContent {
35 
36  public String createSearchURL() {
37  return createURL() + "?search=";
38  }
39 
40  public String createURL() {
43  }
44 
45  /* IDirectContent */
46 
47  @Override
48  public boolean itsMe(String id) {
49  return getIdentifier().equals(id);
50  }
51 
52  @Override
53  public boolean myTurn(HttpServletRequest request) {
54  return DirectContents.isYourTurn(request, getIdentifier());
55  }
56 
57  @Override
58  public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
59  IConstructor execConstructor = ElephantContext.getConstructor(request, response);
60  KeyValueMap map = Actions.isRightNowAction(execConstructor) ?
61  Actions.getRightNowAction(execConstructor) :
62  Actions.getAction(execConstructor);
63  if(map == null && "POST".equals(request.getMethod())) {
64  map = new KeyValueMap(Collections.EMPTY_MAP);
65  for(String key : request.getParameterMap().keySet()) {
66  map.put(key, request.getParameter(key));
67  }
68  }
69  if(map != null) {
70  doExecute(execConstructor, map);
71  }
72  }
73 
74  protected abstract String getIdentifier();
75  protected abstract void doExecute(IConstructor constructor, KeyValueMap map);
76 
77 }
static boolean isRightNowAction(IConstructor constructor)
Definition: Actions.java:288
static KeyValueMap getRightNowAction(IConstructor constructor)
Definition: Actions.java:341
static KeyValueMap getAction(IConstructor constructor)
Definition: Actions.java:252
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
abstract void doExecute(IConstructor constructor, KeyValueMap map)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
static boolean isYourTurn(HttpServletRequest request, String path)