Skip to content

Commit

Permalink
Remove XML tagging from org.dogtagpki.common
Browse files Browse the repository at this point in the history
  • Loading branch information
ckelleyRH committed Jun 29, 2021
1 parent 85d4d23 commit f307b2f
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 198 deletions.
26 changes: 0 additions & 26 deletions base/common/src/main/java/org/dogtagpki/common/CAInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

package org.dogtagpki.common;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -36,7 +27,6 @@
/**
* @author Ade Lee
*/
@XmlRootElement(name="CAInfo")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class CAInfo extends ResourceMessage {
Expand All @@ -48,7 +38,6 @@ public class CAInfo extends ResourceMessage {
String encryptAlgorithm;
String keyWrapAlgorithm;

@XmlElement(name="ArchivalMechanism")
public String getArchivalMechanism() {
return archivalMechanism;
}
Expand All @@ -57,7 +46,6 @@ public void setArchivalMechanism(String archivalMechanism) {
this.archivalMechanism = archivalMechanism;
}

@XmlElement(name="EncryptAlgorithm")
public String getEncryptAlgorithm() {
return encryptAlgorithm;
}
Expand All @@ -66,7 +54,6 @@ public void setEncryptAlgorithm(String encryptAlgorithm) {
this.encryptAlgorithm = encryptAlgorithm;
}

@XmlElement(name="WrapAlgorithm")
public String getKeyWrapAlgorithm() {
return keyWrapAlgorithm;
}
Expand Down Expand Up @@ -112,19 +99,6 @@ public boolean equals(Object obj) {
return true;
}

public String toXML() throws Exception {
Marshaller marshaller = JAXBContext.newInstance(CAInfo.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
marshaller.marshal(this, sw);
return sw.toString();
}

public static CAInfo fromXML(String string) throws Exception {
Unmarshaller unmarshaller = JAXBContext.newInstance(CAInfo.class).createUnmarshaller();
return (CAInfo)unmarshaller.unmarshal(new StringReader(string));
}

public String toJSON() throws Exception {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
Expand Down
61 changes: 0 additions & 61 deletions base/common/src/main/java/org/dogtagpki/common/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@

package org.dogtagpki.common;

import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -47,8 +32,6 @@
/**
* @author Endi S. Dewata
*/
@XmlRootElement(name="Configuration")
@XmlAccessorType(XmlAccessType.NONE)
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class ConfigData {
Expand All @@ -58,7 +41,6 @@ public class ConfigData {

Link link;

@XmlElement(name="Status")
public String getStatus() {
return status;
}
Expand All @@ -67,8 +49,6 @@ public void setStatus(String status) {
this.status = status;
}

@XmlElement(name="Properties")
@XmlJavaTypeAdapter(MapAdapter.class)
public Map<String, String> getProperties() {
return properties;
}
Expand All @@ -77,45 +57,17 @@ public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

public static class MapAdapter extends XmlAdapter<PropertyList, Map<String, String>> {

@Override
public PropertyList marshal(Map<String, String> map) {
PropertyList list = new PropertyList();
for (Map.Entry<String, String> entry : map.entrySet()) {
Property property = new Property();
property.name = entry.getKey();
property.value = entry.getValue();
list.properties.add(property);
}
return list;
}

@Override
public Map<String, String> unmarshal(PropertyList list) {
Map<String, String> map = new LinkedHashMap<>();
for (Property property : list.properties) {
map.put(property.name, property.value);
}
return map;
}
}

public static class PropertyList {
@XmlElement(name="Property")
public List<Property> properties = new ArrayList<>();
}

public static class Property {

@XmlAttribute
public String name;

@XmlValue
public String value;
}

@XmlElement(name="Link")
public Link getLink() {
return link;
}
Expand Down Expand Up @@ -161,19 +113,6 @@ public boolean equals(Object obj) {
return true;
}

public String toXML() throws Exception {
Marshaller marshaller = JAXBContext.newInstance(ConfigData.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
marshaller.marshal(this, sw);
return sw.toString();
}

public static ConfigData fromXML(String string) throws Exception {
Unmarshaller unmarshaller = JAXBContext.newInstance(ConfigData.class).createUnmarshaller();
return (ConfigData)unmarshaller.unmarshal(new StringReader(string));
}

public String toJSON() throws Exception {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
Expand Down
26 changes: 0 additions & 26 deletions base/common/src/main/java/org/dogtagpki/common/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

package org.dogtagpki.common;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +30,6 @@
/**
* @author Endi S. Dewata
*/
@XmlRootElement(name="Info")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class Info extends ResourceMessage {
Expand All @@ -50,7 +40,6 @@ public class Info extends ResourceMessage {
String version;
String banner;

@XmlElement(name="Name")
public String getName() {
return name;
}
Expand All @@ -59,7 +48,6 @@ public void setName(String name) {
this.name = name;
}

@XmlElement(name="Version")
public String getVersion() {
return version;
}
Expand All @@ -68,7 +56,6 @@ public void setVersion(String version) {
this.version = version;
}

@XmlElement(name="Banner")
public String getBanner() {
return banner;
}
Expand Down Expand Up @@ -124,17 +111,4 @@ public static Info fromJSON(String json) throws Exception {
return mapper.readValue(json, Info.class);
}

public String toXML() throws Exception {
StringWriter sw = new StringWriter();
Marshaller marshaller = JAXBContext.newInstance(Info.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(this, sw);
return sw.toString();
}

public static Info fromXML(String string) throws Exception {
Unmarshaller unmarshaller = JAXBContext.newInstance(Info.class).createUnmarshaller();
return (Info)unmarshaller.unmarshal(new StringReader(string));
}

}
27 changes: 0 additions & 27 deletions base/common/src/main/java/org/dogtagpki/common/KRAInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

package org.dogtagpki.common;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -36,7 +27,6 @@
/**
* @author Ade Lee
*/
@XmlRootElement(name="KRAInfo")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class KRAInfo extends ResourceMessage {
Expand All @@ -46,7 +36,6 @@ public class KRAInfo extends ResourceMessage {
String encryptAlgorithm;
String wrapAlgorithm;

@XmlElement(name="ArchivalMechanism")
public String getArchivalMechanism() {
return archivalMechanism;
}
Expand All @@ -55,7 +44,6 @@ public void setArchivalMechanism(String archivalMechanism) {
this.archivalMechanism = archivalMechanism;
}

@XmlElement(name="RecoveryMechanism")
public String getRecoveryMechanism() {
return recoveryMechanism;
}
Expand All @@ -64,7 +52,6 @@ public void setRecoveryMechanism(String recoveryMechanism) {
this.recoveryMechanism = recoveryMechanism;
}

@XmlElement(name="EncryptAlgorithm")
public String getEncryptAlgorithm() {
return encryptAlgorithm;
}
Expand All @@ -73,7 +60,6 @@ public void setEncryptAlgorithm(String encryptAlgorithm) {
this.encryptAlgorithm = encryptAlgorithm;
}

@XmlElement(name="WrapAlgorithm")
public String getWrapAlgorithm() {
return wrapAlgorithm;
}
Expand Down Expand Up @@ -135,18 +121,5 @@ public static KRAInfo fromJSON(String json) throws Exception {
return mapper.readValue(json, KRAInfo.class);
}

public String toXML() throws Exception {
StringWriter sw = new StringWriter();
Marshaller marshaller = JAXBContext.newInstance(KRAInfo.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(this, sw);
return sw.toString();
}

public static KRAInfo fromXML(String string) throws Exception {
Unmarshaller unmarshaller = JAXBContext.newInstance(KRAInfo.class).createUnmarshaller();
return (KRAInfo)unmarshaller.unmarshal(new StringReader(string));
}

}

13 changes: 0 additions & 13 deletions base/common/src/test/java/org/dogtagpki/common/CAInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ public void setUpBefore() {
before.setKeyWrapAlgorithm(CAInfo.KEYWRAP_MECHANISM);
}

@Test
public void testXML() throws Exception {
// Act
String xml = before.toXML();
System.out.println("XML (before): " + xml);

CAInfo afterXML = CAInfo.fromXML(xml);
System.out.println("XML (after): " + afterXML.toXML());

// Assert
Assert.assertEquals(before, afterXML);
}

@Test
public void testJSON() throws Exception {
// Act
Expand Down
13 changes: 0 additions & 13 deletions base/common/src/test/java/org/dogtagpki/common/ConfigDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ public void setUpBefore() throws URISyntaxException {
before.setStatus("ENABLED");
}

@Test
public void testXML() throws Exception {
// Act
String xml = before.toXML();
System.out.println("XML (before): " + xml);

ConfigData afterXML = ConfigData.fromXML(xml);
System.out.println("XML (after): " + afterXML.toXML());

// Assert
Assert.assertEquals(before, afterXML);
}

@Test
public void testJSON() throws Exception {
// Act
Expand Down
13 changes: 0 additions & 13 deletions base/common/src/test/java/org/dogtagpki/common/InfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ public void setUpBefore() {
"specific permissions.");
}

@Test
public void testXML() throws Exception {
// Act
String xml = before.toXML();
System.out.println("XML (before): " + xml);

Info afterXML = Info.fromXML(xml);
System.out.println("XML (after): " + afterXML.toXML());

// Assert
Assert.assertEquals(before, afterXML);
}

@Test
public void testJSON() throws Exception {
// Act
Expand Down
Loading

0 comments on commit f307b2f

Please sign in to comment.