Create a category tree.
975007
def run(self):
        """"""
        config = self.state.document.settings.env.config

        # Group processes by category
        processes = get_processes(config.autoprocess_process_dir, config.autoprocess_source_base_url)
        processes.sort(key=itemgetter('category'))
        categorized_processes = {k: list(g) for k, g in groupby(processes, itemgetter('category'))}

        # Build category tree
        category_sections = {'': nodes.container(ids=['categories'])}
        top_categories = []

        for category in sorted(categorized_processes.keys()):
            category_path = ''

            for category_node in category.split(':'):
                parent_category_path = category_path
                category_path += '{}:'.format(category_node)

                if category_path in category_sections:
                    continue

                category_name = category_node.capitalize()

                section = nodes.section(ids=['category-' + category_node])
                section += nodes.title(category_name, category_name)

                # Add process list
                category_key = category_path[:-1]
                if category_key in categorized_processes:
                    listnode = nodes.bullet_list()
                    section += listnode

                    for process in categorized_processes[category_key]:
                        par = nodes.paragraph()

                        node = nodes.reference('', process['name'], internal=True)
                        node['refuri'] = config.autoprocess_definitions_uri + '#process-' + process['slug']
                        node['reftitle'] = process['name']

                        par += node
                        listnode += nodes.list_item('', par)

                category_sections[parent_category_path] += section
                category_sections[category_path] = section

                if parent_category_path == '':
                    top_categories.append(section)

        # Return top sections only
        return top_categories
235528
def set_categories(self):
        """"""
        self.categories = []
        temp_categories = self.soup.findAll('category')
        for category in temp_categories:
            category_text = category.string
            self.categories.append(category_text)
1247793
protected void buildJsonCategoryList() {

        CmsCategoryService catService = CmsCategoryService.getInstance();
        List<CmsCategory> foundCategories = Collections.emptyList();
        String editedResource = null;
        if (CmsStringUtil.isNotEmpty(getParamResource())) {
            editedResource = getParamResource();
        }
        try {
            foundCategories = catService.readCategories(getCms(), "", true, editedResource);
        } catch (CmsException e) {
            // error reading categories
        }

        // the next lines sort the categories according to their path
        Map<String, CmsCategory> sorted = new TreeMap<String, CmsCategory>();

        Iterator<CmsCategory> i = foundCategories.iterator();
        while (i.hasNext()) {
            CmsCategory category = i.next();
            String categoryPath = category.getPath();
            if (sorted.get(categoryPath) != null) {
                continue;
            }
            sorted.put(categoryPath, category);
        }

        foundCategories = new ArrayList<CmsCategory>(sorted.values());
        JSONArray categories = new JSONArray();
        i = foundCategories.iterator();
        while (i.hasNext()) {
            CmsCategory cat = i.next();

            JSONObject jsonObj = new JSONObject();
            try {
                // 1: category title
                jsonObj.put("title", cat.getTitle());
                // 2: category path
                jsonObj.put("path", cat.getPath());
                // 3: category root path
                jsonObj.put("rootpath", cat.getRootPath());
                // 4 category level
                jsonObj.put("level", CmsResource.getPathLevel(cat.getPath()));
                // 4: active flag
                jsonObj.put("active", false);
                categories.put(jsonObj);
            } catch (JSONException e) {
                // TODO: error handling
            }
        }
        JspWriter out = getJsp().getJspContext().getOut();
        try {
            out.print(categories.toString());
        } catch (IOException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }

    }
324246
function() {
        // Initialize category filters
        this._categoryFilters = [];
        var aInitialCategories = Logger.categories;

        for(var j=0; j < aInitialCategories.length; j++) {
            var sCategory = aInitialCategories[j];

            // Add category to the internal array of filters
            this._categoryFilters.push(sCategory);

            // Add checkbox element if UI is enabled
            if(this._elCategoryFilters) {
                this._createCategoryCheckbox(sCategory);
            }
        }
    }
173263
def as_tree(context):
    """"""

    tree = _build_tree(context, 2, 1)
    if type(tree) == dict:
        tree = [tree] 
    
    return Response(content_type='application/json', body=json.dumps(tree))
628568
def create_category(self, category):
        
        content = self._serialize.body(category, 'ExtensionCategory')
        response = self._send(http_method='POST',
                              location_id='476531a3-7024-4516-a76a-ed64d3008ad6',
                              version='5.1-preview.1',
                              content=content)
        return self._deserialize('ExtensionCategory', response)
1196165
private static void displayCategories(List<CategoryNode> categories, String prefix) {
    for (CategoryNode category : categories) {
      System.out.printf("%s%s [%s]%n", prefix, category.name, category.id);
      displayCategories(category.children, String.format("%s%s > ", prefix, category.name));
    }
  }
1371005
public function sort_categories() {
        $this->attach_nodes_to_categories();
        $tempcategories = array();
        foreach ($this->categories as $category) {
            $after = $category->after;
            if ($after == null) {
                // Can go anywhere in the tree.
                $category->sort_nodes();
                $tempcategories = array_merge($tempcategories, array($category->name => $category),
                        $this->find_categories_after($category));
            }
        }
        if (count($tempcategories) !== count($this->categories)) {
            // Orphan categories found.
            throw new \coding_exception('Some of the categories specified contains invalid \'after\' property');
        }
        $this->categories = $tempcategories;
    }
