Index: main/plugin-web/src/org/ametys/web/editor/LocalURIResolver.java =================================================================== --- main/plugin-web/src/org/ametys/web/editor/LocalURIResolver.java (revision 59359) +++ main/plugin-web/src/org/ametys/web/editor/LocalURIResolver.java (working copy) @@ -58,48 +58,22 @@ @Override public String resolve(String uri, boolean download, boolean absolute, boolean internal) { - // uri are like content://UUID@metadata;data/file.ext - int i = uri.indexOf('@'); - int j = uri.indexOf(';', i); - String id = uri.substring(0, i); - String metadata = uri.substring(i + 1, j); - String path = uri.substring(j + 1); + URIInfo localURI = getInfos(uri, true); try { - Request request = ContextHelper.getRequest(_context); - - String contentVersion = null; - Content content = (Content) request.getAttribute(Content.class.getName()); // FIXME the content should be the one from request (UUID) but in that cas, getRevision will be always the head on - if (content == null) - { - throw new IllegalStateException("Cannot resolve a local link to an unknown content for uri " + request.getRequestURI()); - } - - String siteName; - if (content instanceof WebContent) - { - siteName = ((WebContent) content).getSiteName(); - } - else - { - siteName = (String) request.getAttribute("siteName"); - } + Content content = localURI.getContent(); + String siteName = _getSitename(content); if (siteName == null) { return super.resolve(uri, download, absolute, internal); } - if (id.equals(content.getId())) - { - contentVersion = ((VersionableAmetysObject) content).getRevision(); - } - - RichText richText = _getMeta(content.getMetadataHolder(), metadata); + RichText richText = _getMeta(content.getMetadataHolder(), localURI.getMetadata()); try { - richText.getAdditionalDataFolder().getFile(path); + richText.getAdditionalDataFolder().getFile(localURI.getPath()); } catch (UnknownAmetysObjectException e) { @@ -114,6 +88,7 @@ params.put("download", "true"); } + String contentVersion = ((VersionableAmetysObject) content).getRevision(); if (contentVersion != null) { params.put("contentVersion", contentVersion); @@ -137,9 +112,9 @@ // Encode twice resultPath.append("/_contents") .append(content.getPath().replaceAll(":", "%3A")) - .append("/_metadata/").append(metadata) + .append("/_metadata/").append(localURI.getMetadata()) .append("/_data/") - .append(URLEncoder.encodePath(path)); + .append(URLEncoder.encodePath(localURI.getPath())); return URLEncoder.encodeURI(resultPath.toString(), params); } @@ -157,42 +132,16 @@ return resolve(uri, download, absolute, internal); } - // uri are like content://UUID@metadata;data/file.ext - int i = uri.indexOf('@'); - int j = uri.indexOf(';', i); - String id = uri.substring(0, i); - String metadata = uri.substring(i + 1, j); - String path = uri.substring(j + 1); + URIInfo localURI = getInfos(uri, true); try { - Request request = ContextHelper.getRequest(_context); - - String contentVersion = null; - Content content = (Content) request.getAttribute(Content.class.getName()); // FIXME the content should be the one from request (UUID) but in that case, getRevision will be always the head one - if (content == null) - { - throw new IllegalStateException("Cannot resolve a local link to an unknown content for uri " + request.getRequestURI()); - } - if (id.equals(content.getId())) // FIXME should be the right one directly : we should not take the one from the request - { - contentVersion = ((VersionableAmetysObject) content).getRevision(); - } - - String siteName; - if (content instanceof WebContent) - { - siteName = ((WebContent) content).getSiteName(); - } - else - { - siteName = (String) request.getAttribute("siteName"); - } + Content content = localURI.getContent(); - RichText richText = _getMeta(content.getMetadataHolder(), metadata); + RichText richText = _getMeta(content.getMetadataHolder(), localURI.getMetadata()); try { - richText.getAdditionalDataFolder().getFile(path); + richText.getAdditionalDataFolder().getFile(localURI.getPath()); } catch (UnknownAmetysObjectException e) { @@ -205,6 +154,7 @@ return ""; } + String siteName = _getSitename(content); StringBuilder resultPath = new StringBuilder(); if (internal) @@ -222,9 +172,9 @@ resultPath.append("/_contents-images") .append(content.getPath().replaceAll(":", "%3A")) - .append("/_metadata/").append(metadata) + .append("/_metadata/").append(localURI.getMetadata()) .append("/_data/") - .append(URLEncoder.encodePath(path)) + .append(URLEncoder.encodePath(localURI.getPath())) .append("_").append(height).append("x").append(width); Map params = new HashMap(); @@ -232,6 +182,8 @@ { params.put("download", "true"); } + + String contentVersion = ((VersionableAmetysObject) content).getRevision(); if (contentVersion != null) { params.put("contentVersion", contentVersion); @@ -253,42 +205,15 @@ return resolve(uri, download, absolute, internal); } - // uri are like content://UUID@metadata;data/file.ext - int i = uri.indexOf('@'); - int j = uri.indexOf(';', i); - String id = uri.substring(0, i); - String metadata = uri.substring(i + 1, j); - String path = uri.substring(j + 1); + URIInfo localURI = getInfos(uri, true); try { - Request request = ContextHelper.getRequest(_context); - - String contentVersion = null; - Content content = (Content) request.getAttribute(Content.class.getName()); // FIXME the content should be the one from request (UUID) but in that cas, getRevision will be always the head on - if (content == null) - { - throw new IllegalStateException("Cannot resolve a local link to an unknown content for uri " + request.getRequestURI()); - } - if (id.equals(content.getId())) // FIXME should be the right one directly : we should not take the one from the request - { - contentVersion = ((VersionableAmetysObject) content).getRevision(); - } - - String siteName; - if (content instanceof WebContent) - { - siteName = ((WebContent) content).getSiteName(); - } - else - { - siteName = (String) request.getAttribute("siteName"); - } - - RichText richText = _getMeta(content.getMetadataHolder(), metadata); + Content content = localURI.getContent(); + RichText richText = _getMeta(content.getMetadataHolder(), localURI.getMetadata()); try { - richText.getAdditionalDataFolder().getFile(path); + richText.getAdditionalDataFolder().getFile(localURI.getPath()); } catch (UnknownAmetysObjectException e) { @@ -296,6 +221,7 @@ return ""; } + String siteName = _getSitename(content); StringBuilder resultPath = new StringBuilder(); if (internal) @@ -313,9 +239,9 @@ resultPath.append("/_contents-images") .append(content.getPath().replaceAll(":", "%3A")) - .append("/_metadata/").append(metadata) + .append("/_metadata/").append(localURI.getMetadata()) .append("/_data/") - .append(URLEncoder.encodePath(path)) + .append(URLEncoder.encodePath(localURI.getPath())) .append("_max").append(maxWidth).append("x").append(maxWidth); Map params = new HashMap(); @@ -323,6 +249,8 @@ { params.put("download", "true"); } + + String contentVersion = ((VersionableAmetysObject) content).getRevision(); if (contentVersion != null) { params.put("contentVersion", contentVersion); @@ -335,4 +263,21 @@ throw new IllegalStateException(e); } } + + /** + * Get the sitename of the content or the request. + * @param content The content + * @return The sitename + */ + protected String _getSitename(Content content) + { + Request request = ContextHelper.getRequest(_context); + + if (content instanceof WebContent) + { + return ((WebContent) content).getSiteName(); + } + + return (String) request.getAttribute("siteName"); + } }