Determine included content type during publishing

Is it possible to determine if a particular content type is being used (inline and within a slot) when generating the location scheme?

Some Background:
We would like to create a php content type that say has a field to insert php code. We would like to embed that into other pages by 1. inline (via ephox editor) and 2. as a slot item. On publishing, we would like to figure out if that content type is being used and if so, then give the page and extension of “.php” or else it would get the standard “.html” extension.

See this post: http://forum.percussion.com/showpost.php?p=1159&postcount=14

This same formula works in location schemes as well as assembly templates.

Ahh…I didn’t clarify my original request well enough. Yes, that code does work for determining say the original content type (i’ve used $relresult.getNode().getPrimaryNodeType().getType() as most of my checking for content types are done within a raw slot macro, but i digress). What i need is the content types/templates being included WITHIN the primary content type.

For example say the pgGeneral (template) which is for ctGeneral (content type) has a slot (say slStuff). In both the body (as an inline template) and in the slot, i can “add”/reference another content type (say ctPHP) with its unique template (say snPHP). So the question becomes, when publishing pgGeneral, how can i figure out that snPHP is “part” of the rendered page (and thus give pgGeneral and extension of “.php” as opposed to “.html”?

I have tried a variety of methods, even stooping so low as to attempt to do a match function to see if i could get at the rendered page (and see if a particular text was found), but no luck.

Let me ask for one more clarification: are all of these slots “ordinary” slots? That is, they are manually populated with content items from search?

If this is true there will be a relationship between the items that we can use for this.

Dave

That would be correct. I do not anticipate using an auto content finder for the slots.

In a location scheme, you don’t have an assembly item, but you can access JEXL functions.

To find the included content types, you’re going to need to create your own JEXL function in Java. This JEXL function will use the IPSContentWs.loadContentRelations() method to find the contents of the appropriate slots. (This function works a lot faster if you do NOT need to load the reference info).

Once you’ve identified the items in a required slots, you will have to load the component summaries for all of these items with IPSCmsContentSummaries.loadComponentSummaries().

These summaries contain the content type id.

If you use this function in a location scheme, it will be called for EVERY item that gets published, so it makes sense to try and optimize performance, and to eliminate as many unnecessary steps as possible. You will also want to “fail fast”. As soon as you find 1 PHP content item, you can return true immediately, rather than searching the rest of the slots.

This approach won’t work for Auto Slots, only slots where there is a relationship stored in the tables (Inline Slots are okay)

For other advice, you can consult API Recommendations document here: http://forum.percussion.com/showthread.php?t=147

I hope this helps.

Dave

Thanks for the information!
I’ll look over it and see what I can do…

I also need to get slot information for my Location Scheme. I’m trying to use loadContentRelations, but I can’t find any examples of how it’s used. there’s nothing in the src/ under the Exits directory. I’ve looked through the API PDF and searched the forum. Is there anywhere else that I can find information on how to use this method?

Thanks.

April,

Look at the JavaDoc, which is located at /Rhythmyx/Docs/Rhythmyx/Javadocs/index.html on your server.

The interface IPSContentWs has documentation for this methods.

You need to create a new PSRelationshipFilter and specify the slot id in the relationship properties of the filter (use IPSHtmlParameters.SYS_SLOTID) and set the owner property of the filter to the PSLocator that specifies the parent content item.

Unfortunately, I don’t have a completed sample of this handy, but if you have further trouble, post your code and I’ll try to help you.

Do you mean I that I should update PSFilter like this:
PSFilter.setRelationshipID(IPSHtmlParameters.SYS_SLOTID)
?

I’m thinking that’s wrong. But I can’t figure out what you mean. I have been looking through the API, honest.

[QUOTE=dbenua;11175]April,

Look at the JavaDoc, which is located at /Rhythmyx/Docs/Rhythmyx/Javadocs/index.html on your server.

The interface IPSContentWs has documentation for this methods.

You need to create a new PSRelationshipFilter and specify the slot id in the relationship properties of the filter (use IPSHtmlParameters.SYS_SLOTID) and set the owner property of the filter to the PSLocator that specifies the parent content item.

Unfortunately, I don’t have a completed sample of this handy, but if you have further trouble, post your code and I’ll try to help you.[/QUOTE]

No, use the setProperty() method. Something like this…


PSRelationshipFilter filter = new PSRelationshipFilter();
filter.setOwner(new PSLocator(myId, myRevision)); 
filter.setProperty(IPSHtmlParameters.SYS_SLOTID, mySlotId); 

Since I’m in the Location Scheme, and so don’t have access to $rx.session to pass to my extension, how do I get the session? Here’s what I have so far:



public String getProductFieldValue (Node item, Integer slotId, String productFieldName) throws PSErrorException, PSErrorResultsException, ValueFormatException, IllegalStateException, PathNotFoundException, RepositoryException {
String path = null;
	
		initServices();
		PSRelationshipFilter psFilter = new PSRelationshipFilter();
		
		PSLocator locator = new PSLocator(item.getProperty("sys_contentid").getValue().getString());
		psFilter.setOwner(locator); 
		psFilter.setProperty(IPSHtmlParameters.SYS_SLOTID, slotId.toString());
		IPSGuid guid = gmgr.makeGuid(locator);
		List<PSItemSummary> summaries = contentService.findDependents(guid, psFilter, false, "admin1");
		if (summaries.size() == 0){
			PSErrorException e = new PSErrorException();
			e.setErrorMessage("Can't lookup path. No associated Product Reference found.");
			throw e;
		}
		IPSGuid cid = summaries.get(0).getGUID();
		List<IPSGuid> glist = Collections.<IPSGuid>singletonList(cid);
		PSSessionUtils sessionGetter = new PSSessionUtils();
		String sessionId = sessionGetter.getPSSessionID();
		List<PSCoreItem> items = contentService.viewItems(glist, false, false, false,
		false, ???, "admin1");
		
		path = items.get(0).getFieldByName("producturl").toString();
		return path;
	}

Woo hoo! Looks like I pretty much got it working. Here is the method:


@IPSJexlMethod(description = "Finds the dependent mwProductReference item and retrieves the field value", params = {
			@IPSJexlParam(name = "item", description = "the sys.item"),
			@IPSJexlParam(name = "slotId", description = "the mwProductReference slot id"),
			@IPSJexlParam(name = "productFieldName", description = "an mwProductReference field name.")
			
	})
	public String getProductFieldValue (Node item, Integer slotId, String productFieldName) throws PSErrorException, PSErrorResultsException, ValueFormatException, IllegalStateException, PathNotFoundException, RepositoryException, PSCmsException {
		String path = null;
	
		initServices();
		
		PSLocator locator = new PSLocator(item.getProperty("rx:sys_contentid").getString());
		
		PSRelationshipFilter psFilter = new PSRelationshipFilter();
		psFilter.setOwner(locator); 
		psFilter.setProperty(IPSHtmlParameters.SYS_SLOTID, slotId.toString());
	
		IPSGuid guid = gmgr.makeGuid(locator);
		List<PSItemSummary> summaries = contentService.findDependents(guid, psFilter, false, "admin1");
		if (summaries.size() == 0){
			PSErrorException e = new PSErrorException();
			e.setErrorMessage("Can't lookup path. No associated Product Reference found.");
			throw e;
		}
		IPSGuid cid = summaries.get(0).getGUID();
		List<IPSGuid> glist = Collections.<IPSGuid>singletonList(cid);
		PSSessionUtils sessionGetter = new PSSessionUtils();
		String sessionId = sessionGetter.getPSSessionID();
		List<PSCoreItem> items = contentService.viewItems(glist, false, false, false,
		false, sessionId, "admin1");
		
		path = items.get(0).getFieldByName("producturl").getValue().getValueAsString();
		return path;
	}