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:edu.harvard.i2b2.fhir.FhirUtil.java

private static Meta createMeta() {
    Meta meta = new Meta();
    Id vId = new Id();
    vId.setValue("1");
    meta.setVersionId(vId);//from   w  w w .  j a va  2s.  c om
    Instant instantVal = new Instant();
    XMLGregorianCalendar xmlGregvalue;
    try {
        xmlGregvalue = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    } catch (DatatypeConfigurationException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
    instantVal.setValue(xmlGregvalue);
    meta.setLastUpdated(instantVal);
    return meta;
}

From source file:io.uengine.util.DateUtils.java

/**
 * java.util.Date  javax.xml.datatype.XMLGregorianCalendar  .
 *
 * @param date /*from w ww . j  ava2 s . co m*/
 * @return XMLGregorianCalendar
 * @throws DatatypeConfigurationException
 */
public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) throws DatatypeConfigurationException {
    if (date == null)
        return null;
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateToGregorianCalendar(date));
}

From source file:com.qut.middleware.delegator.openid.authn.impl.AuthnProcessorImpl.java

/**
 * Generates an XML gregorian calendar instance based on 0 offset UTC current time.
 *
 * @return The created calendar for the current UTC time, else null if an error
 * occurs creating the calendar./*  w  w w .jav  a  2s .  com*/
 */
private XMLGregorianCalendar generateXMLCalendar() {
    GregorianCalendar calendar;

    SimpleTimeZone tz = new SimpleTimeZone(0, ConfigurationConstants.timeZone);
    calendar = new GregorianCalendar(tz);

    try {
        DatatypeFactory factory = DatatypeFactory.newInstance();
        return factory.newXMLGregorianCalendar(calendar);
    } catch (DatatypeConfigurationException e) {
        return null;
    }
}

From source file:fr.efl.chaine.xslt.GauloisPipe.java

/**
 * Execute the pipe for the specified input stream to the specified
 * serializer.<br>//from   w  w  w.  j a  va 2s .co  m
 * <b>Warning</b>: this method is public for implementation reasons,
 * and <b>must not</b> be called outside of GauloisPipe
 *
 * @param pipe the pipe to run
 * @param input the specified input stream
 * @param listener the message listener to use
 * @throws SaxonApiException when a problem occurs
 * @throws java.net.MalformedURLException When an URL is not correctly formed
 * @throws fr.efl.chaine.xslt.InvalidSyntaxException When config file is invalid
 * @throws java.net.URISyntaxException When URI is invalid
 * @throws java.io.FileNotFoundException And when the file can not be found !
 */
public void execute(Pipe pipe, ParametrableFile input, MessageListener listener) throws SaxonApiException,
        MalformedURLException, InvalidSyntaxException, URISyntaxException, FileNotFoundException, IOException {
    boolean avoidCache = input.getAvoidCache();
    long start = System.currentTimeMillis();
    String key = input.getFile().getAbsolutePath().intern();
    XdmNode source = documentCache.get(key);
    if (source == null || avoidCache) {
        if (!avoidCache && documentCache.isLoading(instanceName)) {
            source = documentCache.waitForLoading(key);
        }
        if (source == null || avoidCache) {
            synchronized (key) {
                if (!avoidCache) {
                    source = documentCache.get(key);
                }
                if (source == null) {
                    documentCache.setLoading(key);
                    if (config.isLogFileSize()) {
                        LOGGER.info("[" + instanceName + "] " + input.toString() + " as input: "
                                + input.getFile().length());
                    }
                    source = builder.build(input.getFile());
                    if (!avoidCache && config.getSources().getFileUsage(input.getFile()) > 1) {
                        // on ne le met en cache que si il est utilis plusieurs fois !
                        LOGGER.debug("[" + instanceName + "] caching " + key);
                        documentCache.put(key, source);
                    } else {
                        documentCache.ignoreLoading(key);
                        if (avoidCache) {
                            LOGGER.trace("[" + instanceName + "] " + key + " exclued from cache");
                        } else {
                            LOGGER.trace("[" + instanceName + "] " + key + " used only once, no cache");
                        }
                    }
                }
            }
        }
    }
    HashMap<QName, ParameterValue> parameters = ParametersMerger.addInputInParameters(
            ParametersMerger.merge(input.getParameters(), config.getParams()), input.getFile());
    XsltTransformer transformer = buildTransformer(pipe, input.getFile(),
            input.getFile().toURI().toURL().toExternalForm(), parameters, listener, source);
    LOGGER.debug("[" + instanceName + "] transformer build");
    transformer.setInitialContextNode(source);
    transformer.transform();
    long duration = System.currentTimeMillis() - start;
    String distinctName = input.toString();
    try {
        Duration duree = DatatypeFactory.newInstance().newDuration(duration);
        LOGGER.info(
                "[" + instanceName + "] - " + distinctName + " - transform terminated: " + duree.toString());
    } catch (Exception ex) {
        LOGGER.info("[" + instanceName + "] - " + distinctName + " - transform terminated");
    }
}

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

