Skip to content

Commit

Permalink
Make XmlEditorBean.fileName attribute relative to workspace root
Browse files Browse the repository at this point in the history
  • Loading branch information
copierrj committed Dec 1, 2023
1 parent 3088ebf commit e91b851
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.xerces.xni.parser.XMLParseException;
import org.deegree.commons.config.DeegreeWorkspace;
import org.deegree.commons.xml.schema.SchemaValidationEvent;
import org.deegree.commons.xml.schema.SchemaValidator;
import org.deegree.services.controller.OGCFrontController;
Expand Down Expand Up @@ -159,6 +160,25 @@ public void setNextView(String nextView) {
this.nextView = nextView;
}

private File getFile() {
File workspaceRoot = new File(DeegreeWorkspace.getWorkspaceRoot());

String separator = "";
StringBuilder sb = new StringBuilder();
for (String filePart : fileName.split("[/\\\\]+")) {
if ("..".equals(filePart)) {
continue;
}

sb.append(separator);
sb.append(filePart);

separator = File.separator;
}

return new File(workspaceRoot, sb.toString());
}

public String getContent() throws IOException, ClassNotFoundException {
LOG.trace("Editing file: " + getFileName() + " with ID + " + getId());
LOG.trace("Using schema: " + getSchemaUrl());
Expand All @@ -168,7 +188,7 @@ public String getContent() throws IOException, ClassNotFoundException {
if (content == null) {
LOG.trace("No content set for " + this.toString());
if (resourceProviderClass == null) {
File file = new File(fileName);
File file = getFile();
if (fileName != null && file.exists()) {
LOG.trace("Loading content from file: " + file.getAbsolutePath());
content = FileUtils.readFileToString(file);
Expand Down Expand Up @@ -257,7 +277,7 @@ private ResourceManager<?> lookupResourceManager(Workspace workspace, Class<?> c
private void activate() {
try {
if (resourceProviderClass == null) {
FileUtils.write(new File(fileName), content);
FileUtils.write(getFile(), content);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@
----------------------------------------------------------------------------*/
package org.deegree.console.proxy;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.deegree.commons.config.DeegreeWorkspace;
import org.deegree.commons.proxy.ProxySettings;

/**
Expand All @@ -47,12 +42,7 @@
public class ProxyBean {

public ProxyConfig getProxyConfig() throws IOException {
Path workspaceDir = Paths.get(DeegreeWorkspace.getWorkspaceRoot());
File proxyFile = new File(workspaceDir.toFile(), "proxy.xml");
if (!proxyFile.exists()) {
proxyFile.createNewFile();
}
return new ProxyConfig(proxyFile.getAbsolutePath());
return new ProxyConfig();
}

public String getNonftpProxyHosts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,16 @@ public class ProxyConfig extends Config {

private static final URL PROXY_EXAMPLE_URL = ProxyConfig.class.getResource("/META-INF/schemas/proxy/example.xml");

private String file;

public ProxyConfig(String file) {
public ProxyConfig() {
super(null, null, "/console/proxy/index", false);
this.file = file;
}

@Override
public String edit() throws IOException {
StringBuilder sb = new StringBuilder("/console/generic/xmleditor?faces-redirect=true");
sb.append("&id=").append(id);
sb.append("&schemaUrl=").append(PROXY_SCHEMA_URL.toString());
sb.append("&fileName=").append(file);
sb.append("&fileName=proxy.xml");
sb.append("&nextView=").append(getResourceOutcome());
sb.append("&emptyTemplate=").append(getTemplate());
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.apache.commons.io.IOUtils;
import org.deegree.console.Config;
import org.deegree.services.controller.OGCFrontController;

/**
* Config implementation for the main.xml.
Expand All @@ -47,23 +48,19 @@ public class MainConfig extends Config implements Serializable {
private static final URL MAIN_SCHEMA_URL = ServicesBean.class
.getResource("/META-INF/schemas/services/controller/controller.xsd");

private String file;

public MainConfig() {
super(null, null, "/console/webservices/index", false);
}

public MainConfig(String file) {
super(null, null, "/console/webservices/index", false);
this.file = file;
}

@Override
public String edit() throws IOException {
String workspaceName = OGCFrontController.getServiceWorkspace().getName();
String fileName = workspaceName + "/services/main.xml";

StringBuilder sb = new StringBuilder("/console/generic/xmleditor?faces-redirect=true");
sb.append("&id=").append(id);
sb.append("&schemaUrl=").append(MAIN_SCHEMA_URL.toString());
sb.append("&fileName=").append(file);
sb.append("&fileName=").append(fileName);
sb.append("&emptyTemplate=").append(getTemplate());
sb.append("&nextView=").append(getResourceOutcome());
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
----------------------------------------------------------------------------*/
package org.deegree.console.webservices;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -39,10 +38,7 @@
import org.deegree.console.AbstractResourceManagerBean;
import org.deegree.console.Config;
import org.deegree.services.OwsManager;
import org.deegree.services.controller.OGCFrontController;
import org.deegree.workspace.ResourceMetadata;
import org.deegree.workspace.Workspace;
import org.deegree.workspace.standard.DefaultWorkspace;

/**
* TODO add class documentation here
Expand All @@ -55,16 +51,11 @@ public class ServicesBean extends AbstractResourceManagerBean<OwsManager> implem

private static final long serialVersionUID = -8669333203479413121L;

private Config mainConfig;
private final Config mainConfig;

public ServicesBean() {
super(OwsManager.class);
Workspace workspace = OGCFrontController.getServiceWorkspace().getNewWorkspace();
if (workspace instanceof DefaultWorkspace) {
File file = new File(((DefaultWorkspace) workspace).getLocation(), "services");
file = new File(file, "main.xml");
mainConfig = new MainConfig(file.getAbsolutePath());
}
mainConfig = new MainConfig();
}

public Config getMainConfig() {
Expand Down

0 comments on commit e91b851

Please sign in to comment.