private DitaTopicDocumentBuilder getCurrentTopic() { if (currentTopic == null) { try { currentTopicFile = computeFile(latestHeadingId); currentTopicOut = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(currentTopicFile)), "utf-8"); //$NON-NLS-1$ } catch (IOException e1) { throw new IllegalStateException(e1); } // create a DITA map entry String relativeTopic = currentTopicFile.getName(); if (topicFolder != null) { relativeTopic = topicFolder + '/' + relativeTopic; } writer.writeEmptyElement("chapter"); //$NON-NLS-1$ writer.writeAttribute("href", relativeTopic); //$NON-NLS-1$ titleText = ""; //$NON-NLS-1$ mapEntryOpen = true; currentTopic = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(currentTopicOut), formattingDependencies); if (topicDoctype != null) { currentTopic.setDoctype(topicDoctype); } currentTopic.setTopicBreakLevel(topicBreakLevel); currentTopic.setOutline(outline); currentTopic.setFilename(currentTopicFile.getName()); currentTopic.beginDocument(); } return currentTopic; }
@Override public void acronym(String text, String definition) { getCurrentTopic().acronym(text, definition); }
@Override public void beginHeading(int level, Attributes attributes) { closeTopics(Math.max(level - 1, 0)); if (topicInfos.isEmpty() || topicInfos.peek().headingLevel < level) { TopicInfo topicInfo = new TopicInfo(); topicInfo.headingLevel = level; topicInfo.openElements = 2; topicInfos.push(topicInfo); writer.writeStartElement("topic"); //$NON-NLS-1$ if (attributes != null) { applyAttributes(attributes); attributes = null; } writer.writeStartElement("title"); //$NON-NLS-1$ } }
private void ensureOpenTopic() { if (topicInfos.isEmpty()) { beginHeading(1, new Attributes()); endHeading(); } }
DitaTopicDocumentBuilder builder = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(writer), formatting); builder.setRootTopicTitle(bookTitle); parser.setBuilder(builder); if (topicDoctype != null) { builder.setDoctype(topicDoctype); builder.setFilename(outputFile.getName()); builder.setOutline(outline);
@Override public void beginBlock(BlockType type, Attributes attributes) { ensureOpenTopic(); case DEFINITION_TERM: BlockDescription blockDescription = findBlockDescription(BlockType.DEFINITION_LIST); if (blockDescription.entrySize > 0) { endBlockEntry(blockDescription); openBlockEntry(blockDescription, new String[] { "dlentry" }); //$NON-NLS-1$ endBlockEntry(previousBlock); break; applyAttributes(attributes);
@Override public void beginSpan(SpanType type, Attributes attributes) { ensureOpenTopic(); switch (type) { case BOLD: LinkAttributes linkAttributes = (LinkAttributes) attributes; writer.writeStartElement("xref"); //$NON-NLS-1$ writer.writeAttribute("href", computeDitaXref(linkAttributes.getHref())); //$NON-NLS-1$ break; applyAttributes(attributes);
@Override public void image(Attributes attributes, String url) { ensureOpenTopic(); boolean emitAsFigure = attributes.getTitle() != null; if (emitAsFigure) { writer.writeStartElement("fig"); //$NON-NLS-1$ writer.writeStartElement("title");//$NON-NLS-1$ writer.writeCharacters(attributes.getTitle()); writer.writeEndElement(); } writer.writeEmptyElement("image"); //$NON-NLS-1$ writer.writeAttribute("href", url); //$NON-NLS-1$ applyImageAttributes(attributes); if (emitAsFigure) { writer.writeEndElement(); } }
@Override public void beginBlock(BlockType type, Attributes attributes) { getCurrentTopic().beginBlock(type, attributes); }
@Override public void beginHeading(int level, Attributes attributes) { headingLevels.push(level); if (level <= topicBreakLevel) { closeCurrentTopic(); latestHeadingId = attributes.getId(); } getCurrentTopic().beginHeading(level, attributes); }
private void applyImageAttributes(Attributes imageAttributes) { applyAttributes(imageAttributes); if (imageAttributes instanceof ImageAttributes) { ImageAttributes attributes = (ImageAttributes) imageAttributes; if (attributes.getAlt() != null) { writer.writeAttribute("alt", attributes.getAlt()); //$NON-NLS-1$ } if (attributes.getHeight() > 0) { writer.writeAttribute("height", Integer.toString(attributes.getHeight())); //$NON-NLS-1$ } if (attributes.getWidth() > 0) { writer.writeAttribute("width", Integer.toString(attributes.getWidth())); //$NON-NLS-1$ } if (attributes.getAlign() != null) { switch (attributes.getAlign()) { case Left: writer.writeAttribute("align", "center"); //$NON-NLS-1$ //$NON-NLS-2$ break; case Right: writer.writeAttribute("align", "right"); //$NON-NLS-1$ //$NON-NLS-2$ break; case Center: writer.writeAttribute("align", "center"); //$NON-NLS-1$ //$NON-NLS-2$ break; } writer.writeAttribute("placement", "break"); //$NON-NLS-1$ //$NON-NLS-2$ } } }