<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="AdminException.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.PlanVersionHistoryElement"
%><%@page import="com.fujitsu.iflow.model.workflow.DMS"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstantiator"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.wfadapter.DocRepository"
%><%@page import="com.fujitsu.iflow.model.workflow.AttachmentRef"
%><%@page import="com.fujitsu.iflow.model.workflow.DMSEntityValue"
%><%@page import="com.fujitsu.iflow.common.exceptions.IflowException"
%><%@page import="com.fujitsu.iflow.model.util.ModelException"
%><%@page import="com.fujitsu.iflow.model.util.ModelInternalException"
%><%@page import="com.fujitsu.iflow.common.ErrorMessage"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@page import="java.util.*"
%><%@page import="java.io.File"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMAdminImpl"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    BPMAdmin bpas = bps.getAdmin();
    WFAdminSessionImpl wfSession = ((BPMAdminImpl)bpas)._wfas;

%>



<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--

document.onmouseover = mOver ;
document.onmouseout = mOut ;

function mOver() {
    var eSrc = window.event.srcElement ;
    if (eSrc.className == "item") {
        window.event.srcElement.className = "highlight";
    }
}

function mOut() {
    var eSrc = window.event.srcElement ;
    if (eSrc.className == "highlight") {
        window.event.srcElement.className = "item";
    }
}


var bV=parseInt(navigator.appVersion);
NS4=(document.layers) ? true : false;
IE4=((document.all)&&(bV>=4))?true:false;
ver4 = (NS4 || IE4) ? true : false;

isExpanded = false;

function getIndex($1) {
    ind = null;
    for (i=0; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.id == $1) {
            ind = i;
            break;
        }
    }
    return ind;
}

function arrange() {
    nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY = nextY;
            nextY += whichEl.document.height;
        }
    }
}

function FolderInit(){
    if (NS4) {
    firstEl = "mParent";
    firstInd = getIndex(firstEl);
    showAll();
        for (i=0; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
        }
        arrange();
    }
    else {
        tempColl = document.all.tags("DIV");
        for (i=0; i<tempColl.length; i++) {
            if (tempColl(i).className == "child") tempColl(i).style.display = "none";
        }
    }
}

function FolderExpand($1,$2) {
    if (!ver4) return;
    if (IE4) { ExpandIE($1,$2) } 
    else { ExpandNS($1,$2) }
}

function ExpandIE($1,$2) {
    Expanda = eval($1 + "a");
    Expanda.blur()
    ExpandChild = eval($1 + "Child");
        if ($2 != "top") { 
        ExpandTree = eval($1 + "Tree");
        ExpandFolder = eval($1 + "Folder");
    }
    if (ExpandChild.style.display == "none") {
        ExpandChild.style.display = "block";
                if ($2 != "top") { 
                    if ($2 == "last") { ExpandTree.src = "images/Lminus.gif"; }
            else { ExpandTree.src = "images/Tminus.gif"; }
            ExpandFolder.src = "images/openfoldericon.gif"; 
        }
        else { mTree.src = "images/topopen.gif"; }
    }
    else {
        ExpandChild.style.display = "none";
                if ($2 != "top") { 
                    if ($2 == "last") { ExpandTree.src = "images/Lplus.gif"; }
            else { ExpandTree.src = "images/Tplus.gif"; }
            ExpandFolder.src = "images/foldericon.gif";
        }
        else { mTree.src = "images/top.gif"; }
    }
}
function ExpandNS($1,$2) {
    ExpandChild = eval("document." + $1 + "Child")
        if ($2 != "top") { 
        ExpandTree = eval("document." + $1 + "Parent.document." + $1 + "Tree")
        ExpandFolder = eval("document." + $1 + "Parent.document." + $1 + "Folder")
    }   
    if (ExpandChild.visibility == "hide") {
        ExpandChild.visibility = "show";
                if ($2 != "top") { 
                    if ($2 == "last") { ExpandTree.src = "images/Lminus.gif"; }
            else { ExpandTree.src = "images/Tminus.gif"; }
            ExpandFolder.src = "images/openfoldericon.gif"; 
        }
        else { mTree.src = "images/topopen.gif"; }
    }
    else {
        ExpandChild.visibility = "hide";
                if ($2 != "top") { 
                    if ($2 == "last") { ExpandTree.src = "images/Lplus.gif"; }
            else { ExpandTree.src = "images/Tplus.gif"; }
            ExpandFolder.src = "images/foldericon.gif"; 
        }
        else { mTree.src = "images/top.gif"; }
    }
    arrange();
}

