Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Dec 12, 2024
1 parent 0a80880 commit ee5f20c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<exec executable="mvn">
<arg value="package"/>
</exec>
<copy file="module-main/target/plugin_intranda_administration_${name}.jar" todir="/opt/digiverso/goobi/plugins/administration/" overwrite="true"/>
<copy file="module-gui/target/plugin_intranda_administration_${name}-GUI.jar" todir="/opt/digiverso/goobi/plugins/GUI/" overwrite="true"/>
<copy file="module-base/target/plugin-administration-ruleset-editor-base.jar" todir="/opt/digiverso/goobi/plugins/administration/" overwrite="true"/>
<copy file="module-gui/target/plugin-administration-ruleset-editor-gui.jar" todir="/opt/digiverso/goobi/plugins/GUI/" overwrite="true"/>
</target>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
import de.sub.goobi.persistence.managers.RulesetManager;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import net.xeoh.plugins.base.annotations.PluginImplementation;

@Log4j2
@PluginImplementation
public class RulesetEditorAdministrationPlugin implements IAdministrationPlugin {

private static final long serialVersionUID = 2758642874624084899L;

@Getter
private String title = "intranda_administration_ruleset_editor";

Expand Down Expand Up @@ -82,19 +82,14 @@ public class RulesetEditorAdministrationPlugin implements IAdministrationPlugin
@Setter
private String currentRulesetFileContent = null;

/**
* null means that no config file is selected
*/
private String currentRulesetFileContentBase64 = null;

@Getter
private List<String> rulesetDates;

@Getter
private boolean validationError;

@Getter
private List<XMLError> validationErrors;
private transient List<XMLError> validationErrors;

@Getter
private boolean showMore = false;
Expand Down Expand Up @@ -135,7 +130,6 @@ private void initRulesetDates() {
for (int index = 0; index < this.rulesets.size(); index++) {
try {
String pathName = RulesetFileUtils.getRulesetDirectory() + this.rulesets.get(index).getDatei();
//System.out.println(pathName);
long lastModified = storageProvider.getLastModifiedDate(Paths.get(pathName));
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
this.rulesetDates.add(formatter.format(lastModified));
Expand Down Expand Up @@ -224,7 +218,7 @@ public void editRuleset(Ruleset ruleset) {
return;
}
this.setRuleset(index);
if (!this.writable.get(index)) {
if (!this.writable.get(index).booleanValue()) {
String key = "plugin_administration_ruleset_editor_ruleset_not_writable_check_permissions";
Helper.setMeldung("rulesetEditor", Helper.getTranslation(key), "");
}
Expand All @@ -244,7 +238,7 @@ public int findRulesetIndex(Ruleset ruleset) {
return -1;
}

public void save() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
public void save() throws ParserConfigurationException, SAXException, IOException {
if (!checkXML()) {
return;
}
Expand All @@ -253,8 +247,7 @@ public void save() throws ParserConfigurationException, SAXException, IOExceptio
RulesetFileUtils.createBackup(this.currentRuleset.getDatei());
RulesetFileUtils.writeFile(this.getCurrentRulesetFileName(), this.currentRulesetFileContent);
}
// Uncomment this when the file should be closed after saving
// this.setRuleset(-1);

// Switch to an other file (rulesetIndexAfterSaveOrIgnore) when "Save" was clicked
// because the file should be changed and an other file is already selected
if (this.rulesetIndexAfterSaveOrIgnore != -1) {
Expand Down Expand Up @@ -301,7 +294,7 @@ private void setRuleset(int index) {
}
}

private boolean checkXML() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
private boolean checkXML() throws ParserConfigurationException, SAXException, IOException {
boolean ok = true;

List<XMLError> errors = new ArrayList<>();
Expand All @@ -327,7 +320,7 @@ private boolean checkXML() throws ParserConfigurationException, SAXException, IO
return ok;
}

private List<XMLError> checkXMLWellformed(String xml) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
private List<XMLError> checkXMLWellformed(String xml) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
Expand All @@ -337,9 +330,7 @@ private List<XMLError> checkXMLWellformed(String xml) throws ParserConfiguration
builder.setErrorHandler(eh);

try (ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
Document document = builder.parse(bais);
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xpath = xPathFactory.newXPath();
builder.parse(bais);
} catch (SAXParseException e) {
//ignore this, because we collect the errors in the errorhandler and give them to the user.
}
Expand Down Expand Up @@ -439,8 +430,7 @@ private void checkRulesetXsd(String xml) {
StreamSource source = new StreamSource(new StringReader(xml));
validator.validate(source);
} catch (Exception e) {
if (e instanceof SAXParseException) {
SAXParseException se = (SAXParseException) e;
if (e instanceof SAXParseException se) {
validationErrors.add(new XMLError(se.getLineNumber(), 0, "ERROR", e.getMessage()));
} else {
validationErrors.add(new XMLError(0, 0, "ERROR", e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public abstract class RulesetFileUtils {

private static Charset standardCharset;

private RulesetFileUtils() {
// hide public default constructor
}

public static void init(XMLConfiguration configuration) {
RulesetFileUtils.rulesetDirectory = ConfigurationHelper.getInstance().getRulesetFolder();
RulesetFileUtils.backupDirectory = configuration.getString("rulesetBackupDirectory", "/opt/digiverso/goobi/rulesets/backup/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ReportErrorsErrorHandler implements ErrorHandler {
private List<XMLError> errors;

public ReportErrorsErrorHandler() {
errors = new ArrayList<XMLError>();
errors = new ArrayList<>();
}

private void addError(SAXParseException e, String severity) {
Expand Down

0 comments on commit ee5f20c

Please sign in to comment.