Skip to content

Commit

Permalink
various refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Aug 16, 2024
1 parent 5ee2af2 commit 5f8c868
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public void internalConvert(String sid, Document document, File src, File dest)
throw new IOException("Unable to convert image to " + ext);

try {
int timeout = getTimeout();

List<String> commandLine = List.of(getParameter("path"), "-compress JPEG", src.getPath(), dest.getPath());
new Exec().exec(commandLine, null, null, timeout);
new Exec().exec(List.of(getParameter("path"), "-compress JPEG", src.getPath(), dest.getPath()), null, null, getTimeout());

if (!dest.exists() || dest.length() < 1)
throw new IOException("Empty conversion");
Expand Down
4 changes: 2 additions & 2 deletions logicaldoc-i18n/src/main/java/com/logicaldoc/i18n/I18N.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class I18N {
String[] languages = Locale.getISOLanguages();
iso3LocaleMap = new HashMap<>(languages.length);
for (String language : languages) {
Locale locale = Locale.of(language);
Locale locale = new Locale(language);

iso3LocaleMap.put(locale.getISO3Language().toLowerCase(), locale);
}
Expand All @@ -49,7 +49,7 @@ public static String message(String key) {
public static String message(String key, String language) {
if (language == null)
language = "en";
return message(key, Locale.of(language));
return message(key, new Locale(language));
}

public static String message(String key, Locale locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ sequences=Sequences
frequency=Frequency
value=Value
customidhint=The Scheme may be defined of the following tokens\: <br /> <b>&lt;id&gt;</b>, <b>&lt;customId&gt;</b>, <b>&lt;filename&gt;</b>, <b>&lt;title&gt;</b>, <b>&lt;extension&gt;</b>, <b>&lt;template&gt;</b>, <b>&lt;version&gt;</b>, <b>&lt;path&gt;</b>, <b>&lt;folder&gt;</b>, <b>&lt;year&gt;</b>, <b>&lt;month&gt;</b>, <b>&lt;yy&gt;</b>, <b>&lt;mm&gt;</b>, <b>&lt;dd&gt;</b>. <br /> <br /> You can call an automation routine with\: <b>&lt;automation\:routine_name&gt;</b> <br /> <br />You can also define special sequence tokens and these must end with <i>_seq</i> \: <br /> <b>&lt;standard_seq&gt;</b>, <b>&lt;year_seq&gt;</b>, <b>&lt;month_seq&gt;</b>, <b>&lt;template_seq&gt;</b>, <b>&lt;folder_seq&gt;</b>, <b>&lt;folder_template_seq&gt;</b>. <br /><br />You may use the format <i>&lt;name_seq\:padding&gt;</i>, where <i>padding</i> is a number by which the counter should be padded; for example, &lt;year&gt;-&lt;year_seq\:5&gt; will result in something like 2008-00001. <br /><br />Including <i>year</i> and <i>month</i> in a sequence name indicates that it should be reset yearly with <b>&lt;template_year_seq&gt;</b> or monthly with <b>&lt;template_month_seq&gt;</b>. <br /><br />You can also use your own sequence with: <b>&lt;sequence:name_of_your_sequence&gt;</b><br /><br />To refer to extended attributes use the notation\: <b>&lt;name-of-the-attribute&gt;</b><br />To refer to sequences bound to an extended attribute's value use the notation\: <b>&lt;name-of-the-attribute_seq&gt;</b>, <b>&lt;name-of-the-attribute_year_seq&gt;</b> or <b>&lt;name-of-the-attribute_month_seq&gt;</b>
task.name.Audit=Audit
task.name.AuditTask=Audit
task.name.NetworkBrowser=Network Discovery
searchinsubfolders2=Search in subfolders
scandocument=Scan a document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.util.Set;
import java.util.StringTokenizer;

public class PurifyRB {
public class PurifyWorkbench {

public static void main(String[] args) throws IOException {

List<Locale> locales = new ArrayList<Locale>();
Properties loc = new Properties();
loc.load(PurifyRB.class.getResourceAsStream("/i18n/i18n.properties"));
loc.load(PurifyWorkbench.class.getResourceAsStream("/i18n/i18n.properties"));
StringTokenizer st = new StringTokenizer(loc.getProperty("locales"), ",", false);
while (st.hasMoreElements()) {
String elem = (String) st.nextElement();
Expand Down Expand Up @@ -120,6 +120,6 @@ public static Locale toLocale(String str) {
country = st.nextToken();
if (st.hasMoreTokens())
variant = st.nextToken();
return Locale.of(lang, country, variant);
return new Locale(lang, country, variant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public static Locale toLocale(String str) {
country = st.nextToken();
if (st.hasMoreTokens())
variant = st.nextToken();
return Locale.of(language, country, variant);
return new Locale(language, country, variant);
}
}
19 changes: 17 additions & 2 deletions logicaldoc-util/src/main/java/com/logicaldoc/util/exec/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
public class Exec {

private static final String EXECUTING_COMMAND = "Executing command {}";

private static final String COMMAND_FAILED_TO_EXECUTE = "Command failed to execute - {}";

private static final String TIMEOUT_COMMAND = "Timeout command {}";
Expand Down Expand Up @@ -89,7 +91,8 @@ public int execPB(List<String> commandLine, Map<String, String> environment, Fil
throws IOException {
checkAllowed(commandLine);

log.debug("Executing command: {}", commandLine);
if(log.isDebugEnabled())
log.debug("Executing command: {}", commandLine);
ProcessBuilder pb = new ProcessBuilder();
pb.redirectErrorStream(true);
pb.command(commandLine);
Expand Down Expand Up @@ -176,6 +179,9 @@ public int exec(List<String> commandLine) throws IOException {
public int exec(List<String> commandLine, List<String> env, File dir, int timeout) throws IOException {
checkAllowed(commandLine);

if(log.isDebugEnabled())
log.debug(EXECUTING_COMMAND, commandLine);

int exit = 0;

final Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]),
Expand Down Expand Up @@ -243,7 +249,10 @@ public int exec(List<String> commandLine, List<String> env, File dir, int timeou
*/
public String execGetOutput(List<String> commandLine, List<String> env, File dir, int timeout) throws IOException {
checkAllowed(commandLine);


if(log.isDebugEnabled())
log.debug(EXECUTING_COMMAND, commandLine);

final Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]),
env != null ? env.toArray(new String[0]) : null, dir);
if (timeout > 0) {
Expand Down Expand Up @@ -315,6 +324,9 @@ public int exec(String commandLine, List<String> env, File dir, StringBuilder bu
throws IOException {
checkAllowed(commandLine);

if(log.isDebugEnabled())
log.debug(EXECUTING_COMMAND, commandLine);

int exit = 0;

final Process process = Runtime.getRuntime().exec(commandLine.split(" "),
Expand Down Expand Up @@ -370,6 +382,9 @@ public int exec(String commandLine, List<String> env, File dir, Writer outputWri
throws IOException {
checkAllowed(commandLine);

if(log.isDebugEnabled())
log.debug(EXECUTING_COMMAND, commandLine);

int exit = 0;

final Process process = Runtime.getRuntime().exec(commandLine.split(" "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.LocaleUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -354,9 +355,9 @@ public static long getFolderSize(File folder) {
*/
public static String getDisplaySize(long size, String language) {
String displaySize = "";
Locale locale = Locale.of("en");
Locale locale = LocaleUtils.toLocale("en");
if (StringUtils.isNotEmpty(language))
locale = Locale.of(language);
locale = LocaleUtils.toLocale(language);
NumberFormat nf = new DecimalFormat("###,###,###.0", new DecimalFormatSymbols(locale));
if (size > 1000000000) {
displaySize = nf.format((double) size / 1024 / 1024 / 1024) + " GB";
Expand All @@ -382,9 +383,9 @@ public static String getDisplaySize(long size, String language) {
*/
public static String getDisplaySizeKB(long size, String language) {
String displaySize = "";
Locale locale = Locale.of("en");
Locale locale = LocaleUtils.toLocale("en");
if (StringUtils.isNotEmpty(language))
locale = Locale.of(language);
locale = LocaleUtils.toLocale(language);
NumberFormat nf = new DecimalFormat("###,###,##0.0", new DecimalFormatSymbols(locale));
displaySize = nf.format((double) size / 1024) + " KB";
return displaySize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ public void uninstallPlugin(String pluginId) throws ServerException {
Runtime.getRuntime().exec(
new String[] { "cmd.exe", "/c", "del /F /Q \"" + pluginJarFile.getAbsolutePath() + "\"" });
else
new Exec().exec(List.of("rm", "-rf", pluginJarFile.getAbsolutePath()), null, null, -1);
Runtime.getRuntime().exec(new String[] { "rm", "-rf", pluginJarFile.getAbsolutePath() });
}
} catch (IOException e) {
throwServerException(session, log, e);
Expand Down
10 changes: 5 additions & 5 deletions logicaldoc-webapp/src/main/resources/log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>
<RollingFile name="Audit_WEB" fileName="${root}/audit_web.log.html" filePattern="${root}/audit_web.log.html.%i">
<RollingFile name="AuditTask_WEB" fileName="${root}/audit_web.log.html" filePattern="${root}/audit_web.log.html.%i">
<LDHtmlLayout datePattern="${dateformat}" fontSize="${fontsize}" />
<Policies>
<SizeBasedTriggeringPolicy size="5 MB" />
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>
<RollingFile name="Audit" fileName="${root}/audit.log" filePattern="${root}/audit.log.%i">
<RollingFile name="AuditTask" fileName="${root}/audit.log" filePattern="${root}/audit.log.%i">
<PatternLayout>
<Pattern>${pattern}</Pattern>
</PatternLayout>
Expand Down Expand Up @@ -607,9 +607,9 @@
<Appender-Ref ref="Notifier" />
<Appender-Ref ref="Notifier_WEB" />
</Logger>
<Logger name="com.logicaldoc.audit.Audit" level="info" additivity="false">
<Appender-Ref ref="Audit" />
<Appender-Ref ref="Audit_WEB" />
<Logger name="com.logicaldoc.audit.AuditTask" level="info" additivity="false">
<Appender-Ref ref="AuditTask" />
<Appender-Ref ref="AuditTask_WEB" />
</Logger>
<Logger name="com.logicaldoc.impex.ArchiveBuilder" level="info" additivity="false">
<Appender-Ref ref="ArchiveBuilder" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,11 @@ public void testGetVersionsById() throws ServerException {
@Test
public void testDeleteVersions() throws ServerException {
List<Long> ids = List.of(21L, 22L, 23L);
GUIDocument gdoc;s
GUIDocument gdoc;
try {
service.deleteVersions(ids);
fail("No exception here");
} catch (AssertionError | ServerException e) {
} catch (ServerException e) {
// All ok
}

Expand Down Expand Up @@ -1354,7 +1354,7 @@ public void testSaveEmailAttachment() {
}

@Test
public void testGetEnabledPermissions() throws ParseException, PersistenceException, ServerException {
public void testGetEnabledPermissions() throws PersistenceException, ServerException {
GUIAccessControlEntry permissions = service.getAllowedPermissions(List.of(2L, 3L, 4L));
for (Permission permission : Permission.all())
assertTrue("Does not allow " + permission.name(),
Expand Down

0 comments on commit 5f8c868

Please sign in to comment.