ResourceType resourceType = null;
SourceResolver resolver = null;
try {
org.w3c.dom.Document xml = SourceUtil.readDOM(metaUri, this.manager);
NamespaceHelper helper = new NamespaceHelper(
"http://apache.org/cocoon/lenya/page-envelope/1.0", "", xml);
Element metaElement = helper.getFirstChild(xml.getDocumentElement(), "meta");
Element internalElement = helper.getFirstChild(metaElement, "internal");
Element resourceTypeElement = helper.getFirstChild(internalElement, "resourceType");
String resourceTypeName = DocumentHelper.getSimpleElementText(resourceTypeElement);
Element mimeTypeElement = helper.getFirstChild(internalElement, "mimeType");
String mimeType = DocumentHelper.getSimpleElementText(mimeTypeElement);
selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
resourceType = (ResourceType) selector.select(resourceTypeName);
docManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
Document newDoc;
SiteStructure site = area.getSite();
if (!site.contains(path) || site.getNode(path).getLanguages().length == 0) {
newDoc = docManager.add(area.getPublication().getFactory(), resourceType,
contentUri, area.getPublication(), area.getName(), path, language, "xml",
navigationTitle, visibleInNav);
newDoc.setMimeType(mimeType);
} else {
SiteNode node = site.getNode(path);
Document doc = node.getLink(node.getLanguages()[0]).getDocument();
newDoc = docManager.addVersion(doc, area.getName(), language, true);
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
SourceUtil.copy(resolver, contentUri, newDoc.getOutputStream());
newDoc.getLink().setLabel(navigationTitle);
}
String dcNamespace = "http://purl.org/dc/elements/1.1/";
Element dcElement = helper.getFirstChild(metaElement, "dc");
NamespaceHelper dcHelper = new NamespaceHelper(dcNamespace, "dc", xml);
Element[] dcElements = dcHelper.getChildren(dcElement);
MetaData meta = newDoc.getMetaData(dcNamespace);
for (int i = 0; i < dcElements.length; i++) {
String key = dcElements[i].getLocalName();
String value = DocumentHelper.getSimpleElementText(dcElements[i]);