Example usage for javax.xml.stream XMLStreamWriter writeAttribute

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

Introduction

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

Prototype

public void writeAttribute(String localName, String value) throws XMLStreamException;

Source Link

Document

Writes an attribute to the output stream without a prefix.

Usage

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 {/*from  w ww . j  av  a2s.c om*/
        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.flowable.cmmn.converter.export.TaskExport.java

protected static <T extends Task> void writeCommonTaskAttributes(T task, XMLStreamWriter xtw) throws Exception {
    // Blocking//w ww . jav a  2 s.  co  m
    if (StringUtils.isEmpty(task.getBlockingExpression())) {
        if (!task.isBlocking()) { // if omitted, by default assumed true
            xtw.writeAttribute(ATTRIBUTE_IS_BLOCKING, "false");
        }
    } else {
        xtw.writeAttribute(ATTRIBUTE_IS_BLOCKING, "true");
    }

    if (StringUtils.isNotEmpty(task.getBlockingExpression())) {
        xtw.writeAttribute(ATTRIBUTE_IS_BLOCKING_EXPRESSION, task.getBlockingExpression());
    }

    // Async
    if (task.isAsync()) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_IS_ASYNCHRONOUS,
                String.valueOf(task.isAsync()));
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_IS_EXCLUSIVE,
                String.valueOf(task.isExclusive()));
    }
}

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

public static void writeTimerEventListener(TimerEventListener timerEventListener, XMLStreamWriter xtw)
        throws Exception {
    xtw.writeStartElement(ELEMENT_TIMER_EVENT_LISTENER);
    writeCommonPlanItemDefinitionAttributes(timerEventListener, xtw);

    if (StringUtils.isNotEmpty(timerEventListener.getTimerExpression())) {
        xtw.writeStartElement(ELEMENT_TIMER_EXPRESSION);
        xtw.writeCData(timerEventListener.getTimerExpression());
        xtw.writeEndElement();//from   w w w  .  ja  v  a 2 s  .  c o m
    }

    if (StringUtils.isNotEmpty(timerEventListener.getTimerStartTriggerSourceRef())) {
        xtw.writeStartElement(ELEMENT_PLAN_ITEM_START_TRIGGER);
        xtw.writeAttribute(ATTRIBUTE_PLAN_ITEM_START_TRIGGER_SRC_REF,
                timerEventListener.getTimerStartTriggerSourceRef());

        xtw.writeStartElement(ELEMENT_STANDARD_EVENT);
        xtw.writeCData(timerEventListener.getTimerStartTriggerStandardEvent());
        xtw.writeEndElement();

        xtw.writeEndElement();
    }

    xtw.writeEndElement();
}

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

@Override
protected void writePlanItemDefinitionSpecificAttributes(UserEventListener userEventListener,
        XMLStreamWriter xtw) throws Exception {
    super.writePlanItemDefinitionSpecificAttributes(userEventListener, xtw);

    String[] authorizedRoleRefs = userEventListener.getAuthorizedRoleRefs();
    if (authorizedRoleRefs != null && authorizedRoleRefs.length > 0) {
        xtw.writeAttribute(ATTRIBUTE_AUTHORIZED_ROLE_REFS, String.join(",", authorizedRoleRefs));
    }//from  w w w . j ava  2  s  .c  om

    if (StringUtils.isNotEmpty(userEventListener.getAvailableConditionExpression())) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_NAMESPACE,
                CmmnXmlConstants.ATTRIBUTE_EVENT_LISTENER_AVAILABLE_CONDITION,
                userEventListener.getAvailableConditionExpression());
    }
}

From source file:org.flowable.cmmn.converter.util.CmmnXmlUtil.java

public static void writeDefaultAttribute(String attributeName, String value, XMLStreamWriter xtw)
        throws Exception {
    if (StringUtils.isNotEmpty(value) && !"null".equalsIgnoreCase(value)) {
        xtw.writeAttribute(attributeName, value);
    }/* w  w  w  .j  a  v a 2  s.c o  m*/
}

From source file:org.flowable.cmmn.converter.util.CmmnXmlUtil.java

/**
 * write attributes to xtw (except blacklisted)
 *
 * @param attributes//  w w  w  .jav  a 2 s  . co m
 * @param xtw
 * @param namespaceMap
 * @param blackLists
 */
