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,12 +71,11 @@ 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)
|
||||||
|
@ -285,8 +274,7 @@ 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();
|
||||||
|
@ -332,8 +320,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
@ -344,8 +331,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -355,8 +341,7 @@ 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);
|
||||||
|
@ -424,8 +409,7 @@ public class Utilities {
|
||||||
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
|
||||||
|
@ -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,7 +430,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -466,8 +447,7 @@ public class Utilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String systemEol()
|
public static String systemEol() {
|
||||||
{
|
|
||||||
return System.getProperty("line.separator");
|
return System.getProperty("line.separator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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