cancel
Showing results for 
Search instead for 
Did you mean: 

Command: Link to KM folder - does it exsist/workaround

Former Member
0 Kudos

Hi,

We have a KM folder where we store articles based on xml forms. One iView displays the last 3 articles from this folder.

Is there a command that can be used in the collection renderer for creating a link to this KM folder and display the content with a selected layout set? The goal is that the user should be able to view all the articles in the folder. Is there maybe another work around? Any pointers?

Best,

Bjorn

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi,

This is possible by implementing a UICommand, which will again call a KM Navigation IView with a specific layoutset.

So the link should look like this:

"/irj/servlet/prt/portal/prtroot/com.sap.km.cm.navigation" + "pathToKMFolder" + "?rndLayoutSet=YourSpecial_LayoutSet"

This link should be called in your UICommand.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Thx,

I know the links to my KM folders, but how do I implement the UI Command? Witch Java Class and parameters to use?

Looking forward to implementing this

Bjorn

Former Member
0 Kudos
Former Member
0 Kudos

OK, I see I have to start programming again.... /me fingers crossed

Hopefully I'll have this ready by the end of the week......

So there is no java class ready for this (as in the example you linked to)?

Edited by: Bjørn Bjørnstad on Apr 16, 2008 7:06 PM

former_member188556
Active Contributor
0 Kudos

Hi Bjorn,

I had the same requirement and this is the code that i used...

I got this from SDN only from Thilo's How to Guide...

I tried to find that link...


package com.company;

import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import com.sap.tc.logging.Location;
import com.sapportals.portal.security.usermanagement.IUser;
import com.sapportals.wcm.WcmException;
import com.sapportals.wcm.rendering.base.IRenderingEvent;
import com.sapportals.wcm.rendering.base.IScreenflowData;
import com.sapportals.wcm.rendering.uicommand.AbstractCommand;
import com.sapportals.wcm.rendering.uicommand.ICommand;
import com.sapportals.wcm.rendering.uicommand.LinkAttributes;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.IResourceContext;
import com.sapportals.wcm.repository.ResourceContext;
import com.sapportals.wcm.repository.ResourceException;
import com.sapportals.wcm.repository.ResourceFactory;
import com.sapportals.wcm.service.IServiceTypesConst;
import com.sapportals.wcm.service.urlgenerator.IURLGeneratorService;
import com.sapportals.wcm.service.urlgenerator.PathKey;
import com.sapportals.wcm.util.content.IContent;
import com.sapportals.wcm.util.uri.IHierarchicalUri;
import com.sapportals.wcm.util.uri.IUriReference;
import com.sapportals.wcm.util.uri.RID;
import com.sapportals.wcm.util.usermanagement.WPUMFactory;

/**
 
 */
public class Revisions extends AbstractCommand {

	Location logger = Location.getLocation(Revisions.class);
	//String url = "";
	//private List values;

	public Revisions() {
		super("Revisions", "Revisions");
	}

	public ICommand getNewInstance() {
		return this.initNewInstance(new Revisions());
	}

	public IRenderingEvent execute(IScreenflowData arg0) throws WcmException {

		return null;

	}

	public String[] getTargetParameters() throws WcmException {
		//return new String[0];
		String result[] = new String[1];
		result[0] = this.resource.getRID().getPath();
		return result;
	}

	public void setTargetParameters(List arg0, IResourceContext arg1)
		throws WcmException {
		//		this.context = arg1;
		//
		//		this.values = arg0;
	}

	public boolean isExecutable() {
		return true;
	}

