List of usage examples for javax.xml.bind DatatypeConverter printDateTime
public static String printDateTime(java.util.Calendar val)
Converts a Calendar value into a string.
From source file:cz.cas.lib.proarc.common.export.cejsh.CejshBuilder.java
File writeProperties(File packageFolder, int articleCount) throws IOException, FileNotFoundException { File propertiesFile = new File(packageFolder, IMPORT_PROPERTIES_FILENAME); Properties properties = new Properties(); gcalendar.setTimeInMillis(System.currentTimeMillis()); String importDate = DatatypeConverter.printDateTime(gcalendar); properties.setProperty(PROP_IMPORT_INFODATE, importDate); properties.setProperty(PROP_IMPORT_OBJECTS, String.valueOf(articleCount)); properties.setProperty(PROP_IMPORT_CONTENT_FILES, "0"); properties.setProperty(PROP_IMPORT_BWMETA_FILES, "1"); Writer propsWriter = new NoCommentsWriter( new OutputStreamWriter(new FileOutputStream(propertiesFile), Charsets.UTF_8)); try {/*from w w w. jav a2s .c o m*/ properties.store(propsWriter, null); return propertiesFile; } finally { propsWriter.close(); } }
From source file:com.smartbear.jenkins.plugins.testcomplete.TcLogParser.java
private void processProject(ZipFile logArchive, Node rootOwnerNode, Node rootOwnerNodeInfoSummary, XMLStreamWriter writer) throws ParsingException, XMLStreamException { String totalTests = NodeUtils.getTextProperty( NodeUtils.findNamedNode(rootOwnerNodeInfoSummary.getChildNodes(), "total"), "total (sum)"); String failedTests = NodeUtils.getTextProperty( NodeUtils.findNamedNode(rootOwnerNodeInfoSummary.getChildNodes(), "failed"), "total (sum)"); long startDate = Utils.safeConvertDate(NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "start date")); long stopDate = Utils.safeConvertDate(NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "stop date")); long projectDuration = stopDate - startDate > 0 ? stopDate - startDate : 0; String projectName = NodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "test"); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(startDate);/*ww w . j av a 2 s . c o m*/ String timestamp = DatatypeConverter.printDateTime(cal); String rootOwnerNodeFileName = NodeUtils.getTextProperty(rootOwnerNode, "filename"); if (rootOwnerNodeFileName == null || rootOwnerNodeFileName.isEmpty()) { throw new ParsingException("Unable to obtain filename for project node."); } List<Pair<String, Node>> items = null; try { items = NodeUtils.findChildNodesRecursively(logArchive, rootOwnerNode, rootOwnerNode.getParentNode().getChildNodes(), ""); } catch (Exception e) { items = new ArrayList<Pair<String, Node>>(); } writer.writeStartElement("testsuite"); writer.writeAttribute("name", projectName); writer.writeAttribute("failures", failedTests); writer.writeAttribute("tests", totalTests); writer.writeAttribute("time", Double.toString(projectDuration / 1000f)); writer.writeAttribute("timestamp", timestamp); for (Pair<String, Node> pair : items) { processItem(logArchive, pair.getValue(), projectName, writer, pair.getKey()); } writer.writeEndElement(); //testcase }
From source file:com.cloud.bridge.service.controller.s3.S3BucketAction.java
public void executeGetBucketObjectVersions(HttpServletRequest request, HttpServletResponse response) throws IOException { S3ListBucketRequest engineRequest = new S3ListBucketRequest(); String keyMarker = request.getParameter("key-marker"); String versionIdMarker = request.getParameter("version-id-marker"); engineRequest.setBucketName((String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY)); engineRequest.setDelimiter(request.getParameter("delimiter")); engineRequest.setMarker(keyMarker);/*from w w w. j a v a 2 s. co m*/ engineRequest.setPrefix(request.getParameter("prefix")); engineRequest.setVersionIdMarker(versionIdMarker); int maxKeys = Converter.toInt(request.getParameter("max-keys"), 1000); engineRequest.setMaxKeys(maxKeys); S3ListBucketResponse engineResponse = ServiceProvider.getInstance().getS3Engine() .listBucketContents(engineRequest, true); // -> the SOAP version produces different XML StringBuffer xml = new StringBuffer(); xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); xml.append("<ListVersionsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"); xml.append("<Name>").append(engineResponse.getBucketName()).append("</Name>"); if (null == keyMarker) xml.append("<KeyMarker/>"); else xml.append("<KeyMarker>").append(StringEscapeUtils.escapeHtml(keyMarker)).append("</KeyMarker"); if (null == versionIdMarker) xml.append("<VersionIdMarker/>"); else xml.append("<VersionIdMarker>").append(StringEscapeUtils.escapeHtml(versionIdMarker)) .append("</VersionIdMarker"); xml.append("<MaxKeys>").append(engineResponse.getMaxKeys()).append("</MaxKeys>"); xml.append("<IsTruncated>").append(engineResponse.isTruncated()).append("</IsTruncated>"); S3ListBucketObjectEntry[] versions = engineResponse.getContents(); for (int i = 0; null != versions && i < versions.length; i++) { S3CanonicalUser owner = versions[i].getOwner(); boolean isDeletionMarker = versions[i].getIsDeletionMarker(); String displayName = owner.getDisplayName(); String id = owner.getID(); if (isDeletionMarker) { xml.append("<DeleteMarker>"); xml.append("<Key>").append(versions[i].getKey()).append("</Key>"); xml.append("<VersionId>").append(versions[i].getVersion()).append("</VersionId>"); xml.append("<IsLatest>").append(versions[i].getIsLatest()).append("</IsLatest>"); xml.append("<LastModified>").append(DatatypeConverter.printDateTime(versions[i].getLastModified())) .append("</LastModified>"); } else { xml.append("<Version>"); xml.append("<Key>").append(versions[i].getKey()).append("</Key>"); xml.append("<VersionId>").append(versions[i].getVersion()).append("</VersionId>"); xml.append("<IsLatest>").append(versions[i].getIsLatest()).append("</IsLatest>"); xml.append("<LastModified>").append(DatatypeConverter.printDateTime(versions[i].getLastModified())) .append("</LastModified>"); xml.append("<ETag>").append(versions[i].getETag()).append("</ETag>"); xml.append("<Size>").append(versions[i].getSize()).append("</Size>"); xml.append("<StorageClass>").append(versions[i].getStorageClass()).append("</StorageClass>"); } xml.append("<Owner>"); xml.append("<ID>").append(id).append("</ID>"); if (null == displayName) xml.append("<DisplayName/>"); else xml.append("<DisplayName>").append(owner.getDisplayName()).append("</DisplayName>"); xml.append("</Owner>"); if (isDeletionMarker) xml.append("</DeleteMarker>"); else xml.append("</Version>"); } xml.append("</ListVersionsResult>"); response.setStatus(200); response.setContentType("text/xml; charset=UTF-8"); S3RestServlet.endResponse(response, xml.toString()); }
From source file:br.com.upic.camel.openedge.OpenEdgeEndpoint.java
@Override protected void onExchange(final Exchange exchange) throws Exception { try {/* w w w . j ava 2 s . c om*/ LOG.info("Unmarshalling the request"); final Request req = (Request) unmarshaller.unmarshal(exchange.getIn().getBody(Document.class)); LOG.info("Setting the input params"); final List<JAXBElement<? extends Serializable>> reqParamElementList = req.getParamElementList(); final ParamArray proParams = new ParamArray(reqParamElementList.size()); for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) { final Serializable reqParam = reqParamElement.getValue(); if (reqParam instanceof CharArrayParam) { final CharArrayParam charArrayParam = (CharArrayParam) reqParam; final ParamMode mode = charArrayParam.getMode(); final int id = charArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<String> value = new ArrayList<String>(); for (final JAXBElement<String> valueElement : charArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseString(valueElement.getValue())); else value.add(null); } proParams.addCharacterArray(id, value.toArray(new String[] {}), mode.value(), value.size()); } else { proParams.addCharacterArray(id, null, mode.value(), 0); } } else if (reqParam instanceof CharParam) { final CharParam charParam = (CharParam) reqParam; final ParamMode mode = charParam.getMode(); final int id = charParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addCharacter(id, DatatypeConverter.parseString(charParam.getContent()), mode.value()); else proParams.addCharacter(id, null, mode.value()); } else if (reqParam instanceof DateArrayParam) { final DateArrayParam dateArrayParam = (DateArrayParam) reqParam; final ParamMode mode = dateArrayParam.getMode(); final int id = dateArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDate(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDateArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDateArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateParam) { final DateParam dateParam = (DateParam) reqParam; final ParamMode mode = dateParam.getMode(); final int id = dateParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDate(dateParam.getContent()).getTime()); proParams.addDate(id, cal, mode.value()); } else { proParams.addDate(id, null, mode.value()); } } else if (reqParam instanceof DateTimeArrayParam) { final DateTimeArrayParam dateTimeArrayParam = (DateTimeArrayParam) reqParam; final ParamMode mode = dateTimeArrayParam.getMode(); final int id = dateTimeArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateTimeArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDatetimeArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDatetimeArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateTimeParam) { final DateTimeParam dateTimeParam = (DateTimeParam) reqParam; final ParamMode mode = dateTimeParam.getMode(); final int id = dateTimeParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(dateTimeParam.getContent()).getTime()); proParams.addDatetime(id, cal, mode.value()); } else { proParams.addDatetime(id, null, mode.value()); } } else if (reqParam instanceof DateTimeTZArrayParam) { final DateTimeTZArrayParam dateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam; final ParamMode mode = dateTimeTZArrayParam.getMode(); final int id = dateTimeTZArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateTimeTZArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDatetimeTZArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDatetimeTZArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateTimeTZParam) { final DateTimeTZParam dateTimeTZParam = (DateTimeTZParam) reqParam; final ParamMode mode = dateTimeTZParam.getMode(); final int id = dateTimeTZParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(dateTimeTZParam.getContent()).getTime()); proParams.addDatetimeTZ(id, cal, mode.value()); } else { proParams.addDatetimeTZ(id, null, mode.value()); } } else if (reqParam instanceof DecArrayParam) { final DecArrayParam decArrayParam = (DecArrayParam) reqParam; final ParamMode mode = decArrayParam.getMode(); final int id = decArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<BigDecimal> value = new ArrayList<BigDecimal>(); for (final JAXBElement<String> valueElement : decArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseDecimal(valueElement.getValue())); else value.add(null); } proParams.addDecimalArray(id, value.toArray(new BigDecimal[] {}), mode.value(), value.size()); } else { proParams.addDecimalArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DecParam) { final DecParam decParam = (DecParam) reqParam; final ParamMode mode = decParam.getMode(); final int id = decParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addDecimal(id, DatatypeConverter.parseDecimal(decParam.getContent()), mode.value()); else proParams.addDecimal(id, null, mode.value()); } else if (reqParam instanceof IntArrayParam) { final IntArrayParam intArrayParam = (IntArrayParam) reqParam; final ParamMode mode = intArrayParam.getMode(); final int id = intArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<Integer> value = new ArrayList<Integer>(); for (final JAXBElement<String> valueElement : intArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseInt(valueElement.getValue())); else value.add(null); } proParams.addIntegerArray(id, value.toArray(new Integer[] {}), mode.value(), value.size()); } else { proParams.addIntegerArray(id, (Integer[]) null, mode.value(), 0); } } else if (reqParam instanceof IntParam) { final IntParam intParam = (IntParam) reqParam; final ParamMode mode = intParam.getMode(); final int id = intParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addInteger(id, new Integer(DatatypeConverter.parseInt(intParam.getContent())), mode.value()); else proParams.addInteger(id, null, mode.value()); } else if (reqParam instanceof LogArrayParam) { final LogArrayParam logArrayParam = (LogArrayParam) reqParam; final ParamMode mode = logArrayParam.getMode(); final int id = logArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<Boolean> value = new ArrayList<Boolean>(); for (final JAXBElement<String> valueElement : logArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseBoolean(valueElement.getValue())); else value.add(null); } proParams.addLogicalArray(id, value.toArray(new Boolean[] {}), mode.value(), value.size()); } else { proParams.addLogicalArray(id, (Boolean[]) null, mode.value(), 0); } } else if (reqParam instanceof LogParam) { final LogParam logParam = (LogParam) reqParam; final ParamMode mode = logParam.getMode(); final int id = logParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addLogical(id, new Boolean(DatatypeConverter.parseBoolean(logParam.getContent())), mode.value()); else proParams.addLogical(id, null, mode.value()); } else if (reqParam instanceof ResultSetParam) { final ResultSetParam rsParam = (ResultSetParam) reqParam; final ParamMode mode = rsParam.getMode(); final int id = rsParam.getId(); final ResultSetMetaData rsMetaData = rsParam.getResultSetMetaData(); final List<Serializable> fieldMetaDataList = rsMetaData.getFieldMetaDataList(); final ProResultSetMetaDataImpl proRsMetaData = new ProResultSetMetaDataImpl( fieldMetaDataList.size()); for (final Serializable fieldMetaData : fieldMetaDataList) { if (fieldMetaData instanceof CharFieldMetaData) { final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(charFieldMetaData.getId(), charFieldMetaData.getName(), charFieldMetaData.getExtent(), Parameter.PRO_CHARACTER); } else if (fieldMetaData instanceof DateFieldMetaData) { final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateFieldMetaData.getId(), dateFieldMetaData.getName(), dateFieldMetaData.getExtent(), Parameter.PRO_DATE); } else if (fieldMetaData instanceof DateTimeFieldMetaData) { final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateTimeFieldMetaData.getId(), dateTimeFieldMetaData.getName(), dateTimeFieldMetaData.getExtent(), Parameter.PRO_DATETIME); } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) { final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateTimeTZFieldMetaData.getId(), dateTimeTZFieldMetaData.getName(), dateTimeTZFieldMetaData.getExtent(), Parameter.PRO_DATETIMETZ); } else if (fieldMetaData instanceof DecFieldMetaData) { final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(decFieldMetaData.getId(), decFieldMetaData.getName(), decFieldMetaData.getExtent(), Parameter.PRO_DECIMAL); } else if (fieldMetaData instanceof IntFieldMetaData) { final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(intFieldMetaData.getId(), intFieldMetaData.getName(), intFieldMetaData.getExtent(), Parameter.PRO_INTEGER); } else if (fieldMetaData instanceof LogFieldMetaData) { final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(logFieldMetaData.getId(), logFieldMetaData.getName(), logFieldMetaData.getExtent(), Parameter.PRO_LOGICAL); } } if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addTable(id, new OpenEdgeResultSet(rsParam.getRowList().iterator()), mode.value(), proRsMetaData); else proParams.addTable(id, null, mode.value(), proRsMetaData); } } LOG.info("Connecting to the AppServer"); if (SESSION_MODEL_MANAGED == sessionModel) RunTimeProperties.setSessionModel(0); else if (SESSION_MODEL_FREE == sessionModel) RunTimeProperties.setSessionModel(1); final OpenAppObject proAppObject = new OpenAppObject(url, user, password, null, null); proAppObject.runProc(req.getProgram(), proParams); LOG.info("Marshalling the response"); final Response res = OBJECT_FACTORY.createResponse(); res.setResult(proParams.getProcReturnString()); LOG.info("Setting the output params"); for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) { final Serializable reqParam = reqParamElement.getValue(); if (reqParam instanceof CharArrayParam) { final CharArrayParam reqCharArrayParam = (CharArrayParam) reqParam; if (ParamMode.INPUT != reqCharArrayParam.getMode()) { final JAXBElement<CharArrayParam> resParamElement = new JAXBElement<CharArrayParam>( new QName(NS, "CharArray"), CharArrayParam.class, null); final CharArrayParam resParam = OBJECT_FACTORY.createCharArrayParam(); resParam.setId(reqCharArrayParam.getId()); resParam.setName(reqCharArrayParam.getName()); final String[] proParam = (String[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printString(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof CharParam) { final CharParam reqCharParam = (CharParam) reqParam; if (ParamMode.INPUT != reqCharParam.getMode()) { final JAXBElement<CharParam> resParamElement = new JAXBElement<CharParam>( new QName(NS, "Char"), CharParam.class, null); final CharParam resParam = OBJECT_FACTORY.createCharParam(); resParam.setId(reqCharParam.getId()); resParam.setName(reqCharParam.getName()); final String proParam = (String) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printString(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateArrayParam) { final DateArrayParam reqDateArrayParam = (DateArrayParam) reqParam; if (ParamMode.INPUT != reqDateArrayParam.getMode()) { final JAXBElement<DateArrayParam> resParamElement = new JAXBElement<DateArrayParam>( new QName(NS, "DateArray"), DateArrayParam.class, null); final DateArrayParam resParam = OBJECT_FACTORY.createDateArrayParam(); resParam.setId(reqDateArrayParam.getId()); resParam.setName(reqDateArrayParam.getName()); final Date[] proParam = (Date[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(proParam[i]); valueElement.setValue(DatatypeConverter.printDate(cal)); } else { valueElement.setNil(true); } resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateParam) { final DateParam reqDateParam = (DateParam) reqParam; if (ParamMode.INPUT != reqDateParam.getMode()) { final JAXBElement<DateParam> resParamElement = new JAXBElement<DateParam>( new QName(NS, "Date"), DateParam.class, null); final DateParam resParam = OBJECT_FACTORY.createDateParam(); resParam.setId(reqDateParam.getId()); resParam.setName(reqDateParam.getName()); final Date proParam = (Date) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(proParam); resParam.setContent(DatatypeConverter.printDate(cal)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeArrayParam) { final DateTimeArrayParam reqDateTimeArrayParam = (DateTimeArrayParam) reqParam; if (ParamMode.INPUT != reqDateTimeArrayParam.getMode()) { final JAXBElement<DateTimeArrayParam> resParamElement = new JAXBElement<DateTimeArrayParam>( new QName(NS, "DateTimeArray"), DateTimeArrayParam.class, null); final DateTimeArrayParam resParam = OBJECT_FACTORY.createDateTimeArrayParam(); resParam.setId(reqDateTimeArrayParam.getId()); resParam.setName(reqDateTimeArrayParam.getName()); final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDateTime(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeParam) { final DateTimeParam reqDateTimeParam = (DateTimeParam) reqParam; if (ParamMode.INPUT != reqDateTimeParam.getMode()) { final JAXBElement<DateTimeParam> resParamElement = new JAXBElement<DateTimeParam>( new QName(NS, "DateTime"), DateTimeParam.class, null); final DateTimeParam resParam = OBJECT_FACTORY.createDateTimeParam(); resParam.setId(reqDateTimeParam.getId()); resParam.setName(reqDateTimeParam.getName()); final GregorianCalendar proParam = (GregorianCalendar) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDateTime(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeTZArrayParam) { final DateTimeTZArrayParam reqDateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam; if (ParamMode.INPUT != reqDateTimeTZArrayParam.getMode()) { final JAXBElement<DateTimeTZArrayParam> resParamElement = new JAXBElement<DateTimeTZArrayParam>( new QName(NS, "DateTimeTZArray"), DateTimeTZArrayParam.class, null); final DateTimeTZArrayParam resParam = OBJECT_FACTORY.createDateTimeTZArrayParam(); resParam.setId(reqDateTimeTZArrayParam.getId()); resParam.setName(reqDateTimeTZArrayParam.getName()); final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDateTime(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeTZParam) { final DateTimeTZParam reqDateTimeTZParam = (DateTimeTZParam) reqParam; if (ParamMode.INPUT != reqDateTimeTZParam.getMode()) { final JAXBElement<DateTimeTZParam> resParamElement = new JAXBElement<DateTimeTZParam>( new QName(NS, "DateTimeTZ"), DateTimeTZParam.class, null); final DateTimeTZParam resParam = OBJECT_FACTORY.createDateTimeTZParam(); resParam.setId(reqDateTimeTZParam.getId()); resParam.setName(reqDateTimeTZParam.getName()); final GregorianCalendar proParam = (GregorianCalendar) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDateTime(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DecArrayParam) { final DecArrayParam reqDecArrayParam = (DecArrayParam) reqParam; if (ParamMode.INPUT != reqDecArrayParam.getMode()) { final JAXBElement<DecArrayParam> resParamElement = new JAXBElement<DecArrayParam>( new QName(NS, "DecArray"), DecArrayParam.class, null); final DecArrayParam resParam = OBJECT_FACTORY.createDecArrayParam(); resParam.setId(reqDecArrayParam.getId()); resParam.setName(reqDecArrayParam.getName()); final BigDecimal[] proParam = (BigDecimal[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDecimal(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DecParam) { final DecParam reqDecParam = (DecParam) reqParam; if (ParamMode.INPUT != reqDecParam.getMode()) { final JAXBElement<DecParam> resParamElement = new JAXBElement<DecParam>( new QName(NS, "Dec"), DecParam.class, null); final DecParam resParam = OBJECT_FACTORY.createDecParam(); resParam.setId(reqDecParam.getId()); resParam.setName(reqDecParam.getName()); final BigDecimal proParam = (BigDecimal) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDecimal(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof IntArrayParam) { final IntArrayParam reqIntArrayParam = (IntArrayParam) reqParam; if (ParamMode.INPUT != reqIntArrayParam.getMode()) { final JAXBElement<IntArrayParam> resParamElement = new JAXBElement<IntArrayParam>( new QName(NS, "IntArray"), IntArrayParam.class, null); final IntArrayParam resParam = OBJECT_FACTORY.createIntArrayParam(); resParam.setId(reqIntArrayParam.getId()); resParam.setName(reqIntArrayParam.getName()); final Integer[] proParam = (Integer[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printInt(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof IntParam) { final IntParam reqIntParam = (IntParam) reqParam; if (ParamMode.INPUT != reqIntParam.getMode()) { final JAXBElement<IntParam> resParamElement = new JAXBElement<IntParam>( new QName(NS, "Int"), IntParam.class, null); final IntParam resParam = OBJECT_FACTORY.createIntParam(); resParam.setId(reqIntParam.getId()); resParam.setName(reqIntParam.getName()); final Integer proParam = (Integer) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printInt(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof LogArrayParam) { final LogArrayParam reqLogArrayParam = (LogArrayParam) reqParam; if (ParamMode.INPUT != reqLogArrayParam.getMode()) { final JAXBElement<LogArrayParam> resParamElement = new JAXBElement<LogArrayParam>( new QName(NS, "LogArray"), LogArrayParam.class, null); final LogArrayParam resParam = OBJECT_FACTORY.createLogArrayParam(); resParam.setId(reqLogArrayParam.getId()); resParam.setName(reqLogArrayParam.getName()); final Boolean[] proParam = (Boolean[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printBoolean(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof LogParam) { final LogParam reqLogParam = (LogParam) reqParam; if (ParamMode.INPUT != reqLogParam.getMode()) { final JAXBElement<LogParam> resParamElement = new JAXBElement<LogParam>( new QName(NS, "Log"), LogParam.class, null); final LogParam resParam = OBJECT_FACTORY.createLogParam(); resParam.setId(reqLogParam.getId()); resParam.setName(reqLogParam.getName()); final Boolean proParam = (Boolean) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printBoolean(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof ResultSetParam) { final ResultSetParam reqResultSetParam = (ResultSetParam) reqParam; if (ParamMode.INPUT != reqResultSetParam.getMode()) { final JAXBElement<ResultSetParam> resParamElement = new JAXBElement<ResultSetParam>( new QName(NS, "ResultSet"), ResultSetParam.class, null); final ResultSetParam resParam = OBJECT_FACTORY.createResultSetParam(); resParam.setId(reqResultSetParam.getId()); resParam.setName(reqResultSetParam.getName()); final ProResultSet proParam = (ProResultSet) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { while (proParam.next()) { final Row row = OBJECT_FACTORY.createRow(); final ResultSetMetaData rsMetaData = reqResultSetParam.getResultSetMetaData(); for (final Serializable fieldMetaData : rsMetaData.getFieldMetaDataList()) { if (fieldMetaData instanceof CharFieldMetaData) { final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData; final int extent = charFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>( new QName(NS, "Char"), CharField.class, null); final CharField field = OBJECT_FACTORY.createCharField(); field.setId(charFieldMetaData.getId()); field.setName(charFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printString(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>( new QName(NS, "Char"), CharField.class, null); final CharField field = OBJECT_FACTORY.createCharField(); field.setId(charFieldMetaData.getId()); field.setName(charFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printString(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateFieldMetaData) { final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData; final int extent = dateFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>( new QName(NS, "Date"), DateField.class, null); final DateField field = OBJECT_FACTORY.createDateField(); field.setId(dateFieldMetaData.getId()); field.setName(dateFieldMetaData.getName()); final Date value = proParam.getDate(field.getId()); if (value != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(value); field.setContent(DatatypeConverter.printDate(cal)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>( new QName(NS, "Date"), DateField.class, null); final DateField field = OBJECT_FACTORY.createDateField(); field.setId(dateFieldMetaData.getId()); field.setName(dateFieldMetaData.getName()); final Date value = proParam.getDate(field.getId(), i); if (value != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(value); field.setContent(DatatypeConverter.printDate(cal)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateTimeFieldMetaData) { final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData; final int extent = dateTimeFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>( new QName(NS, "DateTime"), DateTimeField.class, null); final DateTimeField field = OBJECT_FACTORY.createDateTimeField(); field.setId(dateTimeFieldMetaData.getId()); field.setName(dateTimeFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>( new QName(NS, "DateTime"), DateTimeField.class, null); final DateTimeField field = OBJECT_FACTORY.createDateTimeField(); field.setId(dateTimeFieldMetaData.getId()); field.setName(dateTimeFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) { final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData; final int extent = dateTimeTZFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>( new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null); final DateTimeTZField field = OBJECT_FACTORY.createDateTimeTZField(); field.setId(dateTimeTZFieldMetaData.getId()); field.setName(dateTimeTZFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>( new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null); final DateTimeTZField field = OBJECT_FACTORY .createDateTimeTZField(); field.setId(dateTimeTZFieldMetaData.getId()); field.setName(dateTimeTZFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DecFieldMetaData) { final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData; final int extent = decFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>( new QName(NS, "Dec"), DecField.class, null); final DecField field = OBJECT_FACTORY.createDecField(); field.setId(decFieldMetaData.getId()); field.setName(decFieldMetaData.getName()); final BigDecimal value = proParam.getBigDecimal(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDecimal(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>( new QName(NS, "Dec"), DecField.class, null); final DecField field = OBJECT_FACTORY.createDecField(); field.setId(decFieldMetaData.getId()); field.setName(decFieldMetaData.getName()); final BigDecimal value = proParam.getBigDecimal(field.getId(), i, 0); if (value != null) { field.setContent(DatatypeConverter.printDecimal(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof IntFieldMetaData) { final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData; final int extent = intFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>( new QName(NS, "Int"), IntField.class, null); final IntField field = OBJECT_FACTORY.createIntField(); field.setId(intFieldMetaData.getId()); field.setName(intFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent( DatatypeConverter.printInt(Integer.parseInt(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>( new QName(NS, "Int"), IntField.class, null); final IntField field = OBJECT_FACTORY.createIntField(); field.setId(intFieldMetaData.getId()); field.setName(intFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent( DatatypeConverter.printInt(Integer.parseInt(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof LogFieldMetaData) { final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData; final int extent = logFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>( new QName(NS, "Log"), LogField.class, null); final LogField field = OBJECT_FACTORY.createLogField(); field.setId(logFieldMetaData.getId()); field.setName(logFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent( DatatypeConverter.printBoolean(Boolean.valueOf(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>( new QName(NS, "Log"), LogField.class, null); final LogField field = OBJECT_FACTORY.createLogField(); field.setId(logFieldMetaData.getId()); field.setName(logFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent( DatatypeConverter.printBoolean(Boolean.valueOf(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } } resParam.getRowList().add(row); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } } final Document doc = builder.newDocument(); marshaller.marshal(res, doc); exchange.getOut().setBody(doc); } catch (final RunTime4GLErrorException e) { LOG.error(e.getProcReturnString(), e); throw new OpenEdgeException(e.getProcReturnString(), e); } }
From source file:com.cloud.bridge.service.controller.s3.S3BucketAction.java
/** * Multipart upload is a complex operation with all the options defined by Amazon. Part of the functionality is * provided by the query done against the database. The CommonPrefixes functionality is done the same way * as done in the listBucketContents function (i.e., by iterating though the list to decide which output * element each key is placed).//w w w .j ava2 s . c o m * * @param request * @param response * @throws IOException */ public void executeListMultipartUploads(HttpServletRequest request, HttpServletResponse response) throws IOException { // [A] Obtain parameters and do basic bucket verification String bucketName = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY); String delimiter = request.getParameter("delimiter"); String keyMarker = request.getParameter("key-marker"); String prefix = request.getParameter("prefix"); int maxUploads = 1000; int nextUploadId = 0; String nextKey = null; boolean isTruncated = false; S3MultipartUpload[] uploads = null; S3MultipartUpload onePart = null; String temp = request.getParameter("max-uploads"); if (null != temp) { maxUploads = Integer.parseInt(temp); if (maxUploads > 1000 || maxUploads < 0) maxUploads = 1000; } // -> upload-id-marker is ignored unless key-marker is also specified String uploadIdMarker = request.getParameter("upload-id-marker"); if (null == keyMarker) uploadIdMarker = null; // -> does the bucket exist, we may need it to verify access permissions SBucketVO bucket = bucketDao.getByName(bucketName); if (bucket == null) { logger.error("listMultipartUpload failed since " + bucketName + " does not exist"); response.setStatus(404); return; } S3PolicyContext context = new S3PolicyContext(PolicyActions.ListBucketMultipartUploads, bucketName); context.setEvalParam(ConditionKeys.Prefix, prefix); context.setEvalParam(ConditionKeys.Delimiter, delimiter); S3Engine.verifyAccess(context, "SBucket", bucket.getId(), SAcl.PERMISSION_READ); // [B] Query the multipart table to get the list of current uploads try { MultipartLoadDao uploadDao = new MultipartLoadDao(); OrderedPair<S3MultipartUpload[], Boolean> result = uploadDao.getInitiatedUploads(bucketName, maxUploads, prefix, keyMarker, uploadIdMarker); uploads = result.getFirst(); isTruncated = result.getSecond().booleanValue(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) { logger.error("List Multipart Uploads failed due to " + e.getMessage(), e); response.setStatus(500); } StringBuffer xml = new StringBuffer(); xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); xml.append("<ListMultipartUploadsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"); xml.append("<Bucket>").append(StringEscapeUtils.escapeHtml(bucketName)).append("</Bucket>"); xml.append("<KeyMarker>").append((null == keyMarker ? "" : StringEscapeUtils.escapeHtml(keyMarker))) .append("</KeyMarker>"); xml.append("<UploadIdMarker>") .append((null == uploadIdMarker ? "" : StringEscapeUtils.escapeHtml(uploadIdMarker))) .append("</UploadIdMarker>"); // [C] Construct the contents of the <Upload> element StringBuffer partsList = new StringBuffer(); for (int i = 0; i < uploads.length; i++) { onePart = uploads[i]; if (null == onePart) break; if (delimiter != null && !delimiter.isEmpty()) { // -> is this available only in the CommonPrefixes element? if (StringHelper.substringInBetween(onePart.getKey(), prefix, delimiter) != null) continue; } nextKey = onePart.getKey(); nextUploadId = onePart.getId(); partsList.append("<Upload>"); partsList.append("<Key>").append(nextKey).append("</Key>"); partsList.append("<UploadId>").append(nextUploadId).append("</UploadId>"); partsList.append("<Initiator>"); partsList.append("<ID>").append(onePart.getAccessKey()).append("</ID>"); partsList.append("<DisplayName></DisplayName>"); partsList.append("</Initiator>"); partsList.append("<Owner>"); partsList.append("<ID>").append(onePart.getAccessKey()).append("</ID>"); partsList.append("<DisplayName></DisplayName>"); partsList.append("</Owner>"); partsList.append("<StorageClass>STANDARD</StorageClass>"); partsList.append("<Initiated>").append(DatatypeConverter.printDateTime(onePart.getLastModified())) .append("</Initiated>"); partsList.append("</Upload>"); } // [D] Construct the contents of the <CommonPrefixes> elements (if any) for (int i = 0; i < uploads.length; i++) { onePart = uploads[i]; if (null == onePart) break; if (delimiter != null && !delimiter.isEmpty()) { String subName = StringHelper.substringInBetween(onePart.getKey(), prefix, delimiter); if (subName != null) { partsList.append("<CommonPrefixes>"); partsList.append("<Prefix>"); if (prefix != null && prefix.length() > 0) partsList.append(StringEscapeUtils.escapeHtml(prefix) + StringEscapeUtils.escapeHtml(delimiter) + StringEscapeUtils.escapeHtml(subName)); else partsList.append(StringEscapeUtils.escapeHtml(subName)); partsList.append("</Prefix>"); partsList.append("</CommonPrefixes>"); } } } // [D] Finish off the response xml.append("<NextKeyMarker>").append((null == nextKey ? "" : nextKey)).append("</NextKeyMarker>"); xml.append("<NextUploadIdMarker>").append((0 == nextUploadId ? "" : nextUploadId)) .append("</NextUploadIdMarker>"); xml.append("<MaxUploads>").append(maxUploads).append("</MaxUploads>"); xml.append("<IsTruncated>").append(isTruncated).append("</IsTruncated>"); xml.append(partsList.toString()); xml.append("</ListMultipartUploadsResult>"); response.setStatus(200); response.setContentType("text/xml; charset=UTF-8"); S3RestServlet.endResponse(response, xml.toString()); }
From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java
private String getXsDateTimeString(Date date) { Calendar cal = Calendar.getInstance(); if (date != null) { cal.setTime(date);/* ww w. ja va 2 s. c om*/ } return DatatypeConverter.printDateTime(cal); }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistence.java
void setLastModifiedAttribute(Element element) { Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ENGLISH); //$NON-NLS-1$ String lastModified = DatatypeConverter.printDateTime(now); setLastModifiedAttribute(element, lastModified); }
From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java
@Test public void testFromQuery() throws Exception { Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); long fromMillis = now - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); cal.setTimeInMillis(fromMillis);//from www . ja v a 2 s.c o m String fromStr = DatatypeConverter.printDateTime(cal); StatisticsQuery query = new StatisticsQuery(getParams(fromStr, null, null), now); Assert.assertEquals(fromMillis, query.getFrom()); Assert.assertEquals(now, query.getTo()); }
From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java
@Test public void testToQuery() throws Exception { Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); long toMillis = now - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); cal.setTimeInMillis(toMillis);/*from ww w. j a v a 2 s . co m*/ String toStr = DatatypeConverter.printDateTime(cal); StatisticsQuery query = new StatisticsQuery(getParams(null, toStr, null), now); Assert.assertEquals(0, query.getFrom()); Assert.assertEquals(toMillis, query.getTo()); }
From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java
@Test public void testFromToQuery() throws Exception { Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); long fromMillis = now - TimeUnit.MILLISECONDS.convert(2, TimeUnit.DAYS); long toMillis = now - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); cal.setTimeInMillis(fromMillis);//from w ww . j a va 2 s . c o m String fromStr = DatatypeConverter.printDateTime(cal); cal.setTimeInMillis(toMillis); String toStr = DatatypeConverter.printDateTime(cal); StatisticsQuery query = new StatisticsQuery(getParams(fromStr, toStr, null), now); Assert.assertEquals(fromMillis, query.getFrom()); Assert.assertEquals(toMillis, query.getTo()); // period is ignored, if both from and to are specified query = new StatisticsQuery(getParams(fromStr, toStr, "3d"), now); Assert.assertEquals(fromMillis, query.getFrom()); Assert.assertEquals(toMillis, query.getTo()); // from == to query = new StatisticsQuery(getParams(fromStr, fromStr, null), now); Assert.assertEquals(fromMillis, query.getFrom()); Assert.assertEquals(fromMillis, query.getTo()); // from > to query = new StatisticsQuery(getParams(toStr, fromStr, null), now); Assert.assertEquals(fromMillis, query.getFrom()); Assert.assertEquals(fromMillis, query.getTo()); }