private static Book findBookByContentRoot(ServletContext servletContext, PageRef pageRef) { for(Book book : SemanticCMS.getInstance(servletContext).getBooks().values()) { if(book.getContentRoot().equals(pageRef)) { return book; } } return null; }
/** * Gets the book for the provided context-relative servlet path or <code>null</code> if no book configured at that path. * The book with the longest prefix match is used. * The servlet path must begin with a slash (/). */ public Book getBook(String servletPath) { if(servletPath.charAt(0) != '/') throw new IllegalArgumentException("Invalid servletPath: " + servletPath); Book longestPrefixBook = null; int longestPrefixLen = -1; for(Book book : getBooks().values()) { String prefix = book.getPathPrefix(); int prefixLen = prefix.length(); if( prefixLen > longestPrefixLen && servletPath.startsWith(prefix) ) { longestPrefixBook = book; longestPrefixLen = prefixLen; } } return longestPrefixBook; }
/** * Gets the canonical base URL, not including any trailing slash, such as * <code>https://example.com</code> * This is configured in the book via the "canonicalBase" setting. * <p> * TODO: Create central per-request warnings list that could be reported during development mode, include this warning on requests. * TODO: Also could use that for broken link detection instead of throwing exceptions. * </p> */ public static String getCanonicalBase(ServletContext servletContext, HttpServletRequest request, Book book) throws MalformedURLException { String canonicalBase = book.getCanonicalBase(); if(canonicalBase == null) { String autoCanonical = ServletUtil.getAbsoluteURL(request, book.getPathPrefix()); if( // Logger checked first, so if warnings enabled mid-run, will get first warning still logger.isLoggable(Level.WARNING) ) { String bookName = book.getName(); String warningAttribute = CANONICAL_BASE_WARNED_ATTRIBUTE + bookName; if(servletContext.getAttribute(warningAttribute) == null) { servletContext.setAttribute(warningAttribute, true); logger.warning("Using generated canonical base URL, please configure the \"canonicalBase\" setting in the \"" + bookName + "\" book: " + autoCanonical); } } return autoCanonical; } else { return canonicalBase; } }
Map<String,String> bookParams = book.getParam(); View view = findNewsView(semanticCMS); List<News> rssNews = findNews( ServletUtil.getAbsoluteURL( req, resp.encodeURL(book.getPathPrefix() + imageUrl), textInXhtmlEncoder, out
for(ParentRef parentRef : page.getParentRefs()) { PageRef parentPageRef = parentRef.getPageRef(); if(book.equals(parentPageRef.getBook())) { if(pageAllowRobots == null) pageAllowRobots = book.getAllowRobots();
for(ParentRef parentRef : page.getParentRefs()) { PageRef parentPageRef = parentRef.getPageRef(); if(book.equals(parentPageRef.getBook())) { if(pageAuthors == null) pageAuthors = book.getAuthors();
for(ParentRef parentRef : page.getParentRefs()) { PageRef parentPageRef = parentRef.getPageRef(); if(book.equals(parentPageRef.getBook())) { Copyright bookCopyright = book.getCopyright(); if(pageRightsHolder==null) { if(parentsRightsHolder == null) {
@Override public String getTitle( ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, Page page ) { return page.getTitle() + TITLE_SEPARATOR + page.getPageRef().getBook().getTitle(); }
out.write(" onclick=\""); encodeJavaScriptInXhtmlAttribute("semanticcms_openfile_servlet.openFile(\"", out); NewEncodingUtils.encodeTextInJavaScriptInXhtmlAttribute(pageRef.getBook().getName(), out); encodeJavaScriptInXhtmlAttribute("\", \"", out); NewEncodingUtils.encodeTextInJavaScriptInXhtmlAttribute(pageRef.getPath(), out);
new Book( name, bookElem.getAttribute("cvsworkDirectory"),
/** * Gets the page title for the view on the given page. * * Defaults to: "view.display - page.title[ - page.pageRef.book.title]" */ public String getTitle( ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, Page page ) { String bookTitle = page.getPageRef().getBook().getTitle(); if(bookTitle != null && !bookTitle.isEmpty()) { return getDisplay() + TITLE_SEPARATOR + page.getTitle() + TITLE_SEPARATOR + bookTitle; } else { return getDisplay() + TITLE_SEPARATOR + page.getTitle(); } }
if(!newPageRef.getBook().equals(pageRef.getBook())) { throw new ServletException( "Page may not move itself into a different book. pageRef="
/** * Finds the path to the current page. * The current page must be in a Book. */ public static PageRef getCurrentPageRef(ServletContext servletContext, HttpServletRequest request) throws ServletException { String pagePath = Dispatcher.getCurrentPagePath(request); Book book = SemanticCMS.getInstance(servletContext).getBook(pagePath); if(book == null) throw new ServletException("Book not found for pagePath: " + pagePath); String bookPrefix = book.getPathPrefix(); if(!pagePath.startsWith(bookPrefix)) throw new AssertionError(); return new PageRef(book, pagePath.substring(bookPrefix.length())); }
resp, book, book.getContentRoot(), new HashSet<PageRef>(), out
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.reset(); resp.setContentType(CONTENT_TYPE); resp.setCharacterEncoding(ENCODING); PrintWriter out = resp.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>"); out.println("<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); for(Book book : SemanticCMS.getInstance(getServletContext()).getBooks().values()) { out.println(" <sitemap>"); out.print(" <loc>"); ServletUtil.getAbsoluteURL( req, resp.encodeURL(book.getPathPrefix() + SiteMapServlet.SERVLET_PATH), textInXhtmlEncoder, out ); out.println("</loc>"); out.println(" </sitemap>"); } out.println("</sitemapindex>"); } }
&& position == ComponentPosition.HEAD_END ) { PageRef contentRoot = SemanticCMS.getInstance(servletContext).getRootBook().getContentRoot();
@Override public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException { ServletRegistration.Dynamic registration = servletContext.addServlet( SiteMapServlet.class.getName(), SiteMapServlet.class ); for(Book book : SemanticCMS.getInstance(servletContext).getBooks().values()) { registration.addMapping(book.getPathPrefix() + SiteMapServlet.SERVLET_PATH); } } }
public static Page captureContentRoot(String level) throws ServletException, IOException { ServletContext servletContext = getServletContext(); return CapturePage.capturePage( servletContext, getRequest(), getResponse(), SemanticCMS.getInstance(servletContext).getRootBook().getContentRoot(), CaptureLevel.valueOf(level.toUpperCase(Locale.ROOT)) ); }
pageRef = new PageRef( book, combinedPath.substring(book.getPathPrefix().length()) );