use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class NGClientWebsocketSession method onOpen.
@SuppressWarnings("nls")
@Override
public void onOpen(final Map<String, List<String>> requestParams) {
super.onOpen(requestParams);
if (requestParams == null) {
CurrentWindow.get().cancelSession("Solution name is required");
return;
}
if (requestParams.containsKey("clienttype")) {
clientType = Utils.getAsInteger(requestParams.get("clienttype").get(0), 1);
if (clientType == 2)
client.getRuntimeProperties().put("NG2", Boolean.TRUE);
else
client.getRuntimeProperties().remove("NG2");
} else {
clientType = 1;
client.getRuntimeProperties().remove("NG2");
}
lastSentStyleSheets = null;
final StartupArguments args = new StartupArguments(requestParams);
final String solutionName = args.getSolutionName();
if (Utils.stringIsEmpty(solutionName)) {
CurrentWindow.get().cancelSession("Invalid solution name");
return;
}
if (!client.isEventDispatchThread())
J2DBGlobals.setServiceProvider(client);
try {
FlattenedSolution solution = client.getFlattenedSolution();
if (solution != null) {
// test for the main solution meta data else a login solution will constantly be closed even if it is for the right main solution.
if (solution.getSolution() != null && !solutionName.equals(solution.getMainSolutionMetaData().getName())) {
client.closeSolution(true, null);
} else {
if (solution.isMainSolutionLoaded() || solution.getSolution() != null && solution.getSolution().getSolutionType() == SolutionMetaData.LOGIN_SOLUTION) {
// this is needed for the situation when the solution is already loaded and the deeplink url was changed (different arg values for instance)
String method = args.getMethodName();
String firstArgument = args.getFirstArgument();
if (method != null) {
try {
client.getScriptEngine().getScopesScope().executeGlobalFunction(null, method, (args.toJSMap().isEmpty() ? null : new Object[] { firstArgument, args.toJSMap() }), false, false);
} catch (Exception e1) {
// $NON-NLS-1$
client.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { method }), e1);
}
}
}
client.getRuntimeWindowManager().setCurrentWindowName(String.valueOf(CurrentWindow.get().getNr()));
IWebFormController currentForm = client.getFormManager().getCurrentForm();
if (currentForm != null) {
// we have to call setcontroller again so that switchForm is called and the form is loaded into the reloaded/new window.
startHandlingEvent();
try {
client.getClientFunctions().clear();
sendUIProperties();
client.getRuntimeWindowManager().getCurrentWindow().setController(currentForm);
sendSolutionCSSURL(solution.getSolution());
} finally {
stopHandlingEvent();
}
return;
}
}
}
getEventDispatcher().addEvent(new Runnable() {
@Override
public void run() {
try {
sendUIProperties();
// the solution was not loaded or another was loaded, now create a main window and load the solution.
client.getRuntimeWindowManager().createMainWindow(CurrentWindow.get().getNr());
client.handleArguments(args.getFirstArgument() != null ? new String[] { args.getSolutionName(), args.getMethodName(), args.getFirstArgument() } : new String[] { args.getSolutionName(), args.getMethodName() }, args);
client.loadSolution(solutionName);
client.showInfoPanel();
} catch (RepositoryException e) {
Debug.error("Failed to load the solution: " + solutionName, e);
sendInternalError(e);
}
}
});
} catch (Exception e) {
Debug.error(e);
sendInternalError(e);
} finally {
if (!client.isEventDispatchThread())
J2DBGlobals.setServiceProvider(null);
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class MediaPropertyType method wrap.
@Override
public MediaWrapper wrap(Object value, MediaWrapper previousValue, PropertyDescription propertyDescription, IWrappingContext dataConverterContext) {
if (previousValue != null && Utils.equalObjects(value, previousValue.mediaUrl)) {
return previousValue;
}
IServoyDataConverterContext servoyDataConverterContext = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext();
FlattenedSolution flattenedSolution = servoyDataConverterContext.getSolution();
INGApplication application = servoyDataConverterContext.getApplication();
String url = getMediaUrl(value, flattenedSolution, application);
if (url != null)
return new MediaWrapper(value, url);
if (value != null && !Utils.equalObjects(value, Integer.valueOf(0)))
Debug.log("cannot convert media " + value + " using converter context " + servoyDataConverterContext);
return null;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class MediaPropertyType method getMediaUrl.
public static String getMediaUrl(Object value, FlattenedSolution flattenedSolution, INGApplication application) {
String url = null;
Media media = null;
if (value instanceof CharSequence) {
value = ((CharSequence) value).toString();
}
if (value instanceof Integer) {
if (((Integer) value).intValue() == 0) {
// 0 means no media
return null;
}
media = flattenedSolution.getMedia(((Integer) value).intValue());
} else if (value instanceof String && ((String) value).toLowerCase().startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
media = flattenedSolution.getMedia(((String) value).substring(MediaURLStreamHandler.MEDIA_URL_DEF.length()));
} else {
if (value != null) {
media = flattenedSolution.getMedia(value.toString());
if (media == null) {
media = (Media) flattenedSolution.searchPersist(value.toString());
}
}
}
if (media != null) {
url = "resources/" + MediaResourcesServlet.FLATTENED_SOLUTION_ACCESS + "/" + media.getRootObject().getName() + "/" + media.getName();
Dimension imageSize = ImageLoader.getSize(media.getMediaData());
boolean paramsAdded = false;
if (imageSize != null) {
paramsAdded = true;
url += "?imageWidth=" + imageSize.width + "&imageHeight=" + imageSize.height;
}
if (application != null) {
Solution sc = flattenedSolution.getSolutionCopy(false);
if (sc != null && sc.getMedia(media.getName()) != null) {
if (paramsAdded)
url += "&";
else
url += "?";
url += "clientnr=" + application.getWebsocketSession().getSessionKey().getClientnr() + "&lm:" + sc.getLastModifiedTime();
}
}
} else if (value instanceof String && ((String) value).startsWith("resources/" + MediaResourcesServlet.FLATTENED_SOLUTION_ACCESS)) {
url = (String) value;
} else if (value != null) {
Debug.warn("Invalid media value received: " + value + ", cannot resolve it.");
}
return url;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class ServoyFunctionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
Map<String, Object> map = new HashMap<>();
if (object != null && fs != null) {
// $NON-NLS-1$
String[] components = object.toString().split("-");
if (components.length == 5) {
String scriptString = null;
// this is a uuid
ScriptMethod sm = fs.getScriptMethod(object.toString());
if (sm != null) {
ISupportChilds parent = sm.getParent();
if (parent instanceof Solution) {
scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
} else if (parent instanceof Form) {
if (formComponent != null) {
// use the real, runtime form
scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
} else {
scriptString = ((Form) parent).getName() + "." + sm.getName();
}
} else if (parent instanceof TableNode && fe != null) {
scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
}
object = scriptString;
} else
Debug.log("can't find a scriptmethod for: " + object);
}
}
try {
if (object instanceof String) {
addScriptToMap((String) object, map);
} else if (object instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) object, map);
} else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
} else if (object instanceof Map) {
map = new HashMap<String, Object>((Map<String, Object>) object);
if (map.get("script") instanceof String)
addScriptToMap((String) map.get("script"), map);
}
} catch (Exception ex) {
Debug.error(ex);
}
return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class FormComponentPropertyType method toTemplateJSONValue.
@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion clientConversion, FormElementContext formElementContext) throws JSONException {
if (formElementValue == null)
return writer;
FlattenedSolution fs = formElementContext.getFlattenedSolution();
Form form = getForm(formElementValue, fs);
if (form != null) {
if (pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) pd.getConfig()).forFoundset != null) {
clientConversion.convert(FormComponentPropertyType.TYPE_NAME);
}
// else this info below seems to be needed client-side even for non-foundset linked form components; but it's just some dumb simple JSON, not a client side type
JSONUtils.addKeyIfPresent(writer, key);
// we output here a uuid that is a uuid that must be used to get the compiled template from the $formcomponentCache
String uuid = FormElementHelper.INSTANCE.getFormComponentCache(formElementContext.getFormElement(), pd, (JSONObject) formElementValue, form, fs).getHtmlTemplateUUIDForAngular();
writer.object();
writer.key("uuid");
writer.value(uuid);
writer.key("formHeight");
writer.value(form.getSize().height);
writer.key("formWidth");
writer.value(form.getSize().width);
writer.key("absoluteLayout");
writer.value(!form.isResponsiveLayout());
writer.endObject();
}
return writer;
}
Aggregations