tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/14140-absolute-links-in-wiziwig-contentCascade CMS: Discussion 2018-10-18T20:37:54Ztag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T13:24:36Z2016-05-09T13:24:36Zabsolute links in wiziwig content<div><p>there was an issue with the code above, this code works but we a
specific issue I can't seem to resolve:</p>
<pre>
<code>#set ($content = $_SerializerTool.serialize($data.getChild("content"), true))
#set ($content2 = $content.replaceAll('<', 'ltsign123').replaceAll('>', 'gtsign123').replaceAll(',', 'comma123').replaceAll('href="', 'linkstart123'))
#set ($linksets = $content2.split("ltsign123a "))
#set ($linked = [])
#foreach ($linkset in $linksets)
#if($linkset.contains("[.]") || $linkset.contains(";") || $linkset.contains(".html") || $linkset.contains(".pdf") || $linkset.contains(".doc"))
#set ($addls = $linked.add($linkset))
#else
#set ($linkset1 = $linkset.replaceFirst('"','.html"'))
#set ($addls = $linked.add($linkset1))
#end
#end
##${linked.size()}
#set ($linked1 = $linked.toString())
#set ($linked2 = $linked1.replaceAll(',','').replace("[","").replace("]","").replaceAll('site://','').replaceAll('Secure Site', $cpath))
#set ($linked3 = $linked2.replaceAll('edu//', 'edu/').replaceAll('ltsign123','<').replaceAll('gtsign123','>').replaceAll('comma123',',').replaceAll('linkstart123','<a href="'))##
$linked3</code>
</pre>
<p>when setting $linked2 I'd like to use $currentPageSiteName
instead of manually setting the site name but every time I use
$currentPageSiteName nothing gets replaced...</p>
<p>thoughts?</p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T14:22:18Z2016-05-09T14:22:18Zabsolute links in wiziwig content<div><p>Hi Nando,</p>
<p>Curious, but I'm not seeing <code>$cpath</code> being
initialized anywhere. If you adjust that does using
<code>$currentPageSiteName</code> work?</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T14:26:16Z2016-05-09T14:28:14Zabsolute links in wiziwig content<div><p>$cpath is initialized in a import above this code (not shown -
sorry)</p>
<p>it populates fine and so does $currentPageSiteName - it just
doesn't see to find the end result of $currentPageSiteName to
replace...</p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T14:56:44Z2016-05-09T14:56:44Zabsolute links in wiziwig content<div><p>Got it, thanks Nando.</p>
<p>I believe I may have ran into a similar issue in the past where
I was not able to use a variable within the first argument in the
<code>replaceAll()</code>. Perhaps try something like:</p>
<pre>
<code>#set ($linked2 = $linked1.replaceAll(',','').replace("[","").replace("]","").replaceAll('site://','').replaceAll("${currentPageSiteName}", $cpath))</code>
</pre>
<p>Let me know if this adjustment helps at all.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T15:03:52Z2016-05-09T15:03:52Zabsolute links in wiziwig content<div><p>no go :(</p>
<pre>
<code>An error occurred while rendering asset preview: Invocation of method 'replaceAll' in class java.lang.String threw exception java.util.regex.PatternSyntaxException: Illegal repetition near index 0
${currentPageSiteName}
^ at templateValidation[line 20, column 103]</code>
</pre>
<p>I also tried:<br></p>
<pre>
<code>replaceAll(${currentPageSiteName}, $cpath) <br><br>
<br>An error occurred while rendering asset preview: Invocation of method 'replaceAll' in class java.lang.String threw exception java.lang.NullPointerException at templateValidation[line 20, column 103]</code>
</pre></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T15:28:12Z2016-05-09T15:28:12Zabsolute links in wiziwig content<div><p>What about <code>replaceAll($currentPageSiteName,
$cpath)</code>?</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T15:31:03Z2016-05-09T15:31:03Zabsolute links in wiziwig content<div><p>nope :(</p>
<p>An error occurred while rendering asset preview: Invocation of
method 'replaceAll' in class java.lang.String threw exception
java.lang.NullPointerException at templateValidation[line 20,
column 103]</p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T17:38:43Z2016-05-09T17:38:43Zabsolute links in wiziwig content<div><p>Thank you for trying, Nando.</p>
<p>I believe the issue here is that
<code>$currentPageSiteName</code> is a variable that is registered
at run time as opposed to something like a static string. So when
the <code>replaceAll</code> is called the variable is null, which
explains the NullPointerException.</p>
<p>Let me keep playing with this a bit to see if there's something
else we can do.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T18:03:08Z2016-05-09T18:03:08Zabsolute links in wiziwig content<div><p>Hi Nando,</p>
<p>I believe I was able to come up with a possible solution using
the String Tool. I've created a macro which basically does a
"string before" and "string after" replacement. Here is the
code:</p>
<pre>
<code>#macro (replaceCurrentPageSiteName $string, $what, $with)
$_StringTool.substringBefore($string, $what)$with$_StringTool.substringAfter($string, $what)
#end</code>
</pre>
<p>Using your Format as an example, you'd call this macro like:</p>
<pre>
<code>#set ($linked2 = $linked1.replaceAll(',','').replace("[","").replace("]","").replaceAll('site://',''))
#set ($linked2 = "#replaceCurrentPageSiteName($linked2, $currentPageSiteName, $clink)")
## Do things with $linked2</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T18:20:56Z2016-05-09T18:20:56Zabsolute links in wiziwig content<div><p>NICE!! that worked great!</p>
<p>few questions:</p>
<p>when setting variables, using the same name is ok? just
overwritten?</p>
<p>the if contains line still messes me up, if I don't specify
.html, .doc, .pdf SOMETIMES it replaces on lines that shouldn't...
thoughts?</p>
<p>in general, what are your thoughts on this for outputting
absolute links when publishing but still using system links
inside?</p>
<p>thanks again!!!</p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T19:36:09Z2016-05-09T19:36:09Zabsolute links in wiziwig content<div><p>Thank you for following up, Nando. I am glad to hear the
proposed solution did the trick.</p>
<blockquote>
<p>when setting variables, using the same name is ok? just
overwritten?</p>
</blockquote>
<p>Correct, the variable will be overwritten.</p>
<blockquote>
<p>the if contains line still messes me up, if I don't specify
.html, .doc, .pdf SOMETIMES it replaces on lines that shouldn't...
thoughts?</p>
</blockquote>
<p>I'm having a tough time following the code without some context.
Can you explain this piece a bit more?</p>
<blockquote>
<p>in general, what are your thoughts on this for outputting
absolute links when publishing but still using system links
inside?</p>
</blockquote>
<p>Generally, clients will append a static domain or use the Site
name (which represents the URL) when building out the links, so
this is not too far fetched. Using a combination of
<code>[system-view:external]</code> and
<code>[system-view:internal]</code> to generate different links for
preview and publish would be recommended so you can still link to
pages within Cascade.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T20:28:48Z2016-05-09T20:33:40Zabsolute links in wiziwig content<div><p>Gotcha.</p>
<p>actually, your previous fix gave me an idea, is there way for me
to check if a variable contains a specific character BEFORE a
specific character?</p>
<p>for example, I would like to check if the variable has a
<code>.</code> or a <code>;</code> before the first
<code>"</code></p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T20:57:07Z2016-05-09T20:57:07Zabsolute links in wiziwig content<div><p>trying something like:</p>
<pre>
<code>#foreach ($linkset in $linksets)
#set($quotechecker = $_StringTool.substringBefore($linkset,'"'))
#if ($quotechecker.contains("[.]") || $quotechecker.contains(";"))</code>
</pre>
<p>but it gets stuck because its breaking elements I guess...</p></div>Nandotag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-09T21:01:29Z2016-05-09T21:01:29Zabsolute links in wiziwig content<div><p>Hm, are you seeing any errors, or is it just not getting into
that conditional? Curious, but do you need <code>[.]</code>, or can
it just be <code>.</code>? The former looks more like you're trying
to perform a regular expression match, which
<code>contains()</code> does not do.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/398086222016-05-11T13:12:59Z2016-05-11T13:12:59Zabsolute links in wiziwig content<div><p>You were right about <code>[.]</code> :)</p>
<p>The big issue I was having here is when I would split the one
value into multiple values I would get a "element must be
terminated by the matching end-tag" error. Which I get bc the split
values were a mix of content missing start/end elements BUT it
would've all worked out in the end... no?</p>
<p>to get around that, I replaced all <, >, a href, etc so
that I can split them without issue... this is my latest code:</p>
<pre>
<code>#import('site://Nova/_cascade/formats/bootstrap/default/css-js/default canonical')
##
#macro (replaceCurrentPageSiteName $string, $what, $with)
$_StringTool.substringBefore($string, $what)$with$_StringTool.substringAfter($string, $what)
#end
#macro (absolute $links)
#set ($content = $content.replaceAll('<','ltsign123').replaceAll('>','gtsign123').replaceAll(',','comma123').replaceAll('href="','linkstart123').replaceAll('style="','style123'))
#set ($content = $content.replaceAll('"','quotes123'))
#set ($linksets = $content.split("ltsign123a "))
#set ($linked = [])
#foreach ($linkset in $linksets)
#set($quotechecker = $_StringTool.substringBefore($linkset,'quotes123'))
##$quotechecker
#if ($quotechecker.contains(".") || $quotechecker.contains(";"))
##if($linkset.contains("[.]") || $linkset.contains(";") || $linkset.contains(".html") || $linkset.contains(".pdf") || $linkset.contains(".doc"))
#set ($addls = $linked.add($linkset))
#else
#set ($linkset = $linkset.replaceFirst('quotes123','.htmlquotes123'))
#set ($addls = $linked.add($linkset))
#end
#end
##${linked.size()}
#set ($linked = $linked.toString())
#set ($linked = $linked.replaceAll(",","").replace("[","").replace("]",""))
#set ($site = "site://" + $currentPageSiteName)
#if ($linked.contains("site://"))
#set ($linked = "#replaceCurrentPageSiteName($linked, $site, $cpath)")
#end
#set ($linked = $linked.replaceAll('edu//', 'edu/').replaceAll('ltsign123','<').replaceAll('gtsign123','>').replaceAll('comma123',',').replaceAll('linkstart123','<a href="'))
#set ($linked = $linked.replaceAll('style123','style="').replaceAll('quotes123','"'))##
$linked
#end
##
#if ($data.getChild("content").value != "" || $data.getChild("content").getChildren())
#set ($content = $_SerializerTool.serialize($data.getChild("content"), true))
#absolute($links)
#end</code>
</pre></div>Nando