parent
b8405c23b8
commit
7bbbd7af0a
|
@ -30,10 +30,10 @@ package org.hl7.fhir.utilities;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -42,7 +42,6 @@ import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -50,27 +49,18 @@ import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
|
||||||
|
|
||||||
import net.sf.saxon.TransformerFactoryImpl;
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
public class Utilities {
|
public class Utilities {
|
||||||
|
|
||||||
// private static final String TOKEN_REGEX = "^a-z[A-Za-z0-9]*$";
|
|
||||||
|
|
||||||
private static final String OID_REGEX = "[0-2](\\.(0|[1-9][0-9]*))+";
|
private static final String OID_REGEX = "[0-2](\\.(0|[1-9][0-9]*))+";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the plural form of the word in the string.
|
* Returns the plural form of the word in the string.
|
||||||
*
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -81,17 +71,16 @@ public class Utilities {
|
||||||
* inflector.pluralize("the blue mailman") #=> "the blue mailmen"
|
* inflector.pluralize("the blue mailman") #=> "the blue mailmen"
|
||||||
* inflector.pluralize("CamelOctopus") #=> "CamelOctopi"
|
* inflector.pluralize("CamelOctopus") #=> "CamelOctopi"
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
* <p>
|
||||||
*
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* Note that if the {@link Object#toString()} is called on the supplied object, so this method works for non-strings, too.
|
* Note that if the {@link Object#toString()} is called on the supplied object, so this method works for non-strings, too.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param word the word that is to be pluralized.
|
* @param word the word that is to be pluralized.
|
||||||
* @return the pluralized form of the word, or the word itself if it could not be pluralized
|
* @return the pluralized form of the word, or the word itself if it could not be pluralized
|
||||||
* @see #singularize(Object)
|
* @see #singularize(Object)
|
||||||
*/
|
*/
|
||||||
public static String pluralizeMe( String word ) {
|
public static String pluralizeMe(String word) {
|
||||||
Inflector inf = new Inflector();
|
Inflector inf = new Inflector();
|
||||||
return inf.pluralize(word);
|
return inf.pluralize(word);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +142,7 @@ public class Utilities {
|
||||||
public static boolean isHex(String string) {
|
public static boolean isHex(String string) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(string, 16);
|
int i = Integer.parseInt(string, 16);
|
||||||
return i != i+1;
|
return i != i + 1;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -208,11 +197,11 @@ public class Utilities {
|
||||||
havePeriod = true;
|
havePeriod = true;
|
||||||
preDecLength = length;
|
preDecLength = length;
|
||||||
length = 0;
|
length = 0;
|
||||||
} else if (next == '-' || next == '+' ) {
|
} else if (next == '-' || next == '+') {
|
||||||
if (haveDigits || haveSign)
|
if (haveDigits || haveSign)
|
||||||
return DecimalStatus.SYNTAX;
|
return DecimalStatus.SYNTAX;
|
||||||
haveSign = true;
|
haveSign = true;
|
||||||
} else if (next == 'e' || next == 'E' ) {
|
} else if (next == 'e' || next == 'E') {
|
||||||
if (!haveDigits || haveExponent || !allowExponent)
|
if (!haveDigits || haveExponent || !allowExponent)
|
||||||
return DecimalStatus.SYNTAX;
|
return DecimalStatus.SYNTAX;
|
||||||
haveExponent = true;
|
haveExponent = true;
|
||||||
|
@ -285,11 +274,10 @@ public class Utilities {
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String capitalize(String s)
|
public static String capitalize(String s) {
|
||||||
{
|
if (s == null) return null;
|
||||||
if( s == null ) return null;
|
if (s.length() == 0) return s;
|
||||||
if( s.length() == 0 ) return s;
|
if (s.length() == 1) return s.toUpperCase();
|
||||||
if( s.length() == 1 ) return s.toUpperCase();
|
|
||||||
|
|
||||||
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -297,18 +285,18 @@ public class Utilities {
|
||||||
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException {
|
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException {
|
||||||
CSFile src = new CSFile(sourceFolder);
|
CSFile src = new CSFile(sourceFolder);
|
||||||
if (!src.exists())
|
if (!src.exists())
|
||||||
throw new FHIRException("Folder " +sourceFolder+" not found");
|
throw new FHIRException("Folder " + sourceFolder + " not found");
|
||||||
createDirectory(destFolder);
|
createDirectory(destFolder);
|
||||||
|
|
||||||
String[] files = src.list();
|
String[] files = src.list();
|
||||||
for (String f : files) {
|
for (String f : files) {
|
||||||
if (new CSFile(sourceFolder+File.separator+f).isDirectory()) {
|
if (new CSFile(sourceFolder + File.separator + f).isDirectory()) {
|
||||||
if (!f.startsWith(".")) // ignore .git files...
|
if (!f.startsWith(".")) // ignore .git files...
|
||||||
copyDirectory(sourceFolder+File.separator+f, destFolder+File.separator+f, notifier);
|
copyDirectory(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier);
|
||||||
} else {
|
} else {
|
||||||
if (notifier != null)
|
if (notifier != null)
|
||||||
notifier.copyFile(sourceFolder+File.separator+f, destFolder+File.separator+f);
|
notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f);
|
||||||
copyFile(new CSFile(sourceFolder+File.separator+f), new CSFile(destFolder+File.separator+f));
|
copyFile(new CSFile(sourceFolder + File.separator + f), new CSFile(destFolder + File.separator + f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,7 +306,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyFile(File sourceFile, File destFile) throws IOException {
|
public static void copyFile(File sourceFile, File destFile) throws IOException {
|
||||||
if(!destFile.exists()) {
|
if (!destFile.exists()) {
|
||||||
if (!new CSFile(destFile.getParent()).exists()) {
|
if (!new CSFile(destFile.getParent()).exists()) {
|
||||||
createDirectory(destFile.getParent());
|
createDirectory(destFile.getParent());
|
||||||
}
|
}
|
||||||
|
@ -332,22 +320,20 @@ public class Utilities {
|
||||||
source = new FileInputStream(sourceFile).getChannel();
|
source = new FileInputStream(sourceFile).getChannel();
|
||||||
destination = new FileOutputStream(destFile).getChannel();
|
destination = new FileOutputStream(destFile).getChannel();
|
||||||
destination.transferFrom(source, 0, source.size());
|
destination.transferFrom(source, 0, source.size());
|
||||||
}
|
} finally {
|
||||||
finally {
|
if (source != null) {
|
||||||
if(source != null) {
|
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
if(destination != null) {
|
if (destination != null) {
|
||||||
destination.close();
|
destination.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkFolder(String dir, List<String> errors)
|
public static boolean checkFolder(String dir, List<String> errors)
|
||||||
throws IOException
|
throws IOException {
|
||||||
{
|
|
||||||
if (!new CSFile(dir).exists()) {
|
if (!new CSFile(dir).exists()) {
|
||||||
errors.add("Unable to find directory "+dir);
|
errors.add("Unable to find directory " + dir);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -355,11 +341,10 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkFile(String purpose, String dir, String file, List<String> errors)
|
public static boolean checkFile(String purpose, String dir, String file, List<String> errors)
|
||||||
throws IOException
|
throws IOException {
|
||||||
{
|
if (!new CSFile(dir + file).exists()) {
|
||||||
if (!new CSFile(dir+file).exists()) {
|
|
||||||
if (errors != null)
|
if (errors != null)
|
||||||
errors.add("Unable to find "+purpose+" file "+file+" in "+dir);
|
errors.add("Unable to find " + purpose + " file " + file + " in " + dir);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -401,7 +386,7 @@ public class Utilities {
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (String f : files) {
|
for (String f : files) {
|
||||||
if (!existsInList(f, exemptions)) {
|
if (!existsInList(f, exemptions)) {
|
||||||
File fh = new CSFile(folder+File.separatorChar+f);
|
File fh = new CSFile(folder + File.separatorChar + f);
|
||||||
if (fh.isDirectory())
|
if (fh.isDirectory())
|
||||||
clearDirectory(fh.getAbsolutePath());
|
clearDirectory(fh.getAbsolutePath());
|
||||||
fh.delete();
|
fh.delete();
|
||||||
|
@ -412,7 +397,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File createDirectory(String path) throws IOException{
|
public static File createDirectory(String path) throws IOException {
|
||||||
new CSFile(path).mkdirs();
|
new CSFile(path).mkdirs();
|
||||||
return new File(path);
|
return new File(path);
|
||||||
}
|
}
|
||||||
|
@ -421,12 +406,11 @@ public class Utilities {
|
||||||
if (name.lastIndexOf('.') > -1)
|
if (name.lastIndexOf('.') > -1)
|
||||||
return name.substring(0, name.lastIndexOf('.')) + ext;
|
return name.substring(0, name.lastIndexOf('.')) + ext;
|
||||||
else
|
else
|
||||||
return name+ext;
|
return name + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String cleanupTextString( String contents )
|
public static String cleanupTextString(String contents) {
|
||||||
{
|
if (contents == null || contents.trim().equals(""))
|
||||||
if( contents == null || contents.trim().equals("") )
|
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
|
@ -438,8 +422,6 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void bytesToFile(byte[] content, String filename) throws IOException {
|
public static void bytesToFile(byte[] content, String filename) throws IOException {
|
||||||
FileOutputStream out = new FileOutputStream(filename);
|
FileOutputStream out = new FileOutputStream(filename);
|
||||||
out.write(content);
|
out.write(content);
|
||||||
|
@ -448,13 +430,12 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String appendSlash(String definitions) {
|
public static String appendSlash(String definitions) {
|
||||||
return definitions.endsWith(File.separator) ? definitions : definitions+File.separator;
|
return definitions.endsWith(File.separator) ? definitions : definitions + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String appendForwardSlash(String definitions) {
|
public static String appendForwardSlash(String definitions) {
|
||||||
return definitions.endsWith("/") ? definitions : definitions+"/";
|
return definitions.endsWith("/") ? definitions : definitions + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -462,12 +443,11 @@ public class Utilities {
|
||||||
if (file == null)
|
if (file == null)
|
||||||
return null;
|
return null;
|
||||||
String s = new File(file).getName();
|
String s = new File(file).getName();
|
||||||
return s.indexOf(".") == -1? s : s.substring(0, s.indexOf("."));
|
return s.indexOf(".") == -1 ? s : s.substring(0, s.indexOf("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String systemEol()
|
public static String systemEol() {
|
||||||
{
|
|
||||||
return System.getProperty("line.separator");
|
return System.getProperty("line.separator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,9 +479,9 @@ public class Utilities {
|
||||||
else if (e.toString().equals("quot"))
|
else if (e.toString().equals("quot"))
|
||||||
b.append("\"");
|
b.append("\"");
|
||||||
else if (e.toString().equals("mu"))
|
else if (e.toString().equals("mu"))
|
||||||
b.append((char)956);
|
b.append((char) 956);
|
||||||
else
|
else
|
||||||
throw new FHIRException("unknown XML entity \""+e.toString()+"\"");
|
throw new FHIRException("unknown XML entity \"" + e.toString() + "\"");
|
||||||
} else
|
} else
|
||||||
b.append(xml.charAt(i));
|
b.append(xml.charAt(i));
|
||||||
i++;
|
i++;
|
||||||
|
@ -545,11 +525,11 @@ public class Utilities {
|
||||||
b.append('\t');
|
b.append('\t');
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
String hex = json.substring(i+1, i+5);
|
String hex = json.substring(i + 1, i + 5);
|
||||||
b.append((char) Integer.parseInt(hex, 16));
|
b.append((char) Integer.parseInt(hex, 16));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new FHIRException("Unknown JSON escape \\"+ch);
|
throw new FHIRException("Unknown JSON escape \\" + ch);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
b.append(json.charAt(i));
|
b.append(json.charAt(i));
|
||||||
|
@ -591,7 +571,7 @@ public class Utilities {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
boolean d = false;
|
boolean d = false;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for(String arg: args) {
|
for (String arg : args) {
|
||||||
if (first && arg == null)
|
if (first && arg == null)
|
||||||
continue;
|
continue;
|
||||||
first = false;
|
first = false;
|
||||||
|
@ -609,7 +589,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
} else if ("[user]".equals(a)) {
|
} else if ("[user]".equals(a)) {
|
||||||
a = System.getProperty("user.home");
|
a = System.getProperty("user.home");
|
||||||
} else if (a.startsWith("[") && a.endsWith("]")){
|
} else if (a.startsWith("[") && a.endsWith("]")) {
|
||||||
String ev = System.getenv(a.replace("[", "").replace("]", ""));
|
String ev = System.getenv(a.replace("[", "").replace("]", ""));
|
||||||
if (ev != null) {
|
if (ev != null) {
|
||||||
a = ev;
|
a = ev;
|
||||||
|
@ -623,22 +603,22 @@ public class Utilities {
|
||||||
if (s.length() > 0 && a.startsWith(File.separator))
|
if (s.length() > 0 && a.startsWith(File.separator))
|
||||||
a = a.substring(File.separator.length());
|
a = a.substring(File.separator.length());
|
||||||
|
|
||||||
while (a.startsWith(".."+File.separator)) {
|
while (a.startsWith(".." + File.separator)) {
|
||||||
if (s.length() == 0) {
|
if (s.length() == 0) {
|
||||||
s = new StringBuilder(Paths.get(".").toAbsolutePath().normalize().toString());
|
s = new StringBuilder(Paths.get(".").toAbsolutePath().normalize().toString());
|
||||||
} else {
|
} else {
|
||||||
String p = s.toString().substring(0, s.length()-1);
|
String p = s.toString().substring(0, s.length() - 1);
|
||||||
if (!p.contains(File.separator)) {
|
if (!p.contains(File.separator)) {
|
||||||
s = new StringBuilder();
|
s = new StringBuilder();
|
||||||
} else {
|
} else {
|
||||||
s = new StringBuilder(p.substring(0, p.lastIndexOf(File.separator))+File.separator);
|
s = new StringBuilder(p.substring(0, p.lastIndexOf(File.separator)) + File.separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a = a.substring(3);
|
a = a.substring(3);
|
||||||
}
|
}
|
||||||
if ("..".equals(a)) {
|
if ("..".equals(a)) {
|
||||||
int i = s.substring(0, s.length()-1).lastIndexOf(File.separator);
|
int i = s.substring(0, s.length() - 1).lastIndexOf(File.separator);
|
||||||
s = new StringBuilder(s.substring(0, i+1));
|
s = new StringBuilder(s.substring(0, i + 1));
|
||||||
} else
|
} else
|
||||||
s.append(a);
|
s.append(a);
|
||||||
}
|
}
|
||||||
|
@ -656,7 +636,7 @@ public class Utilities {
|
||||||
public static String pathURL(String... args) {
|
public static String pathURL(String... args) {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
boolean d = false;
|
boolean d = false;
|
||||||
for(String arg: args) {
|
for (String arg : args) {
|
||||||
if (!d)
|
if (!d)
|
||||||
d = !noString(arg);
|
d = !noString(arg);
|
||||||
else if (!s.toString().endsWith("/") && !arg.startsWith("/"))
|
else if (!s.toString().endsWith("/") && !arg.startsWith("/"))
|
||||||
|
@ -667,7 +647,6 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public static void checkCase(String filename) {
|
// public static void checkCase(String filename) {
|
||||||
// File f = new CSFile(filename);
|
// File f = new CSFile(filename);
|
||||||
// if (!f.getName().equals(filename))
|
// if (!f.getName().equals(filename))
|
||||||
|
@ -684,7 +663,7 @@ public class Utilities {
|
||||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
|
||||||
s.append(c);
|
s.append(c);
|
||||||
else if (c != ' ')
|
else if (c != ' ')
|
||||||
s.append("."+Integer.toString(c));
|
s.append("." + Integer.toString(c));
|
||||||
}
|
}
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
@ -722,7 +701,7 @@ public class Utilities {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
if (s.endsWith(".") || s.endsWith("?"))
|
if (s.endsWith(".") || s.endsWith("?"))
|
||||||
return s;
|
return s;
|
||||||
return s+".";
|
return s + ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -730,7 +709,7 @@ public class Utilities {
|
||||||
if (Utilities.noString(s))
|
if (Utilities.noString(s))
|
||||||
return s;
|
return s;
|
||||||
if (s.endsWith("."))
|
if (s.endsWith("."))
|
||||||
return s.substring(0, s.length()-1);
|
return s.substring(0, s.length() - 1);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +722,7 @@ public class Utilities {
|
||||||
public static String oidTail(String id) {
|
public static String oidTail(String id) {
|
||||||
if (id == null || !id.contains("."))
|
if (id == null || !id.contains("."))
|
||||||
return id;
|
return id;
|
||||||
return id.substring(id.lastIndexOf(".")+1);
|
return id.substring(id.lastIndexOf(".") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -785,7 +764,7 @@ public class Utilities {
|
||||||
b.append(Character.toLowerCase(name.charAt(i)));
|
b.append(Character.toLowerCase(name.charAt(i)));
|
||||||
}
|
}
|
||||||
parts.add(b.toString());
|
parts.add(b.toString());
|
||||||
return parts.toArray(new String[] {} );
|
return parts.toArray(new String[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -794,7 +773,6 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String normalize(String s) {
|
public static String normalize(String s) {
|
||||||
if (noString(s))
|
if (noString(s))
|
||||||
return null;
|
return null;
|
||||||
|
@ -921,7 +899,7 @@ public class Utilities {
|
||||||
|
|
||||||
public static File createTempFile(String prefix, String suffix) throws IOException {
|
public static File createTempFile(String prefix, String suffix) throws IOException {
|
||||||
// this allows use to eaily identify all our dtemp files and delete them, since delete on Exit doesn't really work.
|
// this allows use to eaily identify all our dtemp files and delete them, since delete on Exit doesn't really work.
|
||||||
File file = File.createTempFile("ohfu-"+prefix, suffix);
|
File file = File.createTempFile("ohfu-" + prefix, suffix);
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -937,7 +915,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String makeUuidUrn() {
|
public static String makeUuidUrn() {
|
||||||
return "urn:uuid:"+UUID.randomUUID().toString().toLowerCase();
|
return "urn:uuid:" + UUID.randomUUID().toString().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isURL(String s) {
|
public static boolean isURL(String s) {
|
||||||
|
@ -963,7 +941,7 @@ public class Utilities {
|
||||||
else if (c == '\\')
|
else if (c == '\\')
|
||||||
b.append("\\\\");
|
b.append("\\\\");
|
||||||
else if (((int) c) < 32)
|
else if (((int) c) < 32)
|
||||||
b.append("\\u"+Utilities.padLeft(String.valueOf((int) c), '0', 4));
|
b.append("\\u" + Utilities.padLeft(String.valueOf((int) c), '0', 4));
|
||||||
else
|
else
|
||||||
b.append(c);
|
b.append(c);
|
||||||
}
|
}
|
||||||
|
@ -996,9 +974,9 @@ public class Utilities {
|
||||||
|
|
||||||
|
|
||||||
public static String uncapitalize(String s) {
|
public static String uncapitalize(String s) {
|
||||||
if( s == null ) return null;
|
if (s == null) return null;
|
||||||
if( s.length() == 0 ) return s;
|
if (s.length() == 0) return s;
|
||||||
if( s.length() == 1 ) return s.toLowerCase();
|
if (s.length() == 1) return s.toLowerCase();
|
||||||
|
|
||||||
return s.substring(0, 1).toLowerCase() + s.substring(1);
|
return s.substring(0, 1).toLowerCase() + s.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -1013,8 +991,6 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isOid(String cc) {
|
public static boolean isOid(String cc) {
|
||||||
return cc.matches(OID_REGEX) && cc.lastIndexOf('.') >= 5;
|
return cc.matches(OID_REGEX) && cc.lastIndexOf('.') >= 5;
|
||||||
}
|
}
|
||||||
|
@ -1033,10 +1009,10 @@ public class Utilities {
|
||||||
File src = new File(folder);
|
File src = new File(folder);
|
||||||
String[] files = src.list();
|
String[] files = src.list();
|
||||||
for (String f : files) {
|
for (String f : files) {
|
||||||
if (new File(folder+File.separator+f).isDirectory()) {
|
if (new File(folder + File.separator + f).isDirectory()) {
|
||||||
deleteAllFiles(folder+File.separator+f, type);
|
deleteAllFiles(folder + File.separator + f, type);
|
||||||
} else if (f.endsWith(type)) {
|
} else if (f.endsWith(type)) {
|
||||||
new File(folder+File.separator+f).delete();
|
new File(folder + File.separator + f).delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,12 +1050,14 @@ public class Utilities {
|
||||||
if (in1 != null) {
|
if (in1 != null) {
|
||||||
try {
|
try {
|
||||||
in1.close();
|
in1.close();
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (in2 != null) {
|
if (in2 != null) {
|
||||||
try {
|
try {
|
||||||
in2.close();
|
in2.close();
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1095,7 +1073,7 @@ public class Utilities {
|
||||||
|
|
||||||
|
|
||||||
public static boolean isAbsoluteUrl(String ref) {
|
public static boolean isAbsoluteUrl(String ref) {
|
||||||
return ref != null && (ref.startsWith("http:") || ref.startsWith("https:") || ref.startsWith("urn:uuid:") || ref.startsWith("urn:oid:")) ;
|
return ref != null && (ref.startsWith("http:") || ref.startsWith("https:") || ref.startsWith("urn:uuid:") || ref.startsWith("urn:oid:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1120,7 +1098,7 @@ public class Utilities {
|
||||||
|
|
||||||
|
|
||||||
public static String getFileExtension(String fn) {
|
public static String getFileExtension(String fn) {
|
||||||
return fn.contains(".") ? fn.substring(fn.lastIndexOf(".")+1) : "";
|
return fn.contains(".") ? fn.substring(fn.lastIndexOf(".") + 1) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1162,7 +1140,7 @@ public class Utilities {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
break;
|
break;
|
||||||
list.add(line.substring(0, i));
|
list.add(line.substring(0, i));
|
||||||
line = line.substring(i+1);
|
line = line.substring(i + 1);
|
||||||
}
|
}
|
||||||
list.add(line);
|
list.add(line);
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
|
@ -1171,7 +1149,7 @@ public class Utilities {
|
||||||
if (first)
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else
|
||||||
b.append("\r\n"+padLeft("", ' ', indent));
|
b.append("\r\n" + padLeft("", ' ', indent));
|
||||||
b.append(s);
|
b.append(s);
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
|
@ -1269,14 +1247,14 @@ public class Utilities {
|
||||||
while (i < p.length) {
|
while (i < p.length) {
|
||||||
String s = p[i];
|
String s = p[i];
|
||||||
if (s.contains("[")) {
|
if (s.contains("[")) {
|
||||||
String si = s.substring(s.indexOf("[")+1, s.length()-1);
|
String si = s.substring(s.indexOf("[") + 1, s.length() - 1);
|
||||||
if (!Utilities.isInteger(si))
|
if (!Utilities.isInteger(si))
|
||||||
throw new FHIRException("The FHIRPath expression '"+path+"' is not valid");
|
throw new FHIRException("The FHIRPath expression '" + path + "' is not valid");
|
||||||
s = s.substring(0, s.indexOf("["))+"["+Integer.toString(Integer.parseInt(si)+1)+"]";
|
s = s.substring(0, s.indexOf("[")) + "[" + Integer.toString(Integer.parseInt(si) + 1) + "]";
|
||||||
}
|
}
|
||||||
if (i < p.length - 1 && p[i+1].startsWith(".ofType(")) {
|
if (i < p.length - 1 && p[i + 1].startsWith(".ofType(")) {
|
||||||
i++;
|
i++;
|
||||||
s = s + capitalize(p[i].substring(8, p.length-1));
|
s = s + capitalize(p[i].substring(8, p.length - 1));
|
||||||
}
|
}
|
||||||
b.append(s);
|
b.append(s);
|
||||||
i++;
|
i++;
|
||||||
|
@ -1309,5 +1287,4 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
40
pom.xml
40
pom.xml
|
@ -311,6 +311,29 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
|
<version>1.6.7</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<serverId>ossrh</serverId>
|
||||||
|
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||||
|
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>deploy</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
@ -329,21 +352,8 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
|
||||||
<version>1.6.7</version>
|
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
|
||||||
<serverId>ossrh</serverId>
|
|
||||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
|
||||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|
Loading…
Reference in New Issue