use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.
the class J2DBClient method initSettings.
protected void initSettings() throws Exception {
// overload settings from disk
// $NON-NLS-1$
boolean uses_client_installer = (System.getProperty("servoy.server_url") != null);
settings = Settings.getInstance();
if (!uses_client_installer) {
// no disk loading needed for client, rely on webstart
((Settings) settings).loadFromServer(getServerURL());
} else {
// is special case for cytrix users, using a shared disk, to prevent webstarts installs
// $NON-NLS-1$
File file = new File(System.getProperty("user.dir"), Settings.FILE_NAME);
((Settings) settings).loadFromFile(file);
}
}
use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.
the class PluginManager method loadClientPlugins.
/**
* Only load client plugins; do not initialize them.
*/
public void loadClientPlugins(IApplication application) {
synchronized (initLock) {
loadedClientPlugins = new HashMap<String, IClientPlugin>();
if (// Servoy developer loading
application == null || !application.isRunningRemote()) {
Extension<IClientPlugin>[] exts = loadClientPluginDefs();
if (exts != null) {
for (Extension<IClientPlugin> element : exts) {
try {
loadClientPlugin(element.instanceClass);
} catch (Throwable th) {
// $NON-NLS-1$
Debug.error("Error occured loading client plugin class " + element.instanceClass.getName(), th);
}
}
}
} else // Servoy client loading
{
int count = 0;
Settings settings = Settings.getInstance();
// $NON-NLS-1$
String sCount = settings.getProperty("com.servoy.j2db.plugins.PluginManager.PluginCount");
if (sCount != null) {
count = new Integer(sCount).intValue();
}
// $NON-NLS-1$
Debug.trace("plugin count " + count);
for (int x = 0; x < count; x++) {
// $NON-NLS-1$ //$NON-NLS-2$
String clazzName = settings.getProperty("com.servoy.j2db.plugins.PluginManager.Plugin." + x + ".className");
if (clazzName != null && clazzName.length() != 0) {
try {
loadClientPlugin((Class<IClientPlugin>) Class.forName(clazzName.trim()));
} catch (Throwable th) {
// $NON-NLS-1$
Debug.error("Error occured loading client plugin class " + clazzName, th);
}
}
}
}
columnConverterManager = new ConverterManager<IColumnConverter>();
uiConverterManager = new ConverterManager<IUIConverter>();
columnValidatorManager = new ColumnValidatorManager();
checkAllPluginsForConvertersAndValidators();
}
}
use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.
the class WebClientsApplication method init.
/**
* @see wicket.protocol.http.WebApplication#init()
*/
@Override
protected void init() {
// TODO this is a workaround to allow mobile test client that only starts Tomcat not to give exceptions (please remove if mobile test client initialises a full app. server in the future)
if (ApplicationServerRegistry.get() == null)
return;
getResourceSettings().setResourceWatcher(new ServoyModificationWatcher(Duration.seconds(5)));
// getResourceSettings().setResourcePollFrequency(Duration.seconds(5));
getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true);
getResourceSettings().setDefaultCacheDuration((int) Duration.days(365).seconds());
getMarkupSettings().setCompressWhitespace(true);
getMarkupSettings().setMarkupCache(new ServoyMarkupCache(this));
// getMarkupSettings().setStripWicketTags(true);
getResourceSettings().setResourceStreamLocator(new ServoyResourceStreamLocator(this));
getResourceSettings().setPackageResourceGuard(new ServoyPackageResourceGuard());
// getResourceSettings().setResourceFinder(createResourceFinder());
getResourceSettings().setThrowExceptionOnMissingResource(false);
getApplicationSettings().setPageExpiredErrorPage(ServoyExpiredPage.class);
getApplicationSettings().setClassResolver(new ServoyClassResolver());
getSessionSettings().setMaxPageMaps(15);
// getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
getSecuritySettings().setCryptFactory(new CachingKeyInSessionSunJceCryptFactory());
Settings settings = Settings.getInstance();
// $NON-NLS-1$ //$NON-NLS-2$
getDebugSettings().setOutputComponentPath(Utils.getAsBoolean(settings.getProperty("servoy.webclient.debug.wicketpath", "false")));
if (// $NON-NLS-1$ //$NON-NLS-2$
Utils.getAsBoolean(settings.getProperty("servoy.webclient.nice.urls", "false"))) {
// $NON-NLS-1$
mount(new HybridUrlCodingStrategy("/solutions", SolutionLoader.class));
// $NON-NLS-1$
mount(new HybridUrlCodingStrategy("/application", MainPage.class));
mount(new // $NON-NLS-1$
HybridUrlCodingStrategy(// $NON-NLS-1$
"/ss", // $NON-NLS-1$
SolutionLoader.class) {
/**
* @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
*/
@Override
public boolean matches(IRequestTarget requestTarget) {
return false;
}
});
} else {
// $NON-NLS-1$
mountBookmarkablePage("/solutions", SolutionLoader.class);
mount(new // $NON-NLS-1$
BookmarkablePageRequestTargetUrlCodingStrategy(// $NON-NLS-1$
"/ss", // $NON-NLS-1$
SolutionLoader.class, // $NON-NLS-1$
null) {
/**
* @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
*/
@Override
public boolean matches(IRequestTarget requestTarget) {
return false;
}
});
}
// $NON-NLS-1$ //$NON-NLS-2$
long maxSize = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false);
if (maxSize > 0) {
getApplicationSettings().setDefaultMaximumUploadSize(Bytes.kilobytes(maxSize));
}
// $NON-NLS-1$
getSharedResources().putClassAlias(IApplication.class, "application");
// $NON-NLS-1$
getSharedResources().putClassAlias(PageContributor.class, "pc");
// $NON-NLS-1$
getSharedResources().putClassAlias(MaskBehavior.class, "mask");
// $NON-NLS-1$
getSharedResources().putClassAlias(Application.class, "servoy");
// $NON-NLS-1$
getSharedResources().putClassAlias(org.wicketstuff.calendar.markup.html.form.DatePicker.class, "datepicker");
// $NON-NLS-1$
getSharedResources().putClassAlias(YUILoader.class, "yui");
// $NON-NLS-1$
getSharedResources().putClassAlias(JQueryLoader.class, "jquery");
// $NON-NLS-1$
getSharedResources().putClassAlias(TinyMCELoader.class, "tinymce");
// $NON-NLS-1$
getSharedResources().putClassAlias(org.apache.wicket.markup.html.WicketEventReference.class, "wicketevent");
// $NON-NLS-1$
getSharedResources().putClassAlias(org.apache.wicket.ajax.WicketAjaxReference.class, "wicketajax");
// $NON-NLS-1$
getSharedResources().putClassAlias(MainPage.class, "servoyjs");
// $NON-NLS-1$
getSharedResources().putClassAlias(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class, "modalwindow");
// $NON-NLS-1$
PackageResource.bind(this, IApplication.class, "images/open_project.gif");
// $NON-NLS-1$
PackageResource.bind(this, IApplication.class, "images/save.gif");
// $NON-NLS-1$//$NON-NLS-2$
mountSharedResource("/formcss", "servoy/formcss");
sharedMediaResource = new SharedMediaResource();
// $NON-NLS-1$
getSharedResources().add("media", sharedMediaResource);
mount(new // $NON-NLS-1$ //$NON-NLS-2$
SharedResourceRequestTargetUrlCodingStrategy(// $NON-NLS-1$ //$NON-NLS-2$
"mediafolder", // $NON-NLS-1$ //$NON-NLS-2$
"servoy/media") {
@Override
protected void appendParameters(AppendingStringBuffer url, Map<String, ?> parameters) {
if (parameters != null && parameters.size() > 0) {
// $NON-NLS-1$
Object solutionName = parameters.get("s");
if (solutionName != null)
appendPathParameter(url, null, solutionName.toString());
// $NON-NLS-1$
Object resourceId = parameters.get("id");
if (resourceId != null)
appendPathParameter(url, null, resourceId.toString());
StringBuilder queryParams = new StringBuilder();
for (Entry<?, ?> entry1 : parameters.entrySet()) {
Object value = ((Entry<?, ?>) entry1).getValue();
if (value != null) {
Object key = ((Entry<?, ?>) entry1).getKey();
if (// $NON-NLS-1$ //$NON-NLS-2$
!"s".equals(key) && !"id".equals(key)) {
if (value instanceof String[]) {
String[] values = (String[]) value;
for (String value1 : values) {
// $NON-NLS-1$
if (queryParams.length() > 0)
queryParams.append("&");
// $NON-NLS-1$
queryParams.append(key).append("=").append(value1);
}
} else {
// $NON-NLS-1$
if (queryParams.length() > 0)
queryParams.append("&");
// $NON-NLS-1$
queryParams.append(key).append("=").append(value);
}
}
}
}
if (queryParams.length() > 0) {
// $NON-NLS-1$
url.append("?").append(queryParams);
}
}
}
@Override
protected void appendPathParameter(AppendingStringBuffer url, String key, String value) {
String escapedValue = value;
// $NON-NLS-1$
String[] values = escapedValue.split("/");
if (values.length > 1) {
StringBuilder sb = new StringBuilder(escapedValue.length());
for (String str : values) {
sb.append(urlEncodePathComponent(str));
sb.append('/');
}
sb.setLength(sb.length() - 1);
escapedValue = sb.toString();
} else {
escapedValue = urlEncodePathComponent(escapedValue);
}
if (!Strings.isEmpty(escapedValue)) {
if (// $NON-NLS-1$
!url.endsWith("/")) {
// $NON-NLS-1$
url.append("/");
}
// $NON-NLS-1$
if (key != null)
url.append(urlEncodePathComponent(key)).append("/");
url.append(escapedValue);
}
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String, java.util.Map)
*/
@Override
protected ValueMap decodeParameters(String urlFragment, Map<String, ?> urlParameters) {
ValueMap map = new ValueMap();
// $NON-NLS-1$
final String[] pairs = urlFragment.split("/");
if (pairs.length > 1) {
// $NON-NLS-1$
map.add("s", pairs[1]);
StringBuffer sb = new StringBuffer();
for (int i = 2; i < pairs.length; i++) {
sb.append(pairs[i]);
// $NON-NLS-1$
sb.append("/");
}
sb.setLength(sb.length() - 1);
// $NON-NLS-1$
map.add("id", sb.toString());
}
if (urlParameters != null) {
map.putAll(urlParameters);
}
return map;
}
});
// $NON-NLS-1$
getSharedResources().add("resources", new ServeResources());
// $NON-NLS-1$
getSharedResources().add("formcss", new FormCssResource(this));
if (// $NON-NLS-1$
settings.getProperty("servoy.webclient.error.page", null) != null) {
getApplicationSettings().setInternalErrorPage(ServoyErrorPage.class);
}
if (// $NON-NLS-1$
settings.getProperty("servoy.webclient.pageexpired.page", null) != null) {
getApplicationSettings().setPageExpiredErrorPage(ServoyPageExpiredPage.class);
}
addPreComponentOnBeforeRenderListener(new IComponentOnBeforeRenderListener() {
public void onBeforeRender(Component component) {
if (component instanceof IServoyAwareBean) {
IModel model = component.getInnermostModel();
WebForm webForm = component.findParent(WebForm.class);
if (model instanceof RecordItemModel && webForm != null) {
IRecord record = (IRecord) ((RecordItemModel) model).getObject();
FormScope fs = webForm.getController().getFormScope();
if (record != null && fs != null) {
((IServoyAwareBean) component).setSelectedRecord(new ServoyBeanState(record, fs));
}
}
} else if (!(component.getParent() instanceof WebDataCompositeTextField)) {
if (!component.isEnabled()) {
boolean hasOnRender = (component instanceof IFieldComponent && ((IFieldComponent) component).getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()).getRenderEventExecutor().hasRenderCallback());
if (!hasOnRender) {
// onrender may change the enable state
return;
}
}
Component targetComponent = null;
boolean hasFocus = false, hasBlur = false;
if (component instanceof IFieldComponent && ((IFieldComponent) component).getEventExecutor() != null) {
if (component instanceof WebDataCompositeTextField && ((WebDataCompositeTextField) component).getDelegate() instanceof Component) {
targetComponent = (Component) ((WebDataCompositeTextField) component).getDelegate();
} else {
targetComponent = component;
}
if (component instanceof WebBaseSelectBox) {
Component[] cs = ((WebBaseSelectBox) component).getFocusChildren();
if (cs != null && cs.length == 1)
targetComponent = cs[0];
}
if (component instanceof WebDataHtmlArea)
hasFocus = true;
// always install a focus handler when in a table view to detect change of selectedIndex and test for record validation
if (((IFieldComponent) component).getEventExecutor().hasEnterCmds() || component.findParent(WebCellBasedView.class) != null || (((IFieldComponent) component).getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()).getRenderEventExecutor().hasRenderCallback())) {
hasFocus = true;
}
// Always trigger event on focus lost:
// 1) check for new selected index, record validation may have failed preventing a index changed
// 2) prevent focus gained to be called when field validation failed
// 3) general ondata change
hasBlur = true;
} else if (component instanceof WebBaseLabel) {
targetComponent = component;
hasFocus = true;
}
if (targetComponent != null) {
MainPage mainPage = targetComponent.findParent(MainPage.class);
if (mainPage.isUsingAjax()) {
AbstractAjaxBehavior eventCallback = mainPage.getPageContributor().getEventCallback();
if (eventCallback != null) {
String callback = eventCallback.getCallbackUrl().toString();
if (component instanceof WebDataRadioChoice || component instanceof WebDataCheckBoxChoice || component instanceof WebDataLookupField || component instanceof WebDataComboBox || component instanceof WebDataListBox || component instanceof WebDataHtmlArea || component instanceof WebDataCompositeTextField) {
// is updated via ServoyChoiceComponentUpdatingBehavior or ServoyFormComponentUpdatingBehavior, this is just for events
callback += "&nopostdata=true";
}
for (IBehavior behavior : targetComponent.getBehaviors()) {
if (behavior instanceof EventCallbackModifier) {
targetComponent.remove(behavior);
}
}
if (hasFocus) {
StringBuilder js = new StringBuilder();
// $NON-NLS-1$ //$NON-NLS-2$
js.append("eventCallback(this,'focus','").append(callback).append("',event)");
// $NON-NLS-1$
targetComponent.add(new EventCallbackModifier("onfocus", true, new Model<String>(js.toString())));
// $NON-NLS-1$ //$NON-NLS-2$
targetComponent.add(new EventCallbackModifier("onmousedown", true, new Model<String>("focusMousedownCallback(event)")));
}
if (hasBlur) {
boolean blockRequest = false;
// if component has ondatachange, check for blockrequest
if (component instanceof ISupportEventExecutor && ((ISupportEventExecutor) component).getEventExecutor().hasChangeCmd()) {
WebClientSession webClientSession = WebClientSession.get();
blockRequest = webClientSession != null && webClientSession.blockRequest();
}
StringBuilder js = new StringBuilder();
// $NON-NLS-1$ //$NON-NLS-2$
js.append("postEventCallback(this,'blur','").append(callback).append("',event," + blockRequest + ")");
// $NON-NLS-1$
targetComponent.add(new EventCallbackModifier("onblur", true, new Model<String>(js.toString())));
}
}
}
}
}
}
});
}
use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.
the class MediaResourcesServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String path = req.getPathInfo();
if (path.startsWith("/"))
path = path.substring(1);
String[] paths = path.split("/");
String reqEncoding = req.getCharacterEncoding() == null ? "UTF-8" : req.getCharacterEncoding();
if ((paths.length == 2 || paths.length >= 5) && paths[0].equals("upload")) {
if (req.getHeader("Content-Type") != null && req.getHeader("Content-Type").startsWith("multipart/form-data")) {
int clientnr = paths[1].length() == 0 ? -1 : Integer.parseInt(paths[1]);
final INGClientWebsocketSession wsSession = getSession(req, clientnr);
try {
if (wsSession != null) {
Settings settings = Settings.getInstance();
File fileUploadDir = null;
String uploadDir = settings.getProperty("servoy.ng_web_client.temp.uploadir");
if (uploadDir != null) {
fileUploadDir = new File(uploadDir);
if (!fileUploadDir.exists() && !fileUploadDir.mkdirs()) {
fileUploadDir = null;
Debug.error("Couldn't use the property 'servoy.ng_web_client.temp.uploadir' value: '" + uploadDir + "', directory could not be created or doesn't exists");
}
}
int tempFileThreshold = Utils.getAsInteger(settings.getProperty("servoy.ng_web_client.tempfile.threshold", "50"), false) * 1000;
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(tempFileThreshold, fileUploadDir);
diskFileItemFactory.setFileCleaningTracker(FILE_CLEANING_TRACKER);
ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory);
upload.setHeaderEncoding(reqEncoding);
long maxUpload = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false);
if (maxUpload > 0)
upload.setFileSizeMax(maxUpload * 1000);
Iterator<FileItem> iterator = upload.parseRequest(req).iterator();
final List<FileUploadData> aFileUploadData = new ArrayList<FileUploadData>();
List<FileItem> formFields = new ArrayList<>();
while (iterator.hasNext()) {
FileItem item = iterator.next();
if (item.isFormField()) {
formFields.add(item);
} else {
String encoding = StringUtils.defaultString(req.getCharacterEncoding(), "UTF-8");
JSMap<String, String> fieldsMap = new JSMap<>();
for (FileItem fileItem : formFields) {
try {
fieldsMap.put(fileItem.getFieldName(), fileItem.getString(encoding));
} catch (UnsupportedEncodingException e) {
Debug.error(e);
}
}
if (callClient(req, paths, wsSession, fieldsMap, item)) {
formFields = new ArrayList<>();
} else {
// it is a file from the built-in file selector
aFileUploadData.add(new FileUploadData(item));
}
}
}
if (aFileUploadData.size() > 0) {
final IMediaUploadCallback mediaUploadCallback = ((NGClient) wsSession.getClient()).getMediaUploadCallback();
if (mediaUploadCallback != null) {
// leave time for this request to finish, before executing the callback, so the file
// dialog can do its close
((NGClient) wsSession.getClient()).invokeLater(new Runnable() {
@Override
public void run() {
mediaUploadCallback.uploadComplete(aFileUploadData.toArray(new FileUploadData[aFileUploadData.size()]));
mediaUploadCallback.onSubmit();
}
});
}
}
}
} catch (FileSizeLimitExceededException ex) {
res.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
if (wsSession != null)
res.getWriter().print(wsSession.getClient().getI18NMessage("servoy.filechooser.sizeExceeded", new Object[] { ex.getPermittedSize() / 1000 + "KB" }));
} catch (FileUploadException ex) {
ex.printStackTrace();
throw new ServletException(ex.toString());
}
}
}
}
Aggregations