本文整理匯總了Java中javax.xml.bind.DatatypeConverter.parseDate方法的典型用法代碼示例。如果您正苦於以下問題:Java DatatypeConverter.parseDate方法的具體用法?Java DatatypeConverter.parseDate怎麽用?Java DatatypeConverter.parseDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.bind.DatatypeConverter
的用法示例。
在下文中一共展示了DatatypeConverter.parseDate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseDate
import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
public static java.util.Calendar parseDate(String lexicalXSDDate) {
return DatatypeConverter.parseDate(lexicalXSDDate.trim());
}
示例2: createIndex
import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
@SneakyThrows
public void createIndex(String sipId, int xmlVersion, String arclibXml) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document xml;
try {
xml = factory.newDocumentBuilder().parse(new ByteArrayInputStream(arclibXml.getBytes()));
} catch (ParserConfigurationException | SAXException | IOException e) {
log.error("Error during parsing of XML document");
throw e;
}
XPath xpath = getXpathWithNamespaceContext();
ArclibXmlDocument solrArclibXmlDocument = new ArclibXmlDocument();
SolrInputDocument doc = new SolrInputDocument();
for (IndexFieldConfig conf : getFieldsConfig()) {
NodeList fields = (NodeList) xpath.evaluate(conf.getXpath(), xml, XPathConstants.NODESET);
for (int i = 0; i < fields.getLength(); i++) {
try {
switch (conf.getFieldType()) {
case DATETIME:
Calendar parsedDate = DatatypeConverter.parseDateTime(fields.item(i).getTextContent());
String parsedDateTimeString = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(parsedDate.toInstant().atZone(ZoneId.systemDefault()));
solrArclibXmlDocument.addField(conf.getFieldName(), parsedDateTimeString);
break;
case DATE:
parsedDate = DatatypeConverter.parseDate(fields.item(i).getTextContent());
String parsedDateString = DateTimeFormatter.ISO_LOCAL_DATE.format(parsedDate.toInstant().atZone(ZoneId.systemDefault()));
solrArclibXmlDocument.addField(conf.getFieldName(), parsedDateString);
break;
case TIME:
ZonedDateTime time = DatatypeConverter.parseTime(fields.item(i).getTextContent()).toInstant().atZone(ZoneId.systemDefault());
long parsedTime = time.getHour() * 60 * 60 * 1000 + time.getMinute() * 60 * 1000 + time.getSecond() * 1000;
solrArclibXmlDocument.addField(conf.getFieldName(), parsedTime);
break;
default:
if (conf.isFullText()) {
solrArclibXmlDocument.addField(conf.getFieldName(), nodeToString(fields.item(i)));
} else {
solrArclibXmlDocument.addField(conf.getFieldName(), fields.item(i).getTextContent());
}
}
} catch (IllegalArgumentException | NullPointerException parsingEx) {
String msg = String.format("Could not parse %s as %s", fields.item(i).getTextContent(), conf.getFieldType());
log.error(msg);
throw new BadArgument(msg);
}
}
}
solrArclibXmlDocument.setId(sipId + "_" + xmlVersion);
solrArclibXmlDocument.setDocument(arclibXml);
try {
arclibXmlRepository.save(solrArclibXmlDocument);
} catch (UncategorizedSolrException ex) {
log.error(ex.getMessage());
throw ex;
}
}