forked from gCubeSystem/rmp-common-library
updated to #2182
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/rmp-common-library@81419 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6251a7bc2d
commit
7e50bec294
|
@ -30,6 +30,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.GenericResource.Profile;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
@ -43,6 +44,7 @@ import org.gcube.resourcemanagement.support.server.utils.ServerConsole;
|
|||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.InputSource;
|
||||
|
@ -135,7 +137,7 @@ public class GenericResourceManager extends AbstractResourceManager {
|
|||
resource.profile().description(description.trim());
|
||||
}
|
||||
if (body != null) {
|
||||
appendXmlFragment(resource.profile().newBody(), body);
|
||||
resource.profile().newBody(body);
|
||||
}
|
||||
if (subType != null)
|
||||
resource.profile().type(subType.trim());
|
||||
|
@ -184,7 +186,7 @@ public class GenericResourceManager extends AbstractResourceManager {
|
|||
resource.profile().description(description.trim());
|
||||
}
|
||||
if (body != null) {
|
||||
appendXmlFragment(resource.profile().newBody(), body);
|
||||
resource.profile().newBody(body);
|
||||
}
|
||||
resource.profile().type(subType.trim());
|
||||
|
||||
|
@ -215,29 +217,4 @@ 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(Node parent, String fragment) throws IOException, ParserConfigurationException {
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = parent.getOwnerDocument();
|
||||
Node fragmentNode;
|
||||
try {
|
||||
fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement();
|
||||
fragmentNode = doc.importNode(fragmentNode, true);
|
||||
parent.appendChild(fragmentNode);
|
||||
} catch (SAXException e) {
|
||||
//in case no xml is entered, just text
|
||||
System.out.println("to append: " + fragment);
|
||||
Text text = doc.createTextNode(fragment);
|
||||
doc.importNode(text, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue