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 authored and edewata committed Jul 8, 2021
1 parent 16e89c9 commit c781ab6
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 232 deletions.
34 changes: 0 additions & 34 deletions base/common/src/main/java/org/dogtagpki/common/Base64Adapter.java

This file was deleted.

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 @@ -35,7 +26,6 @@
/**
* @author Ade Lee
*/
@XmlRootElement(name="CAInfo")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class CAInfo extends ResourceMessage {
Expand All @@ -47,7 +37,6 @@ public class CAInfo extends ResourceMessage {
String encryptAlgorithm;
String keyWrapAlgorithm;

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

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

@XmlElement(name="WrapAlgorithm")
public String getKeyWrapAlgorithm() {
return keyWrapAlgorithm;
}
Expand Down Expand Up @@ -111,18 +98,5 @@ 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));
}

}

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 implements JSONSerializer {
Expand All @@ -58,7 +41,6 @@ public class ConfigData implements JSONSerializer {

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,17 +113,4 @@ 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));
}

}
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 @@ -38,7 +29,6 @@
/**
* @author Endi S. Dewata
*/
@XmlRootElement(name="Info")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class Info extends ResourceMessage {
Expand All @@ -49,7 +39,6 @@ public class Info extends ResourceMessage {
String version;
String banner;

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

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

@XmlElement(name="Banner")
public String getBanner() {
return banner;
}
Expand Down Expand Up @@ -113,17 +100,4 @@ public boolean equals(Object obj) {
return true;
}

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 @@ -35,7 +26,6 @@
/**
* @author Ade Lee
*/
@XmlRootElement(name="KRAInfo")
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
public class KRAInfo extends ResourceMessage {
Expand All @@ -45,7 +35,6 @@ public class KRAInfo extends ResourceMessage {
String encryptAlgorithm;
String wrapAlgorithm;

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

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

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

@XmlElement(name="WrapAlgorithm")
public String getWrapAlgorithm() {
return wrapAlgorithm;
}
Expand Down Expand Up @@ -124,18 +110,5 @@ public boolean equals(Object obj) {
return true;
}

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 @@ -18,19 +18,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 @@ -27,19 +27,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
Loading

0 comments on commit c781ab6

Please sign in to comment.