Skip to Content
0
Former Member
Aug 04, 2006 at 01:05 AM

Read a text in KM

31 Views

I hate to ask this because I see at least 5 posts related to this, however I cannot get any of the examples to work except one which does not apply in my case.

I am trying to read the file in KM from a MetaData Extension.

I cannot read the file using the URL class.

Doesn't SAP provide an easy way to read a file from KM?

If someone can help me out I would appreciate it. Down in the method "getAllowedValues" is where I have to read the file.

package com.hersheys.all;
 
import java.util.Locale;
import java.util.ResourceBundle;
import com.sap.tc.logging.Location;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.wcm.service.propertyconfig.IMetaContext;
import com.sapportals.wcm.service.propertyconfig.IMetaModel;
import com.sapportals.wcm.service.propertyconfig.IMetaName;
import com.sapportals.wcm.service.propertyconfig.IMetaValue;
import com.sapportals.wcm.service.propertyconfig.IMetaValueList;
import com.sapportals.wcm.service.propertyconfig.PropertyConfigurationServiceException;
import com.sapportals.wcm.service.propertyconfig.metadataextension.IDynamicValues;


import javax.servlet.http.HttpServletRequest;


import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;



import com.sap.security.api.IUser;
import com.sap.security.api.UMFactory;
import com.sap.security.api.umap.IUserMappingData;
import com.sap.security.api.umap.NoLogonDataAvailableException;

public class DynamicMetadataProvider implements IDynamicValues 
{
	private static final Location log = Location.getLocation(DynamicMetadataProvider.class);
	private IMetaModel model = null;

	public DynamicMetadataProvider(IMetaModel model) 
	{
	  	this.model = model;
	}

	/**
	 * Gets a label for a property value depending on the input locale.
	 * @param metaValue metaValue for that a label is requested
	 * @param locale locale to determine the lable language
	 * @return label for a property value, returns null if no label can be found for the value
	 */
	public String getValueLabel(IMetaValue metaValue, Locale locale) throws PropertyConfigurationServiceException 
	{
		String value = metaValue.getValue();
		try 
		{
			value = ResourceBundle.getBundle(this.getClass().getName(), locale).getString("value.lbl."+value);
		} 
		catch (Exception ex) 
		{
			log.errorT("getValueLabel", ex.getMessage());
		}
		return value;
	}

	/**
	 * Returns values depending on the meta name.
	 * @param metaName meta model information of a property
	 * @return list of relevant values (incl. empty list) or null if there is no value domain
	 */
	public IMetaValueList getAllowedValues(IMetaName metaName) throws PropertyConfigurationServiceException 
	{
	  return this.getAllowedValues(metaName, null);
	}
	
	/**
	 * Returns values depending on the meta name and the resource.
	 * @param metaName meta model information of a property
	 * @param metaContext context information
	 * @return list of relevant values (incl. empty list) or null if there is no value domain
	 */
	public IMetaValueList getAllowedValues(IMetaName metaName, IMetaContext metaContext) throws PropertyConfigurationServiceException 
	{
		IMetaValueList valueList = this.model.createEmptyMetaValueList();

                //Here is where I need to read the text file and set the value to the MetaData Extension like this:  valueList.add(model.createMetaValue(model, metaName, this, "string of value to add"));
	}
	/**
	 * Returns a default value depending on the meta name.
	 * @param metaName      meta model information of a property
	 * @return default value or null
	 */
	public IMetaValue getDefaultValue(IMetaName metaName) 
	{
	  return this.model.createMetaValue(this.model, metaName, this, "");
	}

	/**
	 * Gets a label for the property name depending on the input locale.
	 * @param metaName meta name for that the label is requested
	 * @param locale locale to determine the lable language
	 * @return label for a property name, returns null if no label can be found for the name
	 */
	public String getPropertyLabel(IMetaName metaName, Locale locale) throws PropertyConfigurationServiceException 
	{
		String value = metaName.getName();
		try 
		{
			value = ResourceBundle.getBundle(this.getClass().getName(), locale).getString("property.lbl."+value);
		} 
		catch (Exception ex) 
		{
			log.errorT("getPropertyLabel", ex.getMessage());
		}
		return value;
	}

	/**
	 * Gets a description for a property depending on the input locale.
	 * @param metaName meta name for that the description is requested
	 * @param locale locale to determine the description language
	 * @return description for a property, returns null if no description can be found for the property
	 */
	public String getPropertyDescription(IMetaName metaName, Locale locale) throws PropertyConfigurationServiceException 
	{
		String value = metaName.getName();
		try 
		{
			value = ResourceBundle.getBundle(this.getClass().getName(), locale).getString("property.desc."+value);
		} 
		catch (Exception ex) 
		{
			log.errorT("getPropertyDescription", ex.getMessage());
		}
		return value;
	}

	public IMetaValue searchMetaValue(String value) throws PropertyConfigurationServiceException 
	{
		return null;
	}
}