function showAll() {
    for (i=firstInd; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        whichEl.visibility = "show";
    }
}


with (document) {
    write("<STYLE TYPE='text/css'>");
    if (NS4) {
        write(".parent { color: black; font-size:9pt; line-height:0pt; color:black; text-decoration:none; margin-top: 0px; margin-bottom: 0px; position:absolute; visibility:hidden }");
        write(".child { text-decoration:none; font-size:9pt; line-height:15pt; position:absolute }");
            write(".item { color: black; text-decoration:none }");
            write(".highlight { color: blue; text-decoration:none }");
    }
    else {
        write(".parent { font: 12px/13px; Times; text-decoration: none; color: black }");
        write(".child { font:12px/13px Times; display:none }");
            write(".item { color: black; text-decoration:none; cursor: hand }");
            write(".highlight { color: blue; text-decoration:none }");
            write(".icon { margin-right: 5 }")
    }
    write("</STYLE>");
}
onload = FolderInit;


function updateParent() {
	opener.document.attachmentForm.XMLFilePath.value = document.childForm.dmsPath.value;
	
	self.close();
        return false;
}

function updateDmsPathField(filePath) {
    document.childForm.dmsPath.value = filePath;
}

//--></SCRIPT>
<HEAD><title>Interstage Business Process Manager | Admin DMS Browser</title></HEAD>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<BODY>



<TABLE border="0" cellpadding="0" cellspacing="1" class="TABLE Class" width="100%" align="center">
    <tr>
    <td>
        </center>
            <FORM NAME="childForm" onSubmit="return updateParent();">
                <TABLE  border="0" width="100%" border="0" cellpadding="4" cellspacing="0">
                    <tr class="headrow">
                        <td colspan="2" align="center"> Getting DMS Path for Admin DMS Browser </td>
                    </tr>
                    <tr class="oddrow">
                        <td class="prompt" width="25%"> Dms Path: </td>
                        <td width="75%"><input type="text" name="dmsPath">&nbsp;<input type="submit" value="Close" class="submitClass">
                        </td>
                    </tr>
                </TABLE>
        </FORM>
        </center>        

        <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
               <td>

<%
    String pwd = (String)session.getAttribute("password");
    generateTopFolder(wfSession, pwd, out);
%>
               </td>
            </tr>
        </TABLE>
    </td>
    </tr>
</TABLE>
</BODY>
</HTML>


<%!

    private static int counter = 0;
    
    public
    void
    generateTopFolder (
        WFSession wfSession,
        String password,
        java.io.Writer out)
        throws Exception
    {
        DocRepository docRepository = null;
        Properties sysProp = System.getProperties();
        String docRoot = sysProp.getProperty("user.home");
        DMS dms =  WFObjectFactory.getDMS(wfSession, wfSession.getUserName(), password);
        docRepository = WFObjectFactory.getDocRepository(dms, docRoot);
        String[] dmsRootFolders = dms.getRootFolderNames();

        out.write("<div ID=\"mParent\" class=\"parent\">\n");
        out.write("<a name=\"ma\" href=\"#\" onClick=\"FolderExpand('m','top')\">\n");
        out.write("<img name=\"mTree\" src=\"images/topopen.gif\" class=\"icon\" align=\"absmiddle\" border=\"0\" onDblClick=\"alert('dbl clicked')\"><font color=\"black\" face=\"verdana\" size=\"1\" class=\"item\">DMS Roots</font></a>\n");
        out.write("</div>\n");

        out.write("<div ID=\"mChild\">\n");
        if (dmsRootFolders != null && dmsRootFolders.length >0 )
        for (int i=0; i<dmsRootFolders.length; i++) 
        {
            counter = counter + 1;
            out.write("<div ID=\"m"+ counter +"Parent\" CLASS=\"parent\"><a name=\"m"+ counter +"a\" href=\"#\" onClick=\"FolderExpand('m"+ counter +"','last'); updateDmsPathField('"+ dmsRootFolders[i].replace('\\','/') +"') \"><img name=\"m"+ counter +"Tree\" src=\"images/Lplus.gif\" align=\"absmiddle\" border=\"0\"><img name=\"m"+ counter +"Folder\" src=\"images/foldericon.gif\" class=\"icon\" align=\"absmiddle\" border=\"0\"><font color=\"black\" face=\"verdana\" size=\"1\" class=\"item\"> " + dmsRootFolders[i] + "</font></a></div>\n");
            out.write("<div ID=\"m"+ counter +"Child\" CLASS=\"child\">\n");
            generateInnerFolder(dmsRootFolders[i], dms, docRepository, out, 0);
            out.write(" </div> \n");
            
        }
        out.write(" </div> \n");
    }
    
    public
    void
    generateInnerFolder(
        String folderName,
        DMS dms,
        DocRepository docRepository,
        java.io.Writer out,
        int depth)
        throws Exception
    {
    
        folderName = folderName.replace('\\','/');
        if (folderName.endsWith("/") == false) {
            folderName = folderName + "/";
        }
        
        
        DMSEntityValue ev = dms.getFolderContents(folderName);
        String[] names = ev.getNames();
        int[] types = ev.getTypes();
        depth = depth + 1;
        

        for (int j=0; j<names.length; j++) 
        {
            if (types[j] == 1) {
                counter = counter + 1;
                out.write("<div ID=\"m"+ counter +"Parent\" CLASS=\"parent\">");
                for (int k=0; k<depth; k++) {
                    out.write("<img src=\"images/I.gif\" align=\"absmiddle\" border=\"0\">");
                }
                out.write("<a name=\"m"+ counter +"a\" href=\"#\" onClick=\"FolderExpand('m"+ counter +"','last'); updateDmsPathField('"+ folderName + names[j] +"') \"><img name=\"m"+ counter +"Tree\" src=\"images/Lplus.gif\" align=\"absmiddle\" border=\"0\"><img name=\"m"+ counter +"Folder\" src=\"images/foldericon.gif\" class=\"icon\" align=\"absmiddle\" border=\"0\"><font color=\"black\" face=\"verdana\" size=\"1\" class=\"item\"> " + names[j] + "</font></a></div>\n");
                out.write("<div ID=\"m"+ counter +"Child\" CLASS=\"child\">\n");
                generateInnerFolder(folderName + names[j], dms,docRepository, out, depth);
                out.write("</div>");
                
            }
            else {
                String imageName = "";
                if (j == names.length -1)
                    imageName = "L.gif";
                else
                    imageName = "T.gif";
                    
                for (int k=0; k<depth; k++) {
                    out.write("<img src=\"images/I.gif\" align=\"absmiddle\"/>");
                }
                out.write("<img src=\"images/"+ imageName +"\" align=\"absmiddle\"/><img src=\"images/htmlicon.gif\" align=\"absmiddle\" class=\"icon\"/><a class=\"item\" href=\"#\" onClick=\"updateDmsPathField('"+ folderName + names[j] +"') \">" + names[j] + "</a><br>\n");
                
            }// if
            
        }// for
    }
    
    public WFAdminSessionImpl getiFlowSession(Object modelObject)
    {
    		return (WFAdminSessionImpl)(modelObject);
    }         
    
   
    
%> 