Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:org.fiware.cybercaptor.server.informationsystem.InformationSystemHost.java

License:Open Source License

/**
 * Load the host from a DOM element (extracted from an XML file)
 *
 * @param domElement the host root dom element
 * @param topology   the current network topology
 * @throws Exception//from   w w  w .ja v a2s.c  om
 */
public void loadFromDomElement(Element domElement, Topology topology, Database db) throws Exception {
    Element nameElement = domElement.getChild("name");
    if (nameElement != null)
        this.setName(nameElement.getText());

    Element securityRequirementElement = domElement.getChild("security_requirement");
    if (securityRequirementElement != null) {
        double securityRequirementValue = Double.parseDouble(securityRequirementElement.getText());
        SecurityRequirement securityRequirement = new SecurityRequirement("sec-req-xml",
                securityRequirementValue);
        this.addSecurityRequirements(securityRequirement);
    }

    //Host interfaces
    Element interfacesElement = domElement.getChild("interfaces");
    if (interfacesElement != null) {
        List<Element> interfaceListElement = interfacesElement.getChildren("interface");
        for (Element interfaceElement : interfaceListElement) {
            Element interfaceNameElement = interfaceElement.getChild("name");
            Element interfaceAddressElement = interfaceElement.getChild("ipaddress");
            Element interfaceVlanElement = interfaceElement.getChild("vlan");
            if (interfaceNameElement != null && interfaceAddressElement != null) {
                String interfaceName = interfaceNameElement.getText();
                String interfaceAddress = interfaceAddressElement.getText();
                Interface inface;

                if (interfaceVlanElement != null && !interfaceVlanElement.getText().isEmpty()) {
                    inface = new Interface(interfaceName, interfaceAddress, this,
                            topology.getNewOrExistingVlan(interfaceVlanElement.getChildText("label")));
                } else {
                    inface = new Interface(interfaceName, interfaceAddress, this);
                }

                this.getInterfaces().put(interfaceName, inface);

                Element networkElement = interfaceElement.getChild("network");
                Element maskElement = interfaceElement.getChild("mask");
                if (networkElement != null && maskElement != null) {
                    inface.setNetwork(new Network(new IPAddress(networkElement.getText()),
                            new IPAddress(maskElement.getText())));
                }

                Element directlyConnectedElement = interfaceElement.getChild("directly-connected");
                if (directlyConnectedElement != null) {
                    Element connectedToInternetElement = directlyConnectedElement.getChild("internet");
                    if (connectedToInternetElement != null) {
                        inface.setConnectedToTheInternet(true);
                    }
                }
            }
        }
    }

    //Machine services
    Element servicesElement = domElement.getChild("services");
    if (servicesElement != null) {
        List<Element> servicesElementList = servicesElement.getChildren("service");
        for (Element serviceElement : servicesElementList) {
            Element serviceNameElement = serviceElement.getChild("name");
            if (serviceNameElement != null) {
                String serviceName = serviceNameElement.getText();
                Service service;
                if (!this.services.containsKey(serviceName)) {
                    service = new Service(serviceName);
                    this.services.put(serviceName, service);
                    service.setMachine(this);
                } else {
                    service = this.services.get(serviceName);
                }

                Element serviceIPElement = serviceElement.getChild("ipaddress");
                if (serviceIPElement != null && !serviceIPElement.getText().isEmpty()
                        && service.getIpAddress() == null) {
                    service.setIpAddress(new IPAddress(serviceIPElement.getText()));
                }

                Element servicePortElement = serviceElement.getChild("port");
                if (servicePortElement != null && !servicePortElement.getText().isEmpty()
                        && service.getPortNumber() == 0)
                    service.setPortNumber(Service.portStringToInt(servicePortElement.getText()));

                Element serviceProtocolElement = serviceElement.getChild("protocol");
                if (serviceProtocolElement != null && !serviceProtocolElement.getText().isEmpty()
                        && service.getProtocol() == null)
                    service.setProtocol(
                            FirewallRule.Protocol.getProtocolFromString(serviceProtocolElement.getText()));

                Element serviceCPEElement = serviceElement.getChild("CPE");
                if (serviceCPEElement != null)
                    service.setCPE(serviceCPEElement.getText());

                Element serviceAccountElement = serviceElement.getChild("user");
                if (serviceAccountElement != null) {
                    service.setAccount(this.getAccountByName(serviceAccountElement.getText()));
                }

                Element serviceVersionElement = serviceElement.getChild("version");
                if (serviceVersionElement != null)
                    service.setVersion(serviceVersionElement.getText());

                Element vulnerabilitiesElement = serviceElement.getChild("vulnerabilities");
                if (vulnerabilitiesElement != null) {
                    List<Element> vulnsElements = vulnerabilitiesElement.getChildren("vulnerability");
                    for (Element vulnElement : vulnsElements) {
                        Element typeElement = vulnElement.getChild("type");
                        Element goalElement = vulnElement.getChild("goal");
                        Element cveElement = vulnElement.getChild("cve");

                        Vulnerability vuln = new Vulnerability(cveElement.getText());
                        vuln.exploitGoal = goalElement.getText();
                        vuln.exploitType = typeElement.getText();
                        vuln.loadParametersFromDatabase(db.getConn());

                        service.getVulnerabilities().put(vuln.cve, vuln);

                    }
                }

                Element serviceDeployedPatchElement = serviceElement.getChild("deployed-patchs");
                if (serviceDeployedPatchElement != null) {
                    List<Element> patchsElements = serviceDeployedPatchElement.getChildren("patch");
                    for (Element patchElement : patchsElements) {
                        Patch patch = new Patch(patchElement.getText());
                        service.getDeployedPatches().add(patch);
                    }
                }
            }
        }
    }

    Element routesElement = domElement.getChild("routes");
    if (routesElement != null)
        this.getRoutingTable().loadFromDomElement(routesElement, this);

    Element incommingFirewallElement = domElement.getChild("input-firewall");
    if (incommingFirewallElement != null)
        this.getInputFirewallRulesTable().loadFromDomElement(incommingFirewallElement);

    Element outgoingFirewallElement = domElement.getChild("output-firewall");
    if (outgoingFirewallElement != null)
        this.getOutputFirewallRulesTable().loadFromDomElement(outgoingFirewallElement);
}

