cancel
Showing results for 
Search instead for 
Did you mean: 

edit the xml file and save the dom in repo back

alfresco_gopesh
Champ in-the-making
Champ in-the-making
Hi,

I have to write a dashlet that will read the file from the repo.

I successfully read the file from the repository now the changes made to the dashlet i want it to reflect back to the file from the repository.


my code for ftl file is….


<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">

<script type="text/javascript" src="${url.context}/scripts/ajax/yahoo/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="${url.context}/scripts/ajax/yahoo/connection/connection-min.js"></script>
<script type="text/javascript" src="${url.context}/scripts/ajax/mootools.v1.11.js"></script>
<script type="text/javascript" src="${url.context}/scripts/ajax/common.js"></script>
<script type="text/javascript" src="${url.context}/scripts/ajax/summary-info.js"></script>
<script type="text/javascript" src="${url.context}/scripts/ajax/mywebfiles.js"></script>
<script type="text/javascript">setContextPath('${url.context}');</script>

<script>
   // create manager object for the pop-up summary panels
   var AlfNodeInfoMgr = new Alfresco.PanelManager("NodeInfoBean.sendNodeInfo", "noderef", "portlet_node_summary_panel.ftl");
</script>
<STYLE type="text/css">
.webFilesTable
{
   background-color: #F8FCFD;
   border: 1px solid #CCD4DB;
}

#webFilesPanel
{
   height: 320px;
   width: 716px;
   overflow: auto;
   overflow-y: scroll;
   scrollbar-face-color: #fafdfd;
   scrollbar-3dlight-color: #d2dde0;
   scrollbar-highlight-color: #d2dde0;
   scrollbar-shadow-color: #c3cdd0;
   scrollbar-darkshadow-color: #c3cdd0;
   scrollbar-arrow-color: #239ad7;
   scrollbar-track-color: #ecf1f2;
}

a.webPreviewLink:link, a.webPreviewLink:visited, a.webPreviewLink:hover
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   font-weight: bold;
}

a.webProjectLink:link, a.webProjectLink:visited, a.webProjectLink:hover
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 11px;
   padding-left: 16px;
   vertical-align: 60%;
}

a.fileActionLink:link, a.fileActionLink:visited, a.fileActionLink:hover
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 11px;
   padding-left: 8px;
}

span.webProjectInfo
{
   vertical-align: 60%;
}

.webProjectRow
{
   background-color: #EEF7FB;
   border-top: 1px solid #EEF7FB;
   border-bottom: 1px solid #CCD4DB;
}

.webProjectRowSelected
{
   background-color: #CCE7F3;
   border-bottom: 1px solid #0092DD;
   border-top: 1px solid #0092DD;
}

.webProjectFiles
{
   background-color: #BAD7E4;
   overflow: hidden;
}

.webprojectDesc
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   padding-left: 40px;
}

.webProjectTitle
{
   padding: 8px;
}

.fileResources
{
   border: 1px solid #AFBDC3;
   background-color: #F8FCFD;
   margin: 0px 0px 0px 48px;
   width: 360px;
   height: 92px;
   display: block;
   overflow: hidden;
}

.fileTitleRow
{
   border-top: 1px solid #CCD4DB;
   border-bottom: 1px dotted #CCD4DB;
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   font-weight: bold;
   padding: 4px 0px 4px 48px;
}

.fileItemRow
{
   background-color: #F8FCFD;
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   padding: 3px 0px 2px 3px;
}

.fileItemRowAlt
{
   background-color: #EEF7FB;
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   padding: 3px 0px 2px 3px;
}

a.fileItemLink:link, a.fileItemLink:visited, a.fileItemLink:hover
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 11px;
   font-weight: bold;
}

span.fileItemLink
{
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 11px;
}

.filesRow, a.filesRow:link, a.filesRow:visited, a.filesRow:hover
{
   background-color: #F8FCFD;
   color: #5A5741;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   padding-left: 44px;
   padding-top: 4px;
   border-bottom: 1px solid #F8FCFD;
}

.filesRowAlt
{
}

img.itemImageIcon
{
   vertical-align: -25%;
   padding-right:4px;
}

span.websiteLink
{
   padding-left:8px;
   vertical-align:60%;
}

.filesFooter
{
   width: 700px;
   padding: 8px;
   border: 1px solid #F8FCFD;
   background-image: url(${url.context}/images/parts/doclist_footerbg.png);
   text-align: center;
   color: #515D6B;
   font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
   font-size: 13px;
   font-weight: bold;
}

</STYLE>
<script type="text/javascript">
var languageName  = new Array();
var abrevationValue = new Array();
var linkValue  = new Array();
var publish = new Array();
function clickCheckbox(id)
  {
   document.getElementById(id).checked;
   initTraverse(id);
   document.forms[0].action="/alfresco/wcs/ui/languagedashlet";
   //document.forms[0].action="/alfresco/jsp/language/language.jsp?alf_ticket=TICKET_014b9dce386b486db2f20265892d7db3c1631607";
   document.forms[0].submit();
  }
  function loadXML(xmlFile)
   {
         if (document.implementation && document.implementation.createDocument)
         {
            xmlDoc = document.implementation.createDocument("", "", null);
            xmlDoc.async=false;
         }
         else if (window.ActiveXObject)
         {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async=false;
            
         }
         else
         {
            alert('Your browser can\'t handle this script');
            return;
         }
         
         xmlDoc.load(xmlFile);
         return xmlDoc;
         
   }

   function traverse(tree,id)
   {
      //publish=xmlDoc.getElementsByTagName("publish");
      //alert("here"+publish[0].childNodes[0].nodeValue);
      key=id.substring(id.indexOf("_")+1,id.length);
      //alert(key);
       var RootElement1=xmlDoc.documentElement;
      
       if(RootElement1.hasChildNodes())
       {
         var languageTagChild = RootElement1.childNodes;
         for(var i=0; i<languageTagChild.length; i++)
         {
            flag=false;
            var finalLevelChildTags = languageTagChild.childNodes;
            for(var j=0;j < finalLevelChildTags.length; j++)
            {
               
               if(finalLevelChildTags[j].tagName == 'key')
               {
                  if(finalLevelChildTags[j].childNodes[0].nodeValue==key)
                  {
                     flag=true;
                     //alert("here");
                  }
                  abrevationValue.push(finalLevelChildTags[j].childNodes[0].nodeValue);
               }

               if(finalLevelChildTags[j].tagName == 'value')
               {
                  linkValue.push(finalLevelChildTags[j].childNodes[0].nodeValue);
               }

               if(finalLevelChildTags[j].tagName == 'languageName')
               {
                  languageName.push(finalLevelChildTags[j].childNodes[0].nodeValue);
               }
               if(finalLevelChildTags[j].tagName == 'publish')
               {
                  if(flag==true)
                  {
                     var checkedvalue;
                     if(document.getElementById(id).checked)
                     {   
                        checkedvalue="true";
                     }
                     else
                     {
                        checkedvalue="false";
                     }
                     //finalLevelChildTags[j].childNodes[0].nodeValue=checkedvalue;
                     alert(finalLevelChildTags[j].childNodes[0].nodeValue);
                     xmlDoc.documentElement.childNodes.childNodes[j].childNodes[0].nodeValue=checkedvalue;
                     alert(finalLevelChildTags[j].childNodes[0].nodeValue);
                  }
               }
            }
         }
       }
       document.getElementById('xml').value=xmlDoc;
       alert(document.getElementById('xml').value);
         
   }

   function initTraverse(id)
   {
      var file = '${url.context}${document.url}';
      loadXML(file);
      var doc=xmlDoc.documentElement;
      traverse(doc,id);
      //objXMLDoc =  new ActiveXObject("Microsoft.XMLDOM"); ;
      //xmlDoc.save(xmlDoc);
      //alert("here"+xmlDoc);
      
   }
</script>

<#– List the user modified files in all web projects the user is assigned to –>

<table cellspacing=0 cellpadding=0 border=0 class="webFilesTable">
   <tr><td>
   <table>
   <#assign search="TYPE:\"{http://www.alfresco.org/model/wcmappmodel/1.0}webfolder\"">
      <#list companyhome.childrenByLuceneSearch[search]?sort_by('name') as wp>
         <#list wp.childAssocs["wca:webuser"] as user>
            <#if user.properties["wca:username"] = person.properties.userName>
               <#assign file=avm.lookupNode('Demo–admin:/www/avm_webapps/Demo/language.xml')>
               <#– construct the sandbox name based on the webproject and current username –>
               <#assign storeId=wp.properties["wca:avmstore"]>
               <#assign username=person.properties.userName>
               <#assign sandbox=avm.userSandboxStore(storeId, username)>
           <tr bgcolor="black" style="font-color:white">
               <th><b>Language</b></th>
               <th><b>Abbrevation</b></th>
               <th><b>Published</b></th>
               <th><b>Options</b></th>
          </tr>
        <#assign dom=document.xmlNodeModel>
        <#assign count=0>
                <#list dom.myform.language1 as language>
         <#assign count=count+1>
         <#assign lang=language.key?lower_case>
        <tr>
         <td>${language.languageName}</td>
         <td>${language.key}</td>
         <td>
         ${language.publish}
            <#–if ${language.publish}='true'–>
            <input align="center" type=checkbox name="publish"  value="publish" id="publish_${language.key}" checked onclick="clickCheckbox(this.id);"></td>
            </#–if–>
         <td><a href="${url.context}/c/ui/editwebcontent?sandbox=${sandbox}&webproject=${wp.id}&path=${file.path?url}" target="_new">Remove</a> <a href="${url.context}/c/ui/editwebcontent?sandbox=${sandbox}&webproject=${wp.id}&path=${file.path?url}" target="_new">Modify</a></td>
        </tr>
      </#list>
      <tr>
      <td>   <#if file.isDocument>
           <#if file.hasAspect("wca:forminstancedata") && !file.hasAspect("wcmwf:submitted")>
                                 <a class="fileActionLink" href="${url.context}/c/ui/editwebcontent?sandbox=${sandbox}&webproject=${wp.id}&path=${file.path?url}" target="_new"><img class="itemImageIcon" src="${url.context}/images/icons/edit_icon.gif" border="0"/></a>
         </#if>
         <input type="button" value="Add Language"/>
         <input type="file" id="xml"/>
         </td>
      </tr>
      </#if>
      </#if>
      </#list>
      </#list>
      </table>    
</td>
</tr>
<tr>
<td>
   <#–div class="filesFooter">
      Showing ${filecount} files(s) in ${projectcount} web project(s)
   </div–>
</td>
</tr>
</table>


<#macro encodepath node>   
<#list node.children as child>
<#assign filecount=filecount+1>
  <#if child.isContainer>      
   <tr>
   <td>
   ${child.name?url}
   </td>
   </tr>
   <tr>
   <td>
   <table border="1" bgcolor="red">
   <tr>
   <td>${child.properties.creator}</td> <td>${child.size}</td> <td>${child.properties.modified?date}</td>
   <td>
      
       <@encodepath node=child />
       </td></tr>
   </table>
        </td>
   </tr>
  <#else>
      
     <tr>
     <td>${child.properties.creator}</td> <td>${child.size}</td> <td>${child.properties.modified?date}</td>
      <td><a   href="${url.serviceContext}/api/node/content/${child.nodeRef.storeRef.protocol}/${child.nodeRef.storeRef.identifier}/${child.nodeRef.id}/${child.name?url}">${child.name}</a>
      </td>
      </tr>
   </#if>
</#list>
</#macro>

now i want to save the xmldoc from the script back to the file…

anyone have idea about that??
1 REPLY 1

jbarmash
Champ in-the-making
Champ in-the-making
You have an XML file inside your rendered html / javascript.  To save it back to the repository, you need to write a web script that allows you to POST or PUT it back onto the server. 

A potential alternative is to use UploadContentServlet - if you want to store it in a specific space this might work. 
http://wiki.alfresco.com/wiki/URL_Addressability#UploadContentServlet