Search in sources :

Example 1 with ResourceReference

use of org.apache.wicket.ResourceReference in project gitblit by gitblit.

the class NgController method renderHead.

@Override
public void renderHead(IHeaderResponse response) {
    // add Google AngularJS reference
    response.renderJavascriptReference(new ResourceReference(NgController.class, "angular.js"));
    Gson gson = new GsonBuilder().create();
    StringBuilder sb = new StringBuilder();
    line(sb, MessageFormat.format("<!-- AngularJS {0} data controller -->", name));
    line(sb, MessageFormat.format("function {0}($scope) '{'", name));
    for (Map.Entry<String, Object> entry : variables.entrySet()) {
        String var = entry.getKey();
        Object o = entry.getValue();
        String json = gson.toJson(o);
        line(sb, MessageFormat.format("\t$scope.{0} = {1};", var, json));
    }
    line(sb, "}");
    response.renderJavascript(sb.toString(), null);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResourceReference(org.apache.wicket.ResourceReference) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ResourceReference

use of org.apache.wicket.ResourceReference in project servoy-client by Servoy.

the class TemplateGenerator method getFormHTMLAndCSS.

public static Pair<String, String> getFormHTMLAndCSS(Solution solution, Form form, IServiceProvider sp, String formInstanceName) throws RepositoryException, RemoteException {
    if (form == null)
        return null;
    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
    boolean enableAnchoring = sp != null ? Utils.getAsBoolean(sp.getRuntimeProperties().get("enableAnchors")) : Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.webclient.enableAnchors", Boolean.TRUE.toString()));
    String overriddenStyleName = null;
    Pair<String, ArrayList<Pair<String, String>>> retval = formCache.getFormAndCssPair(form, formInstanceName, overriddenStyleName, repository);
    Form f = form;
    FlattenedSolution fsToClose = null;
    try {
        if (retval == null) {
            if (f.getExtendsID() > 0) {
                FlattenedSolution fs = sp == null ? null : sp.getFlattenedSolution();
                if (fs == null) {
                    try {
                        IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                        fsToClose = fs = new FlattenedSolution(solution.getSolutionMetaData(), new AbstractActiveSolutionHandler(as) {

                            @Override
                            public IRepository getRepository() {
                                return repository;
                            }
                        });
                    } catch (RepositoryException e) {
                        Debug.error("Couldn't create flattened form for the template generator", e);
                    }
                }
                f = fs.getFlattenedForm(f);
                if (f == null) {
                    Debug.log("TemplateGenerator couldn't get a FlattenedForm for " + form + ", solution closed?");
                    f = form;
                }
            }
            StringBuffer html = new StringBuffer();
            TextualCSS css = new TextualCSS();
            IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(sp, solution, f, formInstanceName);
            int viewType = layoutProvider.getViewType();
            layoutProvider.renderOpenFormHTML(html, css);
            int startY = 0;
            Iterator<Part> parts = f.getParts();
            while (parts.hasNext()) {
                Part part = parts.next();
                int endY = part.getHeight();
                if (Part.rendersOnlyInPrint(part.getPartType())) {
                    startY = part.getHeight();
                    // is never shown (=printing only)
                    continue;
                }
                Color bgColor = ComponentFactory.getPartBackground(sp, part, f);
                if (part.getPartType() == Part.BODY && (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW)) {
                    layoutProvider.renderOpenTableViewHTML(html, css, part);
                    // tableview == bodypart
                    createCellBasedView(f, f, html, css, layoutProvider.needsHeaders(), startY, endY, bgColor, sp, viewType, enableAnchoring, startY, endY);
                    layoutProvider.renderCloseTableViewHTML(html);
                } else {
                    layoutProvider.renderOpenPartHTML(html, css, part);
                    placePartElements(f, startY, endY, html, css, bgColor, enableAnchoring, sp);
                    layoutProvider.renderClosePartHTML(html, part);
                }
                startY = part.getHeight();
            }
            layoutProvider.renderCloseFormHTML(html);
            retval = new Pair<String, ArrayList<Pair<String, String>>>(html.toString(), css.getAsSelectorValuePairs());
            formCache.putFormAndCssPair(form, formInstanceName, overriddenStyleName, repository, retval);
        }
        Map<String, String> formIDToMarkupIDMap = null;
        if (sp instanceof IApplication) {
            Map runtimeProps = sp.getRuntimeProperties();
            Map<WebForm, Map<String, String>> clientFormsIDToMarkupIDMap = (Map<WebForm, Map<String, String>>) runtimeProps.get("WebFormIDToMarkupIDCache");
            if (clientFormsIDToMarkupIDMap == null) {
                clientFormsIDToMarkupIDMap = new WeakHashMap<WebForm, Map<String, String>>();
                runtimeProps.put("WebFormIDToMarkupIDCache", clientFormsIDToMarkupIDMap);
            }
            IForm wfc = ((IApplication) sp).getFormManager().getForm(formInstanceName);
            if (wfc instanceof FormController) {
                IFormUIInternal wf = ((FormController) wfc).getFormUI();
                if (wf instanceof WebForm) {
                    if (!((WebForm) wf).isUIRecreated())
                        formIDToMarkupIDMap = clientFormsIDToMarkupIDMap.get(wf);
                    if (formIDToMarkupIDMap == null) {
                        ArrayList<Pair<String, String>> formCSS = retval.getRight();
                        ArrayList<String> selectors = new ArrayList<String>(formCSS.size());
                        for (Pair<String, String> formCSSEntry : formCSS) selectors.add(formCSSEntry.getLeft());
                        formIDToMarkupIDMap = getWebFormIDToMarkupIDMap((WebForm) wf, selectors);
                        clientFormsIDToMarkupIDMap.put((WebForm) wf, formIDToMarkupIDMap);
                    }
                }
            }
        }
        String webFormCSS = getWebFormCSS(retval.getRight(), formIDToMarkupIDMap);
        // string the formcss/solutionname/ out of the url.
        webFormCSS = StripHTMLTagsConverter.convertMediaReferences(webFormCSS, solution.getName(), new ResourceReference("media"), "", false).toString();
        return new Pair<String, String>(retval.getLeft(), webFormCSS);
    } finally {
        if (fsToClose != null) {
            fsToClose.close(null);
        }
    }
}
Also used : IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IForm(com.servoy.j2db.IForm) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) ResourceReference(org.apache.wicket.ResourceReference) IFormUIInternal(com.servoy.j2db.IFormUIInternal) Pair(com.servoy.j2db.util.Pair) FormController(com.servoy.j2db.FormController) Color(java.awt.Color) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) IApplication(com.servoy.j2db.IApplication) Part(com.servoy.j2db.persistence.Part) IRepository(com.servoy.j2db.persistence.IRepository) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) TreeMap(java.util.TreeMap)

