Author: jaz
Date: Fri Mar 9 11:23:12 2007 New Revision: 516516 URL: http://svn.apache.org/viewvc?view=rev&rev=516516 Log: updated facade/worker to support decorator content; added datamodel for decorator content Modified: ofbiz/trunk/applications/content/entitydef/entitymodel.xml ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Modified: ofbiz/trunk/applications/content/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/entitydef/entitymodel.xml?view=diff&rev=516516&r1=516515&r2=516516 ============================================================================== --- ofbiz/trunk/applications/content/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/content/entitydef/entitymodel.xml Fri Mar 9 11:23:12 2007 @@ -188,6 +188,7 @@ <field name="contentId" type="id-ne"></field> <field name="contentTypeId" type="id"></field> <field name="ownerContentId" type="id"></field> + <field name="decoratorContentId" type="id"></field> <field name="instanceOfContentId" type="id"></field> <field name="dataResourceId" type="id"></field> <field name="templateDataResourceId" type="id"></field> @@ -245,6 +246,9 @@ </relation> <relation type="one" fk-name="CONTENT_DTSRC" rel-entity-name="DataSource"> <key-map field-name="dataSourceId"/> + </relation> + <relation type="one" fk-name="CONTENT_DCNTNT" title="Decorator" rel-entity-name="Content"> + <key-map field-name="decoratorContentId" rel-field-name="contentId"/> </relation> <relation type="one" fk-name="CONTENT_PCNTNT" title="Owner" rel-entity-name="Content"> <key-map field-name="ownerContentId" rel-field-name="contentId"/> Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java?view=diff&rev=516516&r1=516515&r2=516516 ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java Fri Mar 9 11:23:12 2007 @@ -50,7 +50,7 @@ protected final Locale locale; protected final String mimeType; protected final boolean cache; - protected boolean isTop = false; + protected boolean render = true; // internal objects private DataResource dataResource; @@ -67,7 +67,7 @@ this.cache = cache; this.contentId = content.getString("contentId"); this.delegator = content.getDelegator(); - this.isTop = true; + this.render = false; init(); } @@ -95,6 +95,10 @@ this.content = new Content(); } + public void setRenderFlag(boolean render) { + this.render = render; + } + // interface methods public int size() { return 0; @@ -154,7 +158,7 @@ String name = (String) obj; // fields key, returns value object - if ("fields".equals(name)) { + if ("fields".equalsIgnoreCase(name)) { GenericValue value = null; try { value = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId)); @@ -166,12 +170,12 @@ } // data (resource) object - if ("data".equals(name)) { + if ("data".equalsIgnoreCase(name) || "dataresource".equalsIgnoreCase(name)) { return dataResource; } // subcontent list of ordered subcontent - if ("subcontent_all".equals(name)) { + if ("subcontent_all".equalsIgnoreCase(name)) { List subContent = FastList.newInstance(); List subs = null; try { @@ -192,27 +196,28 @@ } // return the subcontent object - if ("subcontent".equals(name)) { + if ("subcontent".equalsIgnoreCase(name)) { return this.subContent; } // return list of metaData by predicate ID - if ("metadata".equals(name)) { + if ("metadata".equalsIgnoreCase(name)) { return this.metaData; } // content; returns object from contentId - if ("content".equals(name)) { + if ("content".equalsIgnoreCase(name)) { return content; } // render this content - if ("render".equals(name)) { + if ("render".equalsIgnoreCase(name)) { Map renderCtx = FastMap.newInstance(); renderCtx.putAll(context); - if (isTop) { - Debug.logWarning("Cannot render content being rendered! (No Looping!)", module); - return "Cannot render content being rendered! (No Looping!)"; + if (!render) { + String errorMsg = "WARNING: Cannot render content being rendered! (Infinite Recursion NOT allowed!)"; + Debug.logWarning(errorMsg, module); + return "=========> " + errorMsg + " <========="; } try { return ContentWorker.renderContentAsText(dispatcher, delegator, contentId, renderCtx, locale, mimeType, cache); @@ -366,7 +371,7 @@ String name = (String) key; // get the data resource value object - if ("fields".equals(name)) { + if ("fields".equalsIgnoreCase(name)) { GenericValue dr = null; try { dr = value.getRelatedOne("DataResource"); @@ -377,7 +382,7 @@ } // render just the dataresource - if ("render".equals(name)) { + if ("render".equalsIgnoreCase(name)) { try { return DataResourceWorker.renderDataResourceAsText(delegator, value.getString("dataResourceId"), context, locale, mimeType, cache); } catch (GeneralException e) { Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?view=diff&rev=516516&r1=516515&r2=516516 ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Fri Mar 9 11:23:12 2007 @@ -182,74 +182,80 @@ if (templateContext == null) { templateContext = FastMap.newInstance(); } - - // set this contentId in the template context + + // create the content facade ContentMapFacade facade = new ContentMapFacade(dispatcher, content, templateContext, locale, mimeTypeId, cache); - templateContext.put("thisContent", facade); - templateContext.put("contentId", contentId); - // render all sub-content; place in template context under mapKey name - List subContent = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentId, - "contentAssocTypeId", "SUB_CONTENT"), UtilMisc.toList("-fromDate")); - subContent = EntityUtil.filterByDate(subContent); - - if (subContent != null && subContent.size() > 0) { - Iterator i = subContent.iterator(); - while (i.hasNext()) { - GenericValue contentAssoc = (GenericValue) i.next(); - String contentIdTo = contentAssoc.getString("contentIdTo"); - String key = contentAssoc.getString("mapKey"); - String textData = ContentWorker.renderContentAsText(dispatcher, delegator, contentIdTo, FastMap.newInstance(), locale, mimeTypeId, cache); - if (UtilValidate.isNotEmpty(textData)) { - templateContext.put(key, textData); - } + // look for a content decorator + String contentDecoratorId = content.getString("decoratorContentId"); + if (UtilValidate.isNotEmpty(contentDecoratorId)) { + // if there is a decorator content; do not render this content; + // instead render the decorator + GenericValue decorator; + if (cache) { + decorator = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentDecoratorId)); + } else { + decorator = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentDecoratorId)); + } + if (decorator == null) { + throw new GeneralException("No decorator content found for decorator contentId [" + contentDecoratorId + "]"); } - } - - // now if no template; just render the data - if (UtilValidate.isEmpty(templateDataResourceId) || templateContext.containsKey("ignoreTemplate")) { - DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache); - // there is a template; render the data and then the template + // render the decorator + ContentMapFacade decFacade = new ContentMapFacade(dispatcher, decorator, templateContext, locale, mimeTypeId, cache); + templateContext.put("decoratedContent", facade); // decorated content + templateContext.put("thisContent", decFacade); // decorator content + ContentWorker.renderContentAsText(dispatcher, delegator, contentDecoratorId, out, templateContext, locale, mimeTypeId, cache); } else { - Writer dataWriter = new StringWriter(); - DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, dataWriter, - templateContext, locale, mimeTypeId, cache); - - String textData = dataWriter.toString(); - if (textData != null) { - textData = textData.trim(); - } + // set this content facade in the context + templateContext.put("thisContent", facade); + templateContext.put("contentId", contentId); + + // now if no template; just render the data + if (UtilValidate.isEmpty(templateDataResourceId) || templateContext.containsKey("ignoreTemplate")) { + DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache); - String mimeType; - try { - mimeType = DataResourceWorker.getDataResourceMimeType(delegator, dataResourceId, null); - } catch (GenericEntityException e) { - throw new GeneralException(e.getMessage()); - } + // there is a template; render the data and then the template + } else { + Writer dataWriter = new StringWriter(); + DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, dataWriter, + templateContext, locale, mimeTypeId, cache); + + String textData = dataWriter.toString(); + if (textData != null) { + textData = textData.trim(); + } + + String mimeType; + try { + mimeType = DataResourceWorker.getDataResourceMimeType(delegator, dataResourceId, null); + } catch (GenericEntityException e) { + throw new GeneralException(e.getMessage()); + } - // using FTL to handle XML? not really sure what this is doing... - if (UtilValidate.isNotEmpty(mimeType)) { - if (mimeType.toLowerCase().indexOf("xml") >= 0) { - StringReader sr = new StringReader(textData); - try { - NodeModel nodeModel = NodeModel.parse(new InputSource(sr)); - templateContext.put("doc", nodeModel); - } catch (SAXException e) { - throw new GeneralException(e.getMessage()); - } catch (ParserConfigurationException e2) { - throw new GeneralException(e2.getMessage()); + // using FTL to handle XML? not really sure what this is doing... + if (UtilValidate.isNotEmpty(mimeType)) { + if (mimeType.toLowerCase().indexOf("xml") >= 0) { + StringReader sr = new StringReader(textData); + try { + NodeModel nodeModel = NodeModel.parse(new InputSource(sr)); + templateContext.put("doc", nodeModel); + } catch (SAXException e) { + throw new GeneralException(e.getMessage()); + } catch (ParserConfigurationException e2) { + throw new GeneralException(e2.getMessage()); + } + } else { + // must be text + templateContext.put("textData", textData); } } else { - // must be text templateContext.put("textData", textData); } - } else { - templateContext.put("textData", textData); - } - // render the template - DataResourceWorker.renderDataResourceAsText(delegator, templateDataResourceId, out, templateContext, locale, mimeTypeId, cache); + // render the template + DataResourceWorker.renderDataResourceAsText(delegator, templateDataResourceId, out, templateContext, locale, mimeTypeId, cache); + } } } |
Free forum by Nabble | Edit this page |