use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class FormPropertyType method toJSON.
@Override
public JSONWriter toJSON(JSONWriter writer, String key, Object sabloValue, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
if (key != null) {
writer.key(key);
}
String formName = null;
if (sabloValue instanceof String) {
formName = (String) sabloValue;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
FlattenedSolution flattenedSolution = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
Form form = flattenedSolution.getForm(formName);
// form name
if (form == null) {
form = (Form) flattenedSolution.searchPersist((String) sabloValue);
}
if (form != null) {
formName = form.getName();
}
}
} else if (sabloValue instanceof CharSequence) {
formName = ((CharSequence) sabloValue).toString();
} else if (sabloValue instanceof Form) {
formName = ((Form) sabloValue).getName();
} else if (sabloValue instanceof FormController) {
formName = ((FormController) sabloValue).getName();
} else if (sabloValue instanceof FormScope) {
formName = ((FormScope) sabloValue).getFormController().getName();
} else {
formName = null;
Debug.error("Cannot handle unknown value for Form type: " + sabloValue);
}
writer.value(formName);
if (CurrentWindow.get() instanceof INGClientWindow) {
// if this is a web component that triggered it, register to only allow this form for that component
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent)
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement());
else
// else register it for null then this form is allowed globally (a form in dialog of popup)
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, null);
}
return writer;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class FormPropertyType method toTemplateJSONValue.
@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion browserConversionMarkers, FormElementContext formElementContext) throws JSONException {
if (formElementValue == null)
return writer;
FlattenedSolution fs = formElementContext.getFlattenedSolution();
Form form = null;
if (formElementValue instanceof Integer) {
form = fs.getForm(((Integer) formElementValue).intValue());
} else if (formElementValue instanceof String || formElementValue instanceof UUID) {
form = fs.getForm(formElementValue.toString());
if (form == null) {
form = (Form) fs.searchPersist(formElementValue.toString());
}
}
if (form != null) {
writer.key(key);
writer.value(form.getName());
if (CurrentWindow.safeGet() instanceof INGClientWindow) {
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(form.getName(), formElementContext.getFormElement());
}
}
return writer;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class NGClientEntryFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
try {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if ("GET".equalsIgnoreCase(request.getMethod())) {
if (request.getCharacterEncoding() == null)
request.setCharacterEncoding("UTF8");
String uri = request.getRequestURI();
if (handleShortSolutionRequest(request, response)) {
return;
}
if (handleDeeplink(request, response)) {
return;
}
if (handleRecording(request, response)) {
return;
}
if (uri != null && (uri.endsWith(".html") || uri.endsWith(".js"))) {
String solutionName = getSolutionNameFromURI(uri);
if (solutionName != null) {
String clientnr = AngularIndexPageWriter.getClientNr(uri, request);
INGClientWebsocketSession wsSession = null;
HttpSession httpSession = request.getSession(false);
if (clientnr != null && httpSession != null) {
wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
}
FlattenedSolution fs = null;
boolean closeFS = false;
if (wsSession != null) {
fs = wsSession.getClient().getFlattenedSolution();
}
if (fs == null) {
try {
closeFS = true;
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
if (AngularIndexPageWriter.applicationServerUnavailable(response, as)) {
return;
}
SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
if (AngularIndexPageWriter.solutionMissing(response, solutionName, solutionMetaData)) {
return;
}
fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
} catch (Exception e) {
Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
}
}
if (fs != null) {
try {
if (handleMainJs(request, response, fs)) {
return;
}
if (handleForm(request, response, wsSession, fs)) {
return;
}
if (AngularIndexPageWriter.handleMaintenanceMode(request, response, wsSession)) {
return;
}
// prepare for possible index.html lookup
Map<String, Object> variableSubstitution = getSubstitutions(request, solutionName, clientnr, fs);
List<String> extraMeta = new ArrayList<String>();
addManifest(fs, extraMeta);
addHeadIndexContributions(fs, extraMeta);
ContentSecurityPolicyConfig contentSecurityPolicyConfig = addcontentSecurityPolicyHeader(request, response, true);
super.doFilter(servletRequest, servletResponse, filterChain, asList(SERVOY_CSS), new ArrayList<String>(getFormScriptReferences(fs)), extraMeta, variableSubstitution, contentSecurityPolicyConfig == null ? null : contentSecurityPolicyConfig.getNonce());
return;
} finally {
if (closeFS) {
fs.close(null);
}
}
}
}
}
if (!uri.contains(ModifiablePropertiesGenerator.PUSH_TO_SERVER_BINDINGS_LIST))
Debug.log("No solution found for this request, calling the default filter: " + uri);
}
super.doFilter(servletRequest, servletResponse, filterChain, null, null, null, null, null);
} catch (RuntimeException | Error e) {
Debug.error(e);
throw e;
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class NGClientWindow method getRealFormURLAndSeeIfItIsACopy.
protected Pair<String, Boolean> getRealFormURLAndSeeIfItIsACopy(Form form, String realFormName) {
FlattenedSolution fs = getSession().getClient().getFlattenedSolution();
Solution sc = fs.getSolutionCopy(false);
String realUrl = getDefaultFormURLStart(form, realFormName);
boolean copy = false;
if (sc != null && sc.getChild(form.getUUID()) != null) {
realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
copy = true;
} else if (!form.getName().endsWith(realFormName)) {
realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
} else {
realUrl = realUrl + "?clientnr=" + getSession().getSessionKey().getClientnr();
}
return new Pair<String, Boolean>(realUrl, Boolean.valueOf(copy));
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class AngularIndexPageWriter method getFlattenedSolution.
private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
INGClientWebsocketSession wsSession = null;
HttpSession httpSession = request.getSession(false);
if (clientnr != null && httpSession != null) {
wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
}
FlattenedSolution fs = null;
boolean closeFS = false;
if (wsSession != null) {
fs = wsSession.getClient().getFlattenedSolution();
}
if (fs == null) {
try {
closeFS = true;
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
if (applicationServerUnavailable(response, as)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
if (solutionMissing(response, solutionName, solutionMetaData)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
} catch (Exception e) {
Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
}
}
return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
Aggregations