Example usage for javax.xml.datatype XMLGregorianCalendar toXMLFormat

List of usage examples for javax.xml.datatype XMLGregorianCalendar toXMLFormat

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar toXMLFormat.

Prototype

public abstract String toXMLFormat();

Source Link

Document

Return the lexical representation of this instance.

Usage

From source file:eu.europa.esig.dss.xades.signature.XAdESLevelC.java

private void incorporateCRLRefs(Element completeRevocationRefsDom,
        final Set<RevocationToken> processedRevocationTokens) throws DSSException {

    if (processedRevocationTokens.isEmpty()) {

        return;//from  ww w  .  jav a  2 s. co m
    }

    boolean containsCrlToken = false;
    for (RevocationToken revocationToken : processedRevocationTokens) {
        containsCrlToken = revocationToken instanceof CRLToken;
        if (containsCrlToken) {
            break;
        }
    }

    if (!containsCrlToken) {
        return;
    }
    // <xades:CRLRefs>
    // ...<xades:CRLRef>
    // ......<xades:DigestAlgAndValue>
    // .........<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
    // .........<ds:DigestValue>G+z+DaZ6X44wEOueVYvZGmTh4dBkjjctKxcJYEV4HmU=</ds:DigestValue>
    // ......</xades:DigestAlgAndValue>
    // ......<xades:CRLIdentifier URI="LevelACAOK.crl">
    // ...<xades:Issuer>CN=LevelACAOK,OU=Plugtests_STF-428_2011-2012,O=ETSI,C=FR</xades:Issuer>
    // ...<xades:IssueTime>2012-03-13T13:58:28.000-03:00</xades:IssueTime>
    // ...<xades:Number>4415260066222</xades:Number>

    final Element crlRefsDom = DSSXMLUtils.addElement(documentDom, completeRevocationRefsDom,
            XAdESNamespaces.XAdES, "xades:CRLRefs");

    for (final RevocationToken revocationToken : processedRevocationTokens) {

        if (revocationToken instanceof CRLToken) {

            final X509CRL crl = ((CRLToken) revocationToken).getX509crl();

            final Element crlRefDom = DSSXMLUtils.addElement(documentDom, crlRefsDom, XAdESNamespaces.XAdES,
                    "xades:CRLRef");

            final Element digestAlgAndValueDom = DSSXMLUtils.addElement(documentDom, crlRefDom,
                    XAdESNamespaces.XAdES, "xades:DigestAlgAndValue");
            // TODO: to be added as field to eu.europa.esig.dss.AbstractSignatureParameters.
            DigestAlgorithm digestAlgorithm = DigestAlgorithm.SHA1;
            incorporateDigestMethod(digestAlgAndValueDom, digestAlgorithm);

            final InMemoryDocument inMemoryDocument = new InMemoryDocument(revocationToken.getEncoded());
            incorporateDigestValue(digestAlgAndValueDom, digestAlgorithm, inMemoryDocument);

            final Element crlIdentifierDom = DSSXMLUtils.addElement(documentDom, crlRefDom,
                    XAdESNamespaces.XAdES, "xades:CRLIdentifier");
            // crlIdentifierDom.setAttribute("URI",".crl");
            final String issuerX500PrincipalName = crl.getIssuerX500Principal().getName();
            DSSXMLUtils.addTextElement(documentDom, crlIdentifierDom, XAdESNamespaces.XAdES, "xades:Issuer",
                    issuerX500PrincipalName);

            final Date thisUpdate = crl.getThisUpdate();
            XMLGregorianCalendar xmlGregorianCalendar = DSSXMLUtils.createXMLGregorianCalendar(thisUpdate);
            final String thisUpdateAsXmlFormat = xmlGregorianCalendar.toXMLFormat();
            DSSXMLUtils.addTextElement(documentDom, crlIdentifierDom, XAdESNamespaces.XAdES, "xades:IssueTime",
                    thisUpdateAsXmlFormat);

            // DSSXMLUtils.addTextElement(documentDom, crlRefDom, XAdESNamespaces.XAdES, "xades:Number", ???);
        }
    }
}

