Search in sources :

Example 21 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class MediaResourcesServlet method findAndSendMediaData.

protected boolean findAndSendMediaData(HttpServletRequest request, HttpServletResponse response, String mediaName, FlattenedSolution fs) throws IOException {
    Media media = fs.getMedia(mediaName);
    if (media == null && mediaName.endsWith(".css")) {
        media = fs.getMedia(mediaName.replace(".css", ".less"));
        Solution sc = fs.getSolutionCopy(false);
        if (media != null && media.getParent() != sc) {
            // is a less file, try to load the compiled version
            URL url = getServletConfig().getServletContext().getResource('/' + SERVOY_SOLUTION_CSS + '/' + mediaName);
            if (url != null) {
                setHeaders(request, response);
                // cache resources on client until changed
                if (HTTPUtils.checkAndSetUnmodified(request, response, media.getLastModifiedTime() != -1 ? media.getLastModifiedTime() : fs.getLastModifiedTime()))
                    return true;
                response.setContentType("text/css");
                URLConnection con = url.openConnection();
                long lenght = con.getContentLengthLong();
                if (lenght > 0)
                    response.setContentLengthLong(lenght);
                try (InputStream is = con.getInputStream()) {
                    IOUtils.copy(is, response.getOutputStream());
                }
                return true;
            }
        }
    }
    if (media != null) {
        return sendMediaData(request, response, fs, media);
    }
    return false;
}
Also used : InputStream(java.io.InputStream) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 22 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class FoundSetManager method getTriggerFunctions.

private List<TriggerFunction> getTriggerFunctions(ITable table, TypedProperty<Integer> property, Scriptable foundsetScope) {
    FlattenedSolution solutionRoot = getApplication().getFlattenedSolution();
    IExecutingEnviroment scriptEngine = getApplication().getScriptEngine();
    return stream(solutionRoot.getTableNodes(table)).map(tableNode -> {
        Object function = null;
        Scriptable scope = null;
        ScriptMethod scriptMethod = solutionRoot.getScriptMethod(((Integer) tableNode.getProperty(property.getPropertyName())).intValue());
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof Solution) {
                // global method
                GlobalScope gs = scriptEngine.getScopesScope().getGlobalScope(scriptMethod.getScopeName());
                if (gs != null) {
                    scope = gs;
                    function = gs.get(scriptMethod.getName());
                }
            } else if (foundsetScope != null) {
                // foundset method
                scope = foundsetScope;
                function = scope.getPrototype().get(scriptMethod.getName(), scope);
            }
        }
        if (function instanceof Function) {
            return new TriggerFunction((Function) function, scope, tableNode);
        }
        return null;
    }).filter(Objects::nonNull).collect(toList());
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) Function(org.mozilla.javascript.Function) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Scriptable(org.mozilla.javascript.Scriptable) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 23 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, int methodid, IJSParent<?> parent, String propertyName) {
    if (methodid > 0) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = null;
        if (parent instanceof JSForm) {
            // form method
            scriptMethod = ((JSForm) parent).getSupportChild().getScriptMethod(methodid);
            if (scriptMethod == null) {
                Form f = ((JSForm) parent).getSupportChild();
                while (f != null && f.getExtendsID() > 0 && scriptMethod == null) {
                    f = application.getFlattenedSolution().getForm(f.getExtendsID());
                    if (f != null)
                        scriptMethod = f.getScriptMethod(methodid);
                }
                if (scriptMethod != null) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm(f, false);
                }
            }
        }
        if (scriptMethod == null) {
            // foundset method
            if (parent instanceof JSDataSourceNode) {
                scriptMethod = ((JSDataSourceNode) parent).getSupportChild().getFoundsetMethod(methodid);
            } else if (parent instanceof JSForm && ((JSForm) parent).getForm().getDataSource() != null) {
                Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(((JSForm) parent).getForm().getDataSource(), false);
                scriptMethod = AbstractBase.selectById(foundsetMethods, methodid);
                if (scriptMethod != null) {
                    scriptParent = new JSDataSourceNode(application, ((JSForm) parent).getForm().getDataSource());
                }
            }
        }
        if (scriptMethod == null) {
            // global method
            scriptMethod = application.getFlattenedSolution().getScriptMethod(methodid);
        }
        if (scriptMethod != null) {
            if (scriptParent == null) {
                if (scriptMethod.getParent() instanceof TableNode && parent instanceof JSDataSourceNode) {
                    scriptParent = (JSDataSourceNode) parent;
                } else if (scriptMethod.getParent() instanceof Solution) {
                    // global
                    scriptParent = null;
                } else {
                    // form method
                    scriptParent = getJSFormParent(parent);
                }
            }
            List<Object> arguments = persist.getFlattenedMethodArguments(propertyName);
            if (arguments == null || arguments.size() == 0) {
                return new JSMethod(scriptParent, scriptMethod, application, false);
            } else {
                return new JSMethodWithArguments(application, scriptParent, scriptMethod, false, arguments.toArray());
            }
        }
    } else if (methodid == 0 && BaseComponent.isCommandProperty(propertyName)) {
        return (JSMethod) ISMDefaults.COMMAND_DEFAULT;
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) Iterator(java.util.Iterator) TableNode(com.servoy.j2db.persistence.TableNode) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 24 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, String uuidOrName, IJSParent<?> parent, String propertyName) {
    if (uuidOrName != null) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(uuidOrName);
        ;
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof TableNode && parent instanceof JSDataSourceNode) {
                scriptParent = (JSDataSourceNode) parent;
            } else if (scriptMethod.getParent() instanceof Solution) {
                // global
                scriptParent = null;
            } else {
                // form method
                scriptParent = getJSFormParent(parent);
                if (scriptMethod.getParent() != scriptParent.getSupportChild() && scriptParent.getSupportChild() instanceof Form) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm((Form) scriptParent.getSupportChild(), false);
                }
            }
            List<Object> arguments = persist.getFlattenedMethodArguments(propertyName);
            if (arguments == null || arguments.size() == 0) {
                return new JSMethod(scriptParent, scriptMethod, application, false);
            } else {
                return new JSMethodWithArguments(application, scriptParent, scriptMethod, false, arguments.toArray());
            }
        }
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) TableNode(com.servoy.j2db.persistence.TableNode) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 25 with Solution

use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.

the class JSValueList method setGlobalMethod.

@JSSetter
public void setGlobalMethod(IBaseSMMethod method) {
    checkModification();
    if (method == null) {
        valuelist.setCustomValues(null);
        valuelist.setValueListType(IValueListConstants.CUSTOM_VALUES);
    } else {
        ScriptMethod scriptMethod = ((JSMethod) method).getScriptMethod();
        if (scriptMethod.getParent() instanceof Solution) {
            valuelist.setCustomValues(scriptMethod.getUUID().toString());
            valuelist.setValueListType(IValueListConstants.GLOBAL_METHOD_VALUES);
        } else {
            // $NON-NLS-1$
            throw new RuntimeException("Only global methods are supported for a valuelist");
        }
    }
}
Also used : ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) JSSetter(org.mozilla.javascript.annotations.JSSetter)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3