public static void writeCustomAttributes(Collection<List<ExtensionAttribute>> attributes, XMLStreamWriter xtw,
        Map<String, String> namespaceMap, List<ExtensionAttribute>... blackLists) throws XMLStreamException {

    for (List<ExtensionAttribute> attributeList : attributes) {
        if (attributeList != null && !attributeList.isEmpty()) {
            for (ExtensionAttribute attribute : attributeList) {
                if (!isBlacklisted(attribute, blackLists)) {
                    if (attribute.getNamespacePrefix() == null) {
                        if (attribute.getNamespace() == null)
                            xtw.writeAttribute(attribute.getName(), attribute.getValue());
                        else {
                            xtw.writeAttribute(attribute.getNamespace(), attribute.getName(),
                                    attribute.getValue());
                        }
                    } else {
                        if (!namespaceMap.containsKey(attribute.getNamespacePrefix())) {
                            namespaceMap.put(attribute.getNamespacePrefix(), attribute.getNamespace());
                            xtw.writeNamespace(attribute.getNamespacePrefix(), attribute.getNamespace());
                        }
                        xtw.writeAttribute(attribute.getNamespacePrefix(), attribute.getNamespace(),
                                attribute.getName(), attribute.getValue());
                    }
                }
            }
        }
    }
}

From source file:org.gephi.statistics.StatisticsModelImpl.java

public void writeXML(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("statisticsmodel");

    writer.writeStartElement("reports");
    for (Map.Entry<Class, String> entry : reportMap.entrySet()) {
        if (entry.getValue() != null && !entry.getValue().isEmpty()) {
            writer.writeStartElement("report");
            String report = entry.getValue();
            report = embedImages(report);
            writer.writeAttribute("class", entry.getKey().getName());
            writer.writeAttribute("value", report);
            writer.writeEndElement();//w ww . ja  v a2s  .co  m
        }
    }
    writer.writeEndElement();

    writer.writeEndElement();
}

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

@Override
public void beforeInvocation(Object o, Method m, Object[] params) throws Throwable {
    if (isSuppressed())
        return;/*from ww  w .  ja va  2 s  . c  o 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();
}

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

/**
 * Returns the writer associated with the current thread. If none exists, one is
 * created./*from  w w w  . j  a v  a 2s .  c  o m*/
 *
 * @return The writer to use.
 */
private XMLStreamWriter getWriter() {
    XMLStreamWriter writer = writers.get(Thread.currentThread());

    if (writer == null) {
        try {
            writer = xof.createXMLStreamWriter(
                    new FileWriterWithEncoding(file + "_" + Thread.currentThread().getId() + ".xml", "utf8"));
            writer.writeStartDocument("utf-8", "1.0");
            writer.writeStartElement("trace");
            writer.writeAttribute("thread", Long.toString(Thread.currentThread().getId()));
            writers.put(Thread.currentThread(), writer);
        } catch (Throwable e) {
            ErrorLogger.log(getClass(), e);
        }
    }

    return writer;
}

From source file:org.gluu.saml.AuthRequest.java

public String getStreamedRequest(boolean useBase64) throws XMLStreamException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(baos);

    writer.writeStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

    writer.writeAttribute("ID", id);
    writer.writeAttribute("Version", "2.0");
    writer.writeAttribute("IssueInstant", this.issueInstant);
    writer.writeAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
    writer.writeAttribute("AssertionConsumerServiceURL", this.samlSettings.getAssertionConsumerServiceUrl());

    writer.writeStartElement("saml", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeCharacters(this.samlSettings.getIssuer());
    writer.writeEndElement();// w ww. j a  va2  s .  c  om

    writer.writeStartElement("samlp", "NameIDPolicy", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

    writer.writeAttribute("Format", this.samlSettings.getNameIdentifierFormat());
    writer.writeAttribute("AllowCreate", "true");
    writer.writeEndElement();

    writer.writeStartElement("samlp", "RequestedAuthnContext", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

    writer.writeAttribute("Comparison", "exact");

    writer.writeStartElement("saml", "AuthnContextClassRef", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeCharacters("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
    writer.writeEndElement();

    writer.writeEndElement();

    writer.writeEndElement();
    writer.flush();

    if (log.isDebugEnabled()) {
        log.debug("Genereated Saml Request " + new String(baos.toByteArray(), "UTF-8"));
    }

    if (useBase64) {
        byte[] deflated = CompressionHelper.deflate(baos.toByteArray(), true);
        String base64 = Base64.encodeBase64String(deflated);
        String encoded = URLEncoder.encode(base64, "UTF-8");

        return encoded;
    }

    return new String(baos.toByteArray(), "UTF-8");
}