From bfcf92aef97e20fbecf62d2b02acb60c9714c8d6 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 13 Sep 2013 13:53:05 +0000 Subject: [PATCH] updated to #2182 AND TESTED OK git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@81423 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../resources/GenericResourceManager.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java index 1b759f0..ca26588 100644 --- a/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java +++ b/src/main/java/org/gcube/resourcemanagement/support/server/managers/resources/GenericResourceManager.java @@ -137,7 +137,7 @@ public class GenericResourceManager extends AbstractResourceManager { resource.profile().description(description.trim()); } if (body != null) { - resource.profile().newBody(body); + appendXmlFragment(resource.profile(), body); } if (subType != null) resource.profile().type(subType.trim()); @@ -186,7 +186,7 @@ public class GenericResourceManager extends AbstractResourceManager { resource.profile().description(description.trim()); } if (body != null) { - resource.profile().newBody(body); + appendXmlFragment(resource.profile(), body); } resource.profile().type(subType.trim()); @@ -217,4 +217,28 @@ public class GenericResourceManager extends AbstractResourceManager { throw new ResourceAccessException("Cannot load the resource " + this.getType(), e); } } + + /** + * append a well formed xml string to the body + * @param parent + * @param fragment + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + public static void appendXmlFragment(Profile profile, String fragment) throws IOException, ParserConfigurationException { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Element elem = profile.newBody(); + Node fragmentNode; + try { + fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement(); + fragmentNode = elem.getOwnerDocument().importNode(fragmentNode, true); + elem.appendChild(fragmentNode); + } catch (SAXException e) { + //in case no xml is entered, just text + System.out.println("to append: " + fragment); + profile.newBody(fragment); + } + + } }