cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <gregor.bertr...@daimlerchrysler.com>
Subject reload problem
Date Mon, 08 Sep 2003 07:36:01 GMT
Hello,

here are the essential parts of my sitemap:


<map:match pattern="acltrans">
       <map:generate src="content/testacl2.xml" type="file"/>
       <map:transform type="acltransformer">
           <map:parameter name="ignore_type" value="false"/>
       </map:transform>
       <map:serialize type="xml"/>
</map:match>


<map:transformer name="acltransformer" src=
"com.daimlerchrysler.mediathek.acl.ACLTransformer">
</map:transformer>




Here my Java Class, I' m sorry but it' quite big:


public class ACLTransformer extends AbstractSAXTransformer implements
Initializable
{
      /**
       * Field NAMESPACE
       * Value: {@value NAMESPACE}
       */
      public static final String NAMESPACE =
"http://daimlerchrysler.com/mediathek/acl";
      /**
       * Field NAMESPACE_ELEMENT
       * Value: {@value NAMESPACE_ELEMENT}
       */
      public static final String NAMESPACE_ELEMENT = "acl";
      /**
       * Field ACLTRANSFORMER_ELEMENT_FIRST
       * Value: {@value ACLTRANSFORMER_ELEMENT_FIRST}
       */
      public static final String ACLTRANSFORMER_ELEMENT_FIRST = "acl1";
      /**
       * Field ACLTRANSFORMER_ELEMENT_SECOND
       * Value: {@value ACLTRANSFORMER_ELEMENT_SECOND}
       */
      public static final String ACLTRANSFORMER_ELEMENT_SECOND = "acl2";
      /**
       * Field ACLTRANSFORMER_ELEMENT_THIRD
       * Value: {@value ACLTRANSFORMER_ELEMENT_THIRD}
       */
      public static final String ACLTRANSFORMER_ELEMENT_THIRD = "acl3";
      /**
       * Field ACLS
       * Value: {@value ACLS}
       */
      public static final String ACLS = "acls";
      /**
       * Field ITEMS
       * Value: {@value ITEMS}
       */
      public static final String ITEMS = "items";
      /**
       * Field ITEM
       * Value: {@value ITEM}
       */
      public static final String ITEM = "item";
      /**
       * Field TYPE
       * Value: {@value TYPE}
       */
      public static final String TYPE = "type";

      /**
       * Field MODE_TRANSFORM_NONE
       * Value: {@value MODE_TRANSFORM_NONE}
       */
      protected static final int MODE_TRANSFORM_NONE = 0;
      /**
       * Field MODE_TRANSFORM_FIRST
       * Value: {@value MODE_TRANSFORM_FIRST}
       */
      protected static final int MODE_TRANSFORM_FIRST = 1;
      /**
       * Field MODE_TRANSFORM_SECOND
       * Value: {@value MODE_TRANSFORM_SECOND}
       */
      protected static final int MODE_TRANSFORM_SECOND = 2;
      /**
       * Field MODE_TRANSFORM_THIRD
       * Value: {@value MODE_TRANSFORM_THIRD}
       */
      protected static final int MODE_TRANSFORM_THIRD = 3;
      /**
       * Field MODE_NONE
       * Value: {@value MODE_NONE}
       */
      protected static final int MODE_NONE = 4;
      /**
       * Field MODE_ACL
       * Value: {@value MODE_ACL}
       */
      protected static final int MODE_ACL = 7;
      /**
       * Field MODE_FOLDER
       * Value: {@value MODE_FOLDER}
       */
      protected static final int MODE_FOLDER = 8;

      /**
       * Field mode_transform
       */
      protected int mode_transform;
      /**
       * Field mode
       */
      protected int mode;
      /**
       * Field types_count
       */
      protected int types_count;
      /**
       * Field ignore_type
       */
      protected boolean ignore_type;
      /**
       * Field processing_acl
       */
      protected boolean processing_acl;
      /**
       * Field last_in_hierarchy
       */
      protected boolean last_in_hierarchy;
      /**
       * Field rights
       */
      protected HashMap rights;
      /**
       * Field aright
       */
      protected Right aright;
      /**
       * Field hierarch_rights
       */
      protected LinkedList hierarch_rights;
      /**
       * Field types_nums
       */
      protected LinkedList types_nums;
      /**
       * Field endOfTransformation
       */
      protected boolean endOfTransformation;


      /**
       *
       * setzt die Variablen auf Standardwerte
       * @param resolver SourceResolver
       * @param objectModel Map
       * @param src String
       * @param par Parameters
       * @throws ProcessingException
       * @throws SAXException
       * @throws IOException
       * @see
org.apache.cocoon.sitemap.SitemapModelComponent#setup(SourceResolver, Map,
String, Parameters)
       */
      public void setup(SourceResolver resolver,
            Map objectModel,
            String src,
            Parameters par)
            throws ProcessingException, SAXException, IOException
      {

            this.ignore_type = par.getParameterAsBoolean("ignore_type",
false);
            this.mode_transform = par.getParameterAsInteger("trans_mode",
1);
      }

      public void initialize()
      {
            this.mode = MODE_NONE;
            this.mode_transform = MODE_TRANSFORM_NONE;
            this.types_count = 0;
            this.processing_acl = false;
            this.rights = new HashMap();
            this.aright = null;
            this.hierarch_rights = new LinkedList();
            this.types_nums = new LinkedList();
            this.aclt2 = new ACLTransformer2();
      }

      /**
       *
       * verarbeitet die Anfangstags der Elemente der XMLstruktur
       * @param uri String
       * @param name String
       * @param raw String
       * @param attr Attributes
       * @throws SAXException
       * @see org.xml.sax.ContentHandler#startElement(String, String,
String, Attributes)
       */
      public void startElement(String uri, String name, String raw,
            Attributes attr) throws SAXException
      {
            if(uri != null && uri.equals(NAMESPACE))
            {

                  if(name.equals(ACLTRANSFORMER_ELEMENT_FIRST)) //soll zum
ersten Mal...
                  {
                        this.mode_transform = MODE_TRANSFORM_FIRST;
                        this.endOfTransformation = false;
                        super.startElement("", NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_SECOND, NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_SECOND, attr);
                  }
                  else if(name.equals(ACLTRANSFORMER_ELEMENT_SECOND))
//...zum zweiten Mal...
                  {
                        this.mode_transform = MODE_TRANSFORM_SECOND;
                        this.endOfTransformation = false;
                        super.startElement("", NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_THIRD, NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_THIRD, attr);
                  }
                  else if(name.equals(ACLTRANSFORMER_ELEMENT_THIRD))
//...oder zum dritten Mal transformiert werden.
                  {
                        this.endOfTransformation = true;
                        this.mode_transform = MODE_TRANSFORM_THIRD;
                  }
                  else if(name.equals(ACLS))
                  {
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              this.mode = MODE_ACL;
                              super.startElement("", NAMESPACE_ELEMENT +
":" + name, NAMESPACE_ELEMENT + ":" + name, attr);
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_SECOND)
                        {
                              this.mode = MODE_ACL;
                        }
                  }
                  else if(name.equals(ITEMS))
                  {
                        this.mode = MODE_FOLDER;
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              super.startElement("", NAMESPACE_ELEMENT +
":" + name, NAMESPACE_ELEMENT + ":" + name, attr);
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_SECOND)
                        {
                              this.last_in_hierarchy = true;
                        }
                  }
                  else if(name.equals(ITEM))
                  {
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              if(this.mode == MODE_ACL)
                              {
                                    processing_acl = true;
                                    save_acl(name, attr, true);
                              }
                              else
                              {
                                    super.startElement("",
NAMESPACE_ELEMENT + ":" + name, NAMESPACE_ELEMENT + ":" + name, attr);
                              }
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_SECOND)
                        {
                              if(this.mode == MODE_ACL)
                              {
                                    this.last_in_hierarchy = false;
                                    processing_acl = true;
                                    save_acl(name, attr, false);
                              }
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_THIRD)
                        {
                              processing_acl = true;
                              save_acl(name, attr, true);
                        }
                  }
                  else if(this.processing_acl)
                  {
                        if(this.mode_transform == MODE_TRANSFORM_SECOND)
                        {
                              save_subrights(name, attr, false);
                        }
                        else
                        {
                              save_subrights(name, attr, true);
                        }
                  }
                  else
                  {
                        throw new SAXException("Unknown element: " + name);
                  }
            }
            else
            {
                  super.startElement(uri, name, raw, attr);
            }
      }

      /**
       * Method save_acl
       * @param name String
       * @param attr Attributes
       * @param additive boolean
       */
      private void save_acl(String name, Attributes attr, boolean additive)