public EhrPatientClientDto createPatFilter(PatientSearchForm searchForm) {
    EhrPatientClientDto patFilter = new EhrPatientClientDto();
    if (Validator.isNotNull(searchForm.getSurName()))
        patFilter.setFamilyName(searchForm.getSurName());

    if (Validator.isNotNull(searchForm.getGivenName()))
        patFilter.setGivenName(searchForm.getGivenName());

    if (Validator.isNotNull(searchForm.getBirthDate())) {
        try {//  w w  w  .  j a v a 2 s .  c om
            Date date = EpsosHelperService.dateFormat.parse(searchForm.getBirthDate());
            GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
            cal.setTime(date);
            XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
            patFilter.setBirthdate(xmlCal);
        } catch (Exception e) {
        }
    }

    if (Validator.isNotNull(searchForm.getSex()))
        patFilter.setSex(searchForm.getSex());

    if (Validator.isNotNull(searchForm.getStreet()))
        patFilter.setStreetAddress(searchForm.getStreet());

    if (Validator.isNotNull(searchForm.getZipCode()))
        patFilter.setZip(searchForm.getZipCode());

    if (Validator.isNotNull(searchForm.getCity()))
        patFilter.setCity(searchForm.getCity());

    if (Validator.isNotNull(searchForm.getCountry()))
        patFilter.setCountry(searchForm.getCountry());

    // Identifier criteria
    if (Validator.isNotNull(searchForm.country)) {
        String DEFAULT_PATIENT_IDS = GetterUtil.getString(
                GnPropsUtil.get("portalb", "epsos.search.patient.ids.default"),
                "ssnNumber,driversLicense,accountNumber");
        //String[] countryPatientIds = GetterUtil.getString(GnPropsUtil.get("portalb", "epsos.search.patient.ids."+searchForm.country), DEFAULT_PATIENT_IDS).split(",");

        EpsosHelperImpl eh = new EpsosHelperImpl();
        Vector countryPatientIds = EpsosHelperService.getInstance()
                .getCountryIdsFromCS(searchForm.getCountry());
        //         Vector<StrutsFormFields> fields = eh.getFieldsForCountryFromNCP(searchForm.getCountry());

        //         String mainPIDType = GetterUtil.getString(GnPropsUtil.get("portalb", "epsos.patient.identifier.main.type"), "PI");
        //         
        //         if (Validator.isNotNull(searchForm.getPid())) {
        //            EhrPIDClientDto pidDto = new EhrPIDClientDto();
        //            pidDto.setPatientID(searchForm.getPid());
        //            pidDto.setPatientIDType(mainPIDType);
        //            
        //            String RRI_OID = GetterUtil.getString(GnPropsUtil.get("portalb", "RRI." + searchForm.getCountry()), "");
        //            EhrDomainClientDto domain = new EhrDomainClientDto();
        //            domain.setAuthUniversalID(RRI_OID);
        //            pidDto.setDomain(domain);
        //            
        //            patFilter.getPid().add(pidDto);
        //         }

        String idType = "";
        if (countryPatientIds != null && countryPatientIds.size() > 0) {
            int i = 1;
            for (int j = 0; j < countryPatientIds.size(); j++)
            //for (String idType: countryPatientIds)
            {
                SearchMask sm = (SearchMask) countryPatientIds.get(j);
                idType = sm.getDomain();
                if (idType != null && !idType.equals("none") && Validator.isNotNull(searchForm.getPid(i))) {
                    EhrPIDClientDto pidDto = new EhrPIDClientDto();
                    pidDto.setPatientID(searchForm.getPid(i));
                    //pidDto.setPatientIDType(idType);

                    EhrDomainClientDto domain = new EhrDomainClientDto();
                    domain.setAuthUniversalID(idType);
                    pidDto.setDomain(domain);

                    patFilter.getPid().add(pidDto);
                }
                i++;
            }
        }
    }

    if (Validator.isNotNull(searchForm.getSsnNumber()))
        patFilter.setSsnNumber(searchForm.getSsnNumber());

    if (Validator.isNotNull(searchForm.getDriversLicense()))
        patFilter.setDrivingLicense(searchForm.getDriversLicense());

    if (Validator.isNotNull(searchForm.getAccountNumber()))
        patFilter.setAccountNumber(searchForm.getAccountNumber());

    return patFilter;
}

From source file:cz.cas.lib.proarc.common.export.mets.structure.MetsElementVisitor.java

/**
 * Prepares a mets FileType element for a file
 *
 * @param seq/*from  w w w .  ja  va  2s  .  c  o  m*/
 * @param metsStreamName
 * @return
 */
private FileType prepareFileType(int seq, String metsStreamName, HashMap<String, Object> fileNames,
        HashMap<String, String> mimeTypes, MetsContext metsContext, HashMap<String, String> outputFileNames,
        HashMap<String, FileMD5Info> md5InfosMap) throws MetsExportException {
    // String streamName = Const.streamMapping.get(metsStreamName);
    FileType fileType = new FileType();
    fileType.setCHECKSUMTYPE("MD5");
    GregorianCalendar gregory = new GregorianCalendar();
    gregory.setTime(new Date());

    XMLGregorianCalendar calendar;
    try {
        calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory);
    } catch (DatatypeConfigurationException e1) {
        throw new MetsExportException("Unable to create XMLGregorianDate", false, e1);
    }
    fileType.setCREATED(calendar);
    fileType.setSEQ(seq);
    fileType.setMIMETYPE(mimeTypes.get(metsStreamName));
    InputStream is = null;
    fileType.setID(Const.streamMappingPrefix.get(metsStreamName) + "_"
            + MetsUtils.removeNonAlpabetChars(metsContext.getPackageID()) + "_" + String.format("%04d", seq));
    if (fileNames.get(metsStreamName) instanceof String) {
        String fileNameOriginal = (String) fileNames.get(metsStreamName);
        int lastIndex = fileNameOriginal.lastIndexOf('/');
        int preLastIndex = fileNameOriginal.substring(1, lastIndex).lastIndexOf('/');
        String fileName = metsContext.getPath() + fileNameOriginal.substring(preLastIndex + 2);
        File file = new File(fileName);
        try {
            is = new FileInputStream(file);

        } catch (FileNotFoundException e) {
            throw new MetsExportException("File not found:" + fileName, false, e);
        }
    }
    if (fileNames.get(metsStreamName) instanceof byte[]) {
        byte[] bytes = (byte[]) fileNames.get(metsStreamName);
        is = new ByteArrayInputStream(bytes);
    }
    if (fileNames.get(metsStreamName) instanceof InputStream) {
        is = (InputStream) fileNames.get(metsStreamName);
    }

    if (metsStreamName.equalsIgnoreCase("TECHMDGRP")) {
        is = addLabelToAmdSec(is, metsContext);
    }

    String outputFileName = fileType.getID() + "." + MimeType.getExtension(mimeTypes.get(metsStreamName));
    String fullOutputFileName = metsContext.getPackageDir().getAbsolutePath() + File.separator
            + Const.streamMappingFile.get(metsStreamName) + File.separator + outputFileName;
    outputFileNames.put(metsStreamName, fullOutputFileName);
    try {
        FileMD5Info fileMD5Info;
        if (md5InfosMap.get(metsStreamName) == null) {
            fileMD5Info = MetsUtils.getDigestAndCopy(is, new FileOutputStream(fullOutputFileName));
            md5InfosMap.put(metsStreamName, fileMD5Info);
        } else {
            FileMD5Info tempMd5 = MetsUtils.getDigestAndCopy(is, new FileOutputStream(fullOutputFileName));
            fileMD5Info = md5InfosMap.get(metsStreamName);
            fileMD5Info.setSize(tempMd5.getSize());
            fileMD5Info.setMd5(tempMd5.getMd5());
        }
        fileType.setSIZE(Long.valueOf(fileMD5Info.getSize()));
        fileMD5Info.setFileName("." + File.separator + Const.streamMappingFile.get(metsStreamName)
                + File.separator + outputFileName);
        fileMD5Info.setMimeType(fileType.getMIMETYPE());
        fileType.setCHECKSUM(fileMD5Info.getMd5());
        metsContext.getFileList().add(fileMD5Info);
    } catch (Exception e) {
        throw new MetsExportException("Unable to process file " + fullOutputFileName, false, e);
    }
    FLocat flocat = new FLocat();
    flocat.setLOCTYPE("URL");
    String href = "." + "/" + Const.streamMappingFile.get(metsStreamName) + "/" + outputFileName;
    URI uri;
    uri = URI.create(href);
    flocat.setHref(uri.toASCIIString());
    fileType.getFLocat().add(flocat);
    return fileType;
}

From source file:eu.openminted.registry.service.generate.WorkflowOutputMetadataGenerate.java