1340339
private CmsTreeItem buildTreeItem(CmsCategoryTreeEntry category, Collection<String> selectedCategories) {

        // generate the widget that should be shown in the list
        CmsDataValue dataValue = new CmsDataValue(
            600,
            3,
            CmsCategoryBean.SMALL_ICON_CLASSES,
            true,
            category.getTitle(),
            "rtl:" + category.getPath(),
            "hide:" + category.getSitePath());

        // create the check box for this item
        CmsCheckBox checkBox = new CmsCheckBox();
        // if it has to be selected, select it
        boolean isPartofPath = false;
        Iterator<String> it = selectedCategories.iterator();
        while (it.hasNext()) {
            String path = it.next();
            if (path.startsWith(category.getPath()) || path.contains("/" + category.getPath())) {
                isPartofPath = true;
            }
        }
        if (isPartofPath) {
            checkBox.setChecked(true);
        }
        if (!isEnabled()) {
            checkBox.disable(m_disabledReason);
        }
        if (category.getPath().isEmpty()) {
            checkBox.setVisible(false);
        }
        // bild the CmsTreeItem out of the widget and the check box
        CmsTreeItem treeItem = new CmsTreeItem(true, checkBox, dataValue);
        // abb the handler to the check box
        dataValue.addClickHandler(new DataValueClickHander(treeItem));

        checkBox.addValueChangeHandler(new CheckBoxValueChangeHandler(treeItem));

        // set the right style for the small view
        treeItem.setSmallView(true);
        treeItem.setId(category.getPath());
        // add it to the list of all categories
        m_categories.put(treeItem.getId(), treeItem);
        return treeItem;
    }
936235
function createCategories() {
    $cnt = count( $this->categories );
    if( 0 >= $cnt )
      return;
    $output = null;
    foreach( $this->categories as $category ) {
      $attributes = $this->_createParams( $category['params'], array( 'LANGUAGE' ));
      if( is_array( $category['value'] )) {
        foreach( $category['value'] as $cix => $categoryPart )
          $category['value'][$cix] = $this->_strrep( $categoryPart );
        $content  = implode( ',', $category['value'] );
      }
      else
        $content  = $this->_strrep( $category['value'] );
      $output    .= $this->_createElement( 'CATEGORIES', $attributes, $content );
    }
    return $output;
  }
1156582
protected function attach_nodes_to_categories() {
        foreach ($this->nodes as $node) {
            $parentcat = $node->parentcat;
            if (!isset($this->categories[$parentcat])) {
                throw new \coding_exception("Category $parentcat doesn't exist");
            } else {
                $this->categories[$parentcat]->add_node($node);
            }
        }
    }
728743
def validate_categories(categories):
        """"""
        if not set(categories) <= Source.categories:
            invalid = list(set(categories) - Source.categories)
            raise ValueError('Invalid categories: %s' % invalid)
784291
def build_tree(self):
        """"""
        for m in listdir(self.path):
            abs_m = join(self.path, m)
            if isfile(abs_m) and m.endswith('.py'):
                name = splitext(m)[0]
                if not self.limit_to or name in self.limit_to:
                    self.modules.append(Module(name, abs_m, self.dsm, self))
            elif isdir(abs_m):
                if isfile(join(abs_m, '__init__.py')) or not self.enforce_init:
                    heads, new_limit_to = self.split_limits_heads()
                    if not heads or m in heads:
                        self.packages.append(
                            Package(m, abs_m, self.dsm, self, new_limit_to,
                                    build_tree=True,
                                    build_dependencies=False,
                                    enforce_init=self.enforce_init))
680090
def _create_intermediate_nodes(self, name):
        """"""
        hierarchy = self._split_node_name(name, self.root_name)
        node_tree = [
            self.root_name
            + self._node_separator
            + self._node_separator.join(hierarchy[: num + 1])
            for num in range(len(hierarchy))
        ]
        iobj = [
            (child[: child.rfind(self._node_separator)], child)
            for child in node_tree
            if child not in self._db
        ]
        for parent, child in iobj:
            self._db[child] = {"parent": parent, "children": [], "data": []}
            self._db[parent]["children"] = sorted(
                self._db[parent]["children"] + [child]
            )
91884
private void createNodes(DefaultMutableTreeNode top) {

    // categories
    DefaultMutableTreeNode category = null;
    // leaves
    DefaultMutableTreeNode defaultMutableTreeNode = null;

    // PCB Files
    category = new DefaultMutableTreeNode("PCB Images");
    top.add(category);

    long count = PCBDAO.selectCount();
    for (int i = 1; i <= count; i++) {
      PCB pcb = PCBDAO.selectSingle(i);
      defaultMutableTreeNode = new DefaultMutableTreeNode(pcb);
      category.add(defaultMutableTreeNode);
    }
  }
599189
private static CmsCategoryTreeEntry findCategory(List<CmsCategoryTreeEntry> tree, String path) {

        if (path == null) {
            return null;
        }
        // we assume that the category to find is descendant of tree
        List<CmsCategoryTreeEntry> children = tree;
        boolean found = true;
        while (found) {
            if (children == null) {
                return null;
            }
            // since the categories are sorted it is faster to go backwards
            found = false;
            for (int i = children.size() - 1; i >= 0; i--) {
                CmsCategoryTreeEntry child = children.get(i);
                if (path.equals(child.getPath())) {
                    return child;
                }
                if (path.startsWith(child.getPath())) {
                    children = child.getChildren();
                    found = true;
                    break;
                }
            }
        }
        return null;
    }
1152124
def set_category(self, category):
        
        pcategory = self.find("general/category")
        pcategory.clear()
        name = ElementTree.SubElement(pcategory, "name")
        if isinstance(category, Category):
            id_ = ElementTree.SubElement(pcategory, "id")
            id_.text = category.id
            name.text = category.name
        elif isinstance(category, basestring):
            name.text = category