Example 3 with ResourceReference

use of org.apache.wicket.ResourceReference in project servoy-client by Servoy.

the class WebBaseButton method setMediaIcon.

public void setMediaIcon(int iconId) {
    this.icon = null;
    this.iconUrl = null;
    this.iconReference = null;
    if ((media = application.getFlattenedSolution().getMedia(iconId)) != null) {
        addEnabledStyleAttributeModifier();
        // $NON-NLS-1$
        iconReference = new ResourceReference("media");
        text_url = MediaURLStreamHandler.MEDIA_URL_DEF + media.getName();
    } else if (enabledStyle != null) {
        remove(enabledStyle);
        enabledStyle = null;
    }
// mediaSize = null;
}
Also used : ResourceReference(org.apache.wicket.ResourceReference)

Example 4 with ResourceReference

use of org.apache.wicket.ResourceReference in project servoy-client by Servoy.

the class WebBaseLabel method setRolloverIcon.

/**
 * @see com.servoy.j2db.ui.ILabel#setRolloverIcon(byte[])
 */
public void setRolloverIcon(int rolloverId) {
    if ((rolloverMedia = application.getFlattenedSolution().getMedia(rolloverId)) != null) {
        addRolloverBehaviors();
        // $NON-NLS-1$
        rolloverIconReference = new ResourceReference("media");
    }
}
Also used : ResourceReference(org.apache.wicket.ResourceReference)

Example 5 with ResourceReference

use of org.apache.wicket.ResourceReference in project servoy-client by Servoy.

the class StripHTMLTagsConverter method convertBodyText.

/**
 * @param bodyText
 * @param solution
 * @return
 */
