public Object[] getChildren(Object o) { if (o instanceof OutlineItem) { OutlineItem item = (OutlineItem) o; if (!item.getChildren().isEmpty()) { return item.getChildren().toArray(); } } return NO_CHILDREN; }
/** * Get the previous item. The order of the items is determined via document order traversal of all nodes in the * outline. * * @return the previous item or null if there is no previous (ie: the root item). */ public OutlineItem getPrevious() { if (parent == null) { return null; } List<OutlineItem> siblings = parent.getChildren(); int index = siblings.indexOf(this); if (index > 0) { return siblings.get(index - 1); } return parent; }
public void accept(Visitor visitor) { if (visitor.visit(this)) { for (OutlineItem item : getChildren()) { item.accept(visitor); } } }
private void createProjectionAnnotations(List<Annotation> newProjectionAnnotations, Map<HeadingProjectionAnnotation, Position> annotationToPosition, List<OutlineItem> children, int endOffset) { final int size = children.size(); final int lastIndex = size - 1; for (int x = 0; x < size; ++x) { OutlineItem child = children.get(x); if (child.getId() == null || child.getId().length() == 0) { continue; } int offset = child.getOffset(); int end; if (x == lastIndex) { end = endOffset; } else { end = children.get(x + 1).getOffset(); } int length = end - offset; if (length > 0) { HeadingProjectionAnnotation annotation = new HeadingProjectionAnnotation(child.getId()); Position position = new Position(offset, length); newProjectionAnnotations.add(annotation); annotationToPosition.put(annotation, position); } if (!child.getChildren().isEmpty()) { createProjectionAnnotations(newProjectionAnnotations, annotationToPosition, child.getChildren(), end); } } }
/** * get the length of the section, which is the length of the heading text plus the length of any following content * up to the next peer-leveled heading or the parent's following sibling. * * @see #getLength() */ public int getSectionLength() { if (parent == null) { return length; } List<OutlineItem> siblings = getParent().getChildren(); int index = siblings.indexOf(this); if (index < (siblings.size() - 1)) { return siblings.get(index + 1).getOffset() - getOffset(); } int parentRelativeOffset = getOffset() - parent.getOffset(); return parent.getSectionLength() - parentRelativeOffset; }
Map<HeadingProjectionAnnotation, Position> annotationToPosition = new HashMap<HeadingProjectionAnnotation, Position>(); List<OutlineItem> children = outlineModel.getChildren(); if (!children.isEmpty()) { createProjectionAnnotations(newProjectionAnnotations, annotationToPosition, children,
private void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes()); for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
private void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } if ((item.getLevel() + 1) > maxLevel) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null)); //$NON-NLS-1$ //$NON-NLS-2$ for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
protected void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } if ((item.getLevel() + 1) > maxLevel) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null)); //$NON-NLS-1$ //$NON-NLS-2$ for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
private void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } if ((item.getLevel() + 1) > maxLevel) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null)); //$NON-NLS-1$ //$NON-NLS-2$ for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
List<OutlineItem> children = target.getChildren(); if (children.isEmpty()) { insertLocation += target.getLength();
private void emitToc(XmlStreamWriter writer, List<OutlineItem> children) { for (OutlineItem item : children) { writer.writeStartElement("topic"); //$NON-NLS-1$ String file = computeFile(item); file = adjustForPrefix(file); String suffix = ""; //$NON-NLS-1$ // bug 260065: only append document anchor name if this is not the first item in the file. OutlineItem previous = item.getPrevious(); if (previous != null && previous.getParent() != null) { String fileOfPrevious = computeFile(previous); fileOfPrevious = adjustForPrefix(fileOfPrevious); if (file.equals(fileOfPrevious)) { suffix = "#" + item.getId(); //$NON-NLS-1$ } } writer.writeAttribute("href", file + suffix); //$NON-NLS-1$ writer.writeAttribute("label", item.getLabel()); //$NON-NLS-1$ if (!item.getChildren().isEmpty()) { emitToc(writer, item.getChildren()); } writer.writeEndElement(); // topic } }
public String createToc(OutlineItem root) { StringWriter out = new StringWriter(8096); XmlStreamWriter writer = createXmlStreamWriter(out); writer.writeStartDocument("utf-8", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ writer.writeStartElement("toc"); //$NON-NLS-1$ writer.writeAttribute("topic", adjustForPrefix(getHtmlFile())); //$NON-NLS-1$ writer.writeAttribute("label", getBookTitle()); //$NON-NLS-1$ emitToc(writer, root.getChildren()); writer.writeEndElement(); // toc writer.writeEndDocument(); writer.close(); return out.toString(); }
switch (topicStrategy) { case FIRST: if (!outline.getChildren().isEmpty()) { builder.setTopicBreakLevel(outline.getChildren().get(0).getLevel()); } else { builder.setTopicBreakLevel(1);