Search in sources :

Example 1 with Settings

use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.

the class WebClientsApplication method newRequestCycleProcessor.

@Override
protected IRequestCycleProcessor newRequestCycleProcessor() {
    return new UrlCompressingWebRequestProcessor() {

        @Override
        public void respond(RequestCycle requestCycle) {
            // execute events from WebClient.invokeLater() before the respond (render) is started
            Session session = Session.get();
            if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                ((WebClientSession) session).getWebClient().executeEvents();
            }
            super.respond(requestCycle);
        }

        /**
         * @see wicket.protocol.http.WebRequestCycleProcessor#newRequestCodingStrategy()
         */
        @Override
        protected IRequestCodingStrategy newRequestCodingStrategy() {
            Settings settings = Settings.getInstance();
            if (// $NON-NLS-1$ //$NON-NLS-2$
            Utils.getAsBoolean(settings.getProperty("servoy.webclient.crypt-urls", "true"))) {
                return new ServoyCryptedUrlWebRequestCodingStrategy(new UrlCompressingWebCodingStrategy());
            } else {
                return new UrlCompressingWebCodingStrategy();
            }
        }

        @Override
        protected IRequestTarget resolveListenerInterfaceTarget(RequestCycle requestCycle, Page page, String componentPath, String interfaceName, RequestParameters requestParameters) {
            try {
                IRequestTarget requestTarget = super.resolveListenerInterfaceTarget(requestCycle, page, componentPath, interfaceName, requestParameters);
                if (requestTarget instanceof BehaviorRequestTarget) {
                    Component target = ((BehaviorRequestTarget) requestTarget).getTarget();
                    if (!(target instanceof Page)) {
                        boolean invalidPage = false;
                        Page page2 = null;
                        try {
                            // test if it has a page.
                            page2 = target.findParent(Page.class);
                        } catch (Exception e) {
                            Debug.trace(e);
                            invalidPage = true;
                        }
                        if (page2 == null || !page2.getId().equals(page.getId())) {
                            invalidPage = true;
                        }
                        if (invalidPage) {
                            // $NON-NLS-1$
                            Debug.log("Couldn't resolve the page of the component, component already gone from page? returning empty");
                            return EmptyRequestTarget.getInstance();
                        }
                    }
                }
                return requestTarget;
            } catch (Exception e) {
                // $NON-NLS-1$
                Debug.log("couldnt resolve interface, component page already gone from page? returning empty");
            }
            return EmptyRequestTarget.getInstance();
        }

        @Override
        public IRequestTarget resolve(final RequestCycle requestCycle, final RequestParameters requestParameters) {
            try {
                return super.resolve(requestCycle, requestParameters);
            } catch (PageExpiredException e) {
                // if there is a page expired exception
                // then ignore it if there is a current form.
                // $NON-NLS-1$
                Debug.trace("Page expired, checking for a current form");
                Request request = requestCycle.getRequest();
                if (request instanceof WebRequest && ((WebRequest) request).isAjax() && requestParameters.isOnlyProcessIfPathActive()) {
                    // $NON-NLS-1$
                    Debug.trace("Page expired, it is an ajan/process only if active request");
                    Session session = Session.get();
                    if (session instanceof WebClientSession && ((WebClientSession) session).getWebClient() != null) {
                        WebClient webClient = ((WebClientSession) session).getWebClient();
                        if (webClient.getFormManager().getCurrentForm() != null) {
                            // $NON-NLS-1$
                            Debug.trace("Page expired, there is a current form, ignore this ajax request");
                            return EmptyAjaxRequestTarget.getInstance();
                        }
                    }
                }
                throw e;
            }
        }
    };
}
Also used : RequestCycle(org.apache.wicket.RequestCycle) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) WebRequest(org.apache.wicket.protocol.http.WebRequest) Request(org.apache.wicket.Request) Page(org.apache.wicket.Page) RestartResponseException(org.apache.wicket.RestartResponseException) AbstractRestartResponseException(org.apache.wicket.AbstractRestartResponseException) IOException(java.io.IOException) PageExpiredException(org.apache.wicket.protocol.http.PageExpiredException) RequestParameters(org.apache.wicket.request.RequestParameters) UrlCompressingWebCodingStrategy(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebCodingStrategy) BehaviorRequestTarget(org.apache.wicket.request.target.component.listener.BehaviorRequestTarget) WebRequest(org.apache.wicket.protocol.http.WebRequest) IRequestTarget(org.apache.wicket.IRequestTarget) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) Settings(com.servoy.j2db.util.Settings) IWiQuerySettings(org.odlabs.wiquery.core.commons.IWiQuerySettings) IRequestCycleSettings(org.apache.wicket.settings.IRequestCycleSettings) WiQuerySettings(org.odlabs.wiquery.core.commons.WiQuerySettings) UrlCompressingWebRequestProcessor(org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor) Session(org.apache.wicket.Session)

