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:org.yawlfoundation.yawl.util.StringUtil.java

public static Duration strToDuration(String s) {
    if (s != null) {
        try {//from  w  w w.j  av  a2 s.c  o m
            return DatatypeFactory.newInstance().newDuration(s);
        } catch (DatatypeConfigurationException dce) {
            // nothing to do - null will be returned
        } catch (IllegalArgumentException dce) {
            // nothing to do - null will be returned
        }
    }
    return null;
}

From source file:org.yawlfoundation.yawl.util.StringUtil.java

public static boolean isValidDurationString(String s) {
    try {/*from w w  w  . j a  v  a  2 s .  c om*/
        DatatypeFactory.newInstance().newDuration(s);
        return true;
    } catch (DatatypeConfigurationException dce) {
        return false;
    }
}

From source file:org.yawlfoundation.yawl.util.StringUtil.java

public static long xmlDateToLong(String s) {
    if (s == null)
        return -1;
    try {// w ww  . j  a  v a  2  s .  co m
        XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(s);
        return cal.toGregorianCalendar().getTimeInMillis();
    } catch (DatatypeConfigurationException dce) {
        return -1;
    }
}

From source file:org.yawlfoundation.yawl.util.StringUtil.java

public static String longToDateTime(long time) {
    GregorianCalendar gregCal = new GregorianCalendar();
    gregCal.setTimeInMillis(time);/*from  www .ja v a 2  s. co m*/
    try {
        XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
        return cal.toXMLFormat();
    } catch (DatatypeConfigurationException dce) {
        return null;
    }
}

From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java

static XMLGregorianCalendar convert(Date date) {
    try {/*w  w  w.ja  v  a2s. c  o  m*/
        GregorianCalendar gregDate = (GregorianCalendar) GregorianCalendar.getInstance();
        gregDate.setTime(date);

        return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregDate);
    } catch (Exception e) {
        return null;
    }
}

From source file:Presentacion.FUsuarios.java

private void btnRegistrarClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRegistrarClienteMouseClicked
    if (fc == null || !fc.getSelectedFile().isFile()) {
        JOptionPane.showMessageDialog(this, "Debe seleccionar una imagen", "Alerta",
                JOptionPane.WARNING_MESSAGE);
    } else {/*from   w  w w. j a v  a 2 s  .c  o  m*/

        if (txtApellido.getText().isEmpty() || txtDireccion.getText().isEmpty() || txtEmail.getText().isEmpty()
                || txtNickName.getText().isEmpty() || txtNombre.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Debe ingresar todos los datos", "Alerta",
                    JOptionPane.WARNING_MESSAGE);
        } else {
            webservice.Cliente user = new Cliente();
            user.setDireccion(txtDireccion.getText());
            user.setEmail(txtEmail.getText());
            user.setNickname(txtNickName.getText());
            user.setNombre(txtNombre.getText());
            user.setApellido(txtApellido.getText());

            //PORCEDIMIENTO PARA ENCRIPTAR LA CLAVE INGRESADA CUANDO INICIA SESIN UN USUARIO.
            String pass = jPasswordField2.getText();
            String encriptMD5 = DigestUtils.md5Hex(pass);
            pass = "md5:" + encriptMD5;

            user.setPassword(pass);

            try {
                int year = Integer.getInteger(drpYear.getToolTipText());
                int day = Integer.getInteger(drpDay.getModel().getValue().toString());
                int month = Integer.getInteger(drpMes.getValue().toString());

                GregorianCalendar c = new GregorianCalendar();
                c.setTime(new Date(year, month, day));
                XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

                user.setFechaNac(date2);
            } catch (Exception ex) {
                GregorianCalendar c = new GregorianCalendar();
                c.setTime(Date.from(Instant.EPOCH));

                try {
                    XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                    user.setFechaNac(date2);
                } catch (Exception ex2) {
                    System.out.println("Error en fecha");
                }
            }

            user.setImagen(txtNickName.getText() + ".jpg");

            QuickOrderWebService webService = new QuickOrderWebService();
            ControllerInterface port = webService.getQuickOrderWebServicePort();

            String result = port.registrarCliente(user);
            if (result.isEmpty()) {

                JOptionPane.showMessageDialog(this, "Usuario ingresado correctamente");
                txtApellido.setText("");
                txtDireccion.setText("");
                txtEmail.setText("");
                txtNickName.setText("");
                txtNombre.setText("");
                jPasswordField2.setText("");
            } else {
                if (result.equals("emailError1")) {
                    JOptionPane.showMessageDialog(this,
                            "El email ya se encuentra registrado, por favor ingrese otro.", "Alerta",
                            JOptionPane.WARNING_MESSAGE);
                }
                if (result.equals("nicknameError1")) {
                    JOptionPane.showMessageDialog(this,
                            "El nickname no se encuentra disponible, por favor ingrese otro.", "Alerta",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, "Error al ingresar el cliente", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }

        }
    }
}

