I am trying to use this code to recreate similar application in .Net environment, but I am little unclear of the logic. Hence I would like to seek some assistance, in explaining, what is going on in the code below:
There is a contentCreator class, which creates a issue & I am little unsure, what its doing here
return api.create(publication.findLink("issue"), Utils.renderXml(document));
:
public static ApiObject createIssue(NotessaApi api, ApiObject publication, Issue issue) throws IOException {
Document document = Utils.createEmptyDocument();
Node node = Utils.createNode(document, "issue");
Utils.addXml(document, node, "title", issue.getTitle());
Utils.addXml(document, node, "approval_status", issue.getApprovalStatus());
Utils.addXml(document, node, "display_title", issue.getDisplayTitle());
Utils.addXml(document, node, "display_date", issue.getDisplayDate());
List<Property> properties = issue.getProperties();
if(!properties.isEmpty()) {
Node container = Utils.createNode(document, node, "properties");
for(Property property : properties) {
Element element = Utils.createNode(document, container, "property");
element.setAttribute("name", property.getName());
Utils.addXml(document, element, "value", property.getValue());
}
}
return api.create(publication.findLink("issue"), Utils.renderXml(document));
}
Is it creating the issue xml and forwarding it to the findlink url from the API Object class.
API Object class creates the following two methods:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
public URL findLink(String rel) {
String result = xpath("//link[contains(@rel,'" + rel + "')]/@href");
try {
return new URL(result);
} catch(MalformedURLException e) {
throw new RuntimeException(e);
}
}
public URL getSelfLink() throws MalformedURLException {
String uri = xpath("//@uri");
return new URL(uri);
}
Any further advice, would be most appreciated. Many thanks.