Example 2 with Settings

use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.

the class AngularIndexPageWriter method getContentSecurityPolicyConfig.

/**
 * Get the ContentSecurityPolicyConfig is it should be applied, otherwise return null;
 *
 * Only when configured and when the browser is a modern browser that supports Content-Security-Policy level 3.
 */
private static ContentSecurityPolicyConfig getContentSecurityPolicyConfig(HttpServletRequest request) {
    Settings settings = Settings.getInstance();
    if (!getAsBoolean(settings.getProperty("servoy.ngclient.setContentSecurityPolicyHeader", "true"))) {
        Debug.trace("ContentSecurityPolicyHeader is disabled by configuration");
        return null;
    }
    String userAgentHeader = request.getHeader("user-agent");
    if (!HCUtils.supportsContentSecurityPolicyLevel3(userAgentHeader)) {
        if (Debug.tracing()) {
            Debug.trace("ContentSecurityPolicyHeader is disabled, user agent '" + userAgentHeader + "' does not support ContentSecurityPolicy level 3");
        }
        return null;
    }
    ContentSecurityPolicyConfig contentSecurityPolicyConfig = new ContentSecurityPolicyConfig(HTTPUtils.getNonce(request));
    // Overridable directives
    setDirectiveOverride(contentSecurityPolicyConfig, "frame-src", settings);
    setDirectiveOverride(contentSecurityPolicyConfig, "frame-ancestors", settings);
    setDirectiveOverride(contentSecurityPolicyConfig, "style-src", settings);
    setDirectiveOverride(contentSecurityPolicyConfig, "img-src", settings);
    setDirectiveOverride(contentSecurityPolicyConfig, "font-src", settings);
    return contentSecurityPolicyConfig;
}
Also used : Settings(com.servoy.j2db.util.Settings) ContentSecurityPolicyConfig(org.sablo.security.ContentSecurityPolicyConfig)

Example 3 with Settings

use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.

the class ComponentFactory method getWebID.

public static String getWebID(Form form, IPersist meta) {
    StringBuilder prefix = new StringBuilder();
    // to stay javascript id ref compatible
    prefix.append(WEB_ID_PREFIX);
    if (element_name_as_uid_prefix == null) {
        Settings s = Settings.getInstance();
        element_name_as_uid_prefix = Boolean.valueOf(Utils.getAsBoolean(s.getProperty("servoy.webclient.templates.element_name_as_uid_prefix")));
    }
    if (element_name_as_uid_prefix == Boolean.TRUE && meta instanceof ISupportName) {
        String name = ((ISupportName) meta).getName();
        if (name != null && name.trim().length() != 0) {
            prefix.append('_');
            prefix.append(name);
        }
    }
    prefix.append('_');
    String uid = meta.getUUID().toString();
    uid = Utils.stringReplace(uid, "-", "_");
    prefix.append(uid);
    return prefix.toString();
}
Also used : ISupportName(com.servoy.j2db.persistence.ISupportName) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings) Settings(com.servoy.j2db.util.Settings)

Example 4 with Settings

use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.

the class LFPreferencePanel method handleOK.

@Override
public boolean handleOK() {
    boolean update = false;
    // If the L&F or the font size change, we need to remove all dialog bounds,
    // because there is a chance that the dialogs will have different sizes under the
    // new L&F or with the new font. If only the theme changes, there should be no
    // such situation.
    boolean removeAllBounds = false;
    LookAndFeelInfo selected = ((LookAndFeelInfoWrapper) lnfBox.getSelectedItem()).getLookAndFeelInfo();
    String themeName = (String) themesBox.getSelectedItem();
    String themeClassName = (String) themes.get(themeName);
    // $NON-NLS-1$//$NON-NLS-2$
    String currentTheme = _application.getSettings().getProperty("lnf.theme", "");
    if (_choosenFont != null && !_choosenFont.equals(_selectedFont)) {
        update = true;
        removeAllBounds = true;
        _selectedFont = _choosenFont;
        _choosenFont = null;
    }
    if (_current != selected) {
        update = true;
        removeAllBounds = true;
        _current = selected;
    }
    String clientPrefix = "";
    if (RemoteRunnerChecker.getInstance().isRunningWebStart()) {
        URL webstartbase = _application.getServerURL();
        // $NON-NLS-1$
        clientPrefix = webstartbase.getHost() + webstartbase.getPort() + "_";
    }
    if (themeClassName != null) {
        if (!themeClassName.equals(currentTheme)) {
            update = true;
            // $NON-NLS-1$
            _application.getSettings().setProperty(clientPrefix + "lnf.theme", themeClassName);
        }
    } else {
        // clear $NON-NLS-1$//$NON-NLS-2$
        _application.getSettings().setProperty(clientPrefix + "lnf.theme", "");
    }
    if (update) {
        String s_laf = UIManager.getSystemLookAndFeelClassName();
        if (selected != null)
            s_laf = selected.getClassName();
        if (_application.putClientProperty(LookAndFeelInfo.class.getName(), s_laf) && _application.putClientProperty(Font.class.getName(), _selectedFont)) {
            String c_laf = (_current == null ? "" : _current.getClassName());
            // $NON-NLS-1$
            _application.getSettings().setProperty(clientPrefix + "selectedlnf", c_laf);
            if (_selectedFont != null) {
                // $NON-NLS-1$
                _application.getSettings().setProperty(clientPrefix + "font", PersistHelper.createFontString(_selectedFont));
            }
        } else {
            // $NON-NLS-1$
            _application.getSettings().setProperty(clientPrefix + "lnf.theme", currentTheme);
        }
        if (removeAllBounds) {
            ((Settings) _application.getSettings()).deleteAllBounds();
        }
    }
    return true;
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) URL(java.net.URL) Settings(com.servoy.j2db.util.Settings)

Example 5 with Settings

use of com.servoy.j2db.util.Settings in project servoy-client by Servoy.

the class TusServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    Settings settings = Settings.getInstance();
    String uploadDir = settings.getProperty("servoy.ng_web_client.temp.uploadir");
    long maxUpload = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false);
    File fileUploadDir = null;
    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");
        }
    }
    tusFileUploadService = new TusFileUploadService().withUploadURI(config.getServletContext().getContextPath() + "/tus/upload/[0-9]+/.+/.+/.+/");
    if (fileUploadDir != null) {
        try {
            tusFileUploadService = tusFileUploadService.withStoragePath(fileUploadDir.getCanonicalPath());
        } catch (IOException e) {
            throw new ServletException(e);
        }
    }
    if (maxUpload > 0) {
        tusFileUploadService = tusFileUploadService.withMaxUploadSize(Long.valueOf(maxUpload));
    }
}
Also used : TusFileUploadService(me.desair.tus.server.TusFileUploadService) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) IFile(com.servoy.j2db.plugins.IFile) File(java.io.File) Settings(com.servoy.j2db.util.Settings)

Aggregations

Settings (com.servoy.j2db.util.Settings)9 File (java.io.File)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 Component (org.apache.wicket.Component)2 IRequestTarget (org.apache.wicket.IRequestTarget)2 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)1 IColumnConverter (com.servoy.j2db.dataprocessing.IColumnConverter)1 IColumnValidatorManager (com.servoy.j2db.dataprocessing.IColumnValidatorManager)1 IRecord (com.servoy.j2db.dataprocessing.IRecord)1 IUIConverter (com.servoy.j2db.dataprocessing.IUIConverter)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 ISupportName (com.servoy.j2db.persistence.ISupportName)1 IFile (com.servoy.j2db.plugins.IFile)1 IMediaUploadCallback (com.servoy.j2db.plugins.IMediaUploadCallback)1 FormScope (com.servoy.j2db.scripting.FormScope)1 JSMap (com.servoy.j2db.scripting.JSMap)1 RecordItemModel (com.servoy.j2db.server.headlessclient.dataui.RecordItemModel)1 WebBaseLabel (com.servoy.j2db.server.headlessclient.dataui.WebBaseLabel)1