Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (126 sloc) 4.4 KB
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<xwikidoc version="1.1">
<web>XWiki</web>
<name>ExternalLinksJSON</name>
<language/>
<defaultLanguage/>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<parent>XWiki.ExternalLinks</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<version>1.1</version>
<title>JSON Generation for the External Link States LiveTable</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.0</syntaxId>
<hidden>true</hidden>
<content>{{velocity}}
#if("$!{request.xpage}" == 'plain')
$response.setContentType('application/json')
#end
##==============================
## Offset = item # at which to start displaying data
##==============================
#set($offset = $mathtool.toInteger($request.get('offset')))
## offset starts from 0 in velocity and 1 in javascript
#set($offset = $offset - 1)
#if (!$offset || $offset &lt; 0)
#set($offset = 0)
#end
##==================
## Limit = # of items to display
##==================
#set($limit = $mathtool.toInteger($request.get('limit')))
#if (!$limit)
#set ($limit = 15)
#end
##====================================
## Step1: Transform Map into list, one list item per link/page
##====================================
#set ($states = $services.linkchecker.getLinkStates())
#set ($stateList = [])
#foreach ($link in $states.keySet())
#set ($pages = $states.get($link))
#foreach ($page in $pages.keySet())
#set ($tmpMap = {})
#set ($dummy = $tmpMap.put("link", $link))
#set ($dummy = $tmpMap.put("page", $page))
#set ($dummy = $tmpMap.put("code", $pages.get($page).getResponseCode()))
#set ($dummy = $tmpMap.put("date", $datetool.format($pages.get($page).getLastCheckedTime())))
#set ($dummy = $stateList.add($tmpMap))
#end
#end
##============
## Step2: Filter the list
##============
#set ($filteredList = [])
#set ($linkFilter = "$!{request.get('link')}")
#set ($pageFilter = "$!{request.get('page')}")
#set ($codeFilter = "$!{request.get('code')}")
#set ($dateFilter = "$!{request.get('date')}")
#foreach ($entry in $stateList)
#set ($codeString = "$entry.get('code')")
#if ($codeFilter.startsWith("!") &amp;&amp; $codeFilter.length() &gt; 1)
#set ($codeMatch = !$codeString.contains($codeFilter.substring(1)))
#else
#set ($codeMatch = $codeString.contains($codeFilter))
#end
#if ($entry.get("link").contains($linkFilter) &amp;&amp; $entry.get("page").contains($pageFilter) &amp;&amp; $codeMatch &amp;&amp; $entry.get("date").contains($dateFilter))
#set ($dummy = $filteredList.add($entry))
#end
#end
##===================
## Step3: Handle offset and limit
##===================
#set ($added = 0)
#set ($resultList = [])
#if ($offset &lt; $filteredList.size())
#set ($toIndex = $mathtool.min($mathtool.add($offset, $limit), $filteredList.size()))
#set ($resultList = $filteredList.subList($offset, $toIndex))
#end
## ==========
## JSON Generation
## ==========
#set ($json = {
'totalrows': $filteredList.size(),
'matchingtags': {},
'tags': [],
'returnedrows': $resultList.size(),
'offset': $mathtool.add($offset, 1),
'reqNo': $mathtool.toInteger($request.reqNo),
'rows': []
})
#foreach ($entry in $resultList)
#set ($discard = $json.rows.add({
'doc_viewable': true,
'link': $entry.get('link'),
'link_url': $entry.get('link'),
'page': $entry.get('page'),
'page_url': $xwiki.getURL($entry.get('page')),
'code': $entry.get("code"),
'date': $entry.get("date")
}))
#end
$jsontool.serialize($json)
{{/velocity}}</content>
</xwikidoc>
You can’t perform that action at this time.