Example usage for org.dom4j Document setXMLEncoding

List of usage examples for org.dom4j Document setXMLEncoding

Introduction

In this page you can find the example usage for org.dom4j Document setXMLEncoding.

Prototype

void setXMLEncoding(String encoding);

Source Link

Document

Sets the encoding of this document as it will appear in the XML declaration part of the document.

Usage

From source file:com.ah.be.ls.stat.StatManager.java

private Document generateDocumentTemplate() {
    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding("UTF-8");
    return document;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * ReaderDocument encodingStrnull""GB2312
 *
 * @param in//from  w  ww. j a v  a 2 s.  c  o m
 *            Reader
 * @param encoding
 *            
 * @return documment
 * @throws XMLDocException
 * @throws BaseException
 */
public static Document fromXML(Reader in, String encoding) throws BaseException {
    try {
        if (encoding == null || encoding.equals("")) {
            encoding = DEFAULT_ENCODING;
        }
        SAXReader reader = new SAXReader();
        InputSource source = new InputSource(in);
        source.setEncoding(encoding);
        Document document = reader.read(source);
        document.setXMLEncoding(encoding);
        return document;
    } catch (Exception ex) {
        throw new BaseException("UTIL-0001", ex);
    }

}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * XMLDocument encodingStrnull""GB2312//from   w  w  w.  j a va 2  s .c om
 *
 * @param inputSource
 *            
 * @param encoding
 *            
 * @return document
 * @throws XMLDocException
 * @throws BaseException
 */
public static Document fromXML(InputStream inputSource, String encoding) throws BaseException {
    try {
        if (encoding == null || encoding.equals("")) {
            encoding = DEFAULT_ENCODING;
        }
        SAXReader reader = new SAXReader();
        Document document = reader.read(inputSource);
        document.setXMLEncoding(encoding);
        return document;
    } catch (Exception ex) {
        throw new BaseException("UTIL-0001", ex);
    }
}

From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java

License:Open Source License

/**
 * Creates a generic artifact XML representation out of the Java object
 * /*from   w w  w . j av a 2 s  .c o m*/
 * @param genericArtifact
 *            Java object that will be represented as XML document
 * @return XML representation of generic artifact
 */
public static Document createGenericArtifactXMLDocument(GenericArtifact genericArtifact)
        throws GenericArtifactParsingException {
    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding(EncodingAwareObject.UTF_8);
    // Create XML elements with attributes
    Element root = addRootElement(document, ARTIFACT_ROOT_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE);

    switch (genericArtifact.getArtifactAction()) {
    case CREATE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_CREATE);
        break;
    }
    case DELETE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_DELETE);
        break;
    }
    case IGNORE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_IGNORE);
        break;
    }
    case UPDATE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UPDATE);
        break;
    }
    case RESYNC: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_RESYNC);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_ACTION + " specified.");
    }
    }

    switch (genericArtifact.getArtifactMode()) {
    case CHANGEDFIELDSONLY: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_CHANGED_FIELDS_ONLY);
        break;
    }
    case COMPLETE: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_COMPLETE);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_MODE + "specified.");
    }
    }

    ArtifactTypeValue artifactType = genericArtifact.getArtifactType();
    switch (artifactType) {
    case ATTACHMENT: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_ATTACHMENT);
        String content = genericArtifact.getArtifactValue();
        // TODO BASE64 validation?
        if (content != null)
            // embed content in CDATA section
            setValue(root, content, true);
        break;
    }
    case DEPENDENCY: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_DEPENDENCY);
        break;
    }
    case PLAINARTIFACT: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_PLAIN_ARTIFACT);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_TYPE + " specified.");
    }
    }

    switch (genericArtifact.getIncludesFieldMetaData()) {
    case TRUE: {
        addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_TRUE);
        break;
    }
    case FALSE: {
        addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_FALSE);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_MODE + "specified.");
    }
    }

    addAttribute(root, SOURCE_ARTIFACT_LAST_MODIFICATION_DATE,
            genericArtifact.getSourceArtifactLastModifiedDate());
    addAttribute(root, TARGET_ARTIFACT_LAST_MODIFICATION_DATE,
            genericArtifact.getTargetArtifactLastModifiedDate());
    // addAttribute(root, ARTIFACT_LAST_READ_TRANSACTION_ID, genericArtifact
    // .getLastReadTransactionId());
    addAttribute(root, ERROR_CODE, genericArtifact.getErrorCode());
    addAttribute(root, SOURCE_ARTIFACT_VERSION, genericArtifact.getSourceArtifactVersion());
    addAttribute(root, TARGET_ARTIFACT_VERSION, genericArtifact.getTargetArtifactVersion());
    addAttribute(root, CONFLICT_RESOLUTION_PRIORITY, genericArtifact.getConflictResolutionPriority());

    // only create optional attributes if necessary
    if (artifactType == ArtifactTypeValue.DEPENDENCY || artifactType == ArtifactTypeValue.ATTACHMENT
            || artifactType == ArtifactTypeValue.PLAINARTIFACT) {
        addAttribute(root, DEP_PARENT_SOURCE_ARTIFACT_ID, genericArtifact.getDepParentSourceArtifactId());
        addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_ID, genericArtifact.getDepParentSourceRepositoryId());
        addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_KIND,
                genericArtifact.getDepParentSourceRepositoryKind());
        addAttribute(root, DEP_PARENT_TARGET_ARTIFACT_ID, genericArtifact.getDepParentTargetArtifactId());
        addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_ID, genericArtifact.getDepParentTargetRepositoryId());
        addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_KIND,
                genericArtifact.getDepParentTargetRepositoryKind());
    }

    // dependencies have even more optional attributes
    if (artifactType == ArtifactTypeValue.DEPENDENCY) {
        addAttribute(root, DEP_CHILD_SOURCE_ARTIFACT_ID, genericArtifact.getDepChildSourceArtifactId());
        addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_ID, genericArtifact.getDepChildSourceRepositoryId());
        addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_KIND, genericArtifact.getDepChildSourceRepositoryKind());
        addAttribute(root, DEP_CHILD_TARGET_ARTIFACT_ID, genericArtifact.getDepChildTargetArtifactId());
        addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_ID, genericArtifact.getDepChildTargetRepositoryId());
        addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_KIND, genericArtifact.getDepChildTargetRepositoryKind());
    }

    addAttribute(root, SOURCE_ARTIFACT_ID, genericArtifact.getSourceArtifactId());
    addAttribute(root, SOURCE_REPOSITORY_ID, genericArtifact.getSourceRepositoryId());
    addAttribute(root, SOURCE_REPOSITORY_KIND, genericArtifact.getSourceRepositoryKind());
    addAttribute(root, SOURCE_SYSTEM_ID, genericArtifact.getSourceSystemId());
    addAttribute(root, SOURCE_SYSTEM_KIND, genericArtifact.getSourceSystemKind());
    addAttribute(root, TARGET_ARTIFACT_ID, genericArtifact.getTargetArtifactId());
    addAttribute(root, TARGET_REPOSITORY_ID, genericArtifact.getTargetRepositoryId());
    addAttribute(root, TARGET_REPOSITORY_KIND, genericArtifact.getTargetRepositoryKind());
    addAttribute(root, TARGET_SYSTEM_ID, genericArtifact.getTargetSystemId());
    addAttribute(root, TARGET_SYSTEM_KIND, genericArtifact.getTargetSystemKind());
    addAttribute(root, SOURCE_SYSTEM_TIMEZONE, genericArtifact.getSourceSystemTimezone());
    addAttribute(root, TARGET_SYSTEM_TIMEZONE, genericArtifact.getTargetSystemTimezone());
    // addAttribute(root, SOURCE_SYSTEM_ENCODING, genericArtifact
    // .getSourceSystemEncoding());
    // addAttribute(root, TARGET_SYSTEM_ENCODING, genericArtifact
    // .getTargetSystemEncoding());
    addAttribute(root, TRANSACTION_ID, genericArtifact.getTransactionId());

    if (genericArtifact.getAllGenericArtifactFields() != null) {
        // now add fields
        for (GenericArtifactField genericArtifactField : genericArtifact.getAllGenericArtifactFields()) {
            Element field = addElement(root, ARTIFACT_FIELD_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE);
            switch (genericArtifactField.getFieldAction()) {
            case APPEND: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_APPEND);
                break;
            }
            case DELETE: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_DELETE);
                break;
            }
            case REPLACE: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_REPLACE);
                break;
            }
            case UNKNOWN: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_UNKNOWN);
                break;
            }
            default: {
                throw new GenericArtifactParsingException(
                        "Non valid value for field-attribute " + FIELD_ACTION + " specified.");
            }
            }

            addAttribute(field, FIELD_NAME, genericArtifactField.getFieldName());
            addAttribute(field, FIELD_TYPE, genericArtifactField.getFieldType());
            if (genericArtifactField.getFieldValueHasChanged()) {
                addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_TRUE);
            } else {
                addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_FALSE);
            }

            if (genericArtifact.getIncludesFieldMetaData()
                    .equals(GenericArtifact.IncludesFieldMetaDataValue.TRUE)) {
                addAttribute(field, MIN_OCCURS, genericArtifactField.getMinOccursValue());
                addAttribute(field, MAX_OCCURS, genericArtifactField.getMaxOccursValue());
                addAttribute(field, NULL_VALUE_SUPPORTED, genericArtifactField.getNullValueSupported());
            } else if (!GenericArtifactField.VALUE_UNKNOWN
                    .equals(genericArtifactField.getAlternativeFieldName())
                    && genericArtifactField.getAlternativeFieldName() != null) {
                // if the alternative field name field has been set, we will ship it even if the other meta data has not been populated
                addAttribute(field, ALTERNATIVE_FIELD_NAME, genericArtifactField.getAlternativeFieldName());
            }

            setFieldValue(field, genericArtifactField.getFieldValue(),
                    genericArtifactField.getFieldValueType());
        }
    }
    root.addAttribute(
            new QName(SCHEMA_LOCATION_ATTRIBUTE, new Namespace(SCHEMA_NAMESPACE_PREFIX, SCHEMA_NAMESPACE)),
            CCF_SCHEMA_LOCATION);
    return document;
}

