Search in sources :

Example 1 with WritesAttribute

use of org.apache.nifi.annotation.behavior.WritesAttribute in project nifi by apache.

the class HtmlProcessorDocumentationWriter method handleWritesAttributes.

/**
 * Writes out just the attributes that are being written to in a table form.
 *
 * @param xmlStreamWriter the xml stream writer to use
 * @param processor the processor to describe
 * @throws XMLStreamException xse
 */
private void handleWritesAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor) throws XMLStreamException {
    List<WritesAttribute> attributesRead = getWritesAttributes(processor);
    writeSimpleElement(xmlStreamWriter, "h3", "Writes Attributes: ");
    if (attributesRead.size() > 0) {
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "writes-attributes");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();
        for (WritesAttribute attribute : attributesRead) {
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "td", defaultIfBlank(attribute.attribute(), "Not Specified"));
            // TODO allow for HTML characters here.
            writeSimpleElement(xmlStreamWriter, "td", defaultIfBlank(attribute.description(), "Not Specified"));
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
    } else {
        xmlStreamWriter.writeCharacters("None specified.");
    }
}
Also used : WritesAttribute(org.apache.nifi.annotation.behavior.WritesAttribute)

Example 2 with WritesAttribute

use of org.apache.nifi.annotation.behavior.WritesAttribute in project nifi by apache.

the class HtmlProcessorDocumentationWriter method getWritesAttributes.

/**
 * Collects the attributes that a processor is writing to.
 *
 * @param processor the processor to describe
 * @return the list of attributes the processor is writing
 */
private List<WritesAttribute> getWritesAttributes(Processor processor) {
    List<WritesAttribute> attributes = new ArrayList<>();
    WritesAttributes writesAttributes = processor.getClass().getAnnotation(WritesAttributes.class);
    if (writesAttributes != null) {
        attributes.addAll(Arrays.asList(writesAttributes.value()));
    }
    WritesAttribute writeAttribute = processor.getClass().getAnnotation(WritesAttribute.class);
    if (writeAttribute != null) {
        attributes.add(writeAttribute);
    }
    return attributes;
}
Also used : ArrayList(java.util.ArrayList) WritesAttribute(org.apache.nifi.annotation.behavior.WritesAttribute) WritesAttributes(org.apache.nifi.annotation.behavior.WritesAttributes)

Aggregations

WritesAttribute (org.apache.nifi.annotation.behavior.WritesAttribute)2 ArrayList (java.util.ArrayList)1 WritesAttributes (org.apache.nifi.annotation.behavior.WritesAttributes)1