<%--
  Copyright 2003 Sun Microsystems, Inc. All rights reserved 
  Use is subject to license terms.
 --%>
<%-- @(#)browseHeader.jsp  --%>
<%@ page  import="com.iplanet.sso.SSOTokenManager,
		  com.iplanet.sso.SSOToken, 
		  com.iplanet.am.sdk.AMStoreConnection, 
		  com.iplanet.sso.SSOException, 
		  com.sun.portal.search.util.Encoder, 
		  com.iplanet.am.sdk.AMUser" %>

<% pageContext.setAttribute("idvalue", formbean.getBrowseCategory()); %>

<A class="noUnderline" HREF="javascript:document.searchform.browseCategory.value='ROOT';document.searchform.scope.value='';document.searchform.mode.value='browse';document.searchform.submit();"><font face="<%=tFontFace%>"><b><jx:expr value="$taxid"/></b></font></A>

<jx:choose>
<jx:when test = "$idvalue != 'ROOT'">
<%
String hrefval = "";
String idval = "";
String id = (String)pageContext.getAttribute("idvalue");
StringTokenizer st = new StringTokenizer(id, ":");
while (st.hasMoreTokens()) {
    idval = st.nextToken();
	if (hrefval.equals(""))
	    hrefval = idval;
	else
	    hrefval = hrefval+":"+idval;
	%>
	> <nobr><A class="noUnderline" HREF="javascript:document.searchform.browseCategory.value=&quot;<%=SearchContext.htmlEncode(Encoder.quotedEscape(hrefval))%>&quot;;document.searchform.scope.value='';document.searchform.mode.value='browse';document.searchform.submit();"><font face="<%=tFontFace%>"><b><%=SearchContext.htmlEncode(idval)%></b></font></A></nobr>
	<%
}
	try {
		SSOTokenManager mgr = SSOTokenManager.getInstance(); 
		SSOToken token = mgr.createSSOToken(request);
		if (token !=null) {
				AMStoreConnection amstore = new AMStoreConnection(token);
				AMUser user = amstore.getUser(token.getPrincipal().getName() );
				boolean subscriptionsService = user.getAssignedServices().contains("SunPortalSubscriptionsService");
				if ((user != null) && (subscriptionsService != false)) {
					%>
 <A target="ps_main" href="?action=edit&provider=JSPEditContainer&targetprovider=Subscriptions&containerName=SearchTabPanelContainer&newCatSubscription=<%=Encoder.urlEncode(hrefval,"UTF-8")%>&newServer=<%=Encoder.urlEncode((String)pageContext.findAttribute("searchServer"),"UTF-8")%>&newDB=default"><font size="-2">[Subscribe]</font></A>
				<%
				}
		}
	} catch (Exception e) {
			// failed to get token or AMUser, anayway means not subscription allowed
	}	
%>
<BR>

</jx:when>
<jx:otherwise>
<BR>
</jx:otherwise>
</jx:choose>
