001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.cms.transformation; 017 018import org.ametys.runtime.i18n.I18nizableText; 019 020/** 021 * Resolver for link uris put by the inline editor in rich text fields. 022 */ 023public interface URIResolver 024{ 025 /** 026 * Returns the type of links handled by this {@link URIResolver}. 027 * @return the type of links handled by this {@link URIResolver}. 028 */ 029 public String getType(); 030 031 /** 032 * Resolves a link URI for rendering purposes.<br> 033 * The output must be a properly encoded path, relative to the webapp context, accessible from a browser. 034 * @param uri the link URI. 035 * @param download true if the pointed resource is to be downloaded. 036 * @param absolute true if the url must be absolute 037 * @param internal true to get an internal URI. 038 * @return the path to the resource. 039 */ 040 public String resolve(String uri, boolean download, boolean absolute, boolean internal); 041 042 /** 043 * Resolves a link URI for rendering image.<br> 044 * The output must be a properly encoded path, relative to the webapp context, accessible from a browser. 045 * @param uri the link URI. 046 * @param height the height of the image. 047 * @param width the width of the image 048 * @param download true if the pointed resource is to be downloaded. 049 * @param absolute true if the url must be absolute 050 * @param internal true to get an internal URI. 051 * @return the path to the image. 052 */ 053 public String resolveImage(String uri, int height, int width, boolean download, boolean absolute, boolean internal); 054 055 /** 056 * Resolve an image and return it as a base64-encoded string. 057 * @param uri the link URI. 058 * @param height the height of the image. 059 * @param width the width of the image 060 * @return a base64-encoded string representing the image. 061 */ 062 public String resolveImageAsBase64(String uri, int height, int width); 063 064 /** 065 * Resolves a link URI for rendering image.<br> 066 * The output must be a properly encoded path, relative to the webapp context, accessible from a browser. 067 * @param uri the link URI. 068 * @param maxHeight the max height 069 * @param maxWidth the max width 070 * @param download true if the pointed resource is to be downloaded. 071 * @param absolute true if the url must be absolute 072 * @param internal true to get an internal URI. 073 * @return the path to the image. 074 */ 075 public String resolveBoundedImage(String uri, int maxHeight, int maxWidth, boolean download, boolean absolute, boolean internal); 076 077 /** 078 * Resolve an image and return it as a base64-encoded string. 079 * @param uri the link URI. 080 * @param maxHeight the max height 081 * @param maxWidth the max width 082 * @return a base64-encoded string representing the image. 083 */ 084 public String resolveBoundedImageAsBase64(String uri, int maxHeight, int maxWidth); 085 086 /** 087 * Resolves a link URI for rendering image.<br> 088 * The output must be a properly encoded path, relative to the webapp context, accessible from a browser. 089 * @param uri the link URI. 090 * @param cropHeight the crop height 091 * @param cropWidth the crop width 092 * @param download true if the pointed resource is to be downloaded. 093 * @param absolute true if the url must be absolute 094 * @param internal true to get an internal URI. 095 * @return the path to the image. 096 */ 097 public String resolveCroppedImage(String uri, int cropHeight, int cropWidth, boolean download, boolean absolute, boolean internal); 098 099 /** 100 * Resolve an image and return it as a base64-encoded string. 101 * @param uri the link URI. 102 * @param cropHeight the crop height 103 * @param cropWidth the crop width 104 * @return a base64-encoded string representing the image. 105 */ 106 public String resolveCroppedImageAsBase64(String uri, int cropHeight, int cropWidth); 107 108 /** 109 * Tests if the URI is not broken. 110 * @param uri The uri to test 111 * @param shortTest If shortTest is to true, only fast check should be done. If false, complete test (even if long) should be done. 112 * @return SUCCESS if the test was done and ok, FAILURE if the test was done and ko, UNKNOWN if the test was not done (because too long). UNKNOWN can not be returned when shortTest is set to false 113 */ 114 public ConsistencyChecker.CHECK checkLink(String uri, boolean shortTest); 115 116 /** 117 * Get an URI label. 118 * @param uri the uri which label to get. 119 * @return the label. 120 */ 121 public I18nizableText getLabel(String uri); 122 123 /** 124 * Get the mime type for the targeted URI. 125 * @param uri the link URI. 126 * @return the mime type, can be empty or null. 127 */ 128 public default String getMimeType(String uri) 129 { 130 return "application/octet-stream"; 131 } 132}