	protected String getLabel() {
		String label = "Revisions";
		try {
			label = getproperty("COMMAND_LABEL");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return label;
	}
	protected String getTooltip() {
		String toolTip = "View all revsions";
		try {
			toolTip = getproperty("TOOL_TIP");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return toolTip;
	}

	public boolean raisesEvent() {
		return false;
		//Changed false to true to make the call to EXECUTE method
	}

	public LinkAttributes getLinkAttributes() {
		LinkAttributes linkAttributes = null;
		IResource res = this.getResource();
		String resURL = "";
		try {
			resURL = urlGeneration(resource.getRID());
		} catch (ResourceException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		resURL =
			resURL.replaceAll("com.sap.km.cm.docs", "com.sap.km.cm.navigation");
	

		try {
			linkAttributes =
				new LinkAttributes(
					resURL + "?rndLayoutSet=" + getproperty("rndLayoutSet"),
					"_blank");
		} catch (Exception e) {
			//			 TODO Auto-generated catch block
			e.printStackTrace();
		}
		return linkAttributes;
	}
	public java.lang.String urlGeneration(
		com.sapportals.wcm.util.uri.RID rid) {
		//@@begin urlGeneration()

		IURLGeneratorService ug;
		IUriReference uriRef = null;
		String uriString = "";

		try {
			ug =
				(IURLGeneratorService) ResourceFactory
					.getInstance()
					.getServiceFactory()
					.getService(IServiceTypesConst.URLGENERATOR_SERVICE);
			uriRef =
				ug.getResourcePageUri(PathKey.CONTENT_ACCESS_PATH, rid, null);
			IHierarchicalUri uri = ug.createAbsoluteUri(uriRef);

			uriString = uri.toExternalForm();
			

			uriString = escapeURLSpace(uriString);
			
		} catch (ResourceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WcmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();

		}
		return uriString;

		//@@end
	}
	public java.lang.String escapeURLSpace(java.lang.String url) {
		//@@begin escapeURLSpace()

		StringBuffer str = new StringBuffer(50);
		int len = (url != null) ? url.length() : 0;
		for (int i = 0; i < len; i++) {
			char ch = url.charAt(i);
			switch (ch) {

				case ' ' :
					str.append("%20");
					break;
				case '&' :
					str.append("%26");
					break;
				default :
					str.append(ch);
			}
		}
		return str.toString();

		//@@end
	}
	public String getproperty(String key) throws Exception {

		IUser adminUser =
			WPUMFactory.getServiceUserFactory().getServiceUser(
				"cmadmin_service");

		InputStream is = null;
		String value = "";
		String configFilePath =
			"/documents/command.properties";
		RID ridOfConfigFile = RID.getRID(configFilePath);

		try {
			if (adminUser.isAuthenticated()) {
				// create a resource context with the authenticated user
				ResourceContext resourceContext =
					new ResourceContext(adminUser);
				IResource resource =
					ResourceFactory.getInstance().getResource(
						ridOfConfigFile,
						resourceContext);

				IContent iContent = resource.getContent();
				is = iContent.getInputStream();
				Properties props = new Properties();
				props.load(is);
				value = props.getProperty(key);

			}
		} finally {
			if (is != null)
				is.close();
		}
		return value;

	}

}

0 Kudos

Hi,

The code from BP, should work.

The implementation where you should set your layoutset is in getLinkAttributes() method.

Regards,

Praveen Gudapati

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Bjorn,

By default the KM Navigation iView with "NewsExplorer" layoutset will display all the content of the folder (i.e what ever you have defined in RenderList form at design time in XML form builder... A row for every article) and one of the fields in every article can be used as a link to display the Show Form (with full details of the article). If I understand your objective correctly ...... You want to display all the articles in the KM iview. If Yes you can try as follows....

Give a try by creating another KM Navigation iView with "NewsExplorer" layout set pointing to the same folder. If it still does'nt show all articles - Create a new xml forms project, use the same schema as in your current project, design the RenderList form so that it display the article name, id etc... and make the article name as hyper link to open the show form with all the details.... And publish the new form on the same KM folder.... and refer this new form's usage in navigation iview.

Regards

Ramesh.

Former Member
0 Kudos

Hi Bjorn,

You wrote that you have a KM folder that contains the articles created through xml forms. This content can not be displayed by all the layouts (as you want to give a command link to the user through which he will choose a layout to display the folder content). So I don't get the point in implementing an UI Command. If you want display all the articles (.xml) in that folder, just we can create a KM Navigation iView with the layoutset "newsexplorer" or "newsbrowser" that points to your KM Folder and it will display all the articles available in that folder. Let me know if i am wrong and did'nt understood your requirement correctly...

Regards

Ramesh

Former Member
0 Kudos

Ramesh,

You are correct - we can use KM Navigation iView to view the xml articles in the folder. But my question is how to create a link at the bottom of an KM Navigation iVew that shows the full content of that folder. Today the KM Navigation iView we have shows the 3 latest articles - and the link will function as a link to the complete content of the folder - or a link to the "archive" of older articles.

Bjorn