From source file:org.fnppl.opensdx.dmi.wayin.PieToOpenSDXImporter.java

License:Open Source License

private Feed getImportFeed() {
    // do the import
    Feed feed = null;//  w w w.java  2 s . c o m

    try {
        // (1) get XML-Data from import document
        Document impDoc = Document.fromFile(this.importFile);
        Element root = impDoc.getRootElement();

        //(1.1) sets the activen namespace for this root element to avoid parameter overhead for all Element getters.
        root.setActiveNamespace(root.getNamespace());

        // (2) get FeedInfo from import and create feedid and new FeedInfo for openSDX
        String feedid = UUID.randomUUID().toString();
        Calendar cal = Calendar.getInstance();

        long creationdatetime = cal.getTimeInMillis();
        long effectivedatetime = cal.getTimeInMillis();

        String lic = root.getChildTextNN("provider");
        if (lic.length() == 0)
            lic = "[NOT SET]";

        ContractPartner sender = ContractPartner.make(ContractPartner.ROLE_SENDER, lic, "1");
        ContractPartner licensor = ContractPartner.make(ContractPartner.ROLE_LICENSOR, lic, "1");
        ContractPartner licensee = ContractPartner.make(ContractPartner.ROLE_LICENSEE, "1", "1");

        FeedInfo feedinfo = FeedInfo.make(onlytest, feedid, creationdatetime, effectivedatetime, sender,
                licensor, licensee);

        // (3) create new feed with feedinfo
        feed = Feed.make(feedinfo);

        // path to importfile
        String path = this.importFile.getParent() + File.separator;

        Element album = root.getChild("album");

        // Information
        String streetReleaseDate = album.getChildTextNN("original_release_date");
        if (streetReleaseDate.length() > 0) {
            cal.setTime(ymd.parse(streetReleaseDate));
        } else {
            // MUST: when not provided then today
            cal.setTime(new Date());
        }

        // streetRelease = physicalRelease (?)
        long srd = cal.getTimeInMillis();
        long prd = cal.getTimeInMillis();

        BundleInformation info = BundleInformation.make(srd, prd);

        // language
        if (root.getChild("language") != null && root.getChildTextNN("language").length() > 0) {
            info.main_language(root.getChildText("language").substring(0, 2));
        }

        // IDs of bundle -> more (?)
        IDs bundleids = IDs.make();
        if (album.getChild("upc") != null)
            bundleids.upc(album.getChildTextNN("upc"));

        // displayname
        String displayname = album.getChildTextNN("title");

        // display_artistname
        String display_artistname = null; //album.getChildTextNN("album_display_artist");
        //Get first performer
        Vector<Element> contributors = album.getChild("artists").getChildren("artist");
        for (Iterator<Element> itContributors = contributors.iterator(); itContributors.hasNext();) {
            Element contributor = itContributors.next();
            if (contributor.getChild("roles") != null
                    && contributor.getChild("roles").getChild("role") != null) {
                String role = contributor.getChild("roles").getChildTextNN("role").trim().toLowerCase();
                if (role.equals("performer") && "true".equals(contributor.getChildText("primary"))) {
                    display_artistname = contributor.getChildTextNN("artist_name");
                    break;
                }
            }
        }

        // license basis
        Territorial territorial = Territorial.make();

        // Release
        LicenseBasis license_basis = LicenseBasis.make(territorial, srd, prd);

        // license specifics -> empty!
        LicenseSpecifics license_specifics = LicenseSpecifics.make();

        // receiver -> "MUST" -> empty!
        Receiver rec = Receiver.make(Receiver.TRANSFER_TYPE_OSDX_FILESERVER);
        rec.servername("servername");
        rec.serveripv4("0.0.0.0");
        rec.authtype("login");
        rec.username("testuser");
        feedinfo.receiver(rec);

        // Album Territories, Streaming and Download
        HashMap<String, Element> albumTerritories = new HashMap<String, Element>(); //Global album territories to match with Pies track territories
        boolean downloadAllowed = false;
        boolean streamingAllowed = false;

        //calculate major streaming & sales date
        HashMap<String, String> majorDates = calculateDateMajorities(
                album.getChild("products").getChildren("product").iterator());

        Element albumProducts = album.getChild("products");
        if (albumProducts != null) {
            Vector<Element> products = albumProducts.getChildren("product");
            if (products != null && products.size() > 0) {
                for (Element p : products) {
                    albumTerritories.put(p.getChildTextNN("territory"), p); //Puts the current territory for later track territory comparison
                    String territory = p.getChildText("territory");
                    if (forceImport) {
                        //no rules necessary, just import. Download and streaming allowed = true, streaming start & enddate are the regular releasedate
                        downloadAllowed = true;
                        streamingAllowed = true;
                        territorial.allow(territory);
                    } else {
                        downloadAllowed |= p.getChildBoolean("cleared_for_sale", false);
                        streamingAllowed |= p.getChildBoolean("cleared_for_stream", false);
                        if (p.getChildBoolean("cleared_for_sale", false)
                                || p.getChildBoolean("cleared_for_stream", false)) {
                            territorial.allow(territory);
                            //rules in case <sales_start_date> != <stream_start_date>
                            if (!p.getChildTextNN("sales_start_date")
                                    .equals(p.getChildTextNN("stream_start_date"))) {
                                //add rule
                                LicenseRule rule = LicenseRule.make(1, "streaming_allowed", "equals", "true");
                                rule.addThenProclaim("timeframe_from", p.getChildTextNN("sales_start_date"));
                                license_specifics.addRule(rule);
                            }

                            if (!p.getChildTextNN("sales_start_date").equals(majorDates.get("sales"))) {
                                //add rule for sales
                                LicenseRule rule = LicenseRule.make(2, "territory", "equals", territory);
                                rule.addThenProclaim("timeframe_from", majorDates.get("sales"));
                                license_specifics.addRule(rule);
                            }

                            if (!p.getChildTextNN("stream_start_date").equals(majorDates.get("stream"))) {
                                //add rule for streaming
                                LicenseRule rule = LicenseRule.make(3, "territory", "equals", territory);
                                rule.addThenProclaim("streaming_timeframe_from", majorDates.get("stream"));
                                license_specifics.addRule(rule);
                            }
                        } else {
                            territorial.disallow(territory);
                        }
                    }
                }
            }
        }

        //allow download and streaming based on territories.
        license_basis.download_allowed(downloadAllowed);
        license_basis.streaming_allowed(streamingAllowed);

        Bundle bundle = Bundle.make(bundleids, displayname, displayname, "", display_artistname, info,
                license_basis, license_specifics);

        // add contributor label
        Contributor con = Contributor.make(album.getChildTextNN("label_name"), Contributor.TYPE_LABEL,
                IDs.make());
        bundle.addContributor(con);

        // add contributor display_artist
        con = Contributor.make(display_artistname, Contributor.TYPE_DISPLAY_ARTIST, IDs.make());
        bundle.addContributor(con);

        contributors = album.getChild("artists").getChildren("artist");
        for (Iterator<Element> itContributors = contributors.iterator(); itContributors.hasNext();) {
            Element contributor = itContributors.next();

            if (contributor.getChild("roles") != null
                    && contributor.getChild("roles").getChild("role") != null) {
                String role = contributor.getChild("roles").getChildTextNN("role").trim().toLowerCase();
                if (role.equals("performer")) {
                    con = Contributor.make(contributor.getChildTextNN("artist_name"),
                            Contributor.TYPE_PERFORMER, IDs.make());
                } else if (role.equals("featuring")) {
                    con = Contributor.make(contributor.getChildTextNN("artist_name"),
                            Contributor.TYPE_FEATURING, IDs.make());
                } else if (role.equals("composer")) {
                    con = Contributor.make(contributor.getChildTextNN("artist_name"), Contributor.TYPE_COMPOSER,
                            IDs.make());
                } else if (role.equals("producer")) {
                    con = Contributor.make(contributor.getChildTextNN("artist_name"), Contributor.TYPE_PRODUCER,
                            IDs.make());
                }

                // Maybe more roles? Insert!

                bundle.addContributor(con);
            } else {
                con = Contributor.make(contributor.getChildTextNN("artist_name"), Contributor.TYPE_PERFORMER,
                        IDs.make());
                bundle.addContributor(con);
            }
        }

        String copyright = album.getChildTextNN("copyright_cline");
        String production = album.getChildTextNN("copyright_pline");

        if (copyright.length() > 0) {
            con = Contributor.make(copyright.substring(5), Contributor.TYPE_COPYRIGHT, IDs.make());
            con.year(copyright.substring(0, 4));
            bundle.addContributor(con);
        }

        if (production.length() > 0) {
            con = Contributor.make(production.substring(5), Contributor.TYPE_PRODUCTION, IDs.make());
            con.year(production.substring(0, 4));
            bundle.addContributor(con);
        }

        // cover: license_basis & license_specifics from bundle, right?           
        if (album.getChild("artwork_files") != null
                && album.getChild("artwork_files").getChild("file") != null) {
            Element cover = album.getChild("artwork_files").getChild("file");

            ItemFile itemfile = ItemFile.make();
            itemfile.type("frontcover");
            // check if file exist at path
            String filename = cover.getChildTextNN("file_name");
            File f = new File(path + filename);
            if (f != null && f.exists()) {
                itemfile.setFile(f);

                // set delivered path to file 
                itemfile.setLocation(FileLocation.make(filename, filename));
            } else {
                //file does not exist -> so we have to set the values "manually"

                //-> use filename for location
                itemfile.setLocation(FileLocation.make(filename, filename));

                //file size
                if (cover.getChild("size") != null) {
                    itemfile.bytes(Integer.parseInt(cover.getChildText("size")));
                }

                // checksum md5
                if (cover.getChild("checksum") != null) {
                    Element cs = cover.getChild("checksum");
                    if (cs != null) {
                        if (cs.getAttribute("type").equals("md5")) {
                            String sMd5 = cover.getChildText("checksum");
                            byte[] md5 = SecurityHelper.HexDecoder.decode(sMd5);
                            itemfile.checksums(Checksums.make().md5(md5));
                        }
                    }
                }
            }

            bundle.addFile(itemfile);
        }

        // init GenreConverter
        GenreConverter gc = GenreConverter.getInstance(GenreConverter.PIE_TO_OPENSDX);

        // add Tags
        ItemTags tags = ItemTags.make();

        Vector<Element> genres = album.getChild("genres").getChildren("genre");
        for (Iterator<Element> itGenres = genres.iterator(); itGenres.hasNext();) {
            Element genre = itGenres.next();
            tags.addGenre(gc.convert(genre.getAttribute("code")));
        }

        bundle.tags(tags);
        //           
        Vector<Element> tracks = album.getChild("tracks").getChildren("track");
        for (Iterator<Element> itTracks = tracks.iterator(); itTracks.hasNext();) {
            Element track = itTracks.next();

            IDs trackids = IDs.make();
            if (track.getChild("isrc") != null)
                trackids.isrc(track.getChildTextNN("isrc"));

            // displayname
            String track_displayname = track.getChildTextNN("title");

            // display_artistname / later set this to track artist if available
            String track_display_artistname = display_artistname;

            BundleInformation track_info = BundleInformation.make(srd, prd);

            // num
            if (track.getChildTextNN("number").length() > 0) {
                track_info.num(Integer.parseInt(track.getChildText("number")));
            }

            // setnum
            if (track.getChildTextNN("volume_number").length() > 0) {
                track_info.setnum(Integer.parseInt(track.getChildText("volume_number")));
            }

            // tracklength
            if (track.getChildTextNN("duration").length() > 0) {
                track_info.playlength(Integer.parseInt(track.getChildText("duration")));
            }

            // suggested prelistining offset
            if (track.getChild("preview_start_index") != null
                    && track.getChildTextNN("preview_start_index").length() > 0) {
                track_info.suggested_prelistening_offset(
                        Integer.parseInt(track.getChildText("preview_start_index")));
            }

            // track license basis
            LicenseBasis track_license_basis = LicenseBasis.make();

            Territorial track_territorial = Territorial.make();

            track_license_basis.setTerritorial(track_territorial);

            // license specifics -> empty!
            LicenseSpecifics track_license_specifics = LicenseSpecifics.make();

            // license_basis of Bundle / license_specifics of Bundle / others (?)
            Item item = Item.make(trackids, track_displayname, track_display_artistname, "", "audio",
                    track_display_artistname, track_info, track_license_basis, track_license_specifics);

            contributors = track.getChild("artists").getChildren("artist");
            for (Iterator<Element> itContributors = contributors.iterator(); itContributors.hasNext();) {
                Element contributor = itContributors.next();

                boolean display_artist_isSet = false;
                if (contributor.getChild("primary") != null) {
                    if (contributor.getChildTextNN("primary").equals("true") && !display_artist_isSet) {
                        item.display_artistname(contributor.getChildTextNN("artist_name"));
                        display_artist_isSet = true;
                    }
                }

                if (contributor.getChild("roles") != null
                        && contributor.getChild("roles").getChild("role") != null) {
                    String role = contributor.getChild("roles").getChildTextNN("role").trim().toLowerCase();
                    if (role.equals("performer")) {
                        con = Contributor.make(contributor.getChildTextNN("artist_name"),
                                Contributor.TYPE_PERFORMER, IDs.make());
                    } else if (role.equals("featuring")) {
                        con = Contributor.make(contributor.getChildTextNN("artist_name"),
                                Contributor.TYPE_FEATURING, IDs.make());
                    } else if (role.equals("composer")) {
                        con = Contributor.make(contributor.getChildTextNN("artist_name"),
                                Contributor.TYPE_COMPOSER, IDs.make());
                    } else if (role.equals("producer")) {
                        con = Contributor.make(contributor.getChildTextNN("artist_name"),
                                Contributor.TYPE_PRODUCER, IDs.make());
                    }

                    // Maybe more roles? Insert!

                    item.addContributor(con);
                } else {
                    con = Contributor.make(contributor.getChildTextNN("name"), Contributor.TYPE_PERFORMER,
                            IDs.make());
                    item.addContributor(con);
                }
            }

            // Check if track territory equal to those on bundle level
            if (forceImport) {
                //In case of force import, just like on bundle (Just allow everything)
                track_license_basis.as_on_bundle(true);
            } else {
                boolean asOnBundle = asOnBundle(albumTerritories,
                        track.getChild("products").getChildren("product"));
                if (asOnBundle) {
                    track_license_basis.as_on_bundle(asOnBundle);
                } else {
                    //Check track territories again.
                    Vector<Element> tmp = track.getChild("products").getChildren("product");
                    for (Element t : tmp) {
                        String territory = t.getChildText("territory");
                        if (t.getChildBoolean("cleared_for_sale", false)
                                || t.getChildBoolean("cleared_for_stream", false)) {
                            track_territorial.allow(territory);
                        } else {
                            track_territorial.disallow(territory);
                        }
                    }
                }
            }

            // add Tags
            ItemTags track_tags = ItemTags.make();

            Vector<Element> track_genres = track.getChild("genres").getChildren("genre");
            for (Iterator<Element> itTrackGenres = track_genres.iterator(); itTrackGenres.hasNext();) {
                Element genre = itTrackGenres.next();
                tags.addGenre(gc.convert(genre.getAttribute("code")));
            }

            item.tags(track_tags);

            Element audioFile = track.getChild("audio_file");
            // check if file exist at path (Optional, in case of an update XML this element may be missing)
            if (audioFile != null) {
                ItemFile itemfile = ItemFile.make();
                itemfile.type("full");
                String filename = track.getChild("audio_file").getChildTextNN("file_name");
                File f = new File(path + filename);
                if (f != null && f.exists()) {
                    itemfile.setFile(f); //this will also set the filesize and calculate the checksums

                    // set delivered path to file 
                    itemfile.setLocation(FileLocation.make(filename, filename));
                } else {
                    //file does not exist -> so we have to set the values "manually"

                    //-> use filename as location
                    itemfile.setLocation(FileLocation.make(filename, filename));

                    //file size
                    if (track.getChild("audio_file").getChild("size") != null) {
                        itemfile.bytes(Integer.parseInt(track.getChild("audio_file").getChildText("size")));
                    }

                    // checksum md5
                    if (track.getChild("audio_file").getChild("checksum") != null) {
                        Element cs = track.getChild("audio_file").getChild("checksum");
                        if (cs != null) {
                            if (cs.getAttribute("type").equals("md5")) {
                                String sMd5 = cs.getText();
                                byte[] md5 = SecurityHelper.HexDecoder.decode(sMd5);
                                itemfile.checksums(Checksums.make().md5(md5));
                            }
                        }
                    }

                }
                item.addFile(itemfile);
            }

            bundle.addItem(item);
        }

        feed.addBundle(bundle);

    } catch (Exception e) {
        e.printStackTrace();
        ir.succeeded = false;
        ir.errorMessage = e.getMessage();
        ir.exception = e;
    }
    return feed;
}

