Java Code Examples for org.jdom.Element#getChildTextTrim()
The following examples show how to use
org.jdom.Element#getChildTextTrim() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 6 votes |
/** * Grabs the show/shot/user/uid for this spec. */ private void handleSpecTag() { Element rootElement = doc.getRootElement(); facility = rootElement.getChildTextTrim("facility"); if (facility != null) { facility = facility.toLowerCase(); } show = rootElement.getChildTextTrim("show"); shot = rootElement.getChildTextTrim("shot"); user = rootElement.getChildTextTrim("user"); uid = Optional.ofNullable(rootElement.getChildTextTrim("uid")).map(Integer::parseInt); email = rootElement.getChildTextTrim("email"); if (user == "root" || uid.equals(Optional.of(0))) { throw new SpecBuilderException("Cannot launch jobs as root."); } }
Example 2
Source File: UserXmlParser.java From rice with Educational Community License v2.0 | 6 votes |
protected PrincipalBo constructPrincipal(Element userElement, String entityId) { String principalId = userElement.getChildTextTrim(WORKFLOW_ID_ELEMENT, NAMESPACE); if (principalId == null) { principalId = userElement.getChildTextTrim(PRINCIPAL_ID_ELEMENT, NAMESPACE); } String principalName = userElement.getChildTextTrim(AUTHENTICATION_ID_ELEMENT, NAMESPACE); if (principalName == null) { principalName = userElement.getChildTextTrim(PRINCIPAL_NAME_ELEMENT, NAMESPACE); } PrincipalBo principal = new PrincipalBo(); principal.setActive(true); principal.setPrincipalId(principalId); principal.setPrincipalName(principalName); principal.setEntityId(entityId); principal = KradDataServiceLocator.getDataObjectService().save(principal); return principal; }
Example 3
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 6 votes |
/** * Cores may be specified as a decimal or core points. * * If no core value is specified, we default to the value of * Dispatcher.CORE_POINTS_RESERVED_DEFAULT * * If the value is specified but is less than the minimum allowed, then the * value is reset to the default. * * If the value is specified but is greater than the max allowed, then the * value is reset to the default. * */ private void determineMinimumCores(Element layerTag, LayerDetail layer) { String cores = layerTag.getChildTextTrim("cores"); if (cores == null) { return; } int corePoints = layer.minimumCores; if (cores.contains(".")) { corePoints = (int) (Double.valueOf(cores) * 100 + .5); } else { corePoints = Integer.valueOf(cores); } if (corePoints < Dispatcher.CORE_POINTS_RESERVED_MIN || corePoints > Dispatcher.CORE_POINTS_RESERVED_MAX) { corePoints = Dispatcher.CORE_POINTS_RESERVED_DEFAULT; } layer.minimumCores = corePoints; }
Example 4
Source File: CreoleAnnotationHandler.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * Process the given RESOURCE element, adding extra elements to it based on * the annotations on the resource class. * * @param element * the RESOURCE element to process. */ private void processAnnotationsForResource(Element element) throws GateException { String className = element.getChildTextTrim("CLASS"); if(className == null) { throw new GateException( "\"CLASS\" element not found for resource in " + plugin); } Class<?> resourceClass = null; try { resourceClass = Gate.getClassLoader().loadClass(className); } catch(ClassNotFoundException e) { log.debug("Couldn't load class " + className + " for resource in " + plugin, e); throw new GateException("Couldn't load class " + className + " for resource in " + plugin); } processCreoleResourceAnnotations(element, resourceClass); }
Example 5
Source File: FeatureSpecification.java From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 | 6 votes |
/** * Return the text of a single child element or a default value. This checks that there is at most * one child of this annType and throws and exception if there are more than one. If there is no * child of this name, then the value elseVal is returned. NOTE: the value returned is trimmed if * it is a string, but case is preserved. * NOTE: this tries both the all-uppercase and the all-lowercase variant of the given name. */ private static String getChildTextOrElse(Element parent, String name, String elseVal) { @SuppressWarnings("unchecked") List<Element> children = parent.getChildren(name); if (children.size() > 1) { throw new GateRuntimeException("Element " + parent.getName() + " has more than one nested " + name + " element"); } if(children.isEmpty()) { return elseVal; } String tmp = parent.getChildTextTrim(name.toUpperCase()); if(tmp == null) { tmp = parent.getChildText(name.toLowerCase()); } if (tmp == null) { return elseVal; } else { return tmp; } }
Example 6
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static String getStringVal(final Element e, final String childText, final boolean trim) { if (e == null) { return null; } else { if (trim) { return e.getChildTextTrim(childText); } else { return e.getChildText(childText); } } }
Example 7
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static String getStringVal(final Element e, final String childText, final Namespace ns) { if (e == null) { return null; } else { return e.getChildTextTrim(childText, ns); } }
Example 8
Source File: PrintHandler.java From sakai with Educational Community License v2.0 | 5 votes |
public void setManifestMetadataXml(Element the_md) { if (log.isDebugEnabled()) log.debug("manifest md xml: "+the_md); // NOTE: need to handle languages if (the_md != null) { Element general = the_md.getChild(GENERAL, ns.getLom()); if (general != null) { Element tnode = general.getChild(TITLE, ns.getLom()); if (tnode != null) { title = tnode.getChildTextTrim(LANGSTRING, ns.getLom()); if (title == null || title.equals("")) title = tnode.getChildTextTrim(STRING, ns.getLom()); } Element tdescription=general.getChild(DESCRIPTION, ns.getLom()); if (tdescription != null) { description = tdescription.getChildTextTrim(STRING, ns.getLom()); } } } if (title == null || title.equals("")) title = "Cartridge"; if ("".equals(description)) description = null; ContentCollection baseCollection = makeBaseFolder(title); baseName = baseCollection.getId(); baseUrl = baseCollection.getUrl(); // kill the hostname part. We want to use relative URLs int relPart = baseUrl.indexOf("/access/"); if (relPart >= 0) baseUrl = baseUrl.substring(relPart); //Start a folder to hold the entire sites content rather than create new top level pages boolean singlePage = ServerConfigurationService.getBoolean("lessonbuilder.cc.import.singlepage", false); if (singlePage == true) startCCFolder(null); }
Example 9
Source File: PrintHandler.java From sakai with Educational Community License v2.0 | 5 votes |
public void setManifestMetadataXml(Element the_md) { if (log.isDebugEnabled()) log.debug("manifest md xml: "+the_md); // NOTE: need to handle languages if (the_md != null) { Element general = the_md.getChild(GENERAL, ns.getLom()); if (general != null) { Element tnode = general.getChild(TITLE, ns.getLom()); if (tnode != null) { title = tnode.getChildTextTrim(LANGSTRING, ns.getLom()); if (title == null || title.equals("")) title = tnode.getChildTextTrim(STRING, ns.getLom()); } Element tdescription=general.getChild(DESCRIPTION, ns.getLom()); if (tdescription != null) { description = tdescription.getChildTextTrim(STRING, ns.getLom()); } } } if (title == null || title.equals("")) title = "Cartridge"; if ("".equals(description)) description = null; ContentCollection baseCollection = makeBaseFolder(title); baseName = baseCollection.getId(); baseUrl = baseCollection.getUrl(); // kill the hostname part. We want to use relative URLs int relPart = baseUrl.indexOf("/access/"); if (relPart >= 0) baseUrl = baseUrl.substring(relPart); //Start a folder to hold the entire sites content rather than create new top level pages boolean singlePage = ServerConfigurationService.getBoolean("lessonbuilder.cc.import.singlepage", false); if (singlePage == true) startCCFolder(null); }
Example 10
Source File: PodcastService.java From subsonic with GNU General Public License v3.0 | 5 votes |
private String getITunesElement(Element element, String childName) { for (Namespace ns : ITUNES_NAMESPACES) { String value = element.getChildTextTrim(childName, ns); if (value != null) { return value; } } return null; }
Example 11
Source File: PodcastService.java From subsonic with GNU General Public License v3.0 | 5 votes |
private String getChannelImageUrl(Element channelElement) { String result = getITunesAttribute(channelElement, "image", "href"); if (result == null) { Element imageElement = channelElement.getChild("image"); if (imageElement != null) { result = imageElement.getChildTextTrim("url"); } } return result; }
Example 12
Source File: CreoleAnnotationHandler.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private void findResourceElements(Map<String, Element> map, Element elt) { if(elt.getName().equals("RESOURCE")) { String className = elt.getChildTextTrim("CLASS"); if(className != null) { map.put(className, elt); } } else { for(Element child : (List<Element>)elt.getChildren()) { findResourceElements(map, child); } } }
Example 13
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 5 votes |
/** * Converts the job space tagging format into a set of strings. Also * verifies each tag. * * @param job * @param layer * @return */ private void determineTags(BuildableJob job, LayerDetail layer, Element layerTag) { Set<String> newTags = new LinkedHashSet<String>(); String tags = layerTag.getChildTextTrim("tags"); if (tags == null) { return; } if (tags.length() == 0) { return; } String[] e = tags.replaceAll(" ", "").split("\\|"); for (String s : e) { if (e.length == 0) { continue; } Matcher matcher = NAME_PATTERN.matcher(s); if (!matcher.matches()) { throw new SpecBuilderException("error, invalid tag " + s + ", tags must be alpha numberic and at least " + "3 characters in length."); } newTags.add(s); } if (newTags.size() > 0) { layer.tags = newTags; } }
Example 14
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 5 votes |
/** * Determine if the layer is threadable. A manually set threadable * option in the job spec should override the service defaults. * * @param layerTag * @param layer */ private void determineThreadable(Element layerTag, LayerDetail layer) { // Must have at least 1 core to thread. if (layer.minimumCores < 100) { layer.isThreadable = false; } else if (layerTag.getChildTextTrim("threadable") != null) { layer.isThreadable = Convert.stringToBool( layerTag.getChildTextTrim("threadable")); } }
Example 15
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 5 votes |
/** * If the gpu option is set, set minimumGpu to that supplied value * * @param layerTag * @param layer */ private void determineMinimumGpu(BuildableJob buildableJob, Element layerTag, LayerDetail layer) { if (layerTag.getChildTextTrim("gpu") == null) { return; } long minGpu; String memory = layerTag.getChildTextTrim("gpu").toLowerCase(); try { minGpu = convertMemoryInput(memory); // Some quick sanity checks to make sure gpu memory hasn't gone // over or under reasonable defaults. if (minGpu> Dispatcher.GPU_RESERVED_MAX) { throw new SpecBuilderException("Gpu memory requirements exceed " + "maximum. Are you specifying the correct units?"); } else if (minGpu < Dispatcher.GPU_RESERVED_MIN) { logger.warn(buildableJob.detail.name + "/" + layer.name + "Specified too little gpu memory, defaulting to: " + Dispatcher.GPU_RESERVED_MIN); minGpu = Dispatcher.GPU_RESERVED_MIN; } layer.minimumGpu = minGpu; } catch (Exception e) { logger.info("Error setting gpu memory for " + buildableJob.detail.name + "/" + layer.name + " failed, reason: " + e + ". Using default."); layer.minimumGpu = Dispatcher.GPU_RESERVED_DEFAULT; } }
Example 16
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 5 votes |
private void determineMinimumMemory(BuildableJob buildableJob, Element layerTag, LayerDetail layer, BuildableLayer buildableLayer) { if (layerTag.getChildTextTrim("memory") == null) { return; } long minMemory; String memory = layerTag.getChildTextTrim("memory").toLowerCase(); try { minMemory = convertMemoryInput(memory); // Some quick sanity checks to make sure memory hasn't gone // over or under reasonable defaults. if (minMemory> Dispatcher.MEM_RESERVED_MAX) { throw new SpecBuilderException("Memory requirements exceed " + "maximum. Are you specifying the correct units?"); } else if (minMemory < Dispatcher.MEM_RESERVED_MIN) { logger.warn(buildableJob.detail.name + "/" + layer.name + "Specified too little memory, defaulting to: " + Dispatcher.MEM_RESERVED_MIN); minMemory = Dispatcher.MEM_RESERVED_MIN; } buildableLayer.isMemoryOverride = true; layer.minimumMemory = minMemory; } catch (Exception e) { logger.info("Setting setting memory for " + buildableJob.detail.name + "/" + layer.name + " failed, reason: " + e + ". Using default."); layer.minimumMemory = Dispatcher.MEM_RESERVED_DEFAULT; } }
Example 17
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 4 votes |
private BuildableDependency handleDependTag(Element tag) { BuildableDependency depend = new BuildableDependency(); depend.type = DependType.valueOf(tag.getAttributeValue("type").toUpperCase()); /* * If the depend type is layer on layer, allow dependAny to be set. * Depend any is not implemented for any other depend type. */ if (depend.type.equals(DependType.LAYER_ON_LAYER)) { depend.anyFrame = Convert.stringToBool(tag .getAttributeValue("anyframe")); } /* * Set job names */ depend .setDependErJobName(conformJobName(tag .getChildTextTrim("depjob"))); depend .setDependOnJobName(conformJobName(tag .getChildTextTrim("onjob"))); /* * Set layer names */ String depLayer = tag.getChildTextTrim("deplayer"); String onLayer = tag.getChildTextTrim("onlayer"); if (depLayer != null) { depend.setDependErLayerName(conformLayerName(depLayer)); } if (onLayer != null) { depend.setDependOnLayerName(conformLayerName(onLayer)); } /* * Set frame names */ String depFrame = tag.getChildTextTrim("depframe"); String onFrame = tag.getChildTextTrim("onframe"); if (depFrame != null) { depFrame = conformFrameName(depFrame); depend.setDependErFrameName(depFrame); } if (onFrame != null) { onFrame = conformFrameName(onFrame); depend.setDependOnFrameName(onFrame); } // double check to make sure we don't have two of the same frame/ if (onFrame != null && depFrame != null) { if (onFrame.equals(depFrame)) { throw new SpecBuilderException("The frame name: " + depFrame + " cannot depend on itself."); } } return depend; }
Example 18
Source File: UserXmlParser.java From rice with Educational Community License v2.0 | 4 votes |
protected EntityBo constructEntity(Element userElement) { String firstName = userElement.getChildTextTrim(GIVEN_NAME_ELEMENT, NAMESPACE); String lastName = userElement.getChildTextTrim(LAST_NAME_ELEMENT, NAMESPACE); String emplId = userElement.getChildTextTrim(EMPL_ID_ELEMENT, NAMESPACE); String entityTypeCode = userElement.getChildTextTrim(TYPE_ELEMENT, NAMESPACE); if (StringUtils.isBlank(entityTypeCode)) { entityTypeCode = "PERSON"; } Long entityId = new Long(MaxValueIncrementerFactory.getIncrementer(getKimDataSource(), "KRIM_ENTITY_ID_S") .nextLongValue()); // if they define an empl id, let's set that up EntityEmploymentBo emplInfo = null; if (!StringUtils.isBlank(emplId)) { emplInfo = new EntityEmploymentBo(); emplInfo.setActive(true); emplInfo.setEmployeeId(emplId); emplInfo.setPrimary(true); emplInfo.setEntityId("" + entityId); emplInfo.setId(emplId); emplInfo.setEntityAffiliationId(null); } EntityBo entity = new EntityBo(); entity.setActive(true); entity.setId("" + entityId); List<EntityEmploymentBo> emplInfos = new ArrayList<EntityEmploymentBo>(); if (emplInfo != null) { emplInfos.add(emplInfo); } entity.setEmploymentInformation(emplInfos); EntityTypeContactInfoBo entityType = new EntityTypeContactInfoBo(); entityType.setEntityTypeCode(entityTypeCode); entityType.setEntityId(entity.getId()); entityType.setActive(true); String emailAddress = userElement.getChildTextTrim(EMAIL_ELEMENT, NAMESPACE); if (!StringUtils.isBlank(emailAddress)) { Long emailId = new Long(MaxValueIncrementerFactory.getIncrementer(getKimDataSource(), "KRIM_ENTITY_EMAIL_ID_S").nextLongValue()); EntityEmail.Builder email = EntityEmail.Builder.create(); email.setActive(true); email.setId("" + emailId); email.setEntityTypeCode(entityTypeCode); // must be in krim_email_typ_t.email_typ_cd: email.setEmailType(CodedAttribute.Builder.create("WRK")); //email.setVersionNumber(new Long(1)); email.setEmailAddress(emailAddress); email.setDefaultValue(true); email.setEntityId(entity.getId()); List<EntityEmailBo> emailAddresses = new ArrayList<EntityEmailBo>(1); emailAddresses.add(EntityEmailBo.from(email.build())); entityType.setEmailAddresses(emailAddresses); } List<EntityTypeContactInfoBo> entityTypes = new ArrayList<EntityTypeContactInfoBo>(1); entityTypes.add(entityType); entity.setEntityTypeContactInfos(entityTypes); if (!StringUtils.isBlank(firstName) || !StringUtils.isBlank(lastName)) { Long entityNameId = MaxValueIncrementerFactory.getIncrementer(getKimDataSource(), "KRIM_ENTITY_NM_ID_S") .nextLongValue(); EntityNameBo name = new EntityNameBo(); name.setActive(true); name.setId("" + entityNameId); name.setEntityId(entity.getId()); // must be in krim_ent_nm_typ_t.ent_nm_typ_cd name.setNameCode("PRFR"); name.setFirstName(firstName); name.setMiddleName(""); name.setLastName(lastName); name.setDefaultValue(true); entity.setNames(Collections.singletonList(name)); } entity = KradDataServiceLocator.getDataObjectService().save(entity); return entity; }
Example 19
Source File: JobSpec.java From OpenCue with Apache License 2.0 | 4 votes |
/** * * @param jobTag * @return */ private BuildableJob handleJobTag(Element jobTag) { /* * Read in the job tag */ JobDetail job = new JobDetail(); job.name = conformJobName(jobTag.getAttributeValue("name")); job.state = JobState.STARTUP; job.isPaused = Convert.stringToBool(jobTag.getChildTextTrim("paused")); job.isAutoEat = Convert.stringToBool(jobTag.getChildTextTrim("autoeat")); job.isLocal = false; Element local = jobTag.getChild("localbook"); if (local != null) { job.isLocal = true; job.localHostName = local.getAttributeValue("host"); if (local.getAttributeValue("cores") != null) job.localMaxCores = Integer.parseInt(local.getAttributeValue("cores")); if (local.getAttributeValue("memory") != null) job.localMaxMemory = Integer.parseInt(local.getAttributeValue("memory")); if (local.getAttributeValue("threads") != null) job.localThreadNumber = Integer.parseInt(local.getAttributeValue("threads")); if (local.getAttributeValue("gpu") != null) job.localMaxGpu = Integer.parseInt(local.getAttributeValue("gpu")); } job.maxCoreUnits = 20000; job.minCoreUnits = 100; job.startTime = CueUtil.getTime(); job.maxRetries = FRAME_RETRIES_DEFAULT; job.shot = shot; job.user = user; job.uid = uid; job.email = email; job.os = null; // default to no OS specified job.showName = show; job.facilityName = facility; job.deptName = jobTag.getChildTextTrim("dept"); BuildableJob buildableJob = new BuildableJob(job); if (jobTag.getChildTextTrim("os") != null) { job.os = jobTag.getChildTextTrim("os"); } if (jobTag.getChildTextTrim("maxretries") != null) { job.maxRetries = Integer.valueOf(jobTag .getChildTextTrim("maxretries")); if (job.maxRetries > FRAME_RETRIES_MAX) { job.maxRetries = FRAME_RETRIES_MAX; } else if (job.maxRetries < FRAME_RETRIES_MIN) { job.maxRetries = FRAME_RETRIES_MIN; } } handleLayerTags(buildableJob, jobTag); if (buildableJob.getBuildableLayers().size() > MAX_LAYERS) { throw new SpecBuilderException("The job " + job.name + " has over " + MAX_LAYERS + " layers"); } if (buildableJob.getBuildableLayers().size() < 1) { throw new SpecBuilderException("The job " + job.name + " has no layers"); } Element envTag = jobTag.getChild("env"); if (envTag != null) { handleEnvironmentTag(envTag, buildableJob.env); } return buildableJob; }