Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:eu.dasish.annotation.backend.dao.impl.DBDispatcherTest.java

@Test
public void testGetNotebook() throws DatatypeConfigurationException {

    final Notebook mockNotebook = new Notebook();
    mockNotebook.setHref("/api/notebooks/00000000-0000-0000-0000-000000000012");
    mockNotebook.setId("00000000-0000-0000-0000-000000000012");
    mockNotebook.setTitle("Notebook 2");
    mockNotebook.setLastModified(//from  ww  w.  j  a v a2 s . c o  m
            DatatypeFactory.newInstance().newXMLGregorianCalendar("2014-02-12T09:25:00.383000Z"));

    final List<Number> mockAnnotations = new ArrayList<Number>();
    mockAnnotations.add(3);

    final List<Number> mockREADs = new ArrayList<Number>();
    mockREADs.add(1);

    final List<Number> mockWRITEs = new ArrayList<Number>();
    mockWRITEs.add(3);

    mockeryDao.checking(new Expectations() {
        {
            oneOf(notebookDao).getNotebookWithoutAnnotationsAndAccesssAndOwner(2);
            will(returnValue(mockNotebook));

            oneOf(notebookDao).getOwner(2);
            will(returnValue(2));

            oneOf(principalDao).getHrefFromInternalID(2);
            will(returnValue("/api/principals/00000000-0000-0000-0000-000000000112"));

            oneOf(annotationDao).getAnnotations(2);
            will(returnValue(mockAnnotations));

            oneOf(annotationDao).getHrefFromInternalID(3);
            will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000023"));

            oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.READ);
            will(returnValue(mockREADs));

            oneOf(principalDao).getHrefFromInternalID(1);
            will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111"));

            oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.WRITE);
            will(returnValue(mockWRITEs));

            oneOf(principalDao).getHrefFromInternalID(3);
            will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113"));

            oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.ALL);
            will(returnValue(new ArrayList<Number>()));

        }
    });

    Notebook result = dbDispatcher.getNotebook(2);
    assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000012", result.getHref());
    assertEquals("00000000-0000-0000-0000-000000000012", result.getId());
    assertEquals("/api/principals/00000000-0000-0000-0000-000000000112", result.getOwnerRef());
    assertEquals("2014-02-12T09:25:00.383000Z", result.getLastModified().toString());
    assertEquals("Notebook 2", result.getTitle());
    assertEquals(1, result.getAnnotations().getHref().size());
    assertEquals("/api/annotations/00000000-0000-0000-0000-000000000023",
            result.getAnnotations().getHref().get(0));
    assertEquals(2, result.getPermissions().getPermission().size());
    assertEquals("/api/principals/00000000-0000-0000-0000-000000000111",
            result.getPermissions().getPermission().get(0).getPrincipalHref());
    assertEquals("read", result.getPermissions().getPermission().get(0).getLevel().value());
    assertEquals("/api/principals/00000000-0000-0000-0000-000000000113",
            result.getPermissions().getPermission().get(1).getPrincipalHref());
    assertEquals("write", result.getPermissions().getPermission().get(1).getLevel().value());

}

From source file:com.ext.portlet.epsos.EpsosHelperService.java