From source file:ru.schernolyas.websockettest.testproject.ws.command.LoginCommand.java

@Override
public Envelope execute(Envelope envelope) throws Exception {
    JSONParser parser = new JSONParser();
    JSONObject inData = (JSONObject) parser.parse(envelope.getData());
    String email = (String) inData.get("email");
    String password = (String) inData.get("password");
    JSONObject outData = new JSONObject();
    try {/*from   w  w  w  .  j av a  2  s  .  c om*/
        Token token = EJBUtil.getInstance().findUserService().loginUser(email, password);
        outData.put("api_token", token.getId());
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(token.getExpiration());
        String dateFormat = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toXMLFormat();
        outData.put("api_token_expiration_date", dateFormat);

    } catch (UserNotFoundException ue) {

        outData.put("error_description", "Customer not found");
        outData.put("error_code", "customer.notFound");
    }
    envelope.setData(outData.toJSONString());
    return envelope;
}

From source file:test.integ.be.e_contract.mycarenet.genins.GenericInsurabilityClientTest.java

@Test
public void testInvoke() throws Exception {
    EHealthSTSClient client = new EHealthSTSClient("https://wwwacc.ehealth.fgov.be/sts_1_1/SecureTokenService");

    Security.addProvider(new BeIDProvider());
    KeyStore keyStore = KeyStore.getInstance("BeID");
    keyStore.load(null);/*from  www.j  a v a 2  s. c  o  m*/
    PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null);
    X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication");

    KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12");
    FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path());
    eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray());
    Enumeration<String> aliasesEnum = eHealthKeyStore.aliases();
    String alias = aliasesEnum.nextElement();
    X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias);
    PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias,
            this.config.getEHealthPKCS12Password().toCharArray());

    List<Attribute> attributes = new LinkedList<Attribute>();
    attributes.add(new Attribute("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));

    List<AttributeDesignator> attributeDesignators = new LinkedList<AttributeDesignator>();
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributeDesignators
            .add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:ehealth:1.0:doctor:nihii11"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:doctor:boolean"));

    Element assertion = client.requestAssertion(authnCertificate, authnPrivateKey, eHealthCertificate,
            eHealthPrivateKey, attributes, attributeDesignators);

    assertNotNull(assertion);

    String assertionString = client.toString(assertion);

    // String location =
    // "https://services-int.ehealth.fgov.be/GenericInsurability/v1";
    String location = "https://services-acpt.ehealth.fgov.be/GenericInsurability/v1";
    GenericInsurabilityClient genInsClient = new GenericInsurabilityClient(location);
    genInsClient.setCredentials(eHealthPrivateKey, assertionString);

    ObjectFactory objectFactory = new ObjectFactory();
    GetInsurabilityAsXmlOrFlatRequestType body = objectFactory.createGetInsurabilityAsXmlOrFlatRequestType();

    be.e_contract.mycarenet.genins.jaxb.core.ObjectFactory coreObjectFactory = new be.e_contract.mycarenet.genins.jaxb.core.ObjectFactory();
    CommonInputType commonInput = coreObjectFactory.createCommonInputType();
    body.setCommonInput(commonInput);

    RequestType request = coreObjectFactory.createRequestType();
    request.setIsTest(true);
    commonInput.setRequest(request);

    OriginType origin = coreObjectFactory.createOriginType();
    commonInput.setOrigin(origin);
    PackageType packageObject = coreObjectFactory.createPackageType();
    origin.setPackage(packageObject);
    LicenseType license = coreObjectFactory.createLicenseType();
    packageObject.setLicense(license);
    PackageLicenseKey packageLicenseKey = this.config.getPackageLicenseKey();
    license.setUsername(packageLicenseKey.getUsername());
    license.setPassword(packageLicenseKey.getPassword());

    Element namespaceElement = assertion.getOwnerDocument().createElement("ns");
    namespaceElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:saml",
            "urn:oasis:names:tc:SAML:1.0:assertion");
    Node nihiiNode = XPathAPI.selectSingleNode(assertion,
            "saml:AttributeStatement/saml:Attribute[@AttributeName='urn:be:fgov:person:ssin:ehealth:1.0:doctor:nihii11']/saml:AttributeValue/text()",
            namespaceElement);
    String myNihii = nihiiNode.getTextContent();
    LOG.debug("NIHII: " + myNihii);
    Node ssinNode = XPathAPI.selectSingleNode(assertion,
            "saml:AttributeStatement/saml:Attribute[@AttributeName='urn:be:fgov:person:ssin']/saml:AttributeValue/text()",
            namespaceElement);
    String mySsin = ssinNode.getTextContent();

    CareProviderType careProvider = coreObjectFactory.createCareProviderType();
    origin.setCareProvider(careProvider);
    NihiiType nihii = coreObjectFactory.createNihiiType();
    careProvider.setNihii(nihii);
    nihii.setQuality("doctor");
    ValueRefString nihiiValue = coreObjectFactory.createValueRefString();
    nihii.setValue(nihiiValue);
    nihiiValue.setValue(myNihii);
    IdType physicalPerson = coreObjectFactory.createIdType();
    careProvider.setPhysicalPerson(physicalPerson);
    ValueRefString ssinValue = coreObjectFactory.createValueRefString();
    physicalPerson.setSsin(ssinValue);
    ssinValue.setValue(mySsin);

    commonInput.setInputReference("PRIG1234567890");
    RecordCommonInputType recordCommonInput = coreObjectFactory.createRecordCommonInputType();
    body.setRecordCommonInput(recordCommonInput);
    recordCommonInput.setInputReference(new BigDecimal("1234567890123"));

    SingleInsurabilityRequestType singleInsurabilityRequest = coreObjectFactory
            .createSingleInsurabilityRequestType();
    body.setRequest(singleInsurabilityRequest);
    CareReceiverIdType careReceiverId = coreObjectFactory.createCareReceiverIdType();
    singleInsurabilityRequest.setCareReceiverId(careReceiverId);
    careReceiverId.setInss(mySsin);
    InsurabilityRequestDetailType insurabilityRequestDetail = coreObjectFactory
            .createInsurabilityRequestDetailType();
    singleInsurabilityRequest.setInsurabilityRequestDetail(insurabilityRequestDetail);
    InsurabilityRequestTypeType insurabilityRequestType = InsurabilityRequestTypeType.INFORMATION;
    insurabilityRequestDetail.setInsurabilityRequestType(insurabilityRequestType);
    PeriodType period = coreObjectFactory.createPeriodType();
    insurabilityRequestDetail.setPeriod(period);
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar periodStartCal = new GregorianCalendar();
    DateTime periodStartDateTime = new DateTime();
    periodStartCal.setTime(periodStartDateTime.toDate());
    XMLGregorianCalendar periodStart = datatypeFactory.newXMLGregorianCalendar(periodStartCal);
    period.setPeriodStart(periodStart);
    DateTime periodEndDateTime = periodStartDateTime;
    GregorianCalendar periodEndCal = new GregorianCalendar();
    periodEndCal.setTime(periodEndDateTime.toDate());
    XMLGregorianCalendar periodEnd = datatypeFactory.newXMLGregorianCalendar(periodEndCal);
    period.setPeriodEnd(periodEnd);
    insurabilityRequestDetail.setInsurabilityContactType(InsurabilityContactTypeType.HOSPITALIZED_FOR_DAY);

    genInsClient.getInsurability(body);
}

