Search in sources :

Example 1 with Document

use of org.w3._2007.rif.Document in project nhin-d by DirectProject.

the class DirectDocuments method toProvideAndRegisterDocumentSetRequestType.

public ProvideAndRegisterDocumentSetRequestType toProvideAndRegisterDocumentSetRequestType() throws IOException {
    ProvideAndRegisterDocumentSetRequestType request = new ProvideAndRegisterDocumentSetRequestType();
    request.setSubmitObjectsRequest(this.getSubmitObjectsRequest());
    for (DirectDocument2 document : documents) {
        if (document.getData() != null) {
            DataSource source = new ByteArrayDataSource(document.getData(), document.getMetadata().getMimeType());
            DataHandler dhnew = new DataHandler(source);
            Document pdoc = new Document();
            pdoc.setValue(dhnew);
            String id = document.getMetadata().getId();
            pdoc.setId(id);
            request.getDocument().add(pdoc);
        }
    }
    return request;
}
Also used : DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 2 with Document

use of org.w3._2007.rif.Document in project nhin-d by DirectProject.

the class DefaultXdmXdsTransformer method transform.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.transform.XdmXdsTransformer#transform(java.io.File)
     */
@Override
public ProvideAndRegisterDocumentSetRequestType transform(File file) throws TransformationException {
    LOGGER.trace("Begin transformation of XDM to XDS (file)");
    String docId = null;
    ZipFile zipFile = null;
    String docName = getDocName(file);
    if (docName != null) {
        XDM_FILENAME_DATA = docName;
    }
    ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
    try {
        zipFile = new ZipFile(file, ZipFile.OPEN_READ);
        Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
        ZipEntry zipEntry = null;
        // load the ZIP archive into memory
        while (zipEntries.hasMoreElements()) {
            zipEntry = zipEntries.nextElement();
            String zname = zipEntry.getName();
            LOGGER.trace("Processing a ZipEntry " + zname);
            if (!zipEntry.isDirectory()) {
                String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
                // Read metadata
                if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
                    prsr.setSubmitObjectsRequest(submitObjectRequest);
                    docId = getDocId(submitObjectRequest);
                } else // Read data
                if (matchName(zname, subsetDirspec, XDM_FILENAME_DATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    DataSource source = new ByteArrayDataSource(byteArrayOutputStream.toByteArray(), MimeType.APPLICATION_XML + "; charset=UTF-8");
                    DataHandler dhnew = new DataHandler(source);
                    Document pdoc = new Document();
                    pdoc.setValue(dhnew);
                    pdoc.setId(docId);
                    List<Document> docs = prsr.getDocument();
                    docs.add(pdoc);
                }
            }
            if (!prsr.getDocument().isEmpty()) {
                ((Document) prsr.getDocument().get(0)).setId(zname);
            }
        }
        zipFile.close();
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to complete transformation.", e);
        }
        throw new TransformationException("Unable to complete transformation.", e);
    }
    return prsr;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) SubmitObjectsRequest(oasis.names.tc.ebxml_regrep.xsd.lcm._3.SubmitObjectsRequest) TransformationException(org.nhindirect.xd.transform.exception.TransformationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) ZipFile(java.util.zip.ZipFile) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 3 with Document

use of org.w3._2007.rif.Document in project nhin-d by DirectProject.

the class DefaultXdsDirectDocumentsTransformer method transform.

@Override
public DirectDocuments transform(ProvideAndRegisterDocumentSetRequestType provideAndRegisterDocumentSetRequestType) throws TransformationException {
    DirectDocuments documents = new DirectDocuments();
    try {
        documents.setValues(provideAndRegisterDocumentSetRequestType.getSubmitObjectsRequest());
    } catch (MetadataException e) {
        throw new TransformationException("Unable to complete transformation due to metadata error", e);
    }
    for (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document document : provideAndRegisterDocumentSetRequestType.getDocument()) {
        byte[] data = null;
        try {
            DataHandler dataHandler = document.getValue();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            dataHandler.writeTo(outputStream);
            data = outputStream.toByteArray();
        } catch (IOException e) {
            throw new TransformationException("Unable to complete transformation due to document IO error", e);
        }
        DirectDocument2 doc = documents.getDocumentByUniqueId(document.getId());
        if (doc != null) {
            doc.setData(data);
        } else {
            documents.getDocumentById(document.getId()).setData(data);
        }
    }
    return documents;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) DirectDocument2(org.nhindirect.xd.common.DirectDocument2) DirectDocuments(org.nhindirect.xd.common.DirectDocuments) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MetadataException(org.nhindirect.xd.common.exception.MetadataException) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 4 with Document

use of org.w3._2007.rif.Document in project poi by apache.

the class RelationshipTransformService method marshalParams.

@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
    DOMStructure domParent = (DOMStructure) parent;
    Element parentNode = (Element) domParent.getNode();
    // parentNode.setAttributeNS(XML_NS, "xmlns:mdssi", XML_DIGSIG_NS);
    Document doc = parentNode.getOwnerDocument();
    for (String sourceId : this.sourceIds) {
        RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
        relRef.addNewRelationshipReference().setSourceId(sourceId);
        Node n = relRef.getRelationshipReference().getDomNode();
        n = doc.importNode(n, true);
        parentNode.appendChild(n);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DOMStructure(javax.xml.crypto.dom.DOMStructure) RelationshipReferenceDocument(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.RelationshipReferenceDocument) Document(org.w3c.dom.Document) TransformDocument(org.w3.x2000.x09.xmldsig.TransformDocument) RelationshipsDocument(org.openxmlformats.schemas.xpackage.x2006.relationships.RelationshipsDocument) RelationshipReferenceDocument(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.RelationshipReferenceDocument)

Example 5 with Document

use of org.w3._2007.rif.Document in project poi by apache.

the class SignatureInfo method confirmSignature.

/**
     * add the xml signature to the document
     *
     * @throws XMLSignatureException
     * @throws MarshalException
     */
public void confirmSignature() throws XMLSignatureException, MarshalException {
    Document document = DocumentHelper.createDocument();
    // operate
    DigestInfo digestInfo = preSign(document, null);
    // setup: key material, signature value
    byte[] signatureValue = signDigest(digestInfo.digestValue);
    // operate: postSign
    postSign(document, signatureValue);
}
Also used : Document(org.w3c.dom.Document) SignatureDocument(org.w3.x2000.x09.xmldsig.SignatureDocument)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataHandler (javax.activation.DataHandler)5 ProvideAndRegisterDocumentSetRequestType (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)4 Document (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document)4 IOException (java.io.IOException)4 DataSource (javax.activation.DataSource)4 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)4 DirectDocuments (org.nhindirect.xd.common.DirectDocuments)4 DomBasedUnitTest (com.onespatial.jrc.tns.oml_to_rif.fixture.DomBasedUnitTest)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Document (org.w3._2007.rif.Document)3 Document (org.w3c.dom.Document)3 URI (java.net.URI)2 InitialContext (javax.naming.InitialContext)2 RegistryResponseType (oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)2 Test (org.junit.Test)2 MailClient (org.nhind.xdm.MailClient)2 SmtpMailClient (org.nhind.xdm.impl.SmtpMailClient)2 DirectMessage (org.nhindirect.xd.common.DirectMessage)2