Example usage for javax.xml.stream XMLStreamWriter writeCharacters

List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeCharacters.

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

From source file:org.flowable.bpmn.converter.UserTaskXMLConverter.java

protected void writeCustomIdentities(UserTask userTask, String identityType, Set<String> users,
        Set<String> groups, XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_CUSTOM_RESOURCE, FLOWABLE_EXTENSIONS_NAMESPACE);
    writeDefaultAttribute(ATTRIBUTE_NAME, identityType, xtw);

    List<String> identityList = new ArrayList<String>();

    if (users != null) {
        for (String userId : users) {
            identityList.add("user(" + userId + ")");
        }/*from  w  w  w  . j  av  a 2  s . c  o  m*/
    }

    if (groups != null) {
        for (String groupId : groups) {
            identityList.add("group(" + groupId + ")");
        }
    }

    String delimitedString = convertToDelimitedString(identityList);

    xtw.writeStartElement(ELEMENT_RESOURCE_ASSIGNMENT);
    xtw.writeStartElement(ELEMENT_FORMAL_EXPRESSION);
    xtw.writeCharacters(delimitedString);
    xtw.writeEndElement(); // End ELEMENT_FORMAL_EXPRESSION
    xtw.writeEndElement(); // End ELEMENT_RESOURCE_ASSIGNMENT

    xtw.writeEndElement(); // End ELEMENT_CUSTOM_RESOURCE
}

From source file:org.flowable.cmmn.converter.export.AbstractPlanItemDefinitionExport.java

public static void writeCommonPlanItemDefinitionAttributes(PlanItemDefinition planItemDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeAttribute(ATTRIBUTE_ID, planItemDefinition.getId());

    if (StringUtils.isNotEmpty(planItemDefinition.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, planItemDefinition.getName());
    }/*from ww  w  . ja v  a  2 s. c om*/

    if (StringUtils.isNotEmpty(planItemDefinition.getDocumentation())) {

        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(planItemDefinition.getDocumentation());
        xtw.writeEndElement();
    }
}

From source file:org.flowable.cmmn.converter.export.CaseExport.java

public static void writeCase(Case caseModel, XMLStreamWriter xtw) throws Exception {
    // start process element
    xtw.writeStartElement(ELEMENT_CASE);
    xtw.writeAttribute(ATTRIBUTE_ID, caseModel.getId());

    if (StringUtils.isNotEmpty(caseModel.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, caseModel.getName());
    }//ww  w .j  av a2s.co  m

    if (StringUtils.isNotEmpty(caseModel.getInitiatorVariableName())) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                ATTRIBUTE_INITIATOR_VARIABLE_NAME, caseModel.getInitiatorVariableName());
    }

    if (StringUtils.isNotEmpty(caseModel.getDocumentation())) {

        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(caseModel.getDocumentation());
        xtw.writeEndElement();
    }
}

From source file:org.flowable.cmmn.converter.export.PlanItemExport.java

public static void writePlanItem(PlanItem planItem, XMLStreamWriter xtw) throws Exception {
    // start plan item element
    xtw.writeStartElement(ELEMENT_PLAN_ITEM);
    xtw.writeAttribute(ATTRIBUTE_ID, planItem.getId());

    if (StringUtils.isNotEmpty(planItem.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, planItem.getName());
    }/*from   w  w  w.  j  ava 2s . c  om*/

    if (StringUtils.isNotEmpty(planItem.getDefinitionRef())) {
        xtw.writeAttribute(ATTRIBUTE_DEFINITION_REF, planItem.getDefinitionRef());
    }

    if (StringUtils.isNotEmpty(planItem.getDocumentation())) {
        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(planItem.getDocumentation());
        xtw.writeEndElement();
    }
    if (planItem.getItemControl() != null) {
        xtw.writeStartElement(ELEMENT_ITEM_CONTROL);
        RepetitionRule repetitionRule = planItem.getItemControl().getRepetitionRule();
        if (repetitionRule != null) {
            xtw.writeStartElement(ELEMENT_REPETITION_RULE);
            if (StringUtils.isNotEmpty(repetitionRule.getRepetitionCounterVariableName())) {
                xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                        ATTRIBUTE_REPETITION_COUNTER_VARIABLE_NAME,
                        repetitionRule.getRepetitionCounterVariableName());
            }
            if (StringUtils.isNotEmpty(repetitionRule.getCondition())) {
                xtw.writeStartElement(ELEMENT_CONDITION);
                xtw.writeCData(repetitionRule.getCondition());
                xtw.writeEndElement();
            }
            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }

    CriteriaExport.writeCriteriaElements(planItem, xtw);

    // end plan item element
    xtw.writeEndElement();
}

From source file:org.flowable.cmmn.converter.export.SentryExport.java

public static void writeSentry(Sentry sentry, XMLStreamWriter xtw) throws Exception {
    // start sentry element
    xtw.writeStartElement(ELEMENT_SENTRY);
    xtw.writeAttribute(ATTRIBUTE_ID, sentry.getId());

    if (StringUtils.isNotEmpty(sentry.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, sentry.getName());
    }//from   w  ww.ja v a2 s.c om

    for (SentryOnPart sentryOnPart : sentry.getOnParts()) {
        // start sentry on part element
        xtw.writeStartElement(ELEMENT_PLAN_ITEM_ON_PART);

        xtw.writeAttribute(ATTRIBUTE_ID, sentryOnPart.getId());
        xtw.writeAttribute(ATTRIBUTE_SOURCE_REF, sentryOnPart.getSourceRef());

        // start standard event element
        xtw.writeStartElement(ELEMENT_STANDARD_EVENT);
        xtw.writeCharacters(sentryOnPart.getStandardEvent());
        xtw.writeEndElement();

        // end sentry on part element
        xtw.writeEndElement();
    }

    // If part
    if (sentry.getSentryIfPart() != null) {
        xtw.writeStartElement(ELEMENT_IF_PART);
        xtw.writeStartElement(ELEMENT_CONDITION);
        xtw.writeCData(sentry.getSentryIfPart().getCondition());
        xtw.writeEndElement();
        xtw.writeEndElement();
    }

    // end plan item element
    xtw.writeEndElement();
}