From source file:com.collabnet.ccf.core.GenericArtifactHelper.java

License:Apache License

/**
 * Creates a generic artifact XML representation out of the Java object
 * //from   www .j a v  a 2 s .c  o m
 * @param genericArtifact
 *            Java object that will be represented as XML document
 * @return XML representation of generic artifact
 */
public static Document createGenericArtifactXMLDocument(GenericArtifact genericArtifact)
        throws GenericArtifactParsingException {
    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding("UTF-8");
    // Create XML elements with attributes
    Element root = addRootElement(document, ARTIFACT_ROOT_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE);

    switch (genericArtifact.getArtifactAction()) {
    case CREATE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_CREATE);
        break;
    }
    case DELETE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_DELETE);
        break;
    }
    case IGNORE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_IGNORE);
        break;
    }
    case UPDATE: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UPDATE);
        break;
    }
    case RESYNC: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_RESYNC);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_ACTION, ARTIFACT_ACTION_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_ACTION + " specified.");
    }
    }

    switch (genericArtifact.getArtifactMode()) {
    case CHANGEDFIELDSONLY: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_CHANGED_FIELDS_ONLY);
        break;
    }
    case COMPLETE: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_COMPLETE);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_MODE, ARTIFACT_MODE_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_MODE + "specified.");
    }
    }

    ArtifactTypeValue artifactType = genericArtifact.getArtifactType();
    switch (artifactType) {
    case ATTACHMENT: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_ATTACHMENT);
        String content = genericArtifact.getArtifactValue();
        // TODO BASE64 validation?
        if (content != null)
            // embed content in CDATA section
            setValue(root, content, true);
        break;
    }
    case DEPENDENCY: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_DEPENDENCY);
        break;
    }
    case PLAINARTIFACT: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_PLAIN_ARTIFACT);
        break;
    }
    case UNKNOWN: {
        addAttribute(root, ARTIFACT_TYPE, ARTIFACT_TYPE_UNKNOWN);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_TYPE + " specified.");
    }
    }

    switch (genericArtifact.getIncludesFieldMetaData()) {
    case TRUE: {
        addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_TRUE);
        break;
    }
    case FALSE: {
        addAttribute(root, INCLUDES_FIELD_META_DATA, INCLUDES_FIELD_META_DATA_FALSE);
        break;
    }
    default: {
        throw new GenericArtifactParsingException(
                "Non valid value for root-attribute " + ARTIFACT_MODE + "specified.");
    }
    }

    addAttribute(root, SOURCE_ARTIFACT_LAST_MODIFICATION_DATE,
            genericArtifact.getSourceArtifactLastModifiedDate());
    addAttribute(root, TARGET_ARTIFACT_LAST_MODIFICATION_DATE,
            genericArtifact.getTargetArtifactLastModifiedDate());
    // addAttribute(root, ARTIFACT_LAST_READ_TRANSACTION_ID, genericArtifact
    // .getLastReadTransactionId());
    addAttribute(root, ERROR_CODE, genericArtifact.getErrorCode());
    addAttribute(root, SOURCE_ARTIFACT_VERSION, genericArtifact.getSourceArtifactVersion());
    addAttribute(root, TARGET_ARTIFACT_VERSION, genericArtifact.getTargetArtifactVersion());
    addAttribute(root, CONFLICT_RESOLUTION_PRIORITY, genericArtifact.getConflictResolutionPriority());

    // only create optional attributes if necessary
    if (artifactType == ArtifactTypeValue.DEPENDENCY || artifactType == ArtifactTypeValue.ATTACHMENT) {
        addAttribute(root, DEP_PARENT_SOURCE_ARTIFACT_ID, genericArtifact.getDepParentSourceArtifactId());
        addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_ID, genericArtifact.getDepParentSourceRepositoryId());
        addAttribute(root, DEP_PARENT_SOURCE_REPOSITORY_KIND,
                genericArtifact.getDepParentSourceRepositoryKind());
        addAttribute(root, DEP_PARENT_TARGET_ARTIFACT_ID, genericArtifact.getDepParentTargetArtifactId());
        addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_ID, genericArtifact.getDepParentTargetRepositoryId());
        addAttribute(root, DEP_PARENT_TARGET_REPOSITORY_KIND,
                genericArtifact.getDepParentTargetRepositoryKind());
    }

    // dependencies have even more optional attributes
    if (artifactType == ArtifactTypeValue.DEPENDENCY) {
        addAttribute(root, DEP_CHILD_SOURCE_ARTIFACT_ID, genericArtifact.getDepChildSourceArtifactId());
        addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_ID, genericArtifact.getDepChildSourceRepositoryId());
        addAttribute(root, DEP_CHILD_SOURCE_REPOSITORY_KIND, genericArtifact.getDepChildSourceRepositoryKind());
        addAttribute(root, DEP_CHILD_TARGET_ARTIFACT_ID, genericArtifact.getDepChildTargetArtifactId());
        addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_ID, genericArtifact.getDepChildTargetRepositoryId());
        addAttribute(root, DEP_CHILD_TARGET_REPOSITORY_KIND, genericArtifact.getDepChildTargetRepositoryKind());
    }

    addAttribute(root, SOURCE_ARTIFACT_ID, genericArtifact.getSourceArtifactId());
    addAttribute(root, SOURCE_REPOSITORY_ID, genericArtifact.getSourceRepositoryId());
    addAttribute(root, SOURCE_REPOSITORY_KIND, genericArtifact.getSourceRepositoryKind());
    addAttribute(root, SOURCE_SYSTEM_ID, genericArtifact.getSourceSystemId());
    addAttribute(root, SOURCE_SYSTEM_KIND, genericArtifact.getSourceSystemKind());
    addAttribute(root, TARGET_ARTIFACT_ID, genericArtifact.getTargetArtifactId());
    addAttribute(root, TARGET_REPOSITORY_ID, genericArtifact.getTargetRepositoryId());
    addAttribute(root, TARGET_REPOSITORY_KIND, genericArtifact.getTargetRepositoryKind());
    addAttribute(root, TARGET_SYSTEM_ID, genericArtifact.getTargetSystemId());
    addAttribute(root, TARGET_SYSTEM_KIND, genericArtifact.getTargetSystemKind());
    addAttribute(root, SOURCE_SYSTEM_TIMEZONE, genericArtifact.getSourceSystemTimezone());
    addAttribute(root, TARGET_SYSTEM_TIMEZONE, genericArtifact.getTargetSystemTimezone());
    // addAttribute(root, SOURCE_SYSTEM_ENCODING, genericArtifact
    // .getSourceSystemEncoding());
    // addAttribute(root, TARGET_SYSTEM_ENCODING, genericArtifact
    // .getTargetSystemEncoding());
    addAttribute(root, TRANSACTION_ID, genericArtifact.getTransactionId());

    if (genericArtifact.getAllGenericArtifactFields() != null) {
        // now add fields
        for (GenericArtifactField genericArtifactField : genericArtifact.getAllGenericArtifactFields()) {
            Element field = addElement(root, ARTIFACT_FIELD_ELEMENT_NAME, CCF_ARTIFACT_NAMESPACE);
            switch (genericArtifactField.getFieldAction()) {
            case APPEND: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_APPEND);
                break;
            }
            case DELETE: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_DELETE);
                break;
            }
            case REPLACE: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_REPLACE);
                break;
            }
            case UNKNOWN: {
                addAttribute(field, FIELD_ACTION, FIELD_ACTION_UNKNOWN);
                break;
            }
            default: {
                throw new GenericArtifactParsingException(
                        "Non valid value for field-attribute " + FIELD_ACTION + " specified.");
            }
            }

            addAttribute(field, FIELD_NAME, genericArtifactField.getFieldName());
            addAttribute(field, FIELD_TYPE, genericArtifactField.getFieldType());
            if (genericArtifactField.getFieldValueHasChanged()) {
                addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_TRUE);
            } else {
                addAttribute(field, FIELD_VALUE_HAS_CHANGED, FIELD_VALUE_HAS_CHANGED_FALSE);
            }

            if (genericArtifact.getIncludesFieldMetaData()
                    .equals(GenericArtifact.IncludesFieldMetaDataValue.TRUE)) {
                addAttribute(field, MIN_OCCURS, genericArtifactField.getMinOccursValue());
                addAttribute(field, MAX_OCCURS, genericArtifactField.getMaxOccursValue());
                addAttribute(field, NULL_VALUE_SUPPORTED, genericArtifactField.getNullValueSupported());
                addAttribute(field, ALTERNATIVE_FIELD_NAME, genericArtifactField.getAlternativeFieldName());
            }

            setFieldValue(field, genericArtifactField.getFieldValue(),
                    genericArtifactField.getFieldValueType());
        }
    }
    root.addAttribute(
            new QName(SCHEMA_LOCATION_ATTRIBUTE, new Namespace(SCHEMA_NAMESPACE_PREFIX, SCHEMA_NAMESPACE)),
            CCF_SCHEMA_LOCATION);
    return document;
}