From source file:eu.europa.esig.dss.xades.signature.XAdESLevelC.java

/**
 * @param completeRevocationRefsDom//from  ww w. j  a  v  a2 s .c o  m
 * @param processedRevocationTokens
 * @throws eu.europa.esig.dss.DSSException
 */
private void incorporateOCSPRefs(final Element completeRevocationRefsDom,
        final Set<RevocationToken> processedRevocationTokens) throws DSSException {

    if (processedRevocationTokens.isEmpty()) {

        return;
    }

    boolean containsOCSPToken = false;
    for (RevocationToken revocationToken : processedRevocationTokens) {
        containsOCSPToken = revocationToken instanceof OCSPToken;
        if (containsOCSPToken) {
            break;
        }
    }

    if (!containsOCSPToken) {
        return;
    }

    // ...<xades:CRLRefs/>
    // ...<xades:OCSPRefs>
    // ......<xades:OCSPRef>
    // .........<xades:OCSPIdentifier>
    // ............<xades:ResponderID>
    // ...............<xades:ByName>C=AA,O=DSS,CN=OCSP A</xades:ByName>
    // ............</xades:ResponderID>
    // ............<xades:ProducedAt>2013-11-25T12:33:34.000+01:00</xades:ProducedAt>
    // .........</xades:OCSPIdentifier>
    // .........<xades:DigestAlgAndValue>
    // ............<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    // ............<ds:DigestValue>O1uHdchN+zFzbGrBg2FP3/idD0k=</ds:DigestValue>

    final Element ocspRefsDom = DSSXMLUtils.addElement(documentDom, completeRevocationRefsDom,
            XAdESNamespaces.XAdES, "xades:OCSPRefs");

    for (RevocationToken revocationToken : processedRevocationTokens) {

        if (revocationToken instanceof OCSPToken) {

            BasicOCSPResp basicOcspResp = ((OCSPToken) revocationToken).getBasicOCSPResp();

            final Element ocspRefDom = DSSXMLUtils.addElement(documentDom, ocspRefsDom, XAdESNamespaces.XAdES,
                    "xades:OCSPRef");

            final Element ocspIdentifierDom = DSSXMLUtils.addElement(documentDom, ocspRefDom,
                    XAdESNamespaces.XAdES, "xades:OCSPIdentifier");
            final Element responderIDDom = DSSXMLUtils.addElement(documentDom, ocspIdentifierDom,
                    XAdESNamespaces.XAdES, "xades:ResponderID");

            final RespID responderId = basicOcspResp.getResponderId();
            final ResponderID responderIdAsASN1Object = responderId.toASN1Object();
            final DERTaggedObject derTaggedObject = (DERTaggedObject) responderIdAsASN1Object.toASN1Primitive();
            if (2 == derTaggedObject.getTagNo()) {

                final ASN1OctetString keyHashOctetString = (ASN1OctetString) derTaggedObject.getObject();
                final byte[] keyHashOctetStringBytes = keyHashOctetString.getOctets();
                final String base65EncodedKeyHashOctetStringBytes = Base64
                        .encodeBase64String(keyHashOctetStringBytes);
                DSSXMLUtils.addTextElement(documentDom, responderIDDom, XAdESNamespaces.XAdES, "xades:ByKey",
                        base65EncodedKeyHashOctetStringBytes);
            } else {

                final ASN1Primitive derObject = derTaggedObject.getObject();
                final X500Name name = X500Name.getInstance(derObject);
                DSSXMLUtils.addTextElement(documentDom, responderIDDom, XAdESNamespaces.XAdES, "xades:ByName",
                        name.toString());
            }

            final Date producedAt = basicOcspResp.getProducedAt();
            final XMLGregorianCalendar xmlGregorianCalendar = DSSXMLUtils
                    .createXMLGregorianCalendar(producedAt);
            final String producedAtXmlEncoded = xmlGregorianCalendar.toXMLFormat();
            DSSXMLUtils.addTextElement(documentDom, ocspIdentifierDom, XAdESNamespaces.XAdES,
                    "xades:ProducedAt", producedAtXmlEncoded);

            final Element digestAlgAndValueDom = DSSXMLUtils.addElement(documentDom, ocspRefDom,
                    XAdESNamespaces.XAdES, "xades:DigestAlgAndValue");
            // TODO: to be added as field to eu.europa.esig.dss.AbstractSignatureParameters.
            DigestAlgorithm digestAlgorithm = DigestAlgorithm.SHA1;
            incorporateDigestMethod(digestAlgAndValueDom, digestAlgorithm);

            final InMemoryDocument inMemoryDocument = new InMemoryDocument(revocationToken.getEncoded());
            incorporateDigestValue(digestAlgAndValueDom, digestAlgorithm, inMemoryDocument);
        }
    }
}

