-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
75 changed files
with
1,457 additions
and
1,861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, | ||
* (C) 2020 MinIO, Inc. | ||
* | ||
* 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 io.minio; | ||
|
||
import io.minio.errors.XmlParserException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.io.StringWriter; | ||
import org.simpleframework.xml.convert.AnnotationStrategy; | ||
import org.simpleframework.xml.core.Persister; | ||
import org.simpleframework.xml.Serializer; | ||
|
||
|
||
public class Xml { | ||
/** | ||
* This marshal method will traverse the provided object checking for field annotations in order | ||
* to compose the XML data. | ||
*/ | ||
public static String marshal(Object source) throws XmlParserException { | ||
try { | ||
Serializer serializer = new Persister(new AnnotationStrategy()); | ||
StringWriter writer = new StringWriter(); | ||
serializer.write(source, writer); | ||
return writer.toString(); | ||
} catch (Exception e) { | ||
throw new XmlParserException(e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This unmarshal method will read the contents of the XML document from the provided source and | ||
* populate the object with the values deserialized. | ||
*/ | ||
public static <T> T unmarshal(Class<? extends T> type, Reader source) throws XmlParserException { | ||
try { | ||
Serializer serializer = new Persister(new AnnotationStrategy()); | ||
return serializer.read(type, source); | ||
} catch (Exception e) { | ||
throw new XmlParserException(e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This unmarshal method will read the contents of the XML document from the provided source and | ||
* populate the object with the values deserialized. | ||
*/ | ||
public static <T> T unmarshal(Class<? extends T> type, String source) throws XmlParserException { | ||
try { | ||
Serializer serializer = new Persister(new AnnotationStrategy()); | ||
return serializer.read(type, new StringReader(source)); | ||
} catch (Exception e) { | ||
throw new XmlParserException(e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This validate method will validate the contents of the XML document against the specified XML | ||
* class schema. | ||
*/ | ||
public static boolean validate(Class type, String source) throws XmlParserException { | ||
try { | ||
Serializer serializer = new Persister(new AnnotationStrategy()); | ||
return serializer.validate(type, source); | ||
} catch (Exception e) { | ||
throw new XmlParserException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. | ||
* | ||
* 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 io.minio.errors; | ||
|
||
|
||
public class XmlParserException extends MinioException { | ||
Exception exception; | ||
|
||
|
||
public XmlParserException(Exception exception) { | ||
super(); | ||
this.exception = exception; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return exception.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.