protected ResourceCreationInfo generateResourceCreationInfo(String userId)
        throws JsonParseException, JsonMappingException, IOException {
    ResourceCreationInfo resourceCreationInfo = new ResourceCreationInfo();

    // resourceCreators.resourceCreator.relatedPerson
    List<ActorInfo> resourceCreators = new ArrayList<>();
    ActorInfo actorInfo = new ActorInfo();
    actorInfo.setActorType(ActorTypeEnum.PERSON);
    actorInfo.setRelatedPerson(generatePersonInfo(userId, false));
    resourceCreators.add(actorInfo);//from   w  w  w. ja  v  a2 s .  c  o  m
    resourceCreationInfo.setResourceCreators(resourceCreators);

    // resourceCreationDate
    DateCombination creationDate = new DateCombination();
    XMLGregorianCalendar calendar = null;
    try {
        calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
    Date date = new Date();
    date.setYear(calendar.getYear());
    date.setMonth(calendar.getMonth());
    date.setDay(calendar.getDay());

    creationDate.setDate(date);
    resourceCreationInfo.setCreationDate(creationDate);

    return resourceCreationInfo;
}

From source file:mil.navy.med.dzreg.dao.RegistriesManagerDAO.java

/**
 *
 * @param pt/* w  ww  .j a v  a2 s  .  com*/
 * @return
 */
private PersonRegistryProfileType map(DzPatients pt) throws Exception {
    PersonRegistryProfileType profile = new PersonRegistryProfileType();

    profile.setDataSource(pt.getDataSource());

    //--------------------------------------------------------------------------
    // map person info
    //--------------------------------------------------------------------------
    PersonType person = new PersonType();

    if (pt != null) {
        person.setDataSource(pt.getDataSource());
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(pt.getPatientDob());
        person.setDateOfBirth(DatatypeFactory.newInstance().newXMLGregorianCalendar(gc));
        person.setId(pt.getPatid());
        person.setEligibilityIdentifier(pt.getPatientDeersIdentifier());
        person.setFmpssn(pt.getFmpssn());
        person.setName(pt.getName());
        person.setOfficePhone(pt.getOfficePhone());
        person.setHomePhone(pt.getPhone());

        AddressType address = new AddressType();
        address.setStreetAddress(pt.getAddress());
        address.setStreetAddress2(pt.getStreet2());
        address.setCity(pt.getCity());
        address.setPostalCode(pt.getZip());
        address.setState(pt.getState());
        JAXBElement<AddressType> jAddr = new JAXBElement<AddressType>(
                new QName("urn:mil:navy:med:dzreg:service", "AddressType"), AddressType.class, null, address);
        person.setAddress(jAddr);

        profile.setPerson(person);
    }

    //--------------------------------------------------------------------------
    // map registry info
    //--------------------------------------------------------------------------
    Collection<DzReg> dzregColl = pt.getDzRegCollection();

    if (!dzregColl.isEmpty()) {
        for (DzReg d : dzregColl) {
            RegistryProfileType registry = map(d);
            if (registry != null) {
                registry.setRegisteredDate(d.getRegisteredDt());
            }

            profile.getRegistry().add(registry);
        }
    }

    return profile;
}

From source file:fr.esrf.icat.manager.core.part.EntityEditDialog.java

private Object makeCorrectDateValue(final Class<?> clazz, final Date date) {
    // null date do not change
    if (null == date)
        return null;
    // calendar//w w w .  j  ava2 s  . c om
    if (Calendar.class.isAssignableFrom(clazz)) {
        Calendar c = GregorianCalendar.getInstance();
        c.setTime(date);
        return c;
    }
    // xml calendar
    if (clazz.equals(XMLGregorianCalendar.class)) {
        GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance();
        c.setTime(date);
        try {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        } catch (DatatypeConfigurationException e) {
            LOG.error("Unable to create XMLGregorianCalendar", e);
            return null;
        }
    }
    // anything else we do not convert
    return date;
}

From source file:eu.europa.ec.markt.dss.validation102853.xades.XAdESSignature.java

@Override
public Date getSigningTime() {

    try {//from   w ww  .ja v a  2s  .  c om

        final Element signingTimeEl = DSSXMLUtils.getElement(signatureElement, XPATH_SIGNING_TIME);
        if (signingTimeEl == null) {
            return null;
        }
        final String text = signingTimeEl.getTextContent();
        final DatatypeFactory factory = DatatypeFactory.newInstance();
        final XMLGregorianCalendar cal = factory.newXMLGregorianCalendar(text);
        return cal.toGregorianCalendar().getTime();
    } catch (DOMException e) {
        throw new RuntimeException(e);
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
}