@SuppressWarnings("nls")
public static StrippedText convertBodyText(Component component, CharSequence unsanitizedbodyText, boolean trustDataAsHtml, FlattenedSolution solutionRoot) {
    CharSequence bodyText = WebBaseButton.sanitize(unsanitizedbodyText, trustDataAsHtml);
    StrippedText st = new StrippedText();
    if (RequestCycle.get() == null) {
        st.setBodyTxt(bodyText);
        return st;
    }
    // $NON-NLS-1$
    ResourceReference rr = new ResourceReference("media");
    String solutionName = solutionRoot.getSolution().getName();
    StringBuilder bodyTxt = new StringBuilder(bodyText.length());
    XmlPullParser parser = new XmlPullParser();
    ICrypt urlCrypt = null;
    if (Application.exists())
        urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        parser.parse(new ByteArrayInputStream(bodyText.toString().getBytes("UTF8")), "UTF8");
        XmlTag me = (XmlTag) parser.nextTag();
        while (me != null) {
            CharSequence tmp = parser.getInputFromPositionMarker(me.getPos());
            if (tmp.toString().trim().length() > 0)
                bodyTxt.append(tmp);
            parser.setPositionMarker();
            String currentTagName = me.getName().toLowerCase();
            if (// $NON-NLS-1$
            currentTagName.equals("script")) {
                if (!me.isClose()) {
                    // $NON-NLS-1$
                    String srcUrl = (String) me.getAttributes().get("src");
                    // $NON-NLS-1$
                    if (srcUrl == null)
                        srcUrl = (String) me.getAttributes().get("SRC");
                    me = (XmlTag) parser.nextTag();
                    if (srcUrl != null) {
                        st.getJavascriptUrls().add(convertMediaReferences(srcUrl, solutionName, rr, "", true).toString());
                    } else {
                        if (me != null) {
                            st.getJavascriptScripts().add(parser.getInputFromPositionMarker(me.getPos()));
                            parser.setPositionMarker();
                        }
                    }
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            } else if (currentTagName.equals("style")) {
                if (me.isOpen()) {
                    me = (XmlTag) parser.nextTag();
                    List<CharSequence> styles = st.getStyles();
                    String style = parser.getInputFromPositionMarker(me.getPos()).toString().trim();
                    if (!"".equals(style) && !styles.contains(style)) {
                        styles.add(convertMediaReferences(style, solutionName, rr, "", false));
                    }
                    parser.setPositionMarker();
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            } else if (currentTagName.equals("link")) {
                if (me.isOpen() || me.isOpenClose()) {
                    String end = "\n";
                    if (me.isOpen())
                        end = "</link>\n";
                    st.getLinkTags().add(convertMediaReferences(me.toXmlString(null) + end, solutionName, rr, "", false));
                }
                me = (XmlTag) parser.nextTag();
                continue;
            }
            if (ignoreTags.contains(currentTagName)) {
                if (currentTagName.equals("body") && (me.isOpen() || me.isOpenClose())) {
                    if (me.getAttributes().size() > 0) {
                        st.addBodyAttributes(me.getAttributes());
                    }
                    me = (XmlTag) parser.nextTag();
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            }
            if (currentTagName.equals("img") && component instanceof ILabel) {
                ILabel label = (ILabel) component;
                String onload = "Servoy.Utils.setLabelChildHeight('" + component.getMarkupId() + "', " + label.getVerticalAlignment() + ");";
                onload = me.getAttributes().containsKey("onload") ? me.getAttributes().getString("onload") + ";" + onload : onload;
                me.getAttributes().put("onload", onload);
            }
            boolean ignoreOnclick = false;
            IValueMap attributeMap = me.getAttributes();
            // first transfer over the tabindex to anchor tags
            if (currentTagName.equals("a")) {
                int tabIndex = TabIndexHelper.getTabIndex(component);
                if (tabIndex != -1)
                    attributeMap.put("tabindex", Integer.valueOf(tabIndex));
            }
            // now they have to be lowercase. (that is a xhtml requirement)
            for (String attribute : scanTags) {
                // $NON-NLS-1$
                if (ignoreOnclick && attribute.equals("onclick"))
                    continue;
                String src = attributeMap.getString(attribute);
                if (src == null) {
                    continue;
                }
                String lowercase = src.toLowerCase();
                if (lowercase.startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
                    String name = src.substring(MediaURLStreamHandler.MEDIA_URL_DEF.length());
                    if (name.startsWith(MediaURLStreamHandler.MEDIA_URL_BLOBLOADER)) {
                        String url = generateBlobloaderUrl(component, urlCrypt, name);
                        me.getAttributes().put(attribute, url);
                    } else {
                        String translatedUrl = MediaURLStreamHandler.getTranslatedMediaURL(solutionRoot, lowercase);
                        if (translatedUrl != null) {
                            me.getAttributes().put(attribute, translatedUrl);
                        }
                    }
                } else if (component instanceof ISupportScriptCallback && lowercase.startsWith("javascript:")) {
                    String script = src;
                    if (script.length() > 13) {
                        String scriptName = script.substring(11);
                        if ("href".equals(attribute)) {
                            if (attributeMap.containsKey("externalcall")) {
                                attributeMap.remove("externalcall");
                            } else {
                                me.getAttributes().put("href", "#");
                                me.getAttributes().put("onclick", ((ISupportScriptCallback) component).getCallBackUrl(scriptName, true));
                                ignoreOnclick = true;
                            }
                        } else {
                            me.getAttributes().put(attribute, ((ISupportScriptCallback) component).getCallBackUrl(scriptName, "onclick".equals(attribute)));
                        }
                    }
                } else if (component instanceof FormComponent<?> && lowercase.startsWith("javascript:")) {
                    String script = src;
                    if (script.length() > 13) {
                        String scriptName = script.substring(11);
                        if ("href".equals(attribute)) {
                            me.getAttributes().put("href", "#");
                            me.getAttributes().put("onclick", getTriggerJavaScript((FormComponent<?>) component, scriptName));
                            ignoreOnclick = true;
                        } else {
                            me.getAttributes().put(attribute, getTriggerJavaScript((FormComponent<?>) component, scriptName));
                        }
                    }
                }
            }
            bodyTxt.append(me.toString());
            me = (XmlTag) parser.nextTag();
        }
        bodyTxt.append(parser.getInputFromPositionMarker(-1));
        // $NON-NLS-1$
        st.setBodyTxt(convertMediaReferences(convertBlobLoaderReferences(bodyTxt, component), solutionName, rr, "", false));
    } catch (ParseException ex) {
        Debug.error(ex);
        // $NON-NLS-1$
        bodyTxt.append("<span style=\"color : #ff0000;\">");
        bodyTxt.append(HCUtils.sanitize(ex.getMessage()));
        bodyTxt.append(bodyText.subSequence(ex.getErrorOffset(), Math.min(ex.getErrorOffset() + 100, bodyText.length())));
        // $NON-NLS-1$
        bodyTxt.append("</span></body></html>");
        st.setBodyTxt(bodyTxt);
    } catch (Exception ex) {
        Debug.error(ex);
        // $NON-NLS-1$
        bodyTxt.append("<span style=\"color : #ff0000;\">");
        bodyTxt.append(HCUtils.sanitize(ex.getMessage()));
        // $NON-NLS-1$
        bodyTxt.append("</span></body></html>");
        st.setBodyTxt(bodyTxt);
    }
    return st;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) IValueMap(org.apache.wicket.util.value.IValueMap) ILabel(com.servoy.j2db.ui.ILabel) XmlPullParser(org.apache.wicket.markup.parser.XmlPullParser) ParseException(java.text.ParseException) ICrypt(org.apache.wicket.util.crypt.ICrypt) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) List(java.util.List) ResourceReference(org.apache.wicket.ResourceReference) ParseException(java.text.ParseException) XmlTag(org.apache.wicket.markup.parser.XmlTag)

Aggregations

ResourceReference (org.apache.wicket.ResourceReference)13 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormController (com.servoy.j2db.FormController)1 IApplication (com.servoy.j2db.IApplication)1 IForm (com.servoy.j2db.IForm)1 IFormUIInternal (com.servoy.j2db.IFormUIInternal)1 Form (com.servoy.j2db.persistence.Form)1 IRepository (com.servoy.j2db.persistence.IRepository)1 Media (com.servoy.j2db.persistence.Media)1 Part (com.servoy.j2db.persistence.Part)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 WebForm (com.servoy.j2db.server.headlessclient.WebForm)1 TextualStyle (com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)1 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)1