From source file:com.collabnet.ccf.core.hospital.Ambulance.java

License:Open Source License

public static Document createXMLDocument(String encoding) {
    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding(encoding);
    return document;
}

From source file:com.collabnet.ccf.schemageneration.XSLTInitialMFDGenerator.java

License:Apache License

/**
 * Generates an intial MFD document that can be used for the graphical data mapping
 * @param sourceSchemaName file name of the source schema
 * @param targetSchemaName file name of the target schema
 * @return/*w ww. j a  v  a2s.  c o m*/
 * @throws TransformerException
 */
public Document generateInitialMFD(String sourceSchemaName, String targetSchemaName)
        throws TransformerException {
    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding("UTF-8");
    Element rootElement = document.addElement("CreateInitialMFDDocument");
    rootElement.addAttribute("sourceSchemaName", sourceSchemaName);
    rootElement.addAttribute("targetSchemaName", targetSchemaName);
    return transform(initialMFDFileTransformer, document);
}

From source file:com.creditcloud.investmentfund.model.huaan.money.CommonRequestMessage.java

/**
 * ??XML content// w ww  .ja  v  a 2 s  .  c  o m
 *
 * @return
 */
public String buildXMLPayload() {
    try {
        Map<String, String> map = toMapFromXMLPayloadParameters();
        final String rootXMLNodeName = "order";
        XmlFactory factory = new XmlFactory(new InputFactoryImpl(), new CDataXmlOutputFactoryImpl());
        XmlMapper xmlMapper = new XmlMapper(factory);
        xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
        String xml = xmlMapper.writeValueAsString(map);
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        root.setName(rootXMLNodeName);
        doc.setXMLEncoding(FundInterfaceConstants.HUA_AN_MONEY_FUND_HTTP_ENCODING);
        xml = doc.asXML();
        setContentXMLPayloadPlainText(xml);
        return xml;
    } catch (JsonProcessingException | DocumentException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.creditcloud.investmentfund.model.lion.moneyfund.response.NotificationResponseMessage.java

/**
 * ???XML?//from  www .  ja va 2  s.c  o m
 *
 * @return
 * @throws JsonProcessingException
 * @throws org.dom4j.DocumentException
 */
public String toXMLMessage() throws JsonProcessingException, DocumentException {
    final String rootXMLNodeName = "Message";
    ObjectMapper xmlMapper = new XmlMapper();
    String xml = xmlMapper.writeValueAsString(this);
    Document doc = DocumentHelper.parseText(xml);
    Element root = doc.getRootElement();
    root.setName(rootXMLNodeName);
    doc.setXMLEncoding(FundInterfaceConstants.LION_MONEY_FUND_HTTP_ENCODING);
    xml = doc.asXML();
    return xml;
}

From source file:com.dreikraft.axbo.sound.SoundPackageUtil.java

/**
 * creates a package-info.xml from the SoundPackage Bean
 *
 * @param soundPackage a SoundPackage Bean containing all the meta information
 * @return a dom4j document/* ww w. j  a  v  a2 s. c o  m*/
 */
public static Document createPackageInfoXml(final SoundPackage soundPackage) {

    Document document = DocumentHelper.createDocument();
    document.setXMLEncoding(ENCODING);

    Element rootNode = document.addElement(SoundPackageNodes.axboSounds.toString());
    rootNode.addElement(SoundPackageNodes.packageName.toString()).addText(soundPackage.getName());
    rootNode.addElement(SoundPackageNodes.creator.toString()).addText(soundPackage.getCreator());
    rootNode.addElement(SoundPackageNodes.creationDate.toString())
            .addText(new SimpleDateFormat(pattern).format(soundPackage.getCreationDate()));

    Element securityNode = rootNode.addElement(SoundPackageNodes.security.toString());
    securityNode.addElement(SoundPackageNodes.serialNumber.toString()).addText(soundPackage.getSerialNumber());
    securityNode.addElement(SoundPackageNodes.enforced.toString())
            .addText("" + soundPackage.isSecurityEnforced());

    Element soundsNode = rootNode.addElement(SoundPackageNodes.sounds.toString());
    int id = 1;
    for (Sound sound : soundPackage.getSounds()) {
        Element soundNode = soundsNode.addElement(SoundPackageNodes.sound.toString());
        soundNode.addAttribute(SoundPackageAttributes.id.toString(), String.valueOf(id));
        soundNode.addElement(SoundPackageNodes.displayName.toString()).addText(sound.getName());

        Element axboFileNode = soundNode.addElement(SoundPackageNodes.axboFile.toString());
        axboFileNode.addElement(SoundPackageNodes.path.toString()).setText(sound.getAxboFile().extractName());
        axboFileNode.addElement(SoundPackageNodes.type.toString())
                .setText(sound.getAxboFile().getType().toString());

        id++;
    }
    return document;
}