<%@ taglib uri="infoglue-page" prefix="page" %>
<%@ taglib uri="infoglue-common" prefix="common" %>
<%@ taglib uri="infoglue-structure" prefix="structure" %>
<%@ taglib uri="infoglue-content" prefix="content" %>
<%@ taglib uri="infoglue-management" prefix="management" %>
<%@ taglib uri="infoglue-page" prefix="tl" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>

<page:pageContext id="pc"/>
<page:deliveryContext id="dc" evaluateFullPage="false"/>

<c:choose>
	<c:when test="${param.contentId != null && param.contentId > -1}">
		<content:content id="articleContent" contentId="${param.contentId}"/>
	</c:when>
	<c:otherwise>
		<content:content id="articleContent" propertyName="Komponent" useInheritance="false"/>
	</c:otherwise>
</c:choose>

<c:if test="${articleContent != null}">
	<content:contentVersion id="articleContentVersion" content="${articleContent}"/>
	<c:if test="${articleContentVersion != null}">
		<management:principal id="articleModifier" contentVersion="${articleContentVersion}"/>
		<content:contentAttribute id="name" contentId="${articleContent.id}" attributeName="Name" useInheritance="false"/>
		<content:contentAttribute id="description" contentId="${articleContent.id}" attributeName="Description" useInheritance="false"/>
		<content:contentAttribute id="manual" contentId="${articleContent.id}" attributeName="Manual" useInheritance="false" parse="true"/>
		<content:contentAttribute id="template" contentId="${articleContent.id}" attributeName="Template" useInheritance="false" disableEditOnSight="true"/>
		<content:assetUrl id="exportUrl" contentId="${articleContent.id}" assetKey="componentExport" useDownloadAction="true"/>
		<content:contentAttribute id="properties" contentId="${articleContent.id}" attributeName="ComponentProperties" useInheritance="false" disableEditOnSight="true"/>
	</c:if>
</c:if>

<c:if test="${articleContent == null}">
	<c:set var="name" value="empty"/>
	<c:set var="description" value="empty"/>
	<c:set var="manual" value="empty"/>
	<c:set var="template" value="empty"/>
	<c:set var="template" value="empty"/>
</c:if>


<h1><c:out value="${name}" escapeXml="false"/></h1>
<p><c:out value="${description}" escapeXml="false"/></p>
<p><c:out value="${manual}" escapeXml="false"/></p>			
<h3>Code</h3>

<common:transformText id="newTemplate" text="${template}" replaceLineBreaks="true" lineBreakReplacer="<br/>" htmlEncode="true"/>
<common:transformText id="newTemplate" text="${newTemplate}" prefix="<html><body style=’font-family: Courier; font-size: 10px;’><pre>" suffix="</pre></body></html>"/>

<content:assetUrlFromString id="componentCodeUrl" data="${newTemplate}" fileNamePrefix="${pc.componentLogic.infoGlueComponent.name}" fileNameSuffix="html"/>
       
<IFRAME style="height: 300px; width: 700px; margin-bottom: 5px;" src="<c:out value="${componentCodeUrl}"/>">
</IFRAME>	

<c:set var="propertiesXSLT">
	<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	  	<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
	    
		<xsl:template match="/"> 
			<table style="border: 1px solid #333333; width: 700px; margin-bottom: 5px;">
		     	<tr bgcolor="#cccccc">
		       		<th>Name</th>
		       		<th>Type</th>
		       		<th>Entity</th>
		       		<th>Multiple</th>
		       		<th>AssetBinding</th>
		       		<th>Allowed CTD Names</th>
		       		<th>Description</th>
		     	</tr>
	   	    	<xsl:for-each select="//property">
		     	<tr>
		      		<td><xsl:value-of select="@name"/></td>
		      		<td><xsl:value-of select="@type"/></td>
		      		<td><xsl:value-of select="@entity"/></td>
		      		<td><xsl:value-of select="@multiple"/></td>
		      		<td><xsl:value-of select="@assetBinding"/></td>
		      		<td><xsl:value-of select="@allowedContentTypeDefinitionNames"/></td>
		      		<td><xsl:value-of select="@description"/></td>
		     	</tr>
	    		</xsl:for-each>
		   	</table>
	  	</xsl:template>
	</xsl:stylesheet>
</c:set>
<c:catch var="error">
<c:choose>
	<c:when test="${empty properties}">
		<c:set var="propertiesHTML" value="No properties defined for this component"/>
	</c:when>
	<c:otherwise>
		<common:XSLTransform id="propertiesHTML" xmlString="${properties}" styleString="${propertiesXSLT}" outputFormat="string"/>
	</c:otherwise>
</c:choose>
</c:catch>
<c:if test="${not empty error}">
	Error: <c:out value="${error}"/>
</c:if>

<h3>Properties</h3>
<c:out value="${propertiesHTML}" escapeXml="false"/>

<common:transformText id="newProperties" text="${properties}" replaceLineBreaks="true" lineBreakReplacer="<br/>" htmlEncode="true"/>

<h3>Property XML</h3>
<p class="code" style="height: 50px; width: 670px; overflow: auto; margin-bottom: 10px;">
	<c:out value="${newProperties}" escapeXml="false"/>
</p>	

<content:contentExportUrl id="exportUrl" contentId="${pc.componentLogic.infoGlueComponent.contentId}" fileNamePrefix="${pc.componentLogic.infoGlueComponent.name}" includeCategories="false"  includeContentTypeDefinitions="false"/>
<div class="download">
	<a href="<c:out value="${exportUrl}"/>">Download component</a>
</div>