Search in sources :

Example 26 with Media

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

the class MediaURLStreamHandler method getTranslatedMediaURL.

/**
 *   gets translated relative URL from media:///name to  resources/servoy/media?s=sol_name&id=name
 *   used in web client
 * @param solution
 * @param url
 * @return
 */
public static String getTranslatedMediaURL(FlattenedSolution solution, String url) {
    // $NON-NLS-1$
    ResourceReference rr = new ResourceReference("media");
    String lowercase = url.toLowerCase();
    if (lowercase.startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
        String name = url.substring(MediaURLStreamHandler.MEDIA_URL_DEF.length());
        Media media = solution.getMedia(name);
        if (media != null) {
            return RequestCycle.get().urlFor(rr) + "?id=" + media.getName() + "&s=" + solution.getSolution().getName();
        }
    }
    return null;
}
Also used : Media(com.servoy.j2db.persistence.Media) ResourceReference(org.apache.wicket.ResourceReference)

Example 27 with Media

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

the class WebBaseButton method setImageURL.

public void setImageURL(String textUrl) {
    this.text_url = textUrl;
    if (textUrl == null) {
        icon = null;
        iconReference = null;
        iconUrl = null;
    } else {
        int index = textUrl.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
        if (index == -1) {
            icon = null;
            iconReference = null;
            iconUrl = textUrl;
            addEnabledStyleAttributeModifier();
        } else {
            String mediaName = textUrl.substring(index + MediaURLStreamHandler.MEDIA_URL_DEF.length());
            try {
                Media m = application.getFlattenedSolution().getMedia(mediaName);
                if (m != null) {
                    setMediaIcon(m.getID());
                } else if (mediaName.startsWith(MediaURLStreamHandler.MEDIA_URL_BLOBLOADER)) {
                    // clear previous images
                    icon = null;
                    iconReference = null;
                    iconUrl = null;
                    addEnabledStyleAttributeModifier();
                }
            } catch (Exception ex) {
                // $NON-NLS-1$
                Debug.error("Error loading media for url: " + textUrl, ex);
            }
        }
    }
}
Also used : Media(com.servoy.j2db.persistence.Media) Point(java.awt.Point) IOException(java.io.IOException)

Example 28 with Media

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

the class NGClientWebsocketSession method sendSolutionCSSURL.

@SuppressWarnings("nls")
protected void sendSolutionCSSURL(Solution solution) {
    Map<String, String> overrideStyleSheets = client != null ? client.getOverrideStyleSheets() : null;
    List<String> styleSheets = PersistHelper.getOrderedStyleSheets(client.getFlattenedSolution());
    if (styleSheets != null && styleSheets.size() > 0) {
        if (overrideStyleSheets != null) {
            for (String oldStyleSheet : overrideStyleSheets.keySet()) {
                if (styleSheets.contains(oldStyleSheet)) {
                    styleSheets.set(styleSheets.indexOf(oldStyleSheet), overrideStyleSheets.get(oldStyleSheet));
                }
            }
        }
        Collections.reverse(styleSheets);
        boolean ng2 = client.getRuntimeProperties().containsKey("NG2");
        for (int i = 0; i < styleSheets.size(); i++) {
            long timestamp = 0;
            Media media = null;
            String stylesheetName = styleSheets.get(i);
            if (ng2) {
                int lastPoint = stylesheetName.lastIndexOf('.');
                String ng2StylesheetName = stylesheetName.substring(0, lastPoint) + "_ng2" + stylesheetName.substring(lastPoint);
                media = client.getFlattenedSolution().getMedia(ng2StylesheetName);
                if (media == null)
                    media = client.getFlattenedSolution().getMedia(stylesheetName);
                else
                    stylesheetName = ng2StylesheetName;
            } else
                media = client.getFlattenedSolution().getMedia(stylesheetName);
            if (media != null && media.getLastModifiedTime() > 0) {
                timestamp = media.getLastModifiedTime();
                List<Media> references = media.getRuntimeProperty(Media.REFERENCES);
                if (references != null) {
                    Long refLM = references.stream().collect(Collectors.summingLong(Media::getLastModifiedTime));
                    timestamp += refLM.longValue();
                }
            }
            styleSheets.set(i, "resources/" + MediaResourcesServlet.FLATTENED_SOLUTION_ACCESS + "/" + solution.getName() + "/" + stylesheetName.replace(".less", ".css") + "?t=" + Long.toHexString(timestamp == 0 ? client.getSolution().getLastModifiedTime() : timestamp) + "&clientnr=" + getSessionKey().getClientnr() + (ng2 ? "&ng2" : ""));
        }
        if (compareList(lastSentStyleSheets, styleSheets))
            return;
        lastSentStyleSheets = new ArrayList<String>(styleSheets);
        getClientService(NGClient.APPLICATION_SERVICE).executeAsyncServiceCall("setStyleSheets", new Object[] { styleSheets.toArray(new String[0]) });
    } else {
        if (lastSentStyleSheets != null && lastSentStyleSheets.size() > 0) {
            getClientService(NGClient.APPLICATION_SERVICE).executeAsyncServiceCall("setStyleSheets", new Object[] {});
        }
        lastSentStyleSheets = null;
    }
}
Also used : Media(com.servoy.j2db.persistence.Media)

Example 29 with Media

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

the class FlattenedSolutionLessFileManager method getMedia.

/**
 * @param path
 * @return
 */
private Media getMedia(String path) {
    String filename = path;
    // test for arguments (like last modified)
    int questionMark = filename.lastIndexOf('?');
    if (questionMark > 0) {
        filename = filename.substring(0, questionMark);
    }
    Media media = null;
    try {
        URI uri = new URI(startFolder + filename);
        media = fs.getMedia(uri.normalize().toString());
    } catch (URISyntaxException e1) {
        media = fs.getMedia(startFolder + filename);
    }
    return media;
}
Also used : Media(com.servoy.j2db.persistence.Media) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

Media (com.servoy.j2db.persistence.Media)29 FlattenedSolution (com.servoy.j2db.FlattenedSolution)10 IOException (java.io.IOException)8 Point (java.awt.Point)7 Solution (com.servoy.j2db.persistence.Solution)4 JSFunction (org.mozilla.javascript.annotations.JSFunction)3 FormController (com.servoy.j2db.FormController)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ByteArrayResource (com.servoy.j2db.server.headlessclient.ByteArrayResource)2 Image (java.awt.Image)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 IForm (com.servoy.j2db.IForm)1 IFormController (com.servoy.j2db.IFormController)1 IScriptExecuter (com.servoy.j2db.IScriptExecuter)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1