From source file:org.energyos.espi.common.service.impl.NotificationServiceImpl.java

@Override
public void notify(Subscription subscription, XMLGregorianCalendar startDate, XMLGregorianCalendar endDate) {

    String thirdPartyNotificationURI = subscription.getApplicationInformation().getThirdPartyNotifyUri();
    String separator = "?";
    String subscriptionURI = subscription.getApplicationInformation().getDataCustodianResourceEndpoint()
            + "/Batch/Subscription/" + subscription.getId();

    if (startDate != null) {
        subscriptionURI = subscriptionURI + separator + "published-min=" + startDate.toXMLFormat();
        separator = "&";
    }//w  w w. j  av  a2  s  .c o m

    if (endDate != null) {
        subscriptionURI = subscriptionURI + separator + "published-max=" + endDate.toXMLFormat();
    }

    BatchList batchList = new BatchList();
    batchList.getResources().add(subscriptionURI);
    notifyInternal(thirdPartyNotificationURI, batchList);
}

From source file:com.xqdev.jam.MLJAM.java

private static void sendXQueryResponse(HttpServletResponse res, Object o) throws IOException {
    // Make sure to leave the status code alone.  It defaults to 200, but sometimes
    // callers of this method will have set it to a custom code.
    res.setContentType("x-marklogic/xquery; charset=UTF-8");
    //res.setContentType("text/plain");
    Writer writer = res.getWriter(); // care to handle errors later?

    if (o == null) {
        writer.write("()");
    }/* ww w  .j  a  v  a 2  s.  co m*/

    else if (o instanceof byte[]) {
        writer.write("binary {'");
        writer.write(hexEncode((byte[]) o));
        writer.write("'}");
    }

    else if (o instanceof Object[]) {
        Object[] arr = (Object[]) o;
        writer.write("(");
        for (int i = 0; i < arr.length; i++) {
            sendXQueryResponse(res, arr[i]);
            if (i + 1 < arr.length)
                writer.write(", ");
        }
        writer.write(")");
    }

    else if (o instanceof String) {
        writer.write("'");
        writer.write(escapeSingleQuotes(o.toString()));
        writer.write("'");
    } else if (o instanceof Integer) {
        writer.write("xs:int(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Long) {
        writer.write("xs:integer(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Float) {
        Float flt = (Float) o;
        writer.write("xs:float(");
        if (flt.equals(Float.POSITIVE_INFINITY)) {
            writer.write("'INF'");
        } else if (flt.equals(Float.NEGATIVE_INFINITY)) {
            writer.write("'-INF'");
        } else if (flt.equals(Float.NaN)) {
            writer.write("fn:number(())"); // poor man's way to write NaN
        } else {
            writer.write(o.toString());
        }
        writer.write(")");
    } else if (o instanceof Double) {
        Double dbl = (Double) o;
        writer.write("xs:double(");
        if (dbl.equals(Double.POSITIVE_INFINITY)) {
            writer.write("'INF'");
        } else if (dbl.equals(Double.NEGATIVE_INFINITY)) {
            writer.write("'-INF'");
        } else if (dbl.equals(Double.NaN)) {
            writer.write("fn:number(())"); // poor man's way to write NaN
        } else {
            writer.write(o.toString());
        }
        writer.write(")");
    } else if (o instanceof Boolean) {
        writer.write("xs:boolean('");
        writer.write(o.toString());
        writer.write("')");
    } else if (o instanceof BigDecimal) {
        writer.write("xs:decimal(");
        writer.write(o.toString());
        writer.write(")");
    } else if (o instanceof Date) {
        // We want something like: 2006-04-30T01:28:30.499-07:00
        // We format to get:       2006-04-30T01:28:30.499-0700
        // Then we add in the colon
        writer.write("xs:dateTime('");
        String d = dateFormat.format((Date) o);
        writer.write(d.substring(0, d.length() - 2));
        writer.write(":");
        writer.write(d.substring(d.length() - 2));
        writer.write("')");
    } else if (o instanceof XMLGregorianCalendar) {
        XMLGregorianCalendar greg = (XMLGregorianCalendar) o;
        QName type = greg.getXMLSchemaType();
        if (type.equals(DatatypeConstants.DATETIME)) {
            writer.write("xs:dateTime('");
        } else if (type.equals(DatatypeConstants.DATE)) {
            writer.write("xs:date('");
        } else if (type.equals(DatatypeConstants.TIME)) {
            writer.write("xs:time('");
        } else if (type.equals(DatatypeConstants.GYEARMONTH)) {
            writer.write("xs:gYearMonth('");
        } else if (type.equals(DatatypeConstants.GMONTHDAY)) {
            writer.write("xs:gMonthDay('");
        } else if (type.equals(DatatypeConstants.GYEAR)) {
            writer.write("xs:gYear('");
        } else if (type.equals(DatatypeConstants.GMONTH)) {
            writer.write("xs:gMonth('");
        } else if (type.equals(DatatypeConstants.GDAY)) {
            writer.write("xs:gDay('");
        }
        writer.write(greg.toXMLFormat());
        writer.write("')");
    } else if (o instanceof Duration) {
        Duration dur = (Duration) o;
        /*
        // The following fails on Xerces
        QName type = dur.getXMLSchemaType();
        if (type.equals(DatatypeConstants.DURATION)) {
          writer.write("xs:duration('");
        }
        else if (type.equals(DatatypeConstants.DURATION_DAYTIME)) {
          writer.write("xdt:dayTimeDuration('");
        }
        else if (type.equals(DatatypeConstants.DURATION_YEARMONTH)) {
          writer.write("xdt:yearMonthDuration('");
        }
        */
        // If no years or months, must be DURATION_DAYTIME
        if (dur.getYears() == 0 && dur.getMonths() == 0) {
            writer.write("xdt:dayTimeDuration('");
        }
        // If has years or months but nothing else, must be DURATION_YEARMONTH
        else if (dur.getDays() == 0 && dur.getHours() == 0 && dur.getMinutes() == 0 && dur.getSeconds() == 0) {
            writer.write("xdt:yearMonthDuration('");
        } else {
            writer.write("xs:duration('");
        }
        writer.write(dur.toString());
        writer.write("')");
    }

    else if (o instanceof org.jdom.Element) {
        org.jdom.Element elt = (org.jdom.Element) o;
        writer.write("xdmp:unquote('");
        // Because "&lt;" in XQuery is the same as "<" I need to double escape any ampersands
        writer.write(new org.jdom.output.XMLOutputter().outputString(elt).replaceAll("&", "&amp;")
                .replaceAll("'", "''"));
        writer.write("')/*"); // make sure to return the root elt
    } else if (o instanceof org.jdom.Document) {
        org.jdom.Document doc = (org.jdom.Document) o;
        writer.write("xdmp:unquote('");
        writer.write(new org.jdom.output.XMLOutputter().outputString(doc).replaceAll("&", "&amp;")
                .replaceAll("'", "''"));
        writer.write("')");
    } else if (o instanceof org.jdom.Text) {
        org.jdom.Text text = (org.jdom.Text) o;
        writer.write("text {'");
        writer.write(escapeSingleQuotes(text.getText()));
        writer.write("'}");
    } else if (o instanceof org.jdom.Attribute) {
        // <fake xmlns:pref="http://uri.com" pref:attrname="attrvalue"/>/@*:attrname
        // <fake xmlns="http://uri.com" attrname="attrvalue"/>/@*:attrname
        org.jdom.Attribute attr = (org.jdom.Attribute) o;
        writer.write("<fake xmlns");
        if ("".equals(attr.getNamespacePrefix())) {
            writer.write("=\"");
        } else {
            writer.write(":" + attr.getNamespacePrefix() + "=\"");
        }
        writer.write(attr.getNamespaceURI());
        writer.write("\" ");
        writer.write(attr.getQualifiedName());
        writer.write("=\"");
        writer.write(escapeSingleQuotes(attr.getValue()));
        writer.write("\"/>/@*:");
        writer.write(attr.getName());
    } else if (o instanceof org.jdom.Comment) {
        org.jdom.Comment com = (org.jdom.Comment) o;
        writer.write("comment {'");
        writer.write(escapeSingleQuotes(com.getText()));
        writer.write("'}");
    } else if (o instanceof org.jdom.ProcessingInstruction) {
        org.jdom.ProcessingInstruction pi = (org.jdom.ProcessingInstruction) o;
        writer.write("processing-instruction ");
        writer.write(pi.getTarget());
        writer.write(" {'");
        writer.write(escapeSingleQuotes(pi.getData()));
        writer.write("'}");
    }

    else if (o instanceof QName) {
        QName q = (QName) o;
        writer.write("fn:expanded-QName('");
        writer.write(escapeSingleQuotes(q.getNamespaceURI()));
        writer.write("','");
        writer.write(q.getLocalPart());
        writer.write("')");
    }

    else {
        writer.write("error('XQuery tried to retrieve unsupported type: " + o.getClass().getName() + "')");
    }

    writer.flush();
}

From source file:eu.europa.esig.dss.xades.signature.XAdESSignatureBuilder.java

/**
 * Creates SigningTime DOM object element.
 *///from  w w w. j a  v  a2s .  c o m
private void incorporateSigningTime() {

    final Date signingDate = params.bLevel().getSigningDate();
    final XMLGregorianCalendar xmlGregorianCalendar = DSSXMLUtils.createXMLGregorianCalendar(signingDate);
    final String xmlSigningTime = xmlGregorianCalendar.toXMLFormat();

    // <SigningTime>2013-11-23T11:22:52Z</SigningTime>
    final Element signingTimeDom = documentDom.createElementNS(XAdES, XADES_SIGNING_TIME);
    signedSignaturePropertiesDom.appendChild(signingTimeDom);
    final Text textNode = documentDom.createTextNode(xmlSigningTime);
    signingTimeDom.appendChild(textNode);
}

From source file:ebay.dts.client.BulkDataExchangeActions.java

private static XMLGregorianCalendar parseDateTime(String cal) throws DatatypeConfigurationException {

    DatatypeFactory factory1 = DatatypeFactory.newInstance();
    XMLGregorianCalendar calendar1 = factory1.newXMLGregorianCalendar();
    String[] dateItems;/*from  w w w  . j  a  va2s .  c om*/
    try {
        // df.parse(cal);
        if (cal.indexOf("_") == -1) {
            dateItems = cal.split("-");
            calendar1.setYear(Integer.parseInt(dateItems[0]));
            calendar1.setMonth(Integer.parseInt(dateItems[1]));
            calendar1.setDay(Integer.parseInt(dateItems[2]));
            // calendar1.setTime(00, 00, 00,000);
            calendar1.setTime(00, 00, 00);
        } else {
            String[] parts = cal.split("_");
            dateItems = parts[0].split("-");
            String[] timeItems = parts[1].split(":");
            calendar1.setYear(Integer.parseInt(dateItems[0]));
            calendar1.setMonth(Integer.parseInt(dateItems[1]));
            calendar1.setDay(Integer.parseInt(dateItems[2]));
            if (timeItems.length != 0) {
                switch (timeItems.length) {
                case 1: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), 00, 00, 000);
                    break;
                }
                case 2: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]), 00, 000);
                    break;
                }
                case 3: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]),
                            Integer.parseInt(timeItems[2]), 000);
                    break;
                }
                case 4: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]),
                            Integer.parseInt(timeItems[2]), Integer.parseInt(timeItems[3]));
                    break;
                }
                }

            }
        }

        // get here and we know the format is correct
    } catch (java.lang.NumberFormatException e) {
        logger.error("NumberFormatException caught when parse the DateTime string: " + cal);
        return null;
    }

    calendar1.setTimezone(0);
    logger.debug(calendar1.toXMLFormat());
    return calendar1;
}