throws SAXException
      {
            if(this.aright == null) this.aright = new Right(name, attr);
            else aright.addRight(new Right(name, attr), additive, this
.ignore_type);
      }

      /**
       * Method save_subrights
       * @param name String
       * @param attr Attributes
       * @param additive boolean
       */
      private void save_subrights(String name, Attributes attr, boolean
additive)
      {
            this.aright.addSubright(new Simple_right(name, attr), additive,
this.endOfTransformation);
      }

      /**
       *
       * verarbeitet die Texte zwischen den Tags,
       * diese werden vom ACLTransformer nicht verwertet
       * @param buffer char[]
       * @param start int
       * @param length int
       * @throws SAXException
       * @see org.xml.sax.ContentHandler#characters(char[], int, int)
       */
      public void characters(char[] buffer, int start, int length)
            throws SAXException
      {
            switch(this.mode_transform)
            {
                  case MODE_TRANSFORM_NONE :
                        super.characters(buffer, start, length);
                        break;
                  case MODE_TRANSFORM_FIRST :
                        break;
                  case MODE_TRANSFORM_SECOND :
                        break;
                  case MODE_TRANSFORM_THIRD :
                        break;
                  case MODE_ACL :
                        break;
            }
      }

      /**
       *
       * verarbeitet die Endtags
       * @param uri String
       * @param name String
       * @param raw String
       * @throws SAXException
       * @see org.xml.sax.ContentHandler#endElement(String, String, String)
       */
      public void endElement(String uri, String name, String raw)
            throws SAXException
      {
            if(uri != null && uri.equals(NAMESPACE))
            {

                  if(name.equals(ACLTRANSFORMER_ELEMENT_FIRST))
                  {
                        this.mode_transform = MODE_TRANSFORM_SECOND;
                        super.endElement("", NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_SECOND, NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_SECOND);
                  }
                  else if(name.equals(ACLTRANSFORMER_ELEMENT_SECOND))
                  {
                        this.mode_transform = MODE_TRANSFORM_THIRD;
                        super.endElement("", NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_THIRD, NAMESPACE_ELEMENT + ":" +
ACLTRANSFORMER_ELEMENT_THIRD);
                  }
                  else if(name.equals(ACLTRANSFORMER_ELEMENT_THIRD))
                  {
                        this.write_rights_tags(false);
                  }
                  else if(name.equals(ITEM))
                  {
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              if(this.mode == MODE_ACL)
                              // eine ACL wird beim typspezifischen
Addieren
                              // entweder als neue ACL in die HashMap
rights eingetragen
                              // oder zu einer bereits in der HashMap
rights vorhandenen
                              // ACL desselben Typs dazuaddiert, ansonsten
werden die ACLs
                              // einfach alle in aright aufeinanderaddiert
und hier muss
                              // nichts mehr getan werden
                              {
                                    if(this.rights == null) this.rights =
new HashMap();
                                    if(!this.ignore_type)
                                    {
                                          if(this.rights.isEmpty()) this
.rights.put(this.aright.getType(), this.aright);
                                          else
                                          {
                                                Object helper = this
.rights.get(this.aright.getType());
                                                if(helper != null)
                                                {
                                                      Right nright
= (Right) helper;
                                                      this.rights.remove(
this.aright.getType());
                                                      nright.addRight(this
.aright, true, this.ignore_type);

nright.addAllSubrights(this.aright.getSubrights(), true, this
.endOfTransformation);
                                                      this
.rights.put(nright.getType(), nright);
                                                }
                                                else this.rights.put(this
.aright.getType(), this.aright);
                                          }
                                          this.aright = null;
                                    }
                                    processing_acl = false;
                              }
                              else
                              {
                                    super.endElement("", NAMESPACE_ELEMENT
+ ":" + name, NAMESPACE_ELEMENT + ":" + name);
                              }
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_SECOND)
                        // die ACLs werden alle in einer LinkedList
hierarch_rights
                        // zwischengespeichert und, wenn alle innerhalb
einer
                        // Ordnerhierarchie eingetragen sind, verarbeitet
                        {
                              if(this.mode == MODE_ACL)
                              {
                                    this.hierarch_rights.add(this.aright);
                                    this.types_count++;
                                    this.aright = null;
                                    this.processing_acl = false;
                              }
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_THIRD)
                        // die ACLs werden bei der typspezifischen
Verarbeitung,
                        // wie schon im ersten Schritt, in einer HashMap
verwaltet;
                        // ACLs, die sich auf noch nicht innerhalb der
HashMap rights
                        // gespeicherte Typen beziehen, werden in die
HashMap eingetragen;
                        // ACLs mit gespeicherten Typen werden zu denen in
der HashMap
                        // addiert
                        {
                              if(this.rights == null) this.rights = new
HashMap();
                              if(!this.ignore_type)
                              {
                                    Object helper = this.rights.get(this
.aright.getType());
                                    if(helper == null)
                                    {
                                          this.rights.put(this
.aright.getType(), this.aright);
                                    }
                                    else
                                    {
                                          this.rights.remove(this
.aright.getType());
                                          Right existing_right = (Right)
helper;
                                          existing_right.addRight(this
.aright, true, this.ignore_type);
                                          existing_right.addAllSubrights(
this.aright.getSubrights(), true, this.endOfTransformation);
                                          this
.rights.put(existing_right.getType(), existing_right);
                                    }
                                    this.aright = null;
                              }
                              processing_acl = false;
                        }
                  }
                  else if(name.equals(ACLS))
                  {
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              write_rights_tags(true);
                              super.endElement("", NAMESPACE_ELEMENT + ":"
+ name, NAMESPACE_ELEMENT + ":" + name);
                        }
                        else if(this.mode_transform ==
MODE_TRANSFORM_SECOND)
                        // für die typspezifische Speicherung wird die
Anzahl der
                        // ACLs auf einer Ebene in einer LinkedList
gespeichert
                        {
                              if(this.types_nums == null) this.types_nums
= new LinkedList();
                              this.types_nums.add(new Integer(this
.types_count));
                              this.types_count = 0;
                        }
                  }
                  else if(name.equals(ITEMS))
                  {
                        if(this.mode_transform == MODE_TRANSFORM_FIRST)
                        {
                              super.endElement("", NAMESPACE_ELEMENT + ":"
+ name, NAMESPACE_ELEMENT + ":" + name);
                              this.mode = MODE_NONE;
                        }
                        if(this.mode_transform == MODE_TRANSFORM_SECOND)
                        {
                              if(this.last_in_hierarchy)
                              // wir haben den tiefsten Punkt unserer
ACLHierarchie
                              // erreicht und können jetzt die auf dem Weg
in einer LinkedList
                              // gespeicherten ACLs zusammenaddieren,
entweder typübergreifend zu
                              // einer ACL, die in aright gespeichert wird,
oder typspezifisch zu
                              // mehreren ACLs, die in der HashMap rights
gespeichert werden
                              {
                                    if(this.ignore_type)
                                    {
                                          for(int i = 0; i < this
.hierarch_rights.size(); i++)
                                          {
                                                Right helper = (Right)this
.hierarch_rights.get(i);
                                                if(this.aright == null)
this.aright = helper;
                                                else
                                                {
                                                      this
.aright.addRight(helper, false, this.ignore_type);
                                                      this
.aright.addAllSubrights(helper.getSubrights(), false, this
.endOfTransformation);
                                                }
                                          }
                                    }
                                    else
                                    {
                                          for(int i = 0; i < this
.hierarch_rights.size(); i++)
                                          {
                                                Right helper = (Right)this
.hierarch_rights.get(i);
                                                Object helper_2 = this
.rights.get(helper.getType());
                                                if(helper_2 == null) this
.rights.put(helper.getType(), helper);
                                                else
                                                {
                                                      Right existing_right
= (Right) helper_2;
                                                      this
.rights.remove(helper.getType());

existing_right.addRight(helper, false, false);

existing_right.addAllSubrights(helper.getSubrights(), false, this
.endOfTransformation);
                                                      this
.rights.put(existing_right.getType(), existing_right);
                                                }
                                          }
                                    }
                                    this.write_rights_tags(true);
                                    this.last_in_hierarchy = false;
                              }
                              // da wir in der Hierarchie wieder
aufsteigen, müssen wir aus
                              // der LinkedList hierarch_rights die auf der
Hierarchieebene
                              // liegenden ACLs wieder entfernen

                              Integer helper = (Integer)this
.types_nums.getLast();
                              for(int i = 0; i < helper.intValue(); i++)
                              {
                                    this.hierarch_rights.removeLast();
                              }
                              this.types_nums.removeLast();
                        }
                  }
                  else if(this.processing_acl)
                  {

                  }
                  else
                  {
                        this.mode = MODE_NONE;
                  }
            }
            else
            {
                  super.endElement(uri, name, raw);
            }
      }

      protected void start_an_Element(String name, Attributes attr) throws
SAXException
      {
            super.startElement("", name, name, attr);
      }

      protected void end_an_Element(String name) throws SAXException
      {
            super.endElement("", name, name);
      }

      /**
       * schreibt die gespeicherten Rechte, die entweder typspezifisch in
       * einer HashMap rights addiert wurden oder typfremd in der Variable
aright
       * addiert wurden, in entsprechende Tags
       * @param write_nmsp boolean
       * @throws SAXException
       */
      private void write_rights_tags(boolean write_nmsp) throws
SAXException
      {
            String nmsp = (write_nmsp ? NAMESPACE_ELEMENT + ":" : "");
            if(this.rights.isEmpty())  //keine typspezifischen ACLS
            {
                  super.startElement("", nmsp + this.aright.getTarget(),
nmsp + this.aright.getTarget(), this.aright.getAttributes());
                  HashMap helper = this.aright.getSubrights();
                  if(!helper.isEmpty())
                  {
                        Object[] subrights = helper.values().toArray();
                        for(int i = 0; i < subrights.length; i++)
                        {
                              Simple_right sr = (Simple_right)subrights[i];
                              super.startElement("", nmsp + sr.getTarget(),
nmsp + sr.getTarget(), sr.getAttributes());
                              super.endElement("", nmsp + sr.getTarget(),
nmsp + sr.getTarget());
                        }
                  }
                  super.endElement("", nmsp + this.aright.getTarget(), nmsp
+ this.aright.getTarget());
                  this.aright = null;
                  this.processing_acl = false;
            }
            else //Hashmap auslesen und ausgeben
            {
                  Object[] typesrights = this.rights.values().toArray();
                  for(int i = 0; i < typesrights.length; i++)
                  {
                        Right atyperight = (Right)typesrights[i];
                        super.startElement("", nmsp + atyperight.getTarget
(), nmsp + atyperight.getTarget(), atyperight.getAttributes());

                        HashMap helper = atyperight.getSubrights();
                        if(!helper.isEmpty())
                        {
                              Object[] subrights = helper.values().toArray
();
                              for(int j = 0; j < subrights.length; j++)
                              {
                                    Simple_right sr
= (Simple_right)subrights[j];
                                    org.xml.sax.helpers.AttributesImpl
npermissions = new org.xml.sax.helpers.AttributesImpl(sr.getAttributes());
                                    if(this.endOfTransformation)
                                    //am Ende der Transformation werden die
Subrechte
                                    //mit den ACLs abgeglichen, d. h. was
man mit der ACL
                                    //nicht darf, darf man bei den
Subrechten auch nicht
                                    {
                                          for(int k = 0; k <
npermissions.getLength(); k++)
                                          {
                                                if
(atyperight.getRightpermission(npermissions.getQName(k)).equals("-"))
                                                npermissions.setValue(k, "
-");
                                          }
                                    }
                                    sr = new Simple_right(sr.getTarget(),
npermissions);
                                    super.startElement("", nmsp +
sr.getTarget(), nmsp + sr.getTarget(), sr.getAttributes());
                                    super.endElement("", nmsp +
sr.getTarget(), nmsp + sr.getTarget());
                              }
                        }
                        super.endElement("", nmsp + atyperight.getTarget(),
nmsp + atyperight.getTarget());
                  }
                  this.rights.clear();
                  this.processing_acl = false;
            }
      }

}



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message