From source file:org.fnppl.opensdx.keyserverfe.MyServlet.java

License:Open Source License

public static void initLoadDB(int limitconns) {
    Element lbconfig = config.getChild("dbloadbalancer");
    //        BalancingConnectionManager.init(lbconfig,local,limitconns);

    String applicationname = lbconfig.getChildText("applicationname");
    if (applicationname == null) {
        applicationname = System.getProperty("user.name") + "/openSDX";
        try {/*  w w w .  j  a v a2s. c o m*/
            //            applicationname = InetAddress.getLocalHost().getHostName();
            applicationname = System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostName()
                    + "/openSDX";
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }

    String drivermanager = lbconfig.getChildText("drivermanager");
    String dbserver = lbconfig.getChildText("dbserver");
    String dbdbname = lbconfig.getChildText("dbdbname");
    String dbusername = lbconfig.getChildText("dbusername");
    String dbpassword = lbconfig.getChildText("dbpassword");
    int dbport = Integer.parseInt(lbconfig.getChildText("dbport"));
    String dbname = lbconfig.getChildText("dbname");

    int initialconnections = Integer.parseInt(lbconfig.getChildText("initialconnections"));
    int maxconnections = Integer.parseInt(lbconfig.getChildText("maxconnections"));
    if (limitconns > 0) {
        maxconnections = Math.min(limitconns, maxconnections);
    }

    BalancingConnectionManager.initDefaultPool(drivermanager, dbserver, dbport, dbname, dbdbname,
            applicationname, dbusername, dbpassword, initialconnections, maxconnections);

}

From source file:org.jpos.q2.iso.ContextMaker.java

License:Open Source License

public void setConfiguration(Configuration cfg) throws ConfigurationException {
    super.setConfiguration(cfg);

    Element persist = getPersist();

    String ssp = persist.getChildText("space");

    sp = SpaceFactory.getSpace(ssp != null ? ssp : "");

    String sTimeout = persist.getChildText("timeout");
    timeout = sTimeout == null ? 10000 : Long.parseLong(sTimeout);

    contextName = persist.getChildText("context-name");
    if (contextName == null) {
        throw new ConfigurationException(
                "Missing 'context-name' property - the context name of the object received on 'in'");
    }//from  w w w  . j ava  2 s. c o m

    in = persist.getChildText("in");
    if (in == null) {
        throw new ConfigurationException("Missing 'in' property - the queue to process objects from.");
    }

    out = persist.getChildText("out");
    if (out == null) {
        throw new ConfigurationException("Missing 'out' property - the target queue of the created context");
    }

    Element values = persist.getChild("context-values");
    if (values != null) {
        contextValues = values.getChildren();
    }

}

From source file:org.jpos.q2.iso.QServer.java

License:Open Source License

private void initIn() {
    Element persist = getPersist();
    inQueue = persist.getChildText("in");
    if (inQueue != null) {
        /*/*w  w  w .  jav  a2 s .co  m*/
         * We have an 'in' queue to monitor for messages we will
         *  send out through server in our (SpaceListener)notify(Object, Object) method.
         */

        sp.addListener(inQueue, this);
    }
}

From source file:org.jpos.q2.iso.QServer.java

License:Open Source License

private void initOut() {
    Element persist = getPersist();
    outQueue = persist.getChildText("out");
    if (outQueue != null) {
        /*//from   w w w  . j  ava 2s .com
         * We have an 'out' queue to send any messages to that are received
         * by the our requestListener(this).
         *
         * Note, if additional ISORequestListeners are registered with the server after
         *  this point, then they won't see anything as our process(ISOSource, ISOMsg)
         *  always return true.
         */
        server.addISORequestListener(this);
    }
}

From source file:org.jpos.q2.iso.QServer.java

License:Open Source License

private void initWhoToSendTo() {

    Element persist = getPersist();
    sendMethod = persist.getChildText("send-request");
    if (sendMethod == null) {
        sendMethod = "LAST";
    }//from  w  w  w.  j  av a2s. co m

}

From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java

License:Apache License

/**
 *
 * @param aId/*w w w .j  a  v a 2  s .  c om*/
 * @param aEnabled
 * @throws Exception
 */
public void setEnabledPlugIn(String aId, Boolean aEnabled) throws Exception {
    Document lDoc = getDocument(JWebSocketConfig.getConfigPath());
    Element lRootNode = lDoc.getRootElement();
    Element lPlugins = lRootNode.getChild(ELEMENT_PLUGINS);
    List<Element> lPluginsList = lPlugins.getChildren(ELEMENT_PLUGIN);

    for (Element lElement : lPluginsList) {
        if (aId.equals(lElement.getChildText("id"))) {
            if (lElement.getChildText("enabled") == null) {
                lElement.addContent(3, new Element("enabled").setText(aEnabled.toString()));
            } else {
                lElement.getChild("enabled").setText(aEnabled.toString());
            }
        }
    }

    saveChange(lDoc, JWebSocketConfig.getConfigPath());
}

From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java

License:Apache License

/**
 *
 * @param aId/*from w w  w.jav  a  2  s .c o  m*/
 * @param aEnabled
 * @throws Exception
 */
public void setEnabledFilter(String aId, Boolean aEnabled) throws Exception {
    Document lDoc = getDocument(JWebSocketConfig.getConfigPath());
    Element lRootNode = lDoc.getRootElement();
    Element lFilters = lRootNode.getChild(ELEMENT_FILTERS);
    List<Element> lFiltersList = lFilters.getChildren(ELEMENT_FILTER);

    for (Element lElement : lFiltersList) {
        if (aId.equals(lElement.getChildText("id"))) {
            if (lElement.getChildText("enabled") == null) {
                lElement.addContent(3, new Element("enabled").setText(aEnabled.toString()));
            } else {
                lElement.getChild("enabled").setText(aEnabled.toString());
            }
        }
    }

    saveChange(lDoc, JWebSocketConfig.getConfigPath());
}

From source file:org.knoxcraft.database.xml.XmlDatabase.java

License:Open Source License

/**
 * Generates the next auto-increment ID for this table
 *
 * @param doc//from  w ww .  j  a v  a 2s  .  c o  m
 * @param col
 *
 * @return
 *
 * @throws DatabaseTableInconsistencyException
 */
private int getIncrementId(Document doc, Column col) throws DatabaseTableInconsistencyException {
    // Search from last to first content entry for a valid element
    int id;
    int index = doc.getRootElement().getChildren().size() - 1;

    if (index < 1) { // Skip first index as that would be the tableProperties
        // No data in this document yet, start at 1
        return 1;
    }
    Element c = doc.getRootElement().getChildren().get(index);

    try {
        String num = c.getChildText(col.columnName());

        if (num != null) {
            id = Integer.valueOf(num);
            id++;
            return id;
        } else {
            // That means there is no data;
            return 1;
        }
    } catch (NumberFormatException e) {
        throw new DatabaseTableInconsistencyException(
                col.columnName() + " is not an incremental field. Fix your DataAccess!");
    }
}