001/*
002 * (C) Copyright 2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger
018 */
019
020package org.nuxeo.wopi;
021
022import java.io.IOException;
023import java.util.List;
024
025import org.nuxeo.ecm.core.api.NuxeoException;
026
027import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
028import com.fasterxml.jackson.dataformat.xml.XmlMapper;
029import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
030import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
031
032/**
033 * Class used to parse a WOPI discovery XML file.
034 *
035 * @since 10.3
036 */
037@JsonIgnoreProperties(ignoreUnknown = true)
038public class WOPIDiscovery {
039
040    @JacksonXmlProperty(localName = "net-zone")
041    private NetZone netZone;
042
043    @JacksonXmlProperty(localName = "proof-key")
044    private ProofKey proofKey;
045
046    public NetZone getNetZone() {
047        return netZone;
048    }
049
050    public void setNetZone(NetZone netZone) {
051        this.netZone = netZone;
052    }
053
054    public ProofKey getProofKey() {
055        return proofKey;
056    }
057
058    public void setProofKey(ProofKey proofKey) {
059        this.proofKey = proofKey;
060    }
061
062    protected static final XmlMapper XML_MAPPER = new XmlMapper();
063
064    public static WOPIDiscovery read(byte[] discoveryBytes) {
065        try {
066            return XML_MAPPER.readValue(discoveryBytes, WOPIDiscovery.class);
067        } catch (IOException e) {
068            throw new NuxeoException(e);
069        }
070    }
071
072    @JsonIgnoreProperties(ignoreUnknown = true)
073    public static class NetZone {
074
075        @JacksonXmlProperty(localName = "app")
076        @JacksonXmlElementWrapper(useWrapping = false)
077        private List<App> apps;
078
079        public List<App> getApps() {
080            return apps;
081        }
082
083        public void setApps(List<App> apps) {
084            this.apps = apps;
085        }
086    }
087
088    @JsonIgnoreProperties(ignoreUnknown = true)
089    public static class ProofKey {
090
091        private String exponent;
092
093        private String modulus;
094
095        @JacksonXmlProperty(localName = "oldexponent")
096        private String oldExponent;
097
098        @JacksonXmlProperty(localName = "oldmodulus")
099        private String oldModulus;
100
101        public String getExponent() {
102            return exponent;
103        }
104
105        public void setExponent(String exponent) {
106            this.exponent = exponent;
107        }
108
109        public String getModulus() {
110            return modulus;
111        }
112
113        public void setModulus(String modulus) {
114            this.modulus = modulus;
115        }
116
117        public String getOldExponent() {
118            return oldExponent;
119        }
120
121        public void setOldExponent(String oldExponent) {
122            this.oldExponent = oldExponent;
123        }
124
125        public String getOldModulus() {
126            return oldModulus;
127        }
128
129        public void setOldModulus(String oldModulus) {
130            this.oldModulus = oldModulus;
131        }
132    }
133
134    @JsonIgnoreProperties(ignoreUnknown = true)
135    public static class App {
136
137        private String name;
138
139        @JacksonXmlProperty(localName = "action")
140        @JacksonXmlElementWrapper(useWrapping = false)
141        private List<Action> actions;
142
143        public String getName() {
144            return name;
145        }
146
147        public void setName(String name) {
148            this.name = name;
149        }
150
151        public List<Action> getActions() {
152            return actions;
153        }
154
155        public void setActions(List<Action> actions) {
156            this.actions = actions;
157        }
158    }
159
160    @JsonIgnoreProperties(ignoreUnknown = true)
161    public static class Action {
162        private String name;
163
164        private String ext;
165
166        @JacksonXmlProperty(localName = "urlsrc")
167        private String url;
168
169        public String getName() {
170            return name;
171        }
172
173        public void setName(String name) {
174            this.name = name;
175        }
176
177        public String getExt() {
178            return ext;
179        }
180
181        public void setExt(String ext) {
182            this.ext = ext;
183        }
184
185        public String getUrl() {
186            return url;
187        }
188
189        public void setUrl(String url) {
190            this.url = url;
191        }
192
193    }
194}