public final boolean addPatientConsent(PatientConsentObject object, EhrPatientClientDto patient,
        HttpServletRequest request) {//from   w ww. ja v a 2  s  .  c o  m
    boolean consentCreated = false;
    PatientConsentObject result = null;

    SpiritUserClientDto usr = (SpiritUserClientDto) request.getSession()
            .getAttribute(EPSOS_LOGIN_INFORMATION_ATTRIBUTE);
    if (usr != null) {
        //upload consent document
        try {
            SpiritEhrWsClientInterface webservice = this.getWebService(request);

            List<PolicySetGroup> objGroupList = webservice.queryPolicySetsForPatient(patient).getGroupList();

            String[] policyids = request.getParameterValues("policyid");

            if (policyids != null && objGroupList != null) {
                for (PolicySetGroup g : objGroupList) {
                    // first unselect all policies:
                    for (PolicySetItem i : g.getPolicySetItemList()) {
                        i.setSelected(false);
                    }

                    // then only select the ones selected by the user in the interface
                    for (String id : policyids) {
                        String groupCode = id.substring(0, id.indexOf("$$$"));
                        if (groupCode.equals(g.getCode())) {
                            String policyId = id.substring(id.indexOf("$$$") + 3);
                            for (PolicySetItem i : g.getPolicySetItemList()) {
                                if (i.getPolicySetId().equals(policyId)) {
                                    i.setSelected(true);
                                    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
                                    Date fromDate = GetterUtil.getDate(
                                            request.getParameter(groupCode + "$$$" + policyId + "_fromDate"),
                                            dateTimeFormat, null);
                                    if (fromDate != null) {
                                        cal.setTime(fromDate);
                                        XMLGregorianCalendar fromCal = DatatypeFactory.newInstance()
                                                .newXMLGregorianCalendar(cal);
                                        i.setEffectiveDateFrom(fromCal);
                                    }
                                    Date toDate = GetterUtil.getDate(
                                            request.getParameter(groupCode + "$$$" + policyId + "_toDate"),
                                            dateTimeFormat, null);
                                    if (toDate != null) {
                                        cal.setTime(toDate);
                                        XMLGregorianCalendar toCal = DatatypeFactory.newInstance()
                                                .newXMLGregorianCalendar(cal);
                                        i.setEffectiveDateTo(toCal);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            EpsosHelperService.getInstance()
                    .createLog("CREATE PATIENT CONSENT REQUEST:" + patient.getGivenName(), usr);
            webservice.saveConsent(patient, GeneralUtils.getLocale(request), "Patient Consent", objGroupList);
            consentCreated = true;
            EpsosHelperService.getInstance()
                    .createLog("CREATE PATIENT CONSENT RESPONSE OK:" + patient.getGivenName(), usr);

        } catch (Exception e1) {
            EpsosHelperService.getInstance().createLog("CREATE PATIENT CONSENT RESPONSE FAILURE:"
                    + patient.getGivenName() + ".ERROR: " + e1.getMessage(), usr);
            request.setAttribute("exception", e1.getMessage());
            e1.printStackTrace();
        }

        //result = object;
    }
    return consentCreated;
}

From source file:org.motechproject.mobile.omp.manager.intellivr.IntellIVRBeanTest.java

private XMLGregorianCalendar toXMLGregorianCalendar(Date date) throws DatatypeConfigurationException {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(date);/* w  ww . jav  a  2  s . c  o  m*/
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
}

From source file:com.ext.portlet.epsos.EpsosHelperService.java

public static boolean writeConsent(SpiritEhrWsClientInterface webservice, EhrPatientClientDto patient,
        String country, String language, String policy, String fromdate, String todate) {
    boolean consentCreated = false;
    PatientConsentObject result = null;/* www  .ja  va2s  . co m*/
    if (true) {
        //upload consent document
        try {
            List<PolicySetGroup> objGroupList = webservice.queryPolicySetsForPatient(patient).getGroupList();

            String[] policyids = new String[] { policy };
            if (policyids != null && objGroupList != null) {
                for (PolicySetGroup g : objGroupList) {
                    // first unselect all policies:
                    for (PolicySetItem i : g.getPolicySetItemList()) {
                        i.setSelected(false);
                    }

                    // then only select the ones selected by the user in the interface
                    for (String id : policyids) {

                        String groupCode = id.substring(0, id.indexOf("$$$"));
                        _log.info("groupode=" + groupCode);
                        if (groupCode.equals(g.getCode())) {
                            String policyId = id.substring(id.indexOf("$$$") + 3);
                            _log.info("policyid=" + policyId);
                            for (PolicySetItem i : g.getPolicySetItemList()) {
                                if (i.getPolicySetId().equals(policyId)) {
                                    i.setSelected(true);
                                    GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
                                    Date fromDate = GetterUtil.getDate(fromdate, dateTimeFormat, null);
                                    if (fromDate != null) {
                                        cal.setTime(fromDate);
                                        XMLGregorianCalendar fromCal = DatatypeFactory.newInstance()
                                                .newXMLGregorianCalendar(cal);
                                        i.setEffectiveDateFrom(fromCal);
                                    }
                                    Date toDate = GetterUtil.getDate(todate, dateTimeFormat, null);
                                    if (toDate != null) {
                                        cal.setTime(toDate);
                                        XMLGregorianCalendar toCal = DatatypeFactory.newInstance()
                                                .newXMLGregorianCalendar(cal);
                                        i.setEffectiveDateTo(toCal);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            EpsosHelperService.getInstance()
                    .createLog("CREATE PATIENT CONSENT REQUEST:" + patient.getGivenName(), null);
            webservice.saveConsent(patient, language, "Patient Consent", objGroupList);
            consentCreated = true;
            EpsosHelperService.getInstance()
                    .createLog("CREATE PATIENT CONSENT RESPONSE OK:" + patient.getGivenName(), null);

        } catch (Exception e1) {
            EpsosHelperService.getInstance().createLog("CREATE PATIENT CONSENT RESPONSE FAILURE:"
                    + patient.getGivenName() + ".ERROR: " + e1.getMessage(), null);
            e1.printStackTrace();
        }

        //result = object;
    }
    return consentCreated;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

public static XMLGregorianCalendar long2Gregorian(long date) {
    DatatypeFactory dataTypeFactory;
    try {
        dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }/*from  w ww .ja  va2  s  .com*/
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(date);
    return dataTypeFactory.newXMLGregorianCalendar(gc);
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Returns a positive integer if ts1 depicts a time after ts2 (ts1 > ts2), 0 if ts1 and ts2 depict the same time
 * (ts1 == ts2), and a negative integer if if ts1 depicts a time before ts2 (ts1 < ts2).
 * // w w  w  .  j  av a 2  s. co  m
 * @param ts1
 *            The first timestamp.
 * @param ts2
 *            The second timestamp.
 * @return The comparison result.
 * @throws Exception
 *             If anything fails (e.g. one timstamp has incorrect format).
 */
public static int compareTimestamps(final String ts1, final String ts2) throws Exception {

    int result = 0;

    XMLGregorianCalendar date1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts1);
    XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts2);

    int diff = date1.compare(date2);
    if (diff == DatatypeConstants.LESSER) {
        result = -1;
    } else if (diff == DatatypeConstants.GREATER) {
        result = 1;
    } else if (diff == DatatypeConstants.EQUAL) {
        result = 0;
    } else if (diff == DatatypeConstants.INDETERMINATE) {
        throw new Exception("Date comparing: INDETERMINATE");
    }

    return result;
}

From source file:com.ext.portlet.epsos.EpsosHelperService.java

private String xmlEncodeDate(Date date) {
    if (date == null)
        return "";
    try {/*from w  w  w.  j a  v a2s  .c  o  m*/
        GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
        cal.setTime(date);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        return xmlCal.toXMLFormat();
    } catch (Exception e) {
        return date.toString();
    }
}

From source file:nl.clockwork.mule.ebms.stub.ebf.component.AfleverBerichtGenerator.java

@Override
public Object onCall(MuleMessage message) throws Exception {
    if (message.getPayload() instanceof String) {
        Properties p = new Properties();
        p.load(new StringReader((String) message.getPayload()));
        String baseDir = this.baseDir + "/" + p.getProperty("baseDir");
        AfleverBericht afleverBericht = new AfleverBericht();
        afleverBericht.setKenmerk(p.getProperty("kenmerk"));
        afleverBericht.setBerichtsoort(p.getProperty("berichtsoort"));
        afleverBericht.setBerichtkenmerk(p.getProperty("berichtkenmerk"));
        afleverBericht.setAanleverkenmerk(p.getProperty("aanleverkenmerk"));
        afleverBericht.setTijdstempelAangeleverd(
                DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        afleverBericht.setIdentiteitBelanghebbende(new IdentiteitType());
        afleverBericht.getIdentiteitBelanghebbende()
                .setNummer(p.getProperty("identiteitBelanghebbende.nummer"));
        afleverBericht.getIdentiteitBelanghebbende().setType(p.getProperty("identiteitBelanghebbende.type"));
        afleverBericht.setRolBelanghebbende(p.getProperty("rolBelanghebbende"));
        afleverBericht.setIdentiteitOntvanger(new IdentiteitType());
        afleverBericht.getIdentiteitOntvanger().setNummer(p.getProperty("identiteitOntvanger.nummer"));
        afleverBericht.getIdentiteitOntvanger().setType(p.getProperty("identiteitOntvanger.type"));
        afleverBericht.setRolOntvanger(p.getProperty("rolOntvanger"));
        setBerichtInhoud(baseDir, afleverBericht, p.getProperty("berichtInhoud"));
        setBerichtBijlagen(baseDir, afleverBericht, p.getProperty("berichtBijlagen").split(","));
        String result = XMLMessageBuilder.getInstance(AfleverBericht.class).handle(afleverBericht);
        message.setProperty("originalFilename", p.getProperty("berichtInhoud"));
        message.setPayload(result);//  w w w  .  j av a 2  s .co  m
    }
    return message;
}

From source file:nl.clockwork.mule.ebms.stub.ebf.transformer.AanleverBerichtToAanleverBevestiging.java

@Override
public Object transform(MuleMessage message, String outputEncoding) throws TransformerException {
    try {//  ww  w .j  a va 2 s .c o  m
        EbMSMessageContent content = (EbMSMessageContent) message.getPayload();
        AanleverBericht aanleverBericht = XMLMessageBuilder.getInstance(AanleverBericht.class)
                .handle(new String(content.getAttachments().iterator().next().getContent()));
        BevestigAanleverBericht aanleverBevestiging = new BevestigAanleverBericht();

        aanleverBevestiging.setKenmerk(
                StringUtils.isAlpha(aanleverBericht.getKenmerk()) ? aanleverBericht.getKenmerk() : "kenmerk");
        aanleverBevestiging.setBerichtsoort(aanleverBericht.getBerichtsoort());
        aanleverBevestiging.setAanleverkenmerk(aanleverBericht.getAanleverkenmerk());
        aanleverBevestiging.setEerderAanleverkenmerk(aanleverBericht.getEerderAanleverkenmerk());
        aanleverBevestiging.setIdentiteitBelanghebbende(new IdentiteitType());
        aanleverBevestiging.getIdentiteitBelanghebbende()
                .setNummer(aanleverBericht.getIdentiteitBelanghebbende().getNummer());
        aanleverBevestiging.getIdentiteitBelanghebbende()
                .setType(aanleverBericht.getIdentiteitBelanghebbende().getType());
        aanleverBevestiging.setRolBelanghebbende(aanleverBericht.getRolBelanghebbende());
        if (aanleverBericht.getIdentiteitOntvanger() != null) {
            aanleverBevestiging.setIdentiteitOntvanger(new IdentiteitType());
            aanleverBevestiging.getIdentiteitOntvanger()
                    .setNummer(aanleverBericht.getIdentiteitOntvanger().getNummer());
            aanleverBevestiging.getIdentiteitOntvanger()
                    .setType(aanleverBericht.getIdentiteitOntvanger().getType());
        } else {
            aanleverBevestiging.setIdentiteitOntvanger(new IdentiteitType());
            aanleverBevestiging.getIdentiteitOntvanger().setNummer("nummer");
        }
        aanleverBevestiging.setRolOntvanger(aanleverBericht.getRolOntvanger());
        aanleverBevestiging.setAutorisatieAdres(aanleverBericht.getAutorisatieAdres());
        aanleverBevestiging.setStatuscode("0");
        aanleverBevestiging.setTijdstempelStatus(
                DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));

        FoutType error = (FoutType) message.getProperty("AANLEVERBERICHT_ERROR");
        if (error == null)
            aanleverBevestiging.setTijdstempelAangeleverd(
                    DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        else
            aanleverBevestiging.setFout(error);

        List<EbMSAttachment> attachments = new ArrayList<EbMSAttachment>();
        attachments.add(new EbMSAttachment(name, "application/xml", XMLMessageBuilder
                .getInstance(BevestigAanleverBericht.class).handle(aanleverBevestiging).getBytes()));

        return new EbMSMessageContent(
                new EbMSMessageContext(cpaId, service, action, content.getContext().getConversationId()),
                attachments);
    } catch (Exception e) {
        throw new TransformerException(this, e);
    }
}

From source file:nl.clockwork.mule.ebms.transformer.EbMSMessageToEbMSAcknowledgment.java

@Override
public Object transform(MuleMessage message, String outputEncoding) throws TransformerException {
    try {/*from  ww w .jav a  2  s  .  c  o  m*/
        GregorianCalendar timestamp = new GregorianCalendar();

        EbMSMessage msg = (EbMSMessage) message.getPayload();
        MessageHeader messageHeader = EbMSMessageUtils.createMessageHeader(msg.getMessageHeader(), hostname,
                timestamp, EbMSMessageType.ACKNOWLEDGMENT.action());

        Acknowledgment acknowledgment = new Acknowledgment();

        acknowledgment.setVersion(Constants.EBMS_VERSION);
        acknowledgment.setMustUnderstand(true);

        acknowledgment.setTimestamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(timestamp));
        acknowledgment.setRefToMessageId(messageHeader.getMessageData().getRefToMessageId());
        acknowledgment.setFrom(new From()); //optioneel
        acknowledgment.getFrom().getPartyId().addAll(messageHeader.getFrom().getPartyId());
        // ebMS specs 1701
        //acknowledgment.getFrom().setRole(messageHeader.getFrom().getRole());
        acknowledgment.getFrom().setRole(null);

        //TODO resolve actor from CPA
        acknowledgment.setActor(ActorType.URN_OASIS_NAMES_TC_EBXML_MSG_ACTOR_TO_PARTY_MSH.value());

        if (msg.getAckRequested().isSigned() && msg.getSignature() != null)
            for (ReferenceType reference : msg.getSignature().getSignedInfo().getReference())
                acknowledgment.getReference().add(reference);

        message.setPayload(new EbMSAcknowledgment(messageHeader, acknowledgment));
        return message;
    } catch (DatatypeConfigurationException e) {
        throw new TransformerException(this, e);
    }
}