source: publico/SDE/trunk/StrDocElemDef.py @ 802

Última Alteração nesse arquivo desde 802 foi 802, incluída por ciciliati, 14 anos atrás

Importação inicial do SDE (Structured Document Editor), versão 0.0.2, distribuída com o SAPL 2.0.2 .

File size: 6.9 KB
Linha 
1# -*- coding: iso-8859-1 -*-
2
3"""
4from OFS.SimpleItem import SimpleItem
5from Globals import Persistent
6from Acquisition import Implicit
7"""
8from OFS.OrderedFolder import OrderedFolder
9from Products.ZCatalog.CatalogAwareness import CatalogAware
10from OFS.ObjectManager import ObjectManager
11from OFS.PropertyManager import PropertyManager
12import string
13
14def StrDocElemDef_addForm(self, REQUEST):
15    "HTML para adicionar um novo objeto StrDocElemDef"
16    return """
17<HTML>
18<HEAD><TITLE>Add StrDocElementDefinition</TITLE></HEAD>
19<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
20<H2>Add StrDocElementDefinition</H2>
21<form action="StrDocElemDef_add"><table>
22<tr><th>Id</th>
23    <td><input type=text name=id></td>
24</tr>
25<tr><td></td><td><input type=submit value=" Add "></td></tr>
26</table></form>
27</body></html>
28"""
29
30def StrDocElemDef_add(self,REQUEST):
31    "Método para adicionar um objeto StrDocElemDef"
32    instance = StrDocElemDef(REQUEST)
33    instance.reindex_object()
34    self._setObject(REQUEST.id,instance)
35    instance=getattr(self.this(),REQUEST.id)
36    REQUEST.RESPONSE.redirect(instance.aq_parent.absolute_url() + '/manage_main')
37
38class StrDocElemDef(OrderedFolder,CatalogAware,ObjectManager,PropertyManager):
39    "Classe de definição de elementos de documentos estruturados"
40    meta_type = 'StrDocElementDefinition'
41
42    filtered_meta_types = []
43    __tEmPtYPe = {'product': 'StructuredDoc', 'name': 'StrDocElementDefinition', 'permission': 'Add StrDocElementDefinitions', 'interfaces': [], 'visibility': 'Global', 'instance': None, 'action': 'manage_addProduct/StructuredDoc/StrDocElemDef_addForm', 'container_filter': None}
44    filtered_meta_types.append(__tEmPtYPe)
45    __tEmPtYPe = {'product': 'StructuredDoc', 'name': 'StrDocAttrDef', 'permission': 'Add StrDocAttrDefs', 'interfaces': [], 'visibility': 'Global', 'instance': None, 'action': 'manage_addProduct/StructuredDoc/StrDocAttrDef_addForm', 'container_filter': None}
46    filtered_meta_types.append(__tEmPtYPe)
47    __tEmPtYPe = {'product': 'StructuredDoc', 'name': 'StrDocElemDefLink', 'permission': 'Add StrDocElemDefLinks', 'interfaces': [], 'visibility': 'Global', 'instance': None, 'action': 'manage_addProduct/StructuredDoc/StrDocElemDefLink_addForm', 'container_filter': None}
48    filtered_meta_types.append(__tEmPtYPe)
49    __tEmPtYPe = {'product': 'PythonScripts', 'name': 'Script (Python)', 'permission': 'Add Python Scripts', 'interfaces': [], 'visibility': 'Global', 'instance': None, 'action': 'manage_addProduct/PythonScripts/pyScriptAdd', 'container_filter': None}
50    filtered_meta_types.append(__tEmPtYPe)
51    del(__tEmPtYPe)
52
53    def __init__(self,REQUEST):
54        self.id = REQUEST.id
55        self.manage_addProperty('initial_text','','text')
56        self.manage_addProperty('optional','','boolean')
57        self.manage_addProperty('multiple','','boolean')
58        self.manage_addProperty('has_own_value','1','boolean')
59        self.manage_addProperty('exclusivity_group','-1','int')
60        self.manage_addProperty('xml_tag','','string')
61        self.manage_addProperty('element_name','','string')
62
63    # *** isMultiple
64    def isMultiple(self):
65        return self.multiple
66
67    # *** isOptional
68    def isOptional(self):
69        return self.optional
70
71    # *** name
72    def name(self):
73        if self.element_name:
74            return self.element_name
75        else:
76            return self.id
77
78    # *** renderXSD
79    def renderXSD(self,indent=""):
80        group_open = -1
81        tag = self.xmlTag()
82        shift = "   "
83        minOccurs = "minOccurs=\"1\""
84        maxOccurs = "maxOccurs=\"1\""
85        printed =""
86
87        if self.isMultiple():
88            maxOccurs = "maxOccurs=\"unbounded\""
89        if self.isOptional():
90            minOccurs = "minOccurs=\"0\""
91        printed+= "%s<xs:element name=\"%s\" %s %s>" % (indent,tag,minOccurs,maxOccurs)
92        printed+= "%s   <xs:complexType>" % indent
93        printed+= "%s      <xs:sequence>" % indent
94        if self.has_own_value:
95            printed+= "%s         <xs:element name=\"%s_text\" type=\"xs:string\" />" % (indent,tag)
96        subtree = self.objectValues(["StrDocElementDefinition","StrDocElemDefLink"])
97        if len(subtree) > 0:
98            for x in subtree:
99                if x.exclusivity_group != group_open:
100                    if group_open != -1:
101                        printed+= "%s         </xs:choice>" % indent
102                    printed+= "%s         <xs:choice>" % indent
103                    group_open = x.exclusivity_group
104                    shift = shift + shift
105                printed+= x.renderXSD(indent + "      " + shift)
106            if group_open != -1:
107                printed+= "%s         </xs:choice>" % indent
108                group_open = -1
109        printed+= "%s      </xs:sequence>" % indent
110        printed+= "%s   </xs:complexType>" % indent
111        printed+= "%s</xs:element>" % indent
112        return printed
113
114    # *** renderXSDv
115    def renderXSDv(self,indent=""):
116        tag = self.xmlTag()
117        group_open = -1
118        shift = "   "
119        printed=""
120        printed+= "%s<xs:complexType name=\"%sType\">\n" % (indent,tag)
121        printed+= "%s   <xs:sequence>\n" % indent
122        if self.has_own_value:
123            printed+= "%s      <xs:element name=\"%s_text\" type=\"xs:string\" />\n" % (indent,tag)
124        subtree = self.objectValues(["StrDocElementDefinition","StrDocElemDefLink"])
125        if len(subtree) > 0:
126            for x in subtree:
127                if x.exclusivity_group != group_open:
128                    if group_open != -1:
129                        printed+= "%s      </xs:choice>\n" % indent
130                        shift = shift[0:-3]
131                    printed+= "%s      <xs:choice>\n" % indent
132                    group_open = x.exclusivity_group
133                    shift = shift + "   "
134                if x.isOptional():
135                    minOccurs = "0"
136                else:
137                    minOccurs = "1"
138                if x.isMultiple():
139                    maxOccurs = "unbounded"
140                else:
141                    maxOccurs = "1"
142                tag_x = x.xmlTag()
143                printed+= "%s      <xs:element name=\"%s\" type=\"%sType\" minOccurs=\"%s\" maxOccurs=\"%s\"/>\n" % (indent+shift,tag_x,tag_x,minOccurs,maxOccurs)
144            if group_open != -1:
145                printed+= "%s      </xs:choice>\n" % indent
146                group_open = -1
147                shift = shift[0:-3]
148        printed+= "%s   </xs:sequence>\n" % indent
149        printed+= "%s   <xs:attribute name=\"id\" type=\"xs:string\" />\n" % indent
150        for a in self.objectValues('StrDocAttrDef'):
151            printed+= '%s   <xs:attribute name="%s" type="xs:%s" />\n' % (indent,  a.id, a.xsd_type)
152        printed+= "%s</xs:complexType>\n" % indent
153        subtree = self.objectValues("StrDocElementDefinition")
154        for x in subtree:
155            printed+= x.renderXSDv(indent)
156        return printed
157
158    # *** xmlTag
159    def xmlTag(self):
160        if self.xml_tag == "":
161            return string.lower(self.id)
162        else:
163            return self.xml_tag
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.