gt: 		return getHTML(htmlPage, liveMode, null, userAgent);
context: package com.dotmarketing.portlets.htmlpages.business;
  
  import java.io.Serializable;
  import java.io.StringWriter;
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.Proxy;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  
  import javax.servlet.http.Cookie;
  
  import org.apache.velocity.app.VelocityEngine;
  import org.apache.velocity.context.Context;
  import org.apache.velocity.exception.ResourceNotFoundException;
  
  import com.dotcms.enterprise.cmis.QueryResult;
  import com.dotmarketing.beans.Host;
  import com.dotmarketing.beans.Identifier;
  import com.dotmarketing.beans.MultiTree;
  import com.dotmarketing.beans.UserProxy;
  import com.dotmarketing.beans.WebAsset;
  import com.dotmarketing.business.APILocator;
  import com.dotmarketing.business.BaseWebAssetAPI;
  import com.dotmarketing.business.CacheLocator;
  import com.dotmarketing.business.DotIdentifierStateException;
  import com.dotmarketing.business.DotStateException;
  import com.dotmarketing.business.FactoryLocator;
  import com.dotmarketing.business.IdentifierAPI;
  import com.dotmarketing.business.PermissionAPI;
  import com.dotmarketing.business.query.GenericQueryFactory.Query;
  import com.dotmarketing.business.query.QueryUtil;
  import com.dotmarketing.business.query.ValidationException;
  import com.dotmarketing.business.web.LanguageWebAPI;
  import com.dotmarketing.business.web.WebAPILocator;
  import com.dotmarketing.cache.LiveCache;
  import com.dotmarketing.cache.WorkingCache;
  import com.dotmarketing.cmis.proxy.DotInvocationHandler;
  import com.dotmarketing.cmis.proxy.DotRequestProxy;
  import com.dotmarketing.cmis.proxy.DotResponseProxy;
  import com.dotmarketing.db.HibernateUtil;
  import com.dotmarketing.exception.DotDataException;
  import com.dotmarketing.exception.DotRuntimeException;
  import com.dotmarketing.exception.DotSecurityException;
  import com.dotmarketing.factories.MultiTreeFactory;
  import com.dotmarketing.filters.ClickstreamFilter;
  import com.dotmarketing.menubuilders.RefreshMenus;
  import com.dotmarketing.portlets.containers.model.Container;
  import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
  import com.dotmarketing.portlets.contentlet.business.HostAPI;
  import com.dotmarketing.portlets.contentlet.model.Contentlet;
  import com.dotmarketing.portlets.folders.business.FolderAPI;
  import com.dotmarketing.portlets.folders.model.Folder;
  import com.dotmarketing.portlets.htmlpages.business.HTMLPageAPI.TemplateContainersReMap.ContainerRemapTuple;
  import com.dotmarketing.portlets.htmlpages.model.HTMLPage;
  import com.dotmarketing.portlets.templates.business.TemplateAPI;
  import com.dotmarketing.portlets.templates.model.Template;
  import com.dotmarketing.util.Config;
  import com.dotmarketing.util.Constants;
  import com.dotmarketing.util.CookieUtil;
  import com.dotmarketing.util.InodeUtils;
  import com.dotmarketing.util.Logger;
  import com.dotmarketing.util.UtilMethods;
  import com.dotmarketing.util.VelocityUtil;
  import com.dotmarketing.util.WebKeys;
  import com.dotmarketing.velocity.VelocityServlet;
  import com.liferay.portal.model.User;
  
  public class HTMLPageAPIImpl extends BaseWebAssetAPI implements HTMLPageAPI {
  
  	static PermissionAPI permissionAPI = APILocator.getPermissionAPI();
  	static HTMLPageFactory htmlPageFactory = FactoryLocator.getHTMLPageFactory();
  	static HostAPI hostAPI = APILocator.getHostAPI();
  	static TemplateAPI templateAPI = APILocator.getTemplateAPI();
  	static IdentifierAPI identifierAPI = APILocator.getIdentifierAPI();
  	static ContentletAPI contentletAPI = APILocator.getContentletAPI();
  
  	/**
  	 * Will copy the HTMLPage set on the HTMLPageAPI to the passed in folder.
  	 * Currently this method will copy permissions but will not bring the
  	 * content associated with HTMLPage being copied.
  	 *
  	 * @param folderToCopyTo
  	 * @return
  	 * @throws DotDataException
  	 * @throws DotSecurityException
  	 */
  	public HTMLPage copy(HTMLPage htmlPage, Folder destination, User user, boolean respectFrontendRoles)
  			throws DotDataException, DotSecurityException {
  		return copy(htmlPage, destination, true, false, HTMLPageAPI.CopyMode.BLANK_HTMLPAGE, user, respectFrontendRoles);
  	}
  
  
  	public HTMLPage copy(HTMLPage source, Folder destination, boolean forceOverwrite, boolean copyTemplateContainers,
  			HTMLPageAPI.CopyMode copyMode, User user, boolean respectFrontendRoles) throws DotDataException,
  			DotSecurityException {
  
  		Template sourceTemplate = getHTMLPageTemplate(source);
  		Template template;
  
  		if (copyTemplateContainers) {
  			Host hostDestination = hostAPI.find(destination.getHostId(), user, respectFrontendRoles);
  			template = templateAPI.copy(sourceTemplate, hostDestination, false, true, user, respectFrontendRoles);
  		} else {
  			template = sourceTemplate;
  		}
  
  		TemplateAPI templateAPI = APILocator.getTemplateAPI();
  
          List<Container> sourceContainers = templateAPI.getContainersInTemplate(sourceTemplate, user, respectFrontendRoles);
          List<Container> copyContainers = templateAPI.getContainersInTemplate(template, user, respectFrontendRoles);
  
          List<ContainerRemapTuple> containersRemap = new LinkedList<ContainerRemapTuple>();
          for (int i = 0; i < sourceContainers.size(); i++) {
  			Container sourceContainer = sourceContainers.get(i);
  			Container destinationContainer = copyContainers.get(i);
          	containersRemap.add(new ContainerRemapTuple(sourceContainer, destinationContainer));
          }
          TemplateContainersReMap remap = new TemplateContainersReMap(sourceTemplate, template, containersRemap);
  
  		return copy(source, destination, forceOverwrite, copyMode, remap, user, respectFrontendRoles);
  	}
  
  	public HTMLPage copy(HTMLPage source, Folder destination, boolean forceOverwrite, CopyMode copyMode,
  			TemplateContainersReMap reMapping, User user, boolean respectFrontendRoles) throws DotDataException,
  			DotSecurityException {
  
  		if (!permissionAPI.doesUserHavePermission(source, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
  			throw new DotSecurityException("You don't have permission to read the source file.");
  		}
  
  		if (!permissionAPI.doesUserHavePermission(destination, PermissionAPI.PERMISSION_WRITE, user,
  				respectFrontendRoles)) {
  			throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
  		}
  
  		boolean isNew = false;
  		HTMLPage newHTMLPage;
  		if (forceOverwrite) {
  			newHTMLPage = getWorkingHTMLPageByPageURL(source.getPageUrl(), destination);
  			if (newHTMLPage == null) {
  				isNew = true;
  			}
  		} else {
  			isNew = true;
  		}
  
  		newHTMLPage = new HTMLPage();
  		newHTMLPage.copy(source);
  
  		// gets page url before extension
  		String pageURL = UtilMethods.getFileName(source.getPageUrl());
  
  		// gets file extension
  		String fileExtension = UtilMethods.getFileExtension(source.getPageUrl());
  
  		if (!forceOverwrite) {
  			newHTMLPage.setPageUrl(getCopyHTMLPageName(pageURL, fileExtension, destination));
  
  			if (!UtilMethods.getFileName(newHTMLPage.getPageUrl()).equals(pageURL))
  				newHTMLPage.setFriendlyName(source.getFriendlyName() + " (COPY)");
  		}
  
  		Template destinationTemplate = reMapping.getDestinationTemplate();
  
  		List<MultiTree> associatedSourceContentlets = null;
  
  		//Checking if contentlets just need to be remapped or need to be copied on destination
  		if (copyMode == HTMLPageAPI.CopyMode.USE_SOURCE_CONTENT) {
  			associatedSourceContentlets = getHTMLPageMultiTree(source);
  		} else if (copyMode == HTMLPageAPI.CopyMode.COPY_SOURCE_CONTENT) {
  			associatedSourceContentlets = getHTMLPageMultiTree(source);
  
  			Contentlet contentlet;
  			FolderAPI folderAPI = APILocator.getFolderAPI();
  			Host systemHost = hostAPI.findSystemHost(user, respectFrontendRoles);
  			Folder systemFolder = folderAPI.findSystemFolder();
  			Host destinationHost = hostAPI.find(destination.getHostId(), user, respectFrontendRoles);
  
  			for (MultiTree multiTree : associatedSourceContentlets) {
  				contentlet = contentletAPI.findContentletByIdentifier(multiTree.getChild(), false, 0, user,
  						respectFrontendRoles);
  
  				Host contentletHost = null;
  				if(!UtilMethods.isSet(contentlet.getHost()) && !contentlet.getHost().equals(systemHost.getInode())) {
  					contentletHost = hostAPI.find(contentlet.getHost(), user, respectFrontendRoles);
  				}
  				Folder contentletFolder = null;
  				if(!UtilMethods.isSet(contentlet.getFolder()) && !contentlet.getFolder().equals(systemFolder.getInode())) {
  					contentletFolder = folderAPI.find(contentlet.getFolder(),user,false);
  				}
  
  				if (contentletFolder != null) {
  					Folder contentletDestFolder = folderAPI.createFolders(APILocator.getIdentifierAPI().find(contentletFolder).getPath(), destinationHost,user,false);
  					contentlet = contentletAPI.copyContentlet(contentlet, contentletDestFolder, user, respectFrontendRoles);
  				} else if (contentletHost != null) {
  					contentlet = contentletAPI.copyContentlet(contentlet, destinationHost, user, respectFrontendRoles);
  				} else {
  					contentlet = contentletAPI.copyContentlet(contentlet, user, respectFrontendRoles);
  				}
  
  				multiTree.setChild(contentlet.getIdentifier());
  			}
  		}
  
  		//Creating the new pages associations mapping with containers
  		List<MultiTree> newContentletAssociation = new LinkedList<MultiTree>();
  		if (copyMode != HTMLPageAPI.CopyMode.BLANK_HTMLPAGE) {
  			for (MultiTree multiTree : associatedSourceContentlets) {
  				String sourceContainerId = multiTree.getParent2();
  				String destinationContainerId = null;
  				for (int i = 0; i < reMapping.getContainersRemap().size(); i++) {
  					ContainerRemapTuple tuple = reMapping.getContainersRemap().get(i);
  					if(tuple.getSourceContainer().getIdentifier().equals(sourceContainerId)) {
  						destinationContainerId = tuple.getDestinationContainer().getIdentifier();
  					}
  				}
  				if(destinationContainerId != null) {
  					newContentletAssociation.add(new MultiTree("", destinationContainerId, multiTree.getChild()));
  				}
  			}
  		}
          newHTMLPage.setTemplateId(destinationTemplate.getIdentifier());
  		//Persisting the new page
  		if (isNew) {
  			// creates new identifier for this webasset and persists it
  			Identifier newIdentifier = com.dotmarketing.business.APILocator.getIdentifierAPI().createNew(newHTMLPage, destination);
  			
  			newHTMLPage.setIdentifier(newIdentifier.getInode());
  			
  			// persists the webasset
  			save(newHTMLPage);
  		} else {
  			saveHTMLPage(newHTMLPage, destinationTemplate, destination, user, respectFrontendRoles);
  		}
  		
  		if(source.isLive()){
  			APILocator.getVersionableAPI().setWorking(newHTMLPage);
  			APILocator.getVersionableAPI().setLive(newHTMLPage);
  		}
  		    
  
  		//Saving the new content mapping
  		if (copyMode != HTMLPageAPI.CopyMode.BLANK_HTMLPAGE) {
  			MultiTree newMultiTree;
  			for (MultiTree multiTree : newContentletAssociation) {
  				newMultiTree = new MultiTree(newHTMLPage.getIdentifier(), multiTree.getParent2(), multiTree.getChild());
  				MultiTreeFactory.saveMultiTree(newMultiTree);
  			}
  		}
  
  		// Copy permissions
  		permissionAPI.copyPermissions(source, newHTMLPage);
  
  		return newHTMLPage;
  	}
  
  	private List<MultiTree> getHTMLPageMultiTree(HTMLPage htmlPage) throws DotDataException {
  		return MultiTreeFactory.getMultiTree(identifierAPI.findFromInode(htmlPage.getIdentifier()));
  	}
  
  	@SuppressWarnings("unchecked")
  	public HTMLPage getWorkingHTMLPageByPageURL(String htmlPageURL, Folder folder) throws DotStateException, DotDataException, DotSecurityException {
  		HTMLPage ret = null;
  		if(folder != null && InodeUtils.isSet(folder.getInode())){
  			Host h = APILocator.getHostAPI().find(folder.getHostId(), APILocator.getUserAPI().getSystemUser(), true);
  			String p = folder.getPath();
  			if(UtilMethods.isSet(p)){
  				if(!p.startsWith("/")){
  					p = "/" + p;
  				}
  				if(!p.endsWith("/")){
  					p = p + "/";
  				}
  				Identifier i = APILocator.getIdentifierAPI().find(h, folder.getPath() + htmlPageURL);
  				if(i != null && InodeUtils.isSet(i.getId())){
  					ret = (HTMLPage)APILocator.getVersionableAPI().findWorkingVersion(i, APILocator.getUserAPI().getSystemUser(), true);
  				}
  			}
  		}
  		return ret;
  	}
  
  	@SuppressWarnings("unchecked")
  	protected String getCopyHTMLPageName(String htmlPageName, String fileExtension, Folder folder) throws DotStateException, DotDataException, DotSecurityException {
  		String result = new String(htmlPageName);
  
  		List<HTMLPage> htmlPages = APILocator.getFolderAPI().getHTMLPages(folder, APILocator.getUserAPI().getSystemUser(), false);
  
  		boolean isValidHTMLPageName = false;
  		String temp1, temp2;
  
  		for (; !isValidHTMLPageName;) {
  			isValidHTMLPageName = true;
  			temp1 = result + "." + fileExtension;
  
  			for (HTMLPage htmlPage : htmlPages) {
  				temp2 = UtilMethods.getFileName(htmlPage.getPageUrl()) + "."
  						+ UtilMethods.getFileExtension(htmlPage.getPageUrl());
  				if (temp2.equals(temp1)) {
  					isValidHTMLPageName = false;
  					break;
  				}
  			}
  
  			if (!isValidHTMLPageName)
  				result += "_copy";
  			else
  				result = temp1;
  		}
  
  		return result;
  	}
  
  	private void save(HTMLPage htmlPage) throws DotDataException, DotStateException, DotSecurityException {
  		htmlPageFactory.save(htmlPage);
  	}
  	
  	private void save(HTMLPage htmlPage, String existingInode) throws DotDataException, DotStateException, DotSecurityException {
          htmlPageFactory.save(htmlPage, existingInode);
      }
  
  	protected void save(WebAsset webAsset) throws DotDataException, DotStateException, DotSecurityException {
  		save((HTMLPage) webAsset);
  	}
  
  	protected static Template getHTMLPageTemplate(HTMLPage page) throws DotDataException, DotSecurityException {
  		return APILocator.getTemplateAPI().findWorkingTemplate(page.getTemplateId(), APILocator.getUserAPI().getSystemUser(), false);
  	}
  
  
  	public HTMLPage saveHTMLPage(HTMLPage newHtmlPage, Template template, Folder parentFolder, User user,
  			boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
  		HTMLPage existingHTMLPage = getWorkingHTMLPageByPageURL(newHtmlPage.getPageUrl(), parentFolder);
  
  		boolean pageExists = (existingHTMLPage != null) && InodeUtils.isSet(existingHTMLPage.getInode());
  
  		if (pageExists) {
  			if (!permissionAPI.doesUserHavePermission(existingHTMLPage, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
  				throw new DotSecurityException("You don't have permission to read the source file.");
  			}
  		}
  
  		if (!permissionAPI.doesUserHavePermission(template, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
  			throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
  		}
  
  		if (!permissionAPI.doesUserHavePermission(parentFolder, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles)) {
  			throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
  		}
  
  		try {
  		    newHtmlPage.setModUser(user.getUserId());
  		    newHtmlPage.setModDate(new Date());
  		    
  			boolean previousShowMenu = false;
  
  			// parent identifier for this file
  			Identifier identifier = null;
  
  			if (pageExists) {
  				previousShowMenu = existingHTMLPage.isShowOnMenu();
  				identifier = (Identifier) APILocator.getIdentifierAPI().find(existingHTMLPage);
  			}
  
  			// Some checks
  
  			// Get asset host based on the parentFolder of the asset
  			Host host = hostAPI.findParentHost(parentFolder, user, false);
  
  			// get an identifier based on this new uri
  			Identifier testIdentifier = (Identifier) APILocator.getIdentifierAPI().find(host, newHtmlPage.getURI(parentFolder));
  			
  			// if this is a new htmlpage and there is already an identifier with
  			// this uri, return
  			if ((existingHTMLPage != null) && !InodeUtils.isSet(existingHTMLPage.getInode()) && InodeUtils.isSet(testIdentifier.getInode())) {
  				existingHTMLPage.setParent(parentFolder.getInode());
  				throw new DotDataException("Another page with the same page url exists in this folder");
  			}
  			// if this is an existing htmlpage and there is already an
  			// identifier
  			// with this uri, return
  			else if (pageExists
  					&& (!testIdentifier.getInode().equalsIgnoreCase(identifier.getInode()))
  					&& InodeUtils.isSet(testIdentifier.getInode())) {
  				// when there is an error saving should unlock working asset
  				unLockAsset(existingHTMLPage);
  				throw new DotDataException("Another page with the same page url exists in this folder");
  			}
  			if (template != null) {
  				// Adds template children from selected box
  				Identifier templateIdentifier = APILocator.getIdentifierAPI().find(template);
  
  				newHtmlPage.setTemplateId(templateIdentifier.getInode());
  			}
  			
  			boolean existingIdentifier=false;
  			Identifier currentIdentifier=null;
  			if(UtilMethods.isSet(newHtmlPage.getIdentifier())) {
  			    currentIdentifier=APILocator.getIdentifierAPI().find(newHtmlPage.getIdentifier());
  			    existingIdentifier = currentIdentifier==null || !UtilMethods.isSet(currentIdentifier.getId());
  			}
  			
  			boolean existingInode=false;
              if(InodeUtils.isSet(newHtmlPage.getInode())) {
                  try {
                      HTMLPage existing=(HTMLPage) HibernateUtil.load(HTMLPage.class, newHtmlPage.getInode());
                      existingInode= existing==null || !UtilMethods.isSet(existing.getInode());
                  } catch (Exception ex) {
                      existingInode=true;
                  }
              }
  			
  			// Versioning
  			if (pageExists) {
  				// Creation the version asset
  			    
  			    newHtmlPage.setIdentifier(identifier.getId());
  			    
  			    if(existingInode)
  			        save(newHtmlPage,newHtmlPage.getInode());
  			    else
  			        save(newHtmlPage);
  			    APILocator.getVersionableAPI().setWorking(newHtmlPage);
  			    
  				createAsset(newHtmlPage, user.getUserId(), parentFolder, identifier, false);
  				HibernateUtil.flush();
  
  				LiveCache.removeAssetFromCache(existingHTMLPage);
  				APILocator.getVersionableAPI().setWorking(newHtmlPage);
  
  				// if we need to update the identifier
  				if (InodeUtils.isSet(parentFolder.getInode())
  						&& !newHtmlPage.getURI(parentFolder).equals(identifier.getURI())) {
  
  					// assets cache
  					LiveCache.removeAssetFromCache(newHtmlPage);
  					LiveCache.removeAssetFromCache(existingHTMLPage);
  					LiveCache.clearCache(host.getIdentifier());
  					WorkingCache.removeAssetFromCache(newHtmlPage);
  
  					CacheLocator.getIdentifierCache().removeFromCacheByVersionable(newHtmlPage);
  
  					CacheLocator.getIdentifierCache().removeFromCacheByVersionable(existingHTMLPage);
  
  
  					APILocator.getIdentifierAPI().updateIdentifierURI(newHtmlPage, parentFolder);
  
  				}
  
  			} // Creating the new page
  			else {
  			    Identifier ident= (currentIdentifier!=null && UtilMethods.isSet(currentIdentifier.getId())) ?
  			                           currentIdentifier : 
  			                 (existingIdentifier ? 
  			                        APILocator.getIdentifierAPI().createNew(newHtmlPage, parentFolder, newHtmlPage.getIdentifier()) :
  			                        APILocator.getIdentifierAPI().createNew(newHtmlPage, parentFolder));
  			    ident=APILocator.getIdentifierAPI().save(ident);
  			    
  			    newHtmlPage.setIdentifier(ident.getId());
  			    if(existingInode)
  			        save(newHtmlPage, newHtmlPage.getInode());
  			    else
  			        save(newHtmlPage);
  				
  			}
  
  
  
  			HibernateUtil.flush();
  			HibernateUtil.getSession().refresh(newHtmlPage);
  
  			// Refreshing the menues
  			if (previousShowMenu != newHtmlPage.isShowOnMenu()) {
  				// existing folder with different show on menu ... need to
  				// regenerate menu
  				//RefreshMenus.deleteMenus();
  				RefreshMenus.deleteMenu(newHtmlPage);
  				CacheLocator.getNavToolCache().removeNav(parentFolder.getHostId(), parentFolder.getInode());
  			}
  		} catch (Exception e) {
  			throw new DotRuntimeException(e.getMessage(), e);
  		}
  
  		return newHtmlPage;
  	}
  
  	/**
  	 *
  	 * @param path
  	 * @param host
  	 * @return HTMLPage from a path on a given host
  	 * @throws DotSecurityException
  	 * @throws DotDataException
  	 */
  	public HTMLPage loadPageByPath(String path, Host host) throws DotDataException, DotSecurityException {
  		return loadPageByPath(path, host.getIdentifier());
  	}
  
  	/**
  	 *
  	 * @param path
  	 * @param host
  	 * @return HTMLPage from a path on a given hostId
  	 * @throws DotSecurityException
  	 * @throws DotDataException
  	 */
  	public HTMLPage loadPageByPath(String path, String hostId) throws DotDataException, DotSecurityException {
  		return htmlPageFactory.getLiveHTMLPageByPath(path, hostId);
  	}
  
  	/**
  	 *
  	 * @param page
  	 * @param container
  	 * @return true/false on whether or not a Page has content with a specificed
  	 *         container
  	 */
  	public boolean hasContent(HTMLPage page, Container container) {
  		return htmlPageFactory.findNumOfContent(page, container) > 0 ? true : false;
  	}
  
  	/**
  	 * Use to method to get the template for the HTMLPage set on the API. This
  	 * method will hit the database.
  	 *
  	 * @return Template for the working version of a HTMLPage
  	 * @throws DotSecurityException 
  	 * @throws DotDataException 
  	 * @throws DotStateException 
  	 */
  	public Template getTemplateForWorkingHTMLPage(HTMLPage htmlpage) throws DotStateException, DotDataException, DotSecurityException {
  		return (Template) APILocator.getVersionableAPI().findWorkingVersion(htmlpage.getTemplateId(),APILocator.getUserAPI().getSystemUser(), false);
  
  	}
  
  	/**
  	 *
  	 * @param folder
  	 *            to get HTMLPages for
  	 * @return a List of all live HTMLPages
  	 * @throws DotDataException
  	 * @throws DotStateException
  	 * @throws DotSecurityException
  	 */
  	@SuppressWarnings({ "deprecation", "unchecked" })
  	public List<HTMLPage> findLiveHTMLPages(Folder folder) throws DotStateException, DotDataException, DotSecurityException {
  		return APILocator.getFolderAPI().getLiveHTMLPages(folder, APILocator.getUserAPI().getSystemUser(),false);
  	}
  
  	/**
  	 *
  	 * @param folder
  	 *            to get HTMLPages for
  	 * @return a List of all live HTMLPages
  	 * @throws DotDataException
  	 * @throws DotStateException
  	 * @throws DotSecurityException
  	 */
  	@SuppressWarnings("unchecked")
  	public List<HTMLPage> findWorkingHTMLPages(Folder folder) throws DotStateException, DotDataException, DotSecurityException {
  		return APILocator.getFolderAPI().getWorkingHTMLPages(folder,APILocator.getUserAPI().getSystemUser(),false);
  	}
  
  	public Folder getParentFolder(HTMLPage object) throws DotIdentifierStateException, DotDataException, DotSecurityException {
  		return htmlPageFactory.getParentFolder(object);
  	}
  
  	public Host getParentHost(HTMLPage object) throws DotIdentifierStateException, DotDataException, DotSecurityException {
  		return htmlPageFactory.getParentHost(object);
  	}
  
  	public boolean delete(HTMLPage htmlPage, User user, boolean respectFrontendRoles) throws DotSecurityException, Exception {
  		if(permissionAPI.doesUserHavePermission(htmlPage, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles)) {
  			return deleteAsset(htmlPage);
  		} else {
  			throw new DotSecurityException(WebKeys.USER_PERMISSIONS_EXCEPTION);
  		}
  	}
  
  	public List<Map<String, Serializable>> DBSearch(Query query, User user,boolean respectFrontendRoles) throws ValidationException,DotDataException {
  
  		Map<String, String> dbColToObjectAttribute = new HashMap<String, String>();
  
  		if(UtilMethods.isSet(query.getSelectAttributes())){
  
  			if(!query.getSelectAttributes().contains("title")){
  				query.getSelectAttributes().add("title" + " as " + QueryResult.CMIS_TITLE);
  			}
  		}else{
  			List<String> atts = new ArrayList<String>();
  			atts.add("*");
  			atts.add("title" + " as " + QueryResult.CMIS_TITLE);
  			query.setSelectAttributes(atts);
  		}
  
  		return QueryUtil.DBSearch(query, dbColToObjectAttribute, null, user, true, respectFrontendRoles);
  	}
  
  	public String getHTML(HTMLPage htmlPage, String userAgent) throws DotStateException, DotDataException, DotSecurityException {
  
  		return getHTML(htmlPage, true, null, userAgent);
  	}
  	public String getHTML(HTMLPage htmlPage, boolean liveMode, String userAgent) throws DotStateException, DotDataException, DotSecurityException {
  
  