cmdPage function

bool cmdPage (
  1. Map ctx
)

performs page command ctx is zaart context map

Implementation

bool cmdPage(Map ctx) {
  bool _isInitializedFlag;
  try {
    _isInitializedFlag = isInitialized(ctx);
  } catch (err) {
    Logger.root.severe(err.toString());
    return false;
  }

  if (!_isInitializedFlag) {
    return false;
  }

  var cmd = ctx["cmd-page"];

  if (cmd.isEmpty) {
    print("oh no, i faced an internal error!");
    Logger.root
        .severe('"cmd-page" is missing from context in cmdPage() function');
    return false;
  }

  String fun = cmd["fun"];
  String page = cmd["name"];
  String layout = cmd["layout"];
  var configFileName = ctx["config"];

  if (null == fun) {
    print("oh no, i faced an internal error!");
    Logger.root.severe(
        '"fun" key is missing from "cmd-page" map in cmdPage() function');
    return false;
  }

  if (null == page) {
    print("oh no, i faced an internal error!");
    Logger.root.severe(
        '"page" key is missing from "cmd-page" map in cmdPage() function');
    return false;
  }

  if (null == configFileName) {
    print("oh no, i faced an internal error!");
    Logger.root.severe(
        '"config" key is missing from "cmd-page" map in cmdPage() function');
    return false;
  }

  String parent;

  if (page.contains('\\')) {
    page = page.replaceAll('\\', '/');
  }

  if (page.contains('/')) {
    var arr = page.split('/');
    if (arr.length > 2) {
      print("oops, you can only have at most 1 level of depth in page name");
      print("for example: [page] or [page]/[child]");
      Logger.root.warning('page name $page is not acceptable');
      return false;
    }
    parent = arr[0];
    page = arr[1];
  } else {
    parent = null;
  }

  Config config = readConfig(configFileName);

  switch (fun) {
    case "add":
      return _funAdd(config, configFileName, page, parent, layout);
      break;
    case "del":
      return _funDel(config, configFileName, page, parent);
      break;
    default:
      return false;
  }
}