Skip to content

Commit

Permalink
Fix Sonar smells for XML module
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan authored and garyrussell committed May 31, 2019
1 parent 7e0a5e9 commit 0c32a57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Expand Up @@ -71,12 +71,7 @@ else if (object instanceof Node) {
}
else if (object instanceof DOMSource) {
Node node = ((DOMSource) object).getNode();
if (node instanceof Document) {
return (Document) node;
}
else {
return nodeToDocument(node);
}
return nodeToDocument(node);
}
else if (object instanceof Source) {
InputSource inputSource = sourceToInputSource((Source) object);
Expand Down Expand Up @@ -111,6 +106,9 @@ private static InputSource sourceToInputSource(Source source) {
}

protected Document nodeToDocument(Node node) {
if (node instanceof Document) {
return (Document) node;
}
Document document = getDocumentBuilder().newDocument();
document.appendChild(document.importNode(node, true));
return document;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;

import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
Expand All @@ -29,7 +30,6 @@
import org.springframework.integration.transformer.AbstractPayloadTransformer;
import org.springframework.integration.xml.source.DomSourceFactory;
import org.springframework.integration.xml.source.SourceFactory;
import org.springframework.messaging.MessagingException;
import org.springframework.oxm.Unmarshaller;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
Expand Down Expand Up @@ -96,8 +96,7 @@ public String getComponentType() {

@Override
public Object transformPayload(Object payload) {
Source source = null;

Source source;
try {
if (this.mimeMessageUnmarshallerHelper != null) {
Object result = this.mimeMessageUnmarshallerHelper.maybeUnmarshalMimeMessage(payload);
Expand Down Expand Up @@ -127,15 +126,14 @@ else if (payload instanceof Source) {
else {
source = this.sourceFactory.createSource(payload);
}
if (source == null) {
throw new MessagingException(
"failed to transform message, payload not assignable from " + Source.class.getName()
+ "and no conversion possible");
}
Assert.state(source != null, () ->
"failed to transform message, payload not assignable from " + Source.class.getName()
+ "and no conversion possible");

return this.unmarshaller.unmarshal(source);
}
catch (IOException e) {
throw new MessagingException("failed to unmarshal payload", e);
throw new UncheckedIOException("failed to unmarshal payload", e);
}
}

Expand Down
Expand Up @@ -156,9 +156,9 @@ public XsltPayloadTransformer(Resource xslResource, ResultTransformer resultTran
String transformerFactoryClassName) {

Assert.notNull(xslResource, "'xslResource' must not be null.");
Assert.isTrue(xslResource instanceof ClassPathResource || // NOSONAR boolean complexity
Assert.isTrue(xslResource instanceof ClassPathResource ||
xslResource instanceof FileSystemResource ||
xslResource instanceof VfsResource ||
xslResource instanceof VfsResource || // NOSONAR boolean complexity
(SERVLET_CONTEXT_RESOURCE_CLASS != null
&& SERVLET_CONTEXT_RESOURCE_CLASS.isInstance(xslResource)),
"Only 'ClassPathResource', 'FileSystemResource', 'ServletContextResource' or 'VfsResource'" +
Expand Down

0 comments on commit 0c32a57

Please sign in to comment.