// Path: src/main/java/com/xebialabs/overcast/support/libvirt/Filesystem.java
// public class Filesystem {
//     public enum AccessMode {
//         /** The source is accessed with the permissions of the user inside the guest. This is the default. */
//         PASSTHROUGH,
//         /** The source is accessed with the permissions of the hypervisor (QEMU process). */
//         MAPPED,
//         /**
//          * Similar to {@link AccessMode#PASSTHROUGH}, the exception is that failure of privileged operations like
//          * 'chown' are ignored. This makes a passthrough-like mode usable for people who run the hypervisor as non-root.
//          */
//         SQUASH,
//     }
// 
//     public String source;
//     public String target;
//     public AccessMode accessMode;
//     public boolean readOnly;
// 
//     public Filesystem(String source, String target, AccessMode accessMode, boolean readOnly) {
//         checkNotNullOrEmpty(source);
//         checkNotNullOrEmpty(target);
// 
//         this.source = source;
//         this.target = target;
//         this.accessMode = accessMode;
//         this.readOnly = readOnly;
//     }
// 
//     @Override
//     public String toString() {
//         return "Filesystem{" +
//                 "source='" + source + '\'' +
//                 ", target='" + target + '\'' +
//                 ", accessMode=" + accessMode +
//                 ", readOnly=" + readOnly +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/xebialabs/overcast/support/libvirt/Filesystem.java
// public enum AccessMode {
//     /** The source is accessed with the permissions of the user inside the guest. This is the default. */
//     PASSTHROUGH,
//     /** The source is accessed with the permissions of the hypervisor (QEMU process). */
//     MAPPED,
//     /**
//      * Similar to {@link AccessMode#PASSTHROUGH}, the exception is that failure of privileged operations like
//      * 'chown' are ignored. This makes a passthrough-like mode usable for people who run the hypervisor as non-root.
//      */
//     SQUASH,
// }


import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import com.xebialabs.overcast.support.libvirt.Filesystem;
import com.xebialabs.overcast.support.libvirt.Filesystem.AccessMode;
/**
 *    Copyright 2012-2021 Digital.ai
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.xebialabs.overcast.support.libvirt.jdom;




public final class FilesystemXml {
    private static final String XPATH_FILESYSTEM = "/domain/devices/filesystem[@type='mount']";

    private FilesystemXml() {
    }

    public static Element toFileSystemXml(Filesystem fs) {
        Element filesystem = new Element("filesystem")
            .setAttribute("type", "mount")
            .setAttribute("accessmode", fs.accessMode.name().toLowerCase());

        filesystem.addContent(new Element("source").setAttribute("dir", fs.source));
        filesystem.addContent(new Element("target").setAttribute("dir", fs.target));
        if (fs.readOnly) {
// Path: src/main/java/com/xebialabs/overcast/support/libvirt/Filesystem.java
// public class Filesystem {
//     public enum AccessMode {
//         /** The source is accessed with the permissions of the user inside the guest. This is the default. */
//         PASSTHROUGH,
//         /** The source is accessed with the permissions of the hypervisor (QEMU process). */
//         MAPPED,
//         /**
//          * Similar to {@link AccessMode#PASSTHROUGH}, the exception is that failure of privileged operations like
//          * 'chown' are ignored. This makes a passthrough-like mode usable for people who run the hypervisor as non-root.
//          */
//         SQUASH,
//     }
// 
//     public String source;
//     public String target;
//     public AccessMode accessMode;
//     public boolean readOnly;
// 
//     public Filesystem(String source, String target, AccessMode accessMode, boolean readOnly) {
//         checkNotNullOrEmpty(source);
//         checkNotNullOrEmpty(target);
// 
//         this.source = source;
//         this.target = target;
//         this.accessMode = accessMode;
//         this.readOnly = readOnly;
//     }
// 
//     @Override
//     public String toString() {
//         return "Filesystem{" +
//                 "source='" + source + '\'' +
//                 ", target='" + target + '\'' +
//                 ", accessMode=" + accessMode +
//                 ", readOnly=" + readOnly +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/xebialabs/overcast/support/libvirt/Filesystem.java
// public enum AccessMode {
//     /** The source is accessed with the permissions of the user inside the guest. This is the default. */
//     PASSTHROUGH,
//     /** The source is accessed with the permissions of the hypervisor (QEMU process). */
//     MAPPED,
//     /**
//      * Similar to {@link AccessMode#PASSTHROUGH}, the exception is that failure of privileged operations like
//      * 'chown' are ignored. This makes a passthrough-like mode usable for people who run the hypervisor as non-root.
//      */
//     SQUASH,
// }


// Path: src/main/java/com/xebialabs/overcast/support/libvirt/jdom/FilesystemXml.java
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import com.xebialabs.overcast.support.libvirt.Filesystem;
import com.xebialabs.overcast.support.libvirt.Filesystem.AccessMode;

/**
 *    Copyright 2012-2021 Digital.ai
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.xebialabs.overcast.support.libvirt.jdom;




public final class FilesystemXml {
    private static final String XPATH_FILESYSTEM = "/domain/devices/filesystem[@type='mount']";

    private FilesystemXml() {
    }

    public static Element toFileSystemXml(Filesystem fs) {
        Element filesystem = new Element("filesystem")
            .setAttribute("type", "mount")
            .setAttribute("accessmode", fs.accessMode.name().toLowerCase());

        filesystem.addContent(new Element("source").setAttribute("dir", fs.source));
        filesystem.addContent(new Element("target").setAttribute("dir", fs.target));
        if (fs.readOnly) {
            filesystem.addContent(new Element("readonly"));