<commit_before>//
//  SiteMapServlet.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 22 Jul 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import com.willshex.blogwt.server.helper.ServletHelper;
import com.willshex.blogwt.server.service.page.PageServiceProvider;
import com.willshex.blogwt.server.service.post.PostServiceProvider;
import com.willshex.blogwt.server.service.tag.TagServiceProvider;
import com.willshex.blogwt.shared.api.Pager;
import com.willshex.blogwt.shared.api.SortDirectionType;
import com.willshex.blogwt.shared.api.datatype.Page;
import com.willshex.blogwt.shared.api.datatype.Post;
import com.willshex.blogwt.shared.api.datatype.PostSortType;
import com.willshex.blogwt.shared.api.datatype.Tag;
import com.willshex.blogwt.shared.helper.PagerHelper;
import com.willshex.blogwt.shared.page.PageType;
import com.willshex.service.ContextAwareServlet;

/**
 * @author <NAME> (billy1380)
 *
 */
public class SiteMapServlet extends ContextAwareServlet {

	private static final long serialVersionUID = 3133978953838954164L;
	private static final String MIME_TYPE = "application/xml; charset=UTF-8";
	private static final String LOC_FORMAT = "    <url><loc>%s/%s</loc></url>";

	/* (non-Javadoc)
	 * 
	 * @see com.willshex.service.ContextAwareServlet#doGet() */
	@Override
	protected void doGet () throws ServletException, IOException {
		super.doGet();

		String url = ServletHelper.constructBaseUrl(REQUEST.get());

		HttpServletResponse response = RESPONSE.get();
		PrintWriter p = response.getWriter();

		response.setContentType(MIME_TYPE);

		p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		p.println("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");

		//printRoot(p, url);
		printPages(p, url);
		printBlog(p, url);
		printPosts(p, url);
		printTags(p, url);

		p.println("</urlset>");

		p.close();
	}

	protected void doPost () throws ServletException, IOException {
		doGet();
	}

//	private void printRoot (PrintWriter p, String url) {
//		p.println(String.format(LOC_FORMAT, url, ""));
//	}

	private void printBlog (PrintWriter p, String url) {
		p.println(String.format(LOC_FORMAT, url,
				"#" + PageType.PostsPageType.asTargetHistoryToken()));
	}<commit_msg>added root back but with #!<commit_after>//
//  SiteMapServlet.java
//  blogwt
//
//  Created by <NAME> (billy1380) on 22 Jul 2015.
//  Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import com.willshex.blogwt.server.helper.ServletHelper;
import com.willshex.blogwt.server.service.page.PageServiceProvider;
import com.willshex.blogwt.server.service.post.PostServiceProvider;
import com.willshex.blogwt.server.service.tag.TagServiceProvider;
import com.willshex.blogwt.shared.api.Pager;
import com.willshex.blogwt.shared.api.SortDirectionType;
import com.willshex.blogwt.shared.api.datatype.Page;
import com.willshex.blogwt.shared.api.datatype.Post;
import com.willshex.blogwt.shared.api.datatype.PostSortType;
import com.willshex.blogwt.shared.api.datatype.Tag;
import com.willshex.blogwt.shared.helper.PagerHelper;
import com.willshex.blogwt.shared.page.PageType;
import com.willshex.service.ContextAwareServlet;

/**
 * @author <NAME> (billy1380)
 *
 */
public class SiteMapServlet extends ContextAwareServlet {

	private static final long serialVersionUID = 3133978953838954164L;
	private static final String MIME_TYPE = "application/xml; charset=UTF-8";
	private static final String LOC_FORMAT = "    <url><loc>%s/%s</loc></url>";

	/* (non-Javadoc)
	 * 
	 * @see com.willshex.service.ContextAwareServlet#doGet() */
	@Override
	protected void doGet () throws ServletException, IOException {
		super.doGet();

		String url = ServletHelper.constructBaseUrl(REQUEST.get());

		HttpServletResponse response = RESPONSE.get();
		PrintWriter p = response.getWriter();

		response.setContentType(MIME_TYPE);

		p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		p.println("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");

		printRoot(p, url);
		printPages(p, url);
		printBlog(p, url);
		printPosts(p, url);
		printTags(p, url);

		p.println("</urlset>");

		p.close();
	}

	protected void doPost () throws ServletException, IOException {
		doGet();
	}

	private void printRoot (PrintWriter p, String url) {
		p.println(String.format(LOC_FORMAT, url, "#!"));
	}

	private void printBlog (PrintWriter p, String url) {
		p.println(String.format(LOC_FORMAT, url,
				"#" + PageType.PostsPageType.asTargetHistoryToken()));
	}
{'fraction_non_alphanumeric': 0.14093686354378818, 'fraction_numerical': 0.017515274949083504, 'mean_word_length': 4.860381861575179, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 2, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2494790', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1644, 'n_words': 301}