Ejemplo n.º 1
0
def info(dspath):

    # get datastore
    shp = "file://%s" % os.path.abspath(dspath)
    params = HashMap()
    params.put('url', net.URL(shp))
    dataStore = DataStoreFinder.getDataStore(params)

    typeName = dataStore.getTypeNames()[0]
    featureSource = dataStore.getFeatureSource(typeName)
    featureCollection = featureSource.getFeatures()
    featureType = featureSource.getSchema()

    # Print out feature source info (ie layer info)
    #'getBounds', 'getClass', 'getCount', 'getDataStore'
    print "Datastore         : ", featureSource.getDataStore()
    print "Layer Name        : ", typeName
    print "Number of features: ", featureCollection.count
    print "Bounding Box      : ", featureSource.getBounds()

    # Print out feature attribute types
    for atype in featureType.getAttributeTypes():
        print atype.getName(), atype.getType()

    return None

    f_iter = featureCollection.iterator()
    while f_iter.hasNext():
        feat = f_iter.next()
        print "==============", feat.getID()
        for i in range(feat.getNumberOfAttributes()):
            print "\t %s " % feat.getAttribute(i)

    featureCollection.close(f_iter)
Ejemplo n.º 2
0
    def cowebTurnin(self):
        try:
            filehandle = open(self.zipFile, "rb")
            url = net.URL(JESConstants.HW_COWEB_ADDRESS_URL)
            host = url.getHost()
            port = url.getPort()
            finder = JESURLFinder.JESURLFinder()
            turninURL = finder.getTargetURL(self.gtNumber,
                                            string.strip(self.hwTitle))
            if (turninURL == -1):  # check if url is not found - RJC
                raise StandardError, "Unable to find a valid upload url for assignment."

            selector = string.strip(turninURL[turninURL.find("/"):]
                                    ) + JESConstants.HW_COWEB_ATTACH_SUFFIX
            fields = [['specific', 'true'], ['reference', 'true']]
            files = [[
                'filestuff',
                os.path.basename(self.zipFile),
                filehandle.read()
            ]]
            response = self.post_multipart(host, port, selector, fields, files)
            if response.status < 200 or response.status > 399:
                system.out.println("Server resonded with unsuccessful message")
                raise StandardError
            return response
        except:
            import sys
            a, b, c = sys.exc_info()
            print a, b, c
            raise StandardError, "Error turning in to the Coweb."
Ejemplo n.º 3
0
def toURL(o):
    """
  Transforms an object to a URL if possible. This method can take a file, 
  string, uri, or url object.
  """

    if isinstance(o, net.URL):
        return o
    elif isinstance(o, (net.URI, io.File)):
        return o.toURL()
    elif isinstance(o, (str, unicode)):
        try:
            return net.URL(o)
        except net.MalformedURLException:
            try:
                return net.URL('file:%s' % o)
            except net.MalformedURLException:
                return io.File(o).toURL()
Ejemplo n.º 4
0
 def go( self, event ):
     
     text = self.jtf.getText()
     try:
         url = net.URL( text )
     except:
         url = None
         #swing.JOptionPane.showMessageDialog( 
     if url:
         self.browser.setURL( url )
Ejemplo n.º 5
0
 def goToHeadline( self, event ):
     
     c = self.c
     cp = c.currentPosition()
     headline = cp.headString()
     try:
         url = net.URL( headline.strip() )
     except:
         url = None
     
     if url:
         self.browser.setURL( url )
Ejemplo n.º 6
0
 def grabFile(self):
     try:
         url = net.URL(JESConstants.HW_COWEB_ADDRESS_URL)
         if url.getPort() != -1:
             h = httplib.HTTP(url.getHost(), url.getPort())
         else:
             h = httplib.HTTP(url.getHost())
         h.putrequest('GET', url.getFile())
         h.putheader('Accept', 'text/html')
         h.putheader('Accept', 'text/plain')
         h.endheaders()
         errcode, errmsg, headers = h.getreply()
         f = h.getfile()
         data = f.read()  # Get the raw HTML
         f.close()
         h.close()
         return data
     except:
         raise StandardError,("Error: Could not get target web address for submission\n" + \
         "Make sure you are connected to the internet.")
