<%@page contentType="application/json; charset=UTF-8"%> <%@page import="org.json.simple.JSONObject"%> <%@ page import="java.util.*,revize.data.*, revize.servlet.*, revize.db.*,revize.store.*, idetix.util.StringUtils, revize.RevizeConstants, revize.*, java.net.*" %> <% // Set Webspace and filename String webspace = StringUtils.getParameter(request,"webspace"); String filename = StringUtils.getParameter(request,"filename"); String passedId = StringUtils.getParameter(request,"recordid"); boolean fileExists = false; String message = ""; // Variables needed to check redirects module DataStore store = DataStoreFactory.createDefault(webspace); Module module = store.readModule("redirects"); String filterWhere = "rpageid='redirects' AND ralias='" + filename.replaceAll("/index.php","") + "'"; List records = store.readLatestRecords( module, filterWhere ); ListIterator recIter = records.listIterator(); // Find out if filename exists inside the links module LinkManager lm = new LinkManager(webspace); fileExists = lm.fileNameExistsInLinksModule("links",filename); // Create new JSON object JSONObject json = new JSONObject(); if(!fileExists){ while(recIter.hasNext()){ Record record = (Record)recIter.next(); String alias = record.getFieldText("alias"); String recordId = record.getFieldText("_recordid"); alias += "/index.php"; if(alias.equals(filename) && !recordId.equals(passedId)){ fileExists = true; message = "The friendly URL is already taken. Please remove or edit the current friendly URL of \"" + alias + "\""; break; } }// end while loop } else { message = "The friendly URL already exists as a section on your site which can be located here: " + webspace + "\\/" + filename + " Cannot overwrite a page that already exists."; }// end if fileExists if(fileExists){ json.put("file_exists","true"); json.put("message",message); } else { json.put("file_exists","false"); } String jString = JSONObject.toJSONString(json); out.println(jString);%> <%response.setContentType("application/json");%>