- protected Node addNode(Session session, String path, String nodeType)
- throws RepositoryException {
- return JcrUtils.mkdirs(session, path, nodeType != null ? nodeType
- : getDefaultNewNodeType(), getDefaultNewFolderType(), false);
- // not saved, so that the UI can discard it later on
+ private void publishMetaData(String title) throws RepositoryException {
+ HttpServletRequest request = UiContext.getHttpRequest();
+ if (request == null)
+ return;
+ String url = CmsUtils.getCanonicalUrl(node, request);
+ String desc = node.hasProperty(JCR_DESCRIPTION) ? node.getProperty(
+ JCR_DESCRIPTION).getString() : null;
+ String imgUrl = null;
+ for (NodeIterator it = node.getNodes(); it.hasNext();) {
+ Node child = it.nextNode();
+ if (child.isNodeType(CmsTypes.CMS_IMAGE))
+ imgUrl = CmsUtils.getDataUrl(child, request);
+ }
+
+ StringBuilder js = new StringBuilder();
+ js.append("document.title = '" + title + "';");
+ js.append("var metas = document.getElementsByTagName('meta');");
+ js.append("for (var i=0; i<metas.length; i++) {");
+ js.append(" if (metas[i].getAttribute('property'))");
+ js.append(" if(metas[i].getAttribute('property')=='og:title')");
+ js.append(" metas[i].setAttribute('content','" + title + "');");
+ js.append(" else if(metas[i].getAttribute('property')=='og:url')");
+ js.append(" metas[i].setAttribute('content','" + url + "');");
+ js.append(" else if(metas[i].getAttribute('property')=='og:type')");
+ js.append(" metas[i].setAttribute('content','website');");
+ if (desc != null) {
+ js.append(" else if(metas[i].getAttribute('property')=='og:decription')");
+ js.append(" metas[i].setAttribute('content','" + desc + "');");
+ }
+ if (imgUrl != null) {
+ js.append(" else if(metas[i].getAttribute('property')=='og:image')");
+ js.append(" metas[i].setAttribute('content','" + imgUrl + "');");
+ } else {
+ // TODO reset default image
+ }
+ js.append(" };");
+ jsExecutor.execute(js.toString());