Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/main/java/org/fhir/ucum/definitions/XmlDefinitionsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package org.fhir.ucum.definitions;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.fhir.ucum.BaseUnit;
import org.fhir.ucum.Decimal;
Expand All @@ -59,8 +51,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import org.fhir.ucum.utils.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

/**
* Parses the file ucum-essense.xml
Expand All @@ -86,8 +76,16 @@ public UcumModel parse(InputStream stream) throws UcumException {

if (!element.getNodeName().equals("root"))
throw new UcumException("Unable to process XML document: expected 'root' but found '"+element.getNodeName()+"'");
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss' 'Z");
Date date = fmt.parse(element.getAttribute("revision-date").substring(7, 32));
String dt = element.getAttribute("revision-date");
Date date;
if (dt.length() > 25) {
// old format: $Date: 2017-11-21 19:04:52 -0500"
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss' 'Z");
date = fmt.parse(dt.substring(7, 32));
} else {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
date = fmt.parse(dt);
}
UcumModel root = new UcumModel(element.getAttribute("version"), element.getAttribute("revision"), date);
Element focus = XmlUtils.getFirstChild(element);
while (focus != null) {
Expand Down
Loading