From source file:test.integ.be.e_contract.mycarenet.tarification.TarificationClientTest.java

@Test
public void testTarificationConsultation() throws Exception {
    // STS/*from   w ww . jav  a2s .c  o  m*/
    EHealthSTSClient client = new EHealthSTSClient(
            "https://services-acpt.ehealth.fgov.be/IAM/Saml11TokenService/Legacy/v1");

    Security.addProvider(new BeIDProvider());
    KeyStore keyStore = KeyStore.getInstance("BeID");
    BeIDKeyStoreParameter beIDKeyStoreParameter = new BeIDKeyStoreParameter();
    beIDKeyStoreParameter.addPPDUName("digipass 870");
    beIDKeyStoreParameter.addPPDUName("digipass 875");
    beIDKeyStoreParameter.addPPDUName("digipass 920");
    keyStore.load(beIDKeyStoreParameter);
    PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null);
    X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication");

    KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12");
    FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path());
    eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray());
    Enumeration<String> aliasesEnum = eHealthKeyStore.aliases();
    String alias = aliasesEnum.nextElement();
    X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias);
    PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias,
            this.config.getEHealthPKCS12Password().toCharArray());

    List<Attribute> attributes = new LinkedList<>();
    attributes.add(new Attribute("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));

    List<AttributeDesignator> attributeDesignators = new LinkedList<>();
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributeDesignators
            .add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:nurse:boolean"));

    Element assertion = client.requestAssertion(authnCertificate, authnPrivateKey, eHealthCertificate,
            eHealthPrivateKey, attributes, attributeDesignators);

    assertNotNull(assertion);

    String assertionString = client.toString(assertion);

    // Tarification
    TarificationClient tarificationClient = new TarificationClient(
            "https://services-acpt.ehealth.fgov.be/MyCareNet/Tarification/v1");
    tarificationClient.setCredentials(eHealthPrivateKey, assertionString);

    ObjectFactory objectFactory = new ObjectFactory();
    SendRequestType sendRequest = objectFactory.createSendRequestType();

    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar issueInstantCal = new GregorianCalendar();
    DateTime issueInstantDateTime = new DateTime();
    issueInstantCal.setTime(issueInstantDateTime.toDate());
    XMLGregorianCalendar issueInstant = datatypeFactory.newXMLGregorianCalendar(issueInstantCal);
    sendRequest.setIssueInstant(issueInstant);

    // TODO...

    tarificationClient.tarificationConsultation(sendRequest);

}

From source file:test.integ.be.fedict.hsm.ws.WSSecurityTestSOAPHandler.java

private Element addTimestamp(Element wsSecurityHeaderElement)
        throws SOAPException, DatatypeConfigurationException {
    if (false == this.addTimestamp) {
        return null;
    }//from   ww w  .jav a2 s.  co  m
    Document document = wsSecurityHeaderElement.getOwnerDocument();
    Element timestampElement = document.createElementNS(WSU_NAMESPACE, "wsu:Timestamp");
    timestampElement.setAttributeNS(WSU_NAMESPACE, "wsu:Id", "TS");
    Attr idAttr = timestampElement.getAttributeNodeNS(WSU_NAMESPACE, "Id");
    timestampElement.setIdAttributeNode(idAttr, true);

    Element createdElement = document.createElementNS(WSU_NAMESPACE, "wsu:Created");
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    Date now = new Date();
    gregorianCalendar.setTime(now);
    gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
    createdElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
    timestampElement.appendChild(createdElement);

    Element expiresElement = document.createElementNS(WSU_NAMESPACE, "wsu:Expires");
    Date expiresDate = new Date(now.getTime() + 1000 * 60 * 5);
    gregorianCalendar.setTime(expiresDate);
    xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
    expiresElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
    timestampElement.appendChild(expiresElement);
    wsSecurityHeaderElement.appendChild(timestampElement);
    return timestampElement;
}