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;
}
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);
}
}
}
}
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;
}
}
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;
}
Aggregations