Пример #1
0
    def openProject(self, projectdir):   # File projectdir
            # Check to see that no other project is open at the moment
            # It would be interesting to allow multiple projects but this would complicate the view        
        if self.model.getCurrentProject() != None:
            self.view.status("Cannot but open one project at a time, bucko!")
            return None
        
        if projectdir == None: 
            return None
            
        self.view.status( "Processing directory "+projectdir.getName() )
        self.model.openProject( 0, projectdir)
           # Jython doesn't have listdir; use Java instead
        # for item in filter( lambda x: re.search(".*\.story",x), listdir( projectdir.getPath() ) ):
        myitems = filter( self.filefilter, projectdir.listFiles() )
        if len(myitems) > 0:
            for fileitem in myitems:
                inputfile=open(fileitem.getPath(),"r")
                unparsedcontent=inputfile.read()
                inputfile.close()
                try:
                    self.view.status("Examining file "+fileitem.getName() )
                    doc = Builder().build( fileitem )
                    summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
                    content = doc.toXML()
                    self.model.addItemToProject( fileitem, summary, content )
                except XMLException, e:
                    ndebug(unparsedcontent)
                    self.view.status("Can't find an XML parser: "+e.toString() )
                    ndebug("Can't find an XML parser: "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: not well-formed: ``"+e.toString()+"'')" , unparsedcontent )
                except ParsingException, e:
# Yawn! Jython can't seem to call FileReader successfully. It always returns empty content.
# Maybe something to do with wrapping the arguments. 
#                    myunparsedcontent=""
#                    filereader=FileReader( fileitem )
#                    filereader.read(myunparsedcontent)                    
                    ndebug(unparsedcontent)
                    self.view.status("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
                    ndebug("The XML Parser reports errors on the file " + fileitem.getName() + ": "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: parser errors: ``"+e.toString()+"'')" , unparsedcontent )
                    
#                   ndebug("My Junk:" + myjunk)
                    
                except IOException, e:
                    self.view.status("The file "+fileitem.getName()+" could not be opened: "+e.toString() )
                    ndebug("The file "+fileitem.getName()+" could not be opened: "+e.toString() )
                    self.model.addItemToProject( fileitem, fileitem.getName() + " (Error: file may be truncated ``"+e.toString()+"'')" , unparsedcontent )
Пример #2
0
 def openNewItem(self,itempath):
     itempath=self.normalizeItemFileName(itempath)
     # Construct a sane default instance of an item
     defaultcontent = self.defaultItemContent
     # Add the item to the current model
     # ... use xom to create a new document model object with default content
     # then open the new item from the model
     fileitem = File(itempath)
     unparsedcontent=defaultcontent
     
     try:
         self.view.status("Examining file "+fileitem.name )
         doc = Builder().build( unparsedcontent, "" )
         summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
         content = doc.toXML()
         self.model.addItemToProject( fileitem, summary, content )
     except XMLException, e:
         ndebug(unparsedcontent)
         self.view.status("Can't find an XML parser: "+e.toString() )
         ndebug("Can't find an XML parser: "+e.toString() )
         self.model.addItemToProject( fileitem, fileitem.getName() + " (Warning: not well-formed: ``"+e.toString()+"'')" , unparsedcontent )
Пример #3
0
    def openNewItem(self, itempath):
        itempath = self.normalizeItemFileName(itempath)
        # Construct a sane default instance of an item
        defaultcontent = self.defaultItemContent
        # Add the item to the current model
        # ... use xom to create a new document model object with default content
        # then open the new item from the model
        fileitem = File(itempath)
        unparsedcontent = defaultcontent

        try:
            self.view.status("Examining file " + fileitem.name)
            doc = Builder().build(unparsedcontent, "")
            summary = XQueryUtil.xquery(doc, "/story/@title").get(0).getValue()
            content = doc.toXML()
            self.model.addItemToProject(fileitem, summary, content)
        except XMLException, e:
            ndebug(unparsedcontent)
            self.view.status("Can't find an XML parser: " + e.toString())
            ndebug("Can't find an XML parser: " + e.toString())
            self.model.addItemToProject(
                fileitem,
                fileitem.getName() + " (Warning: not well-formed: ``" +
                e.toString() + "'')", unparsedcontent)
Пример #4
0
            j = 1
            while j < i:
                print getValidityError(j)
                j = j + 1
        except ParsingException, ex:
            print >> sys.stderr, "Parsing Exception - audiences xml has malformed markup"
        except IOException, ex:
            print >> sys.stderr, "IO Exception - Couldn't open audiences xml " + audiencesuri
        except ex:
            print >> sys.stderr, "Other Exception during audiences provisioning: " + ex.toString(
            )

        # prepare for querying the structures
        audiences = self.doc.getRootElement()

        doctypes = XQueryUtil.xquery(self.doc, "//type")
        if doctypes == None:
            print >> stderr, "No document types defined!"

        appdomains = audiences.getChildElements("application-domain")
        if appdomains == None:
            print >> stderr, "No document types defined!"

        # LEFTOFF this is a hack to keep it working while I flesh out the rest of the code

        storynode = XQueryUtil.xquery(
            self.doc, "//type[@name='story']/new-instance-template")
        if storynode == None:
            print >> stderr, "Storynode hack couldn't find story type!"
        self.defaultContent = storynode.get(0).getValue()
Пример #5
0
    def openProject(self, projectdir):  # File projectdir
        # Check to see that no other project is open at the moment
        # It would be interesting to allow multiple projects but this would complicate the view
        if self.model.getCurrentProject() != None:
            self.view.status("Cannot but open one project at a time, bucko!")
            return None

        if projectdir == None:
            return None

        self.view.status("Processing directory " + projectdir.getName())
        self.model.openProject(0, projectdir)
        # Jython doesn't have listdir; use Java instead
        # for item in filter( lambda x: re.search(".*\.story",x), listdir( projectdir.getPath() ) ):
        myitems = filter(self.filefilter, projectdir.listFiles())
        if len(myitems) > 0:
            for fileitem in myitems:
                inputfile = open(fileitem.getPath(), "r")
                unparsedcontent = inputfile.read()
                inputfile.close()
                try:
                    self.view.status("Examining file " + fileitem.getName())
                    doc = Builder().build(fileitem)
                    summary = XQueryUtil.xquery(
                        doc, "/story/@title").get(0).getValue()
                    content = doc.toXML()
                    self.model.addItemToProject(fileitem, summary, content)
                except XMLException, e:
                    ndebug(unparsedcontent)
                    self.view.status("Can't find an XML parser: " +
                                     e.toString())
                    ndebug("Can't find an XML parser: " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() + " (Warning: not well-formed: ``" +
                        e.toString() + "'')", unparsedcontent)
                except ParsingException, e:
                    # Yawn! Jython can't seem to call FileReader successfully. It always returns empty content.
                    # Maybe something to do with wrapping the arguments.
                    #                    myunparsedcontent=""
                    #                    filereader=FileReader( fileitem )
                    #                    filereader.read(myunparsedcontent)
                    ndebug(unparsedcontent)
                    self.view.status(
                        "The XML Parser reports errors on the file " +
                        fileitem.getName() + ": " + e.toString())
                    ndebug("The XML Parser reports errors on the file " +
                           fileitem.getName() + ": " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() + " (Warning: parser errors: ``" +
                        e.toString() + "'')", unparsedcontent)

#                   ndebug("My Junk:" + myjunk)

                except IOException, e:
                    self.view.status("The file " + fileitem.getName() +
                                     " could not be opened: " + e.toString())
                    ndebug("The file " + fileitem.getName() +
                           " could not be opened: " + e.toString())
                    self.model.addItemToProject(
                        fileitem,
                        fileitem.getName() +
                        " (Error: file may be truncated ``" + e.toString() +
                        "'')", unparsedcontent)
Пример #6
0
           i=ex.getErrorCount()
           j=1
           while j < i:
              print getValidityError(j)
              j=j+1
        except ParsingException, ex:
           print >>sys.stderr, "Parsing Exception - audiences xml has malformed markup"
        except IOException, ex:
           print >>sys.stderr, "IO Exception - Couldn't open audiences xml "+audiencesuri
        except ex:
           print >>sys.stderr, "Other Exception during audiences provisioning: " + ex.toString()

        # prepare for querying the structures
        audiences = self.doc.getRootElement()
        
        doctypes = XQueryUtil.xquery(self.doc,"//type")
        if doctypes == None:
           print >>stderr, "No document types defined!"
           
        appdomains = audiences.getChildElements("application-domain")
        if appdomains == None:
           print >>stderr, "No document types defined!"
       
        # LEFTOFF this is a hack to keep it working while I flesh out the rest of the code
       
        storynode = XQueryUtil.xquery(self.doc,"//type[@name='story']/new-instance-template")
        if storynode == None:
           print >>stderr, "Storynode hack couldn't find story type!"
        self.defaultContent = storynode.get(0).getValue()