From source file:com.microsoft.exchange.ExchangeRequestFactory.java

protected JAXBElement<IsLessThanOrEqualToType> getCalendarItemEndRestriction(Date endTime) {
    ObjectFactory of = getObjectFactory();
    IsLessThanOrEqualToType endType = new IsLessThanOrEqualToType();
    XMLGregorianCalendar end = DateHelp.convertDateToXMLGregorianCalendar(endTime);
    PathToUnindexedFieldType endPath = new PathToUnindexedFieldType();
    endPath.setFieldURI(UnindexedFieldURIType.CALENDAR_END);
    JAXBElement<PathToUnindexedFieldType> endFieldURI = of.createFieldURI(endPath);
    endType.setPath(endFieldURI);//from  ww  w.  j  a  v a 2s. c o  m
    FieldURIOrConstantType endConstant = new FieldURIOrConstantType();
    ConstantValueType endValue = new ConstantValueType();
    endValue.setValue(end.toXMLFormat());
    endConstant.setConstant(endValue);
    endType.setFieldURIOrConstant(endConstant);
    JAXBElement<IsLessThanOrEqualToType> endSearchExpression = of.createIsLessThanOrEqualTo(endType);
    return endSearchExpression;
}

From source file:com.microsoft.exchange.ExchangeRequestFactory.java

protected JAXBElement<IsGreaterThanOrEqualToType> getCalendarItemStartRestriction(Date startTime) {
    ObjectFactory of = getObjectFactory();
    IsGreaterThanOrEqualToType startType = new IsGreaterThanOrEqualToType();
    XMLGregorianCalendar start = DateHelp.convertDateToXMLGregorianCalendar(startTime);
    PathToUnindexedFieldType startPath = new PathToUnindexedFieldType();
    startPath.setFieldURI(UnindexedFieldURIType.CALENDAR_START);
    JAXBElement<PathToUnindexedFieldType> startFieldURI = of.createFieldURI(startPath);
    startType.setPath(startFieldURI);/*from   w  ww  . j a  va2 s .  c om*/
    FieldURIOrConstantType startConstant = new FieldURIOrConstantType();
    ConstantValueType startValue = new ConstantValueType();
    startValue.setValue(start.toXMLFormat());
    startConstant.setConstant(startValue);
    startType.setFieldURIOrConstant(startConstant);
    JAXBElement<IsGreaterThanOrEqualToType> startSearchExpression = of.createIsGreaterThanOrEqualTo(startType);
    return startSearchExpression;
}

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

private String xmlEncodeDate(Date date) {
    if (date == null)
        return "";
    try {/* w w  w.j  a v  a  2  s . 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:no.uis.service.ws.studinfosolr.json.CalendarSerializer.java

public static String convertToSolrString(XMLGregorianCalendar xcal) {
    if (xcal == null) {
        return null;
    }/*from   w w w  .j ava  2  s  .  com*/
    return xcal.toXMLFormat();
}