From source file:org.flowable.cmmn.converter.export.StageExport.java

public static void writeStage(Stage stage, XMLStreamWriter xtw) throws Exception {
    // start plan model or stage element
    if (stage.isPlanModel()) {
        xtw.writeStartElement(ELEMENT_PLAN_MODEL);
    } else {/*w  w  w.ja va 2s  .  c  o m*/
        xtw.writeStartElement(ELEMENT_STAGE);
    }

    xtw.writeAttribute(ATTRIBUTE_ID, stage.getId());

    if (StringUtils.isNotEmpty(stage.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, stage.getName());
    }

    if (StringUtils.isNotEmpty(stage.getDocumentation())) {

        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(stage.getDocumentation());
        xtw.writeEndElement();
    }

    for (PlanItem planItem : stage.getPlanItems()) {
        PlanItemExport.writePlanItem(planItem, xtw);
    }

    for (Sentry sentry : stage.getSentries()) {
        SentryExport.writeSentry(sentry, xtw);
    }

    for (PlanItemDefinition planItemDefinition : stage.getPlanItemDefinitions()) {
        PlanItemDefinitionExport.writePlanItemDefinition(planItemDefinition, xtw);
    }

    if (stage.isPlanModel() && stage.getExitCriteria() != null && !stage.getExitCriteria().isEmpty()) {
        for (Criterion exitCriterion : stage.getExitCriteria()) {
            xtw.writeStartElement(ELEMENT_EXIT_CRITERION);
            xtw.writeAttribute(ATTRIBUTE_ID, exitCriterion.getId());

            if (StringUtils.isNotEmpty(exitCriterion.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, exitCriterion.getName());
            }

            if (StringUtils.isNotEmpty(exitCriterion.getSentryRef())) {
                xtw.writeAttribute(ATTRIBUTE_SENTRY_REF, exitCriterion.getSentryRef());
            }

            // end entry criterion element
            xtw.writeEndElement();
        }
    }

    // end plan model or stage element
    xtw.writeEndElement();
}

From source file:org.gatein.management.rest.FailureResponse.java

private void writeXml(OutputStream out, boolean pretty) throws IOException {
    XMLStreamWriter writer;
    try {/*  w w  w. j  ava 2s .  co  m*/
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
    } catch (XMLStreamException e) {
        throw new IOException("Could not create XML streaming writer.", e);
    }

    try {
        writer.writeStartDocument("UTF-8", "1.0");
        // root element <failureResult>
        nl(writer, pretty);
        writer.writeStartElement("failureResult");
        nl(writer, pretty);
        indent(writer, 1, pretty);

        // <failure>
        writer.writeStartElement("failure");
        writer.writeCharacters(outcome.getFailureDescription());
        writer.writeEndElement();
        nl(writer, pretty);
        indent(writer, 1, pretty);

        // <operationName>
        writer.writeStartElement("operationName");
        writer.writeCharacters(operationName);
        writer.writeEndElement();
        nl(writer, pretty);

        // </failureResult>
        writer.writeEndElement();

        // End document
        writer.writeCharacters("\n");
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new IOException("Exception writing failure response to XML. Failure response message was '"
                + outcome.getFailureDescription() + "'", e);
    }
    //      finally
    //      {
    //         try
    //         {
    //            writer.close();
    //         }
    //         catch (XMLStreamException e)
    //         {
    //            // ignore
    //         }
    //      }
}

From source file:org.gatein.management.rest.FailureResponse.java

private static void nl(XMLStreamWriter writer, boolean pretty) throws XMLStreamException {
    if (pretty)//  ww w.  j  a v  a  2  s  .  c  o  m
        writer.writeCharacters("\n");
}

From source file:org.gatein.management.rest.FailureResponse.java

private static void indent(XMLStreamWriter writer, int depth, boolean pretty) throws XMLStreamException {
    if (pretty) {
        for (int i = 0; i < depth; i++) {
            writer.writeCharacters("   ");
        }//from   w ww .  ja va2 s . co m
    }
}

From source file:org.gluewine.trace.XMLTracer.java

@Override
public void beforeInvocation(Object o, Method m, Object[] params) throws Throwable {
    if (isSuppressed())
        return;/*from  w ww .j  a  va2s.  co m*/

    XMLStreamWriter writer = getWriter();
    if (writer != null) {
        try {
            writer.writeStartElement("method");
            writer.writeAttribute("class", getClassName(o.getClass()));
            writer.writeAttribute("name", m.getName());
            writer.writeAttribute("start", format.format(new Date()));

            for (Object p : params) {
                if (p != null) {
                    writer.writeStartElement("parameter");
                    writer.writeAttribute("class", getClassName(p.getClass()));
                    writer.writeCharacters(p.toString());
                    writer.writeEndElement();
                } else
                    writer.writeEmptyElement("parameter");
            }

        } catch (Throwable e) {
            ErrorLogger.log(getClass(), e);
        }
    } else
        System.out.println("No Writer");

    clearSuppression();
}