problème avec les actions

cancel
Showing results for 
Search instead for 
Did you mean: 
choixged
Active Member

problème avec les actions

Bonjour,

je voudrais utiliser les actions pour faire tourner mon code java ,j'ai essayer de l'integer au sein de la classe WebscriptDialog,mais ça n'as pas marché,j'ai besoin de votre aide,si quelqu un pourra me montrer ou est le probleme et pourquoi ça marche pas:

je donne ici tous les fichiers que j'ai créer pour réaliser cette action.

merci d'avance

Dans le fichier surce.extension.alfresco on a :

le fichier  logger-action-context.xml  :

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
     
    <!– Logger Action Bean –>
    <bean id="WebscriptDialog-action" class="org.alfresco.sample.WebscriptDialog" parent="WebscriptDialog-executer"/>
  
      <!– Load the Logger Action Messages –>  
      <bean id="WebscriptDialog-action-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
       <property name="resourceBundles">
          <list>
             <value>org.alfresco.sample.WebscriptDialog-action-messages</value>
          </list>
       </property>
      </bean>
     
</beans>


le fichier web-client-config-custom.xml

<alfresco-config>

   <config>
      <actions>
         <!– Launch Add Aspect Dialog –>
         <action id="WebscriptDialog">
            <label>WebscriptDialog Action</label>
            <image>/images/icons/add.gif</image>
            <action>dialog:WebscriptDialog</action>
            <action-listener>#{WebscriptDialog.setupSpaceAction}</action-listener>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>
        
         <!– Add action to more actions menu for each space –>
         <action-group id="space_browse_menu">
            <action idref="WebscriptDialog" />
         </action-group>
      </actions>
     
      <dialogs>
        <dialog name="webscriptDialog" page="/jsp/sample/WebscriptDialog.jsp"
    managed-bean="WebscriptDialog"
    icon="/images/icons/view_properties_large.gif">
</dialog>
      </dialogs>
   </config>

</alfresco-config>



Dans le fichier source.org.alresco.sample on a:

le fichier logger-action-messages.properties:

# Action title and description
WebscriptDialog-action.title=WebscriptDialog Action


le fichier java : WebscriptDialog:

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.sample;

import org.alfresco.sample.LuceneDemo1;
import java.io.File;
import java.util.List;
import java.util.Vector;
import org.alfresco.web.bean.content.AddContentDialog;
import  org.alfresco.sample.SingleResult;

import java.io.File;
import java.util.List;
import java.util.Vector;

import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Logger action executer.
*
* This action will log a message to the application log file at the level specified.
*
* @author Roy Wetherall
*/
public abstract class WebscriptDialog extends BaseDialogBean
{
   

    /*
    /**
     * This action will take the log message and log it at the provided log level.
     *
     * If the log level is not provided the default will be INFO.
     *
     * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
     */
    /**
    *
    */
   

   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
   }
          static SingleResult outcome[];
          private SingleResult results[];

          public WebscriptDialog()
          {
          }

          public SingleResult[] getResults()
          {
              LuceneDemo1 test;
              results = new SingleResult[1];
              results[0] = new SingleResult();
              results[0].setFrequency(4);
             
              results[0].setKeyword("Hello");
              Vector rech = new Vector();
            // juste  certaines mots cle pour tester
              rech.addElement("steak");
              rech.addElement("Deron");
              rech.addElement("plusieurs");
              rech.addElement("bbb");
              rech.addElement("eee");
          
            File file = null;
            File fileToSearch = file;
              test = new LuceneDemo1();
              test.setRech(rech);
              test.setFileToSearch(fileToSearch);
              SingleResult outcome[];
              List res = null;
            try {
               res = test.getResults();
            } catch (Exception e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
              outcome = new SingleResult[res.size()];
              for(int i = 0; i < outcome.length; i++)
              {
                  outcome = new SingleResult();
                  outcome.setKeyword((String)res.get(i));
                  outcome.setFrequency(1);
                
              }

              return outcome;
             /* Exception e;
              e;
              e.printStackTrace();
              return results;*/
             
             
          }

          public void setResults(SingleResult results[])
          {
              this.results = results;
          }
          public static void main (String[] args){
               for(int i = 0; i < outcome.length; i++)
                  {System.out.println( outcome.getFrequency());}}
          }


       
   

je suis débutante sur Alfresco .
Merci


le fichier java LuceneDemo1:


package org.alfresco.sample;




import java.io.*;
import java.security.acl.LastOwnerException;
import java.security.cert.CertificateException;
import java.util.*;

//import javax.jcr.lock.LockException;

//import net.sf.acegisecurity.context.ContextException;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.*;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.store.*;






public class LuceneDemo1
{

    public static final String FILES_TO_INDEX_DIRECTORY = "filesToIndex";
    public static final String INDEX_DIRECTORY = "indexDirectory";
    public static final String FIELD_PATH = "path";
    public static final String FIELD_CONTENTS = "contents";
    int i;
    int j;
    private Vector rech;
    Vector v;
    Vector w;
    int k;
    int h;
    int ind;
    String str;
    private File fileToSearch;

    public LuceneDemo1()
    {
        v = new Vector();
        w = new Vector();
        ind = 0;
    }

    public Vector getRech()
    {
        return rech;
    }

    public void setRech(Vector rech)
    {
        this.rech = rech;
    }

    public File getFileToSearch()
    {
        return fileToSearch;
    }

    public void setFileToSearch(File fileToSearch)
    {
        this.fileToSearch = fileToSearch;
    }

    public List getResults()
        throws Exception
    {
        Map tmp = new HashMap();
        ArrayList results = new ArrayList();
        createIndex(fileToSearch);
        for(; i < rech.size(); i++)
        {
            searchIndex(rech.elementAt(i).toString());
        }

        for(; j < w.size(); j++)
        {
            for(k = 0; k < w.size(); k++)
            {
                if(w.elementAt(j).toString().equals(w.elementAt(k).toString()) && j <= k)
                {
                    if(ind == 0)
                    {
                        if(!w.elementAt(j).toString().equals(fileToSearch.getAbsolutePath()))
                        {
                            tmp.put(w.elementAt(j).toString(), " ");
                        }
                        ind = 1;
                    }
                    if(!v.elementAt(k).toString().equals(fileToSearch.getAbsolutePath()))
                    {
                        tmp.put(v.elementAt(k).toString(), " ");
                    }
                }
            }

            ind = 0;
        }

        String str;
        for(Iterator iterator = tmp.keySet().iterator(); iterator.hasNext(); results.add(str))
        {
            str = (String)iterator.next();
        }

        return results;
    }

    public void createIndex(File file)
        throws CertificateException, LastOwnerException, IOException
    {
        Analyzer analyzer = new StandardAnalyzer();
        boolean recreateIndexIfExists = true;
        IndexWriter indexWriter = new IndexWriter("indexDirectory", analyzer, recreateIndexIfExists);
        Document document = new Document();
        String path = file.getCanonicalPath();
        document.add(new Field("path", path, org.apache.lucene.document.Field.Store.YES, org.apache.lucene.document.Field.Index.UN_TOKENIZED));
        java.io.Reader reader = new FileReader(file);
        document.add(new Field("contents", reader));
        indexWriter.addDocument(document);
        indexWriter.optimize();
        indexWriter.close();
    }

    public void searchIndex(String searchString)
        throws IOException, ParseException
    {
        Directory directory = FSDirectory.getDirectory("indexDirectory");
        IndexReader indexReader = IndexReader.open(directory);
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        Analyzer analyzer = new StandardAnalyzer();
        QueryParser queryParser = new QueryParser("contents", analyzer);
        Query query = queryParser.parse(searchString);
        Hits hits = indexSearcher.search(query);
        String path;
        for(Iterator it = hits.iterator(); it.hasNext(); w.addElement(path))
        {
            Hit hit = (Hit)it.next();
            Document document = hit.getDocument();
            path = document.get("path");
            v.addElement(rech.elementAt(i).toString());
        }

    }
  
}


le fichier java SingleResult::

package org.alfresco.sample;

public class SingleResult
{

