List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace()
From source file:org.artifactory.version.converter.v167.TrashcanConfigConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Starting default trashcan config conversion"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element trashcanConfigElement = rootElement.getChild("trashcanConfig", namespace); if (trashcanConfigElement == null) { log.info("No trashcan config found - adding default one"); addDefaultConfig(rootElement, namespace); }// w w w. java 2 s.c o m log.info("Finished default trashcan config conversion"); }
From source file:org.artifactory.version.converter.v167.TrashcanConfigConverter.java
License:Open Source License
private void addDefaultConfig(Element rootElement, Namespace namespace) { TrashcanConfigDescriptor descriptor = new TrashcanConfigDescriptor(); Element trashcan = new Element("trashcanConfig", namespace); Namespace trashcanConfigNs = trashcan.getNamespace(); ArrayList<Element> elements = Lists.newArrayList(); elements.add(new Element("enabled", trashcanConfigNs).setText(String.valueOf(descriptor.isEnabled()))); elements.add(new Element("retentionPeriodDays", trashcanConfigNs) .setText(String.valueOf(descriptor.getRetentionPeriodDays()))); trashcan.addContent(elements);/*from w w w . j a v a 2 s . c o m*/ rootElement.addContent(rootElement.getContentSize(), trashcan); }
From source file:org.artifactory.version.converter.v167.UserLockConfigConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Starting default 'user locking' conversion"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element securityConfigElement = rootElement.getChild("security", namespace); if (securityConfigElement == null || rootElement.getChild("userLockPolicy", namespace) == null) { addDefaultConfig(rootElement, namespace); }/*ww w . ja v a2 s . c om*/ log.info("Finished default 'user locking' conversion"); }
From source file:org.artifactory.version.converter.v167.UserLockConfigConverter.java
License:Open Source License
private void addDefaultConfig(Element rootElement, Namespace namespace) { Element securityConfigElement = rootElement.getChild("security", namespace); if (securityConfigElement == null || securityConfigElement.getChild("userLockPolicy", namespace) != null) { return;/*from w ww . j av a 2 s .com*/ } Element userLockPolicyElement = securityConfigElement.getChild("userLockPolicy", namespace); if (userLockPolicyElement == null) { UserLockPolicy userLockPolicy = new UserLockPolicy(); userLockPolicyElement = new Element("userLockPolicy", namespace); Namespace passwordConfigNs = userLockPolicyElement.getNamespace(); ArrayList<Element> elements = Lists.newArrayList(); elements.add( new Element("enabled", passwordConfigNs).setText(String.valueOf(userLockPolicy.isEnabled()))); elements.add(new Element("loginAttempts", passwordConfigNs) .setText(String.valueOf(userLockPolicy.getLoginAttempts()))); userLockPolicyElement.addContent(userLockPolicyElement.getContentSize(), elements); securityConfigElement.addContent(securityConfigElement.getContentSize(), userLockPolicyElement); } }
From source file:org.artifactory.version.converter.v168.PasswordPolicyConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Starting user PasswordPolicyConverter conversion"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element securityConfigElement = rootElement.getChild("security", namespace); if (securityConfigElement == null) { securityConfigElement = new Element("security", namespace); }//from w ww . j a v a 2s .c o m Element passwordSettings = securityConfigElement.getChild("passwordSettings", namespace); if (passwordSettings == null) { return; } Element expirationPolicy = passwordSettings.getChild("expirationPolicy", passwordSettings.getNamespace()); if (expirationPolicy == null) { expirationPolicy = new Element("expirationPolicy", passwordSettings.getNamespace()); Namespace expirationPolicyNs = expirationPolicy.getNamespace(); PasswordExpirationPolicy passwordExpirationPolicy = new PasswordExpirationPolicy(); ArrayList<Element> elements = Lists.newArrayList(); elements.add(new Element("enabled", expirationPolicyNs) .setText(String.valueOf(passwordExpirationPolicy.isEnabled()))); elements.add(new Element("passwordMaxAge", expirationPolicyNs) .setText(String.valueOf(passwordExpirationPolicy.getPasswordMaxAge()))); elements.add(new Element("notifyByEmail", expirationPolicyNs) .setText(String.valueOf(passwordExpirationPolicy.isNotifyByEmail()))); expirationPolicy.addContent(expirationPolicy.getContentSize(), elements); passwordSettings.addContent(passwordSettings.getContentSize(), expirationPolicy); } log.info("Finished PasswordPolicyConverter conversion"); }
From source file:org.artifactory.version.converter.v169.PasswordMaxAgeConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Starting user PasswordMaxAgeConverter conversion"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element securityConfigElement = rootElement.getChild("security", namespace); if (securityConfigElement != null) { Element passwordSettings = securityConfigElement.getChild("passwordSettings", namespace); if (passwordSettings != null) { Element expirationPolicy = passwordSettings.getChild("expirationPolicy", namespace); if (expirationPolicy != null) { String passwordMaxAge = String.valueOf(new PasswordExpirationPolicy().getPasswordMaxAge()); if (expirationPolicy.getChild("expiresIn", namespace) != null) { passwordMaxAge = expirationPolicy.getChildText("expiresIn", namespace); expirationPolicy.removeChild("expiresIn", namespace); }/*from www. j a v a 2 s .co m*/ if (expirationPolicy.getChild("passwordMaxAge", namespace) == null) { expirationPolicy.addContent(3, new Element("passwordMaxAge", namespace).setText(passwordMaxAge)); } } } } log.info("Finished PasswordMaxAgeConverter conversion"); }
From source file:org.dvlyyon.net.netconf.Client.java
License:Open Source License
/** * Called when the device sends <b>hello</b> message. This message comes with a list of device capabilities, * so we go process them./* w w w . j a v a2 s . c o m*/ * * @param response XML node representing the RPC response. * @throws RuntimeException if an error occurred processing the hello message. */ @Override public synchronized void processHelloResponse(final Element response) throws RuntimeException { if (!m_helloResponseReceived) { Namespace xmlns = response.getNamespace(); if (!"hello".equals(response.getName())) { s_logger.error("Unexpected message received, expected a hello response"); s_logger.error("No capability information was processed!"); return; } // This gives us the device capabilities - go get them Element capsRoot = response.getChild("capabilities", xmlns); if (capsRoot == null) { s_logger.error("Invalid hello response received; no capabilites sent by device."); } else { Element sessionIdElem = response.getChild("session-id", xmlns); if (sessionIdElem != null) { this.m_sessionID = sessionIdElem.getTextTrim(); s_logger.debug("Got a session id of: " + sessionIdElem.getText()); } else { String msg = "Error: No session ID received in hello message"; s_logger.error(msg); throw new RuntimeException(msg); } m_deviceCaps.fromNetconfXml(capsRoot); } m_helloResponseReceived = true; } }
From source file:org.esipfed.eskg.mapper.PODAACWebServiceObjectMapper.java
License:Apache License
private DIF mapGCMDXMLToPOJO(ByteArrayInputStream gcmdByteArrayInputStream) { //create DIF//www . j av a2 s .c o m DIF dif = new DIF(); try { SAXBuilder jdomBuilder = new SAXBuilder(); // jdomDocument is the JDOM2 Object Document jdomDocument = jdomBuilder.build(gcmdByteArrayInputStream); Element difElement = jdomDocument.getRootElement(); Namespace ns = difElement.getNamespace(); //populate immediate children dif.setEntryID(difElement.getChild("Entry_ID", ns).getTextTrim()); dif.setEntryTitle(difElement.getChild("Entry_Title", ns).getTextTrim()); dif.setAccessConstraints(difElement.getChild("Access_Constraints", ns).getTextTrim()); dif.setUseConstraints(difElement.getChild("Use_Constraints", ns).getTextTrim()); dif.getDataSetLanguage().add(difElement.getChild("Data_Set_Language", ns).getTextTrim()); if (difElement.getChild("Originating_Center", ns).getTextTrim() != null) { dif.setOriginatingCenter(difElement.getChild("Originating_Center", ns).getTextTrim()); } dif.setMetadataName(difElement.getChild("Metadata_Name", ns).getTextTrim()); dif.setMetadataVersion(difElement.getChild("Metadata_Version", ns).getTextTrim()); dif.setDIFCreationDate(difElement.getChild("DIF_Creation_Date", ns).getTextTrim()); dif.setLastDIFRevisionDate(difElement.getChild("Last_DIF_Revision_Date", ns).getTextTrim()); dif.setDIFRevisionHistory(difElement.getChild("DIF_Revision_History", ns).getTextTrim()); //create ISO_Topic_Catgeory(s) List<Element> iSOTopicCategoryList = difElement.getChildren("ISO_Topic_Category", ns); for (Element iSOTopicCategory : iSOTopicCategoryList) { dif.getISOTopicCategory().add(iSOTopicCategory.getTextTrim()); } //create Data_Set_Citation(s) List<Element> dataSetCitationList = difElement.getChildren("Data_Set_Citation", ns); for (Element dataSetCitationElement : dataSetCitationList) { List<Element> dataSetCitationElementChildren = dataSetCitationElement.getChildren(); DataSetCitation dataSetCitation = new DataSetCitation(); for (Element element : dataSetCitationElementChildren) { if ("Dataset_Creator".equals(element.getName())) { dataSetCitation.setDatasetCreator(element.getTextTrim()); } else if ("Dataset_Title".equals(element.getName())) { dataSetCitation.setDatasetTitle(element.getTextTrim()); } else if ("Dataset_Series_Name".equals(element.getName())) { dataSetCitation.setDatasetSeriesName(element.getTextTrim()); } else if ("Dataset_Release_Date".equals(element.getName())) { dataSetCitation.setDatasetReleaseDate(element.getTextTrim()); } else if ("Dataset_Release_Place".equals(element.getName())) { dataSetCitation.setDatasetReleasePlace(element.getTextTrim()); } else if ("Dataset_Publisher".equals(element.getName())) { dataSetCitation.setDatasetPublisher(element.getTextTrim()); } else if ("Version".equals(element.getName())) { dataSetCitation.setVersion(element.getTextTrim()); } else if ("Online_Resource".equals(element.getName())) { dataSetCitation.setOnlineResource(element.getTextTrim()); } } dif.getDataSetCitation().add(dataSetCitation); } //create Personnel(s) List<Element> personnelList = difElement.getChildren("Personnel", ns); for (Element personnelElement : personnelList) { List<Element> personnelElementChildren = personnelElement.getChildren(); Personnel personnel = new Personnel(); for (Element element : personnelElementChildren) { if ("Role".equals(element.getName())) { personnel.getRole().add(element.getTextTrim()); } else if ("First_Name".equals(element.getName())) { personnel.setFirstName(element.getTextTrim()); } else if ("Last_Name".equals(element.getName())) { personnel.setLastName(element.getTextTrim()); } else if ("Email".equals(element.getName())) { personnel.getEmail().add(element.getTextTrim()); } } dif.getPersonnel().add(personnel); } //create Parameters(s) List<Element> parameterList = difElement.getChildren("Parameters", ns); for (Element parameterElement : parameterList) { List<Element> parameterElementChildren = parameterElement.getChildren(); Parameters parameters = new Parameters(); for (Element element : parameterElementChildren) { if ("Category".equals(element.getName())) { parameters.setCategory(element.getTextTrim()); } else if ("Topic".equals(element.getName())) { parameters.setTopic(element.getTextTrim()); } else if ("Detailed_Variable".equals(element.getName())) { parameters.setDetailedVariable(element.getTextTrim()); } else if ("Term".equals(element.getName())) { parameters.setTerm(element.getTextTrim()); } else if ("Variable_Level_1".equals(element.getName())) { parameters.setVariableLevel1(element.getTextTrim()); } else if ("Variable_Level_2".equals(element.getName())) { parameters.setVariableLevel2(element.getTextTrim()); } else if ("Variable_Level_3".equals(element.getName())) { parameters.setVariableLevel3(element.getTextTrim()); } } dif.getParameters().add(parameters); } //create Sensor_Name(s) List<Element> sensorNameList = difElement.getChildren("Sensor_Name", ns); for (Element sensorNameElement : sensorNameList) { List<Element> sensorNameElementChildren = sensorNameElement.getChildren(); SensorName sensorName = new SensorName(); for (Element element : sensorNameElementChildren) { if ("Short_Name".equals(element.getName())) { sensorName.setShortName(element.getTextTrim()); } else if ("Long_Name".equals(element.getName())) { sensorName.setLongName(element.getTextTrim()); } } dif.getSensorName().add(sensorName); } //create Source_Name(s) List<Element> sourceNameList = difElement.getChildren("Source_Name", ns); for (Element sourceNameElement : sourceNameList) { List<Element> sourceNameElementChildren = sourceNameElement.getChildren(); SourceName sourceName = new SourceName(); for (Element element : sourceNameElementChildren) { if ("Short_Name".equals(element.getName())) { sourceName.setShortName(element.getTextTrim()); } else if ("Long_Name".equals(element.getName())) { sourceName.setLongName(element.getTextTrim()); } } dif.getSourceName().add(sourceName); } //create Temporal_Coverage(s) List<Element> temporalCoverageList = difElement.getChildren("Temporal_Coverage", ns); for (Element temporalCoverageElement : temporalCoverageList) { List<Element> temporalCoverageElementChildren = temporalCoverageElement.getChildren(); TemporalCoverage temporalCoverage = new TemporalCoverage(); for (Element element : temporalCoverageElementChildren) { if ("Start_Date".equals(element.getName())) { temporalCoverage.setStartDate(element.getTextTrim()); } else if ("Stop_Date".equals(element.getName())) { temporalCoverage.setStopDate(element.getTextTrim()); } } dif.getTemporalCoverage().add(temporalCoverage); } //create Spatial_Coverage(s) List<Element> spatialCoverageList = difElement.getChildren("Spatial_Coverage", ns); for (Element spatiaCoverageElement : spatialCoverageList) { List<Element> spatiallCoverageElementChildren = spatiaCoverageElement.getChildren(); SpatialCoverage spatialCoverage = new SpatialCoverage(); for (Element element : spatiallCoverageElementChildren) { if ("Easternmost_Longitude".equals(element.getName())) { spatialCoverage.setEasternmostLongitude(element.getTextTrim()); } else if ("Maximum_Altitude".equals(element.getName())) { spatialCoverage.setMaximumAltitude(element.getTextTrim()); } else if ("Maximum_Depth".equals(element.getName())) { spatialCoverage.setMaximumDepth(element.getTextTrim()); } else if ("Minimum_Altitude".equals(element.getName())) { spatialCoverage.setMinimumAltitude(element.getTextTrim()); } else if ("Minimum_Depth".equals(element.getName())) { spatialCoverage.setMinimumDepth(element.getTextTrim()); } else if ("Northernmost_Latitude".equals(element.getName())) { spatialCoverage.setNorthernmostLatitude(element.getTextTrim()); } else if ("Southernmost_Latitude".equals(element.getName())) { spatialCoverage.setSouthernmostLatitude(element.getTextTrim()); } else if ("Westernmost_Longitude".equals(element.getName())) { spatialCoverage.setWesternmostLongitude(element.getTextTrim()); } } dif.getSpatialCoverage().add(spatialCoverage); } //create Location(s) List<Element> locationList = difElement.getChildren("Location", ns); for (Element locationElement : locationList) { List<Element> locationElementChildren = locationElement.getChildren(); Location location = new Location(); for (Element element : locationElementChildren) { if ("Detailed_Location".equals(element.getName())) { location.setDetailedLocation(element.getTextTrim()); } else if ("Location_Category".equals(element.getName())) { location.setLocationCategory(element.getTextTrim()); } else if ("Location_Subregion_1".equals(element.getName())) { location.setLocationSubregion1(element.getTextTrim()); } else if ("Location_Subregion_2".equals(element.getName())) { location.setLocationSubregion2(element.getTextTrim()); } else if ("Location_Subregion_3".equals(element.getName())) { location.setLocationSubregion3(element.getTextTrim()); } else if ("Location_Type".equals(element.getName())) { location.setLocationType(element.getTextTrim()); } } dif.getLocation().add(location); } //create Data_Resolution(s) List<Element> dataResolutionList = difElement.getChildren("Data_Resolution", ns); for (Element dataResolutionElement : dataResolutionList) { List<Element> dataResolutionElementChildren = dataResolutionElement.getChildren(); DataResolution dataResolution = new DataResolution(); for (Element element : dataResolutionElementChildren) { if ("Horizontal_Resolution_Range".equals(element.getName())) { dataResolution.setHorizontalResolutionRange(element.getTextTrim()); } else if ("Latitude_Resolution".equals(element.getName())) { dataResolution.setLatitudeResolution(element.getTextTrim()); } else if ("Longitude_Resolution".equals(element.getName())) { dataResolution.setLongitudeResolution(element.getTextTrim()); } else if ("Temporal_Resolution".equals(element.getName())) { dataResolution.setTemporalResolution(element.getTextTrim()); } else if ("Temporal_Resolution_Range".equals(element.getName())) { dataResolution.setTemporalResolutionRange(element.getTextTrim()); } else if ("Vertical_Resolution".equals(element.getName())) { dataResolution.setVerticalResolution(element.getTextTrim()); } else if ("Vertical_Resolution_Range".equals(element.getName())) { dataResolution.setVerticalResolutionRange(element.getTextTrim()); } } dif.getDataResolution().add(dataResolution); } //create Project(s) List<Element> projectList = difElement.getChildren("Project", ns); for (Element projectElement : projectList) { List<Element> projectElementChildren = projectElement.getChildren(); Project project = new Project(); for (Element element : projectElementChildren) { if ("Long_Name".equals(element.getName())) { project.setLongName(element.getTextTrim()); } else if ("Short_Name".equals(element.getName())) { project.setShortName(element.getTextTrim()); } } dif.getProject().add(project); } //create Data_Center(s) List<Element> dataCenterList = difElement.getChildren("Data_Center", ns); for (Element dataCenterElement : dataCenterList) { List<Element> dataCenterElementChildren = dataCenterElement.getChildren(); DataCenter dataCenter = new DataCenter(); for (Element dataCenterElementChild : dataCenterElementChildren) { if ("Data_Center_Name".equals(dataCenterElementChild.getName())) { //create Data_Center_Name DataCenterName dataCenterName = new DataCenterName(); List<Element> dataCenterNameChildren = dataCenterElementChild.getChildren(); for (Element dataCenterNameChild : dataCenterNameChildren) { if ("Long_Name".equals(dataCenterNameChild.getName())) { dataCenterName.setLongName(dataCenterNameChild.getTextTrim()); } else if ("Short_Name".equals(dataCenterNameChild.getName())) { dataCenterName.setShortName(dataCenterNameChild.getTextTrim()); } } dataCenter.setDataCenterName(dataCenterName); } else if ("Data_Center_URL".equals(dataCenterElementChild.getName())) { dataCenter.setDataCenterURL(dataCenterElementChild.getTextTrim()); } else if ("Personnel".equals(dataCenterElementChild.getName())) { //create data center Personnel Personnel personnel = new Personnel(); List<Element> dataCenterPersonnelChildren = dataCenterElementChild.getChildren(); for (Element element : dataCenterPersonnelChildren) { if ("Role".equals(element.getName())) { personnel.getRole().add(element.getTextTrim()); } else if ("First_Name".equals(element.getName())) { personnel.setFirstName(element.getTextTrim()); } else if ("Last_Name".equals(element.getName())) { personnel.setLastName(element.getTextTrim()); } else if ("Email".equals(element.getName())) { personnel.getEmail().add(element.getTextTrim()); } } dataCenter.getPersonnel().add(personnel); } } dif.getDataCenter().add(dataCenter); } //create Summary(s) List<Element> summaryList = difElement.getChildren("Summary", ns); for (Element summaryListElement : summaryList) { Summary summary = new Summary(); List<Element> summaryListElementChildren = summaryListElement.getChildren(); for (Element summaryListElementChild : summaryListElementChildren) { if ("Abstract".equals(summaryListElementChild.getName())) { ObjectFactory factory = new ObjectFactory(); summary.getContent().add(factory.createAbstract(summaryListElementChild.getTextTrim())); } } dif.setSummary(summary); } //create IDN_Node(s) List<Element> idnNodeList = difElement.getChildren("IDN_Node", ns); for (Element idnNodeListElement : idnNodeList) { IDNNode idnNode = new IDNNode(); List<Element> idnNodeListElementChildren = idnNodeListElement.getChildren(); for (Element element : idnNodeListElementChildren) { if ("Short_Name".equals(element.getName())) { idnNode.setShortName(element.getTextTrim()); } else if ("Long_Name".equals(element.getName())) { idnNode.setLongName(element.getTextTrim()); } } dif.getIDNNode().add(idnNode); } } catch (Exception e) { LOG.error("Error whilst parsing Atom XML response from Dataset Search: ", e); } return dif; }
From source file:org.fnppl.opensdx.dmi.wayin.PieToOpenSDXImporter.java
License:Open Source License
private Feed getImportFeed() { // do the import Feed feed = null;//w ww. j a v a2 s .co 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.helm.notation2.MonomerFactory.java
License:Open Source License
private static MonomerCache buildMonomerCacheFromXML(InputStream monomerDBInputStream) throws MonomerException, IOException, JDOMException, ChemistryException, CTKException { if (null == builder) { setupBuilder();/* w w w . j a va 2 s . c om*/ } Document doc = builder.build(monomerDBInputStream); Element root = doc.getRootElement(); Element polymerList = root.getChild(POLYMER_LIST_ELEMENT, root.getNamespace()); Element attachmentList = root.getChild(ATTACHMENT_LIST_ELEMENT, root.getNamespace()); Map<String, Attachment> newAttachmentDB = buildAttachmentDB(attachmentList); Map<String, Map<String, Monomer>> newMonomerDB = buildMonomerDB(polymerList); Map<String, Monomer> newSmilesMonomerDB = buildSmilesMonomerDB(newMonomerDB); MonomerCache cache = new MonomerCache(); cache.setMonomerDB(newMonomerDB); cache.setAttachmentDB(newAttachmentDB); cache.setSmilesMonomerDB(newSmilesMonomerDB); return cache; }