Ejemplo n.º 7
0
 def grabFile(self):
     try:
         url = net.URL(JESConstants.HW_ADDRESS_URL)
         if url.getPort() != -1:
             h = httplib.HTTP(url.getHost(), url.getPort())
         else:
             h = httplib.HTTP(url.getHost())
         h.putrequest('GET', url.getFile())
         h.putheader('Accept', 'text/html')
         h.putheader('Accept', 'text/plain')
         h.endheaders()
         errcode, errmsg, headers = h.getreply()
         f = h.getfile()
         data = f.read() # Get the raw HTML
         f.close()
         return data
     except:
         import sys
         a,b,c = sys.exc_info()
         print a,b,c
         print "Error in JESAddressFinder.grabFile, could not get target mail address for submission"
         return None
Ejemplo n.º 8
0
def view(url):
    frame = swing.JFrame("Image: " + url, visible=1)
    frame.getContentPane().add(swing.JLabel(swing.ImageIcon(net.URL(url))))
    frame.setSize(400,250)
    frame.show()
Ejemplo n.º 9
0
    def __init__(self):
        #########################################################
        #
        # set up the overall frame (the window itself)
        #
        self.window = swing.JFrame("Swing Sampler!")
        self.window.windowClosing = self.goodbye
        self.window.contentPane.layout = awt.BorderLayout()

        #########################################################
        #
        # under this will be a tabbed pane; each tab is named
        # and contains a panel with other stuff in it.
        #
        tabbedPane = swing.JTabbedPane()
        self.window.contentPane.add("Center", tabbedPane)

        #########################################################
        #
        # The first tabbed panel will be named "Some Basic
        # Widgets", and is referenced by variable 'firstTab'
        #
        firstTab = swing.JPanel()
        firstTab.layout = awt.BorderLayout()
        tabbedPane.addTab("Some Basic Widgets", firstTab)

        #
        # slap in some labels, a list, a text field, etc... Some
        # of these are contained in their own panels for
        # layout purposes.
        #
        tmpPanel = swing.JPanel()
        tmpPanel.layout = awt.GridLayout(3, 1)
        tmpPanel.border = swing.BorderFactory.createTitledBorder(
            "Labels are simple")
        tmpPanel.add(swing.JLabel("I am a label. I am quite boring."))
        tmpPanel.add(
            swing.JLabel(
                "<HTML><FONT COLOR='blue'>HTML <B>labels</B></FONT> are <I>somewhat</I> <U>less boring</U>.</HTML>"
            ))
        tmpPanel.add(
            swing.JLabel("Labels can also be aligned", swing.JLabel.RIGHT))
        firstTab.add(tmpPanel, "North")

        #
        # Notice that the variable "tmpPanel" gets reused here.
        # This next line creates a new panel, but we reuse the
        # "tmpPanel" name to refer to it.  The panel that
        # tmpPanel used to refer to still exists, but we no
        # longer have a way to name it (but that's ok, since
        # we don't need to refer to it any more).

        #
        tmpPanel = swing.JPanel()
        tmpPanel.layout = awt.BorderLayout()
        tmpPanel.border = swing.BorderFactory.createTitledBorder(
            "Tasty tasty lists")

        #
        # Note that here we stash a reference to the list in
        # "self.list".  This puts it in the scope of the object,
        # rather than this function.  This is because we'll be
        # referring to it later from outside this function, so
        # it needs to be "bumped up a level."
        #

        listData = [
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "October", "November", "December"
        ]
        self.list = swing.JList(listData)
        tmpPanel.add("Center", swing.JScrollPane(self.list))
        button = swing.JButton("What's Selected?")
        button.actionPerformed = self.whatsSelectedCallback
        tmpPanel.add("East", button)
        firstTab.add("Center", tmpPanel)

        tmpPanel = swing.JPanel()
        tmpPanel.layout = awt.BorderLayout()

        #
        # The text field also goes in self, since the callback
        # that displays the contents will need to get at it.
        #
        # Also note that because the callback is a function inside
        # the SwingSampler object, you refer to it through self.
        # (The callback could potentially be outside the object,
        # as a top-level function. In that case you wouldn't
        # use the 'self' selector; any variables that it uses
        # would have to be in the global scope.
        #
        self.field = swing.JTextField()
        tmpPanel.add(self.field)
        tmpPanel.add(
            swing.JButton("Click Me", actionPerformed=self.clickMeCallback),
            "East")
        firstTab.add(tmpPanel, "South")

        #########################################################
        #
        # The second tabbed panel is next...  This shows
        # how to build a basic web browser in about 20 lines.
        #
        secondTab = swing.JPanel()
        secondTab.layout = awt.BorderLayout()
        tabbedPane.addTab("HTML Fanciness", secondTab)

        tmpPanel = swing.JPanel()
        tmpPanel.add(swing.JLabel("Go to:"))
        self.urlField = swing.JTextField(40, actionPerformed=self.goToCallback)
        tmpPanel.add(self.urlField)
        tmpPanel.add(swing.JButton("Go!", actionPerformed=self.goToCallback))
        secondTab.add(tmpPanel, "North")

        self.htmlPane = swing.JEditorPane("http://www.google.com",
                                          editable=0,
                                          hyperlinkUpdate=self.followHyperlink,
                                          preferredSize=(400, 400))
        secondTab.add(swing.JScrollPane(self.htmlPane), "Center")

        self.statusLine = swing.JLabel("(status line)")
        secondTab.add(self.statusLine, "South")

        #########################################################
        #
        # The third tabbed panel is next...
        #
        thirdTab = swing.JPanel()
        tabbedPane.addTab("Other Widgets", thirdTab)

        imageLabel = swing.JLabel(
            swing.ImageIcon(
                net.URL("http://www.gatech.edu/images/logo-gatech.gif")))
        imageLabel.toolTipText = "Labels can have images! Every widget can have a tooltip!"
        thirdTab.add(imageLabel)

        tmpPanel = swing.JPanel()
        tmpPanel.layout = awt.GridLayout(3, 2)
        tmpPanel.border = swing.BorderFactory.createTitledBorder(
            "Travel Checklist")
        tmpPanel.add(
            swing.JCheckBox("Umbrella", actionPerformed=self.checkCallback))
        tmpPanel.add(
            swing.JCheckBox("Rain coat", actionPerformed=self.checkCallback))
        tmpPanel.add(
            swing.JCheckBox("Passport", actionPerformed=self.checkCallback))
        tmpPanel.add(
            swing.JCheckBox("Airline tickets",
                            actionPerformed=self.checkCallback))
        tmpPanel.add(
            swing.JCheckBox("iPod", actionPerformed=self.checkCallback))
        tmpPanel.add(
            swing.JCheckBox("Laptop", actionPerformed=self.checkCallback))
        thirdTab.add(tmpPanel)

        tmpPanel = swing.JPanel()
        tmpPanel.layout = awt.GridLayout(4, 1)
        tmpPanel.border = swing.BorderFactory.createTitledBorder("My Pets")
        #
        # A ButtonGroup is used to indicate which radio buttons
        # go together.
        #
        buttonGroup = swing.ButtonGroup()

        radioButton = swing.JRadioButton("Dog",
                                         actionPerformed=self.radioCallback)
        buttonGroup.add(radioButton)
        tmpPanel.add(radioButton)

        radioButton = swing.JRadioButton("Cat",
                                         actionPerformed=self.radioCallback)
        buttonGroup.add(radioButton)
        tmpPanel.add(radioButton)

        radioButton = swing.JRadioButton("Pig",
                                         actionPerformed=self.radioCallback)
        buttonGroup.add(radioButton)
        tmpPanel.add(radioButton)

        radioButton = swing.JRadioButton("Capybara",
                                         actionPerformed=self.radioCallback)
        buttonGroup.add(radioButton)
        tmpPanel.add(radioButton)

        thirdTab.add(tmpPanel)

        self.window.pack()
        self.window.show()
Ejemplo n.º 10
0
import support

support.compileJava("test270p/test270j2.java", classpath=".")

from test270p import *
test270j2.printX(test270j1())

from java import net, lang
clu = net.URL(r'file:%s/' % lang.System.getProperty("user.dir"))
ld1 = net.URLClassLoader([clu])
X = ld1.loadClass("test270p.test270j1")
Y = ld1.loadClass("test270p.test270j2")
Y.printX(X())

#import org
#org.python.core.PyJavaClass.dumpDebug()