    private String keyword;
    private int frequency;
    private boolean select;
    public SingleResult()
    {
    }

    public boolean getselect()
    {
        return select;
    }

    public void setselect(boolean select)
    {
        this.select = select;
    }
    public String getKeyword()
    {
        return keyword;
    }

    public void setKeyword(String keyword)
    {
        this.keyword = keyword;
    }

    public int getFrequency()
    {
        return frequency;
    }

    public void setFrequency(int frequency)
    {
        this.frequency = frequency;
    }
    public static void main(String [] arg){
       
       
    }
   
    abstract class Occurence implements Comparable {

       private int id;
       private String term;
       private int occ;
      
       public Occurence(int id,String term){
         this.id = id;
         this.term = term;
         this.occ = 1;
       }
      
       public boolean incr(int id,String term) {
         if (this.id == id && this.term.equals(term)) {
           this.occ++;
           return true;
         } else {
           return false;
         }
       }
      
       public String toString() {
         String string = "The term '" + this.term + "'";
         string += " has " + this.occ + " occurences";
         string += " in the " + this.id + "-th document.";
         return string;
       }

       public int compareTo(Occurence occ) {
         int diff = 0;
         String fst, snd;
         Integer i,j;
         i = this.id;
         j = occ.id;
         diff = i.compareTo(j);
         if (diff == 0) {
           fst = this.term;
           snd = occ.term;
           diff = fst.compareTo(snd);
           if (diff == 0) {
             i = this.occ;
             j = occ.occ;
             diff = i.compareTo(j);
             return -diff;
           } else { return diff; }
         } else { return diff; }
       }
      
      
     
      
     }
}


et enfin la page jsp dans web.jsp.extension WebscriptDialog:


<%–
* Copyright (C) 2005-2007 Alfresco Software Limited.

* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception.  You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
–%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a"%>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r"%>

<%@ page buffer="32kb" contentType="text/html;charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ page import="javax.faces.context.FacesContext"%>
<%@ page import="org.alfresco.web.app.Application"%>
<%@ page import="org.alfresco.web.bean.content.AddContentDialog"%>
<%@ page import="org.alfresco.web.app.servlet.FacesHelper"%>
<%@ page import="org.alfresco.web.ui.common.PanelGenerator"%>
<%@ page import="org.alfresco.sample.WebscriptDialog"%>
<%@ page import="org.alfresco.sample.LuceneDemo1"%>
<%@ page import="org.alfresco.sample.SingleResult"%>

<%
boolean fileUploaded = false;

WebscriptDialog dialog = (WebscriptDialog) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "WebscriptDialog");
if (dialog != null && dialog.getFileName() != null)
{
fileUploaded = true;
}
%>

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/validation.js"> </script>

<%
if (fileUploaded)
{
PanelGenerator.generatePanelStart(out, request.getContextPath(), "yellowInner", "#ffffcc");
out.write("<img alt='' align='absmiddle' src='");
out.write(request.getContextPath());
out.write("/images/icons/info_icon.gif' />  ");
out.write(dialog.getFileUploadSuccessMsg());
PanelGenerator.generatePanelEnd(out, request.getContextPath(), "yellowInner");
out.write("<div style='padding:2px;'></div>");
}
%>

<table cellpadding="2" cellspacing="2" border="0" width="100%">

<%
if (fileUploaded == false)
{
%>


<tr>
<td colspan="3" class="wizardSectionHeading"><hSmiley SurprisedutputText id="text0" value="#{msg.upload_content}" /></td>
</tr>

<tr>
<td>
<hSmiley TongueanelGrid id="upload_panel" columns="2" cellpadding="2" cellspacing="2" border="0" width="100%" columnClasses="panelGridLabelColumn,panelGridValueColumn,panelGridRequiredImageColumn">

<hSmiley SurprisedutputText value="#{msg.locate_content}" style="padding-left:8px"/>


<hSmiley SurprisedutputText id="out_schema" value="#{msg.file_location}:" style="padding-left:8px" />
<r:upload id="uploader" value="#{DialogManager.bean.fileName}" framework="dialog"/>
</hSmiley TongueanelGrid>

</td>
</tr>
<%}
if (fileUploaded)
{
%>


<tr>
<td colspan="3">

<table border="0" cellspacing="2" cellpadding="2" class="selectedItems">
<tr>
<td colspan="2" class="selectedItemsHeader"><hSmiley SurprisedutputText id="text2" value="#{msg.uploaded_content}" />

</td>
</tr>
<tr>
<td class="selectedItemsRow"><hSmiley SurprisedutputText id="text3" value="#{WebscriptDialog.fileName}" /></td>
<td><a:actionLink image="/images/icons/delete.gif" value="#{msg.remove}" action="#{WebscriptDialog.removeUploadedFile}" showLink="false" id="link1" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="paddingRow"></td>
</tr>
<tr>
<td colspan="3" class="wizardSectionHeading"> <hSmiley SurprisedutputText id="myresults" value="Resultats" />
</td>
</tr>
<tr>
<td class="paddingRow"></td>
</tr>
<tr>
<td colspan="3">


<h:dataTable id="dt1" value="#{DialogManager.bean.results}" var="item" bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3" first="0" rows="4" width="50%" dir="LTR" frame="hsides" rules="all" summary="This is a JSF code to create dataTable." >

<f:facet name="header">
        <hSmiley SurprisedutputText value="Results de rechercge" />
</f:facet>

<h:column>
        <f:facet name="header">
        <hSmiley SurprisedutputText value="Mot cle" />
        </f:facet>
             <hSmiley SurprisedutputText value="#{item.keyword}"></hSmiley SurprisedutputText>
</h:column>

<h:column>
        <f:facet name="header">
        <hSmiley SurprisedutputText value="Frequence"/>
        </f:facet>
             <hSmiley SurprisedutputText value="#{item.frequency}"></hSmiley SurprisedutputText>
</h:column>


<f:facet name="footer">
        <hSmiley SurprisedutputText value="The End" />
</f:facet>

</h:dataTable>


</td>
</tr>
<tr>
<td colspan="3" class="wizardSectionHeading"> <hSmiley SurprisedutputText id="text4" value="#{msg.general_properties}" /></td>
</tr>
<tr>
<td class="paddingRow"></td>
</tr>
<tr>
<td align="middle"><h:graphicImage id="img0" value="/images/icons/required_field.gif" alt="#{msg.required_field}" /></td>
<td><hSmiley SurprisedutputText id="text5" value="#{msg.name}:" /></td>
<td width="85%"><h:inputText id="file-name" value="#{WebscriptDialog.fileName}" maxlength="1024" size="35" onkeyup="checkButtonState();" onchange="checkButtonState();" /></td>
</tr>
<tr>
<td></td>
<td><hSmiley SurprisedutputText id="text6" value="#{msg.type}:" /></td>
<td><h:selectOneMenu id="object-type" value="#{WebscriptDialog.objectType}">
<f:selectItems value="#{WebscriptDialog.objectTypes}" />
</h:selectOneMenu></td>
</tr>
<tr>
<td></td>
<td><hSmiley SurprisedutputText id="text12" value="#{msg.encoding}:" /></td>
<td><h:selectOneMenu id="encoding" value="#{WebscriptDialog.encoding}">
<f:selectItems value="#{WebscriptDialog.encodings}" />
</h:selectOneMenu></td>
</tr>
<tr>
<td></td>
<td><hSmiley SurprisedutputText id="text7" value="#{msg.content_type}:" /></td>
<td><r:mimeTypeSelector id="mime-type" value="#{WebscriptDialog.mimeType}" /></td>
</tr>

<%
if (dialog.getOtherPropertiesChoiceVisible())
{
%>

<tr>
<td class="paddingRow"></td>
</tr>
<tr>
<td colspan="3" class="wizardSectionHeading"> <hSmiley SurprisedutputText id="text8" value="#{msg.other_properties}" /></td>
</tr>
<tr>
<td colspan="3">
<table style="padding-top: 2px;">
<tr>
<td colspan="3"><hSmiley SurprisedutputText id="text9" value="#{msg.modify_props_help_text}" /></td>
</tr>
<tr>
<td class="paddingRow"></td>
</tr>
<tr>
<td><h:selectBooleanCheckbox value="#{WebscriptDialog.showOtherProperties}" /></td>
<td width="100%"><hSmiley SurprisedutputText id="text10" value="#{msg.modify_props_when_page_closes}" /></td>
</tr>

</table>
</td>
</tr>

<%
}
}
%>

</table>

<script type="text/javascript">
var finishButtonPressed = false;
window.onload = pageLoaded;

function pageLoaded()
{
<% if (fileUploaded) { %>
document.getElementById("dialog").onsubmit = validate;
<% } %>
document.getElementById("dialog:finish-button").onclick = function() {finishButtonPressed = true; clear_dialog();}
}

function checkButtonState()
{
if (document.getElementById("dialog:dialog-body:file-name").value.length == 0 )
{
document.getElementById("dialog:finish-button").disabled = true;
}
else
{
document.getElementById("dialog:finish-button").disabled = false;
}
}

function validate()
{
if (finishButtonPressed)
{
finishButtonPressed = false;
return validateName(document.getElementById("dialog:dialog-body:file-name"),
unescape('<aSmiley SurprisedutputText id="text11" value="#{msg.validation_invalid_character}" encodeForJavaScript="true" />'), true);
}
else
{
return true;
}
}
</script>
7 Replies
choixged
Active Member

Re: problème avec les actions

Bonjour tout le monde

il semble que ma question n'est pas bien clair (vue la longueur du message que je viens d'envoyer)
Bref ,le problème est dans la classe WebscriptDialog.java ,je sais pas comment créer ma classe action-executer ,et y introduire mon code (qui fait la recherche par mot clé).

Voila j’espère que quelqu'un a une réponse.

merci
cleseach
Active Member II

Re: problème avec les actions

Bonjour,

il semble que ma question n'est pas bien clair (vue la longueur du message que je viens d'envoyer)
Correct ! Je n'ai pas lu votre premier post car il m'a brûlé les yeux ;-)
Utilisez donc les balises
 : en plus de faciliter la lecture, elles mettent de la jolie couleur qui embélit les pages de ce forum.

[quote="choixged"]ça n'as pas marché[/quote]
Deuxième problème dans votre premier message. Il faut expliquer ce qui n'a pas marché, les erreurs obtenues, les tests réalisés.

Cordialement,
Charles Le Seac'h
choixged
Active Member

Re: problème avec les actions

merci pour votre réponse

Le probleme que je fais Run as –> Ant build j'obtiens comme erreur :


Buildfile: C:\Documents and Settings\Administrateur\workspace\newaction\build.xml
package:

BUILD FAILED
C:\Documents and Settings\Administrateur\workspace\newaction\build.xml:20: A zip file cannot include itself

Total time: 821 milliseconds

et donc le probleme viens du code .
Je veux juste savoir si la structure de la classe WebscriptDialoque est correcte.

merci
cleseach
Active Member II

Re: problème avec les actions

Bonjour,

Je pense que les forums Alfresco ne pourront rien pour vous… votre problème concerne Ant, pas (encore) votre code Alfresco !

Cordialement,
Charles Le Seac'h
choixged
Active Member

Re: problème avec les actions

D'accord ,en tous cas merci de votre réponse.

Mais je ressens que j'ai bien du mal a expliquer le probleme.

Bon voilà si j'ai un script xxx. java et je veux l'introduire dans une classe XXXActionExecuter qui hérite de la classe ActionExecuterAbstractBase ,comment faire?est ce que ce que j'ai fais dans la classe WebscriptDialog est correct?

Merci
cleseach
Active Member II

Re: problème avec les actions

Bonjour,

Je suis vraiment navré, mais je ne comprends rien à ce que vous voulez faire.
Pourquoi ne pas repartir de votre besoin (en français) plutôt que de se lancer dans l'écriture d'un (long et illisible… balise
) code qui n'est pas testé ou déployable vu que le build.xml est erroné ?

Cordialement,
Charles Le Seac'h
choixged
Active Member

Re: problème avec les actions

En tout cas Merci