<commit_before>// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.responders;

import fitnesse.wiki.WikiPage;
import fitnesse.authentication.SecureOperation;
import fitnesse.authentication.SecureReadOperation;
import org.json.JSONArray;
import util.StringUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class NameWikiPageResponder extends BasicWikiPageResponder {
  protected String contentFrom(WikiPage requestedPage) {
    List<String> lines = addLines(requestedPage);

    String format = (String) request.getInput("format");
    if ("json".equalsIgnoreCase(format)) {
      JSONArray jsonPages = new JSONArray(lines);
      return jsonPages.toString();
    }
    return StringUtil.join(lines, System.getProperty("line.separator"));
  }

  private List<String> addLines(WikiPage requestedPage) {
    List<String> lines = new ArrayList<String>();
    for (Iterator<?> iterator = requestedPage.getChildren().iterator(); iterator.hasNext();) {
      WikiPage child = (WikiPage) iterator.next();
      lines.add(makeLine(child));
    }
    return lines;
  }

  private String makeLine(WikiPage child) {
    String line;
    if (request.hasInput("ShowChildCount")) {
      int numberOfChildren = child.getChildren().size();
      line = child.getName() + " " + numberOfChildren;
    } else
      line = child.getName();
    return line;
  }

  protected String getContentType() {
    return "text/plain";
  }

  @Override
  public SecureOperation getSecureOperation() {
    return new SecureReadOperation();
  }
}
<commit_msg>enhance "names" request with optional "Recursive", "LeafOnly", and "ShowTags" parameters<commit_after>// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.responders;

import fitnesse.wiki.WikiPage;
import fitnesse.wiki.PageData;
import fitnesse.authentication.SecureOperation;
import fitnesse.authentication.SecureReadOperation;
import org.json.JSONArray;
import util.StringUtil;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class NameWikiPageResponder extends BasicWikiPageResponder {
  protected String contentFrom(WikiPage requestedPage) {
    List<String> lines = addLines(requestedPage, "");

    String format = (String) request.getInput("format");
    if ("json".equalsIgnoreCase(format)) {
      JSONArray jsonPages = new JSONArray(lines);
      return jsonPages.toString();
    }
    return StringUtil.join(lines, System.getProperty("line.separator"));
  }

  private List<String> addLines(WikiPage requestedPage, String prefix) {
    List<String> lines = new ArrayList<String>();
	
    for (WikiPage child : requestedPage.getChildren()) {
	  if(!request.hasInput("LeafOnly") || child.getChildren().isEmpty()) {
        lines.add(makeLine(child, prefix));
      }
	  
	  if (request.hasInput("Recursive")) {
	    lines.addAll(addLines(child, prefix + child.getName() + "."));
	  }
    }
	
    return lines;
  }

  private String makeLine(WikiPage child, String prefix) {
    int numberOfChildren = child.getChildren().size();
	
    String line = prefix + child.getName();
	
    if (request.hasInput("ShowChildCount")) {
      line += " " + numberOfChildren;
    }
	
    if (request.hasInput("ShowTags")) {
	  Set<String> tags = getTags(child);
	  if(!tags.isEmpty()) {
	    line += " ";
		for(String tag : tags) {
          line += "[" + tag + "]";
		}
      }
	}
	
    return line;
  }
  
  private Set<String> getTags(WikiPage page) {
    Set<String> result = new TreeSet<String>();
	
	// get the tags of the given page
    String tags = page.getData().getAttribute(PageData.PropertySUITES);
    if((tags != null) && !tags.isEmpty()) {
	  result.addAll(Arrays.asList(tags.split(", ")));
    }
	
	// recusrively collect all tags up to the root
	if(!page.isRoot()) {
	  result.addAll(getTags(page.getParent()));
	}
	
	return result;
  }

  protected String getContentType() {
    return "text/plain";
  }

  @Override
  public SecureOperation getSecureOperation() {
    return new SecureReadOperation();
  }
}

{'fraction_non_alphanumeric': 0.1255781683626272, 'fraction_numerical': 0.004625346901017576, 'mean_word_length': 3.898074745186863, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1455327', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1286, 'n_words': 306}