Secció 1a. Béns d'interés cultural

S'ha produït un error mentre es processava la plantilla.
?substring(...) argument #2 had invalid value: The index must be at least 0, but was -1.

----
FTL stack trace ("~" means nesting-related):
	- Failed at: #assign parameterKey = parameterKeyAn...  [in template "10155#10193#161981574" at line 115, column 49]
----
1<#ftl output_format="HTML"> 
2<#-- 
3	* Autor: Andrea Olivero 
4	* Fecha Inicio: 22/06/2020 
5	* Formato migracion: json 
6	* Fecha Finalizacion: 30/06/2020 
7	--> 
8 
9	<#assign reserved_article_title = "${.vars['reserved-article-title'].data}"/> 
10	<#assign reserved_article_id = "${.vars['reserved-article-id'].data}"/> 
11	<#assign viewUrl=""/> 
12	<#assign cuerpo=""/> 
13	<#assign posicion=""/> 
14	<#assign iframeId = "${.vars['reserved-article-id'].data}"/>  
15	<#assign iframeProtocol = ""/> 
16	<#assign width = "100%"/> 
17	<#assign height = "650"/> 
18	<#assign scrolling = "auto"/> 
19	<#assign src = ""/> 
20	<#assign velocityCount = ""/> 
21	<#assign ajustar_alto = false/> 
22	<#assign mostrar_atras = false/> 
23	<#assign mostrar_enlazar = false/> 
24	<#assign mostrar_imprimir = false/> 
25 
26	<div class="webContent" style="float:none;"> 
27		 <#if reserved_article_title?? && reserved_article_title!=""> 
28			<p class="header10">${reserved_article_title}</p> 
29		</#if> 
30	</div> 
31 
32	<#--Dependiendo del valor de la variable posicion el Cuerpo se pinta arriba o abajo 
33	por lo que primero recogemos los valores en variables --> 
34 
35	<#--Posición arriba/abajo--> 
36	<#if Posicion??> 
37		<#assign posicion=Posicion.getData()/> 
38	</#if> 
39 
40	<#--Texto en el cuerpo caja de texto enriquecido.--> 
41	<#if Cuerpo??> 
42		  <#assign cuerpo = Cuerpo.getData()/> 
43	</#if> 
44 
45	<div class="iframe"> 
46		<#--Si el valor seleccionado es arriba entonces imprimimos el contenido del cuerpo.--> 
47		<#if posicion == "arriba"> 
48		   <div class="texto_cuerpo">  
49				${cuerpo?no_esc} 
50		   </div> 
51		</#if> 
52		<#--Comprobamos valores rellenados por usuario--> 
53		<#if ancho.getData()?? && ancho.getData()!="">  
54			<#assign width = ancho.getData()/> 
55		</#if> 
56		 
57		<#if alto.getData()?? && alto.getData()!=""> 
58			<#assign height = alto.getData()/> 
59		</#if> 
60		 
61		<#if barra_desplazamiento.getData()?? && barra_desplazamiento.getData()!=""> 
62			<#assign scrolling = barra_desplazamiento.getData()/> 
63		</#if> 
64		 
65		<#if url.getData()?? && url.getData()!=""> 
66			<#assign src = url.getData()/> 
67		</#if> 
68		 
69		<#if autoajustar_alto?? && autoajustar_alto.getData()=="true"> 
70			<#assign ajustar_alto = true/> 
71		</#if> 
72		 
73		<#if mostrar_enlace_atras?? && mostrar_enlace_atras.getData()=="true"> 
74			<#assign mostrar_atras = true/> 
75		</#if> 
76		 
77		<#if mostrar_enlace_enlazar?? && mostrar_enlace_enlazar.getData()=="true"> 
78			<#assign mostrar_enlazar = true/> 
79		</#if> 
80		 
81		<#if mostrar_boton_imprimir?? && mostrar_boton_imprimir.getData()=="true"> 
82			<#assign mostrar_imprimir = true/> 
83		</#if> 
84		 
85		<#--Obtengo el dominio actual--> 
86		<#assign currentUrl = Request.CURRENT_COMPLETE_URL/> 
87		<#assign urlParts = currentUrl?split("/")/> 
88		<#assign currentDomain = ""/> 
89		<#assign currentProtocol = ""/> 
90		<#list urlParts as urlPart> 
91			<#if velocityCount == "3"> 
92				<#assign currentDomain = urlPart/> 
93			</#if> 
94		</#list> 
95		<#--Obtengo el dominio del iframe --> 
96		<#assign srcParts = src?split("/")/> 
97		<#assign iframeDomain = ""/> 
98		<#assign serverUrl = ""/> 
99		 
100		<#if srcParts[0] == "http:" || srcParts[0] == "https:"> 
101			<#assign iframeDomain = srcParts[2]/> 
102			<#assign iframeProtocol = srcParts[0]/> 
103			<#assign serverUrl = iframeProtocol + "//" + iframeDomain/> 
104		</#if> 
105		 
106		<#if src?? && src!=""> 
107			<#-- parámetros de la url del portal--> 
108 
109				<#assign parametrosString = httpUtil.getQueryString(currentUrl)/> 
110				<#assign parameterList = parametrosString?split("&")/> 
111				<#assign sufijo = ""/> 
112				 
113				<#list parameterList as parameterKeyAndValue> 
114					<#if parameterKeyAndValue?? && parameterKeyAndValue?has_content> 
115						<#assign parameterKey = parameterKeyAndValue?substring(0,parameterKeyAndValue?index_of("="))/> 
116						<#assign parameterValue = parameterKeyAndValue?substring(parameterKeyAndValue?index_of("=")+1)/> 
117 
118						<#assign anyadir = true/> 
119						 
120						<#-- ENT-308086 : Tenemos que ver si se ha añadido algún valor en el campo ignore_parametros--> 
121						<#if ignore_parametros?? && ignore_parametros?has_content> 
122							<#assign ignoreParameters = ignore_parametros.getData()?split(";")/> 
123							<#list ignoreParameters as ignoreParameter> 
124								<#if ignoreParameter?? && ignoreParameter?has_content && ignoreParameter==parameterKey> 
125									<#assign anyadir = false/> 
126								</#if>					 
127							</#list> 
128						</#if> 
129						<#--FIN ENT-308086-->  
130 
131						<#--Buscamos si se ha definido la URL que se ha de ver en el iFrame--> 
132						<#if parameterKey == "viewUrl${iframeId}"> 
133							<#assign viewUrl = parameterValue /> 
134							<#assign anyadir = false/> 
135						</#if> 
136 
137						 
138						<#if anyadir > 
139							<#if sufijo != "" > 
140								<#assign sufijo = sufijo + "&" /> 
141							<#else> 
142								<#assign sufijo = "?" /> 
143							</#if> 
144							<#assign sufijo = sufijo + parameterKeyAndValue /> 
145						</#if> 
146					</#if> 
147				</#list> 
148				 
149				<#--Establecemos la URL que se ha de ver en el iFrame, si se ha definido--> 
150 
151				<#if viewUrl?? && viewUrl!=""> 
152					<#assign src = serverUrl + viewUrl /> 
153				</#if> 
154				 
155				<#if sufijo?? && sufijo!=""> 
156					 
157					<#--Comprobamos si la URL ya trae parametros para concatenarlos--> 
158					<#assign index = src?index_of('?')/> 
159				 
160					<#if (index >= 0) >   
161						<#assign sufijo = sufijo?replace("?", "&")/> 
162					</#if> 
163					<#assign src = "${src}${sufijo}"/> 
164				</#if> 
165 
166				<div class="iframe-error-protocol" style="display: none;"><span><@liferay.language key="iframe.mensaje" /><a href="${src?no_esc}" target="_blank"><b><@liferay.language key="iframe.mensaje.ventana" /></b></a></span></div> 
167				<#if mostrar_enlazar || mostrar_atras || mostrar_imprimir> 
168					<div class="iframe-controls iframe-controls-${reserved_article_id}"> 
169						<#if mostrar_atras> 
170							<a class="back-link pull-right" id="iframe-back-link-${reserved_article_id}" href="javascript:history.go(-1)" style="display: none;">&laquo; <@liferay.language key="back"  /></a> 
171						</#if> 
172						<#if mostrar_enlazar> 
173							<a class="iframe-show-link pull-right" id="iframe-show-link-${reserved_article_id}"  style="display: none;" ><i class="fas fa-link"></i><@liferay.language key="iframe.enlazar" /></a> 
174							<div id="iframe-link-${reserved_article_id}" class="iframe-link"> 
175								<input aria-labelledby="iframe-show-link-${reserved_article_id}" id="iframe-link-input-${reserved_article_id}" class="iframe-link-input" type="text" style="display: none;" /> 
176							</div> 
177						</#if> 
178						<#if mostrar_imprimir> 
179							<a class="taglib-icon pull-right" id="iframe-print-${reserved_article_id}"  target="_self">  
180								<i class="fas fa-print"></i> 
181								<span class="taglib-text"><@liferay.language key="print" /></span>  
182							</a>  
183						</#if> 
184					</div> 
185				</#if> 
186				 
187				<div id="iframe-container-${reserved_article_id}"> 
188					<iframe allow="clipboard-write" src="${src?no_esc}" width="${width}" height="${height}" scrolling="${scrolling}" title="${reserved_article_title}" id="iframe-${reserved_article_id}" name="iframe-${reserved_article_id}"></iframe> 
189				</div> 
190		 
191		  
192				<#--Si el valor seleccionado es abajo imprimimos el contenido del cuerpo.--> 
193				<#if posicion == "abajo"> 
194				  <div class="texto_cuerpo">  
195					  ${cuerpo?no_esc} 
196				 </div> 
197				</#if> 
198 
199			<script type="text/javascript"> 
200 
201				 
202				// Script para que no cargue el src del iframe dos veces por el efecto del SPA https://help.liferay.com/hc/es/requests/41501 
203				var iframe = document.getElementById('iframe-${reserved_article_id}'); 
204				var url = "${src?no_esc}"; 
205				if (Liferay.SPA && iframe) { 
206					iframe.src = url; 
207
208				else { 
209					Liferay.on( 
210						'SPAReady', 
211						function(event) { 
212							if (iframe) { 
213								iframe.src = url; 
214
215
216					); 
217
218 
219				// No es el mismo dominio, así que definimos el valor del document.domain 
220				<#if (ajustar_alto || mostrar_atras) && currentDomain?has_content && iframeDomain?has_content && !currentDomain.equals(iframeDomain) > 
221					document.domain = 'gva.es'; 
222				</#if> 
223			 
224				// ENT-337637 Cogemos protocolo por js 
225				if( location.protocol == "https:" &&  "${iframeProtocol}" == "http:" ) 
226					$('.iframe-error-protocol').css('display','block'); 
227 
228			 
229				// Controlar la visualizacion de los botones de Atras y Enlazar en las sucesivas cargas del iframe 
230				<#if mostrar_enlazar || mostrar_atras > 
231					var numLoads=0; 
232					document.getElementById('iframe-${reserved_article_id}').onload = function () { 
233						if (numLoads > 0) { 
234							if ($(window).scrollTop() > $('#iframe-container-${reserved_article_id}').offset().top) { 
235								$('html, body').animate({ scrollTop: $('#iframe-container-${reserved_article_id}').offset().top - 60 }, 'slow'); 
236
237							$('#iframe-link-input-${reserved_article_id}').fadeOut(); 
238
239						if (numLoads == 1) { 
240								$('#iframe-show-link-${reserved_article_id}').show(); 
241								$('#iframe-back-link-${reserved_article_id}').show(); 
242
243						numLoads++; 
244					}								 
245				</#if> 
246 
247				 
248				//Obtener enlace permanente del iframe 
249				$('#iframe-show-link-${reserved_article_id}').click(function (event) { 
250				 
251					//Cuando le damos click no queremos que se quede el marco del foco 
252					$('#iframe-show-link-${reserved_article_id}').blur(); 
253					 
254					var input = $('#iframe-link-input-${reserved_article_id}'); 
255				 
256					if (!$(input).is(':visible')) { 
257			 
258						var iframeLocation = document.getElementById('iframe-${reserved_article_id}').contentWindow.location; 
259						 
260						var pageUrl = window.location.href; 
261						var iframeParams = iframeLocation.href; 
262 
263						if (pageUrl.includes('?')) { 
264							pageUrl = pageUrl.substring(0, pageUrl.indexOf('?')); 
265
266						 
267						if (iframeParams.includes('?')) { 
268							iframeParams = iframeParams.substring(iframeParams.indexOf('?')+1); 
269							iframeParams = '&' + iframeParams.replace(/(&)?viewUrl=[^&]+/g, ''); 
270						} else { 
271							iframeParams = ''; 
272
273						 
274						$(input).val(pageUrl + '?viewUrl${iframeId}=' + iframeLocation.pathname + iframeParams); 
275					}	 
276					$(input).toggle(); 
277				}); 
278					 
279				$('#iframe-show-link-${reserved_article_id}').keyup(function(event){ 
280					if (event.keyCode == 13) { 
281						event.preventDefault(); 
282						$('#iframe-show-link-${reserved_article_id}').click(); 
283
284				}); 
285				 
286				//Imprimimos sólo el contenido del iframe 
287				$('#iframe-print-${reserved_article_id}').click(function (event) { 
288					var ifr = document.getElementById("iframe-${reserved_article_id}"); 
289					ifr.contentWindow.focus(); 
290					ifr.contentWindow.print(); 
291					console.log("Click") 
292				}); 
293				$('#iframe-print-${reserved_article_id}').keyup(function(event){ 
294					if (event.keyCode == 13) { 
295						event.preventDefault(); 
296						$('#iframe-print-${reserved_article_id}').click(); 
297
298				}); 
299			 
300				//El enlace « Atrás de los publicadores para los contenidos de tipo IFRAME, vuelve atrás en el historial para que deshaga una posible navegación realizada en la página incrustada 
301				$("span[class='header-back-to']").find("a").attr("href", "javascript:window.history.back()"); 
302	    
303				//Autoajustar alto cada vez que se cargue el contenido del iframe 
304				<#if ajustar_alto > 
305					 
306					// Autoajustar el alto del iframe cada segundo 
307					setInterval(function() { 
308						var iframe = document.getElementById('iframe-${reserved_article_id}'); 
309						var style = 0; 
310						if (iframe && iframe !== 'null' && iframe !== 'undefined') { 
311							style = iframe.style.height.replace('px', ''); 
312							if (iframe.contentWindow.document.body && iframe.contentWindow.document.body !== 'null' && iframe.contentWindow.document.body !== 'undefined') { 
313								var offset = iframe.contentWindow.document.body.offsetHeight + 30; 
314								 
315								if(style>=offset+31 || style<=offset-31){ 
316								   iframe.style.height = offset + 'px'; 
317
318
319
320					},1); 
321				</#if>	    
322			</script> 
323			 
324		<#else> 
325			No se ha introduccido una URL de iframe. 
326		</#if> 
327	</div>