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
This commit is contained in:
Massimiliano Assante 2013-09-13 13:53:05 +00:00
parent 7e50bec294
commit bfcf92aef9
1 changed files with 26 additions and 2 deletions

View File

@ -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);
}
}
}