Java Code Examples for org.jdom2.Element#getTextTrim()
The following examples show how to use
org.jdom2.Element#getTextTrim() .
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: CrawlableCatalog.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Constructor. * * @param catalogURL the catalog URL * @param configObj a JDOM Element, example: * * <pre> * <any> * <serviceType>OPENDAP</serviceType> * </any> * </pre> */ public CrawlableCatalog(String catalogURL, Object configObj) { this.catalogURL = catalogURL; this.configObj = configObj; if (configObj instanceof Element) { Element configElement = (Element) configObj; Element serviceElement = configElement.getChild("serviceType", XMLEntityResolver.ncmlNS); if (null != serviceElement) { String service = serviceElement.getTextTrim(); serviceType = ServiceType.getType(service); } } InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(true); catalog = catFactory.readXML(catalogURL); dataset = (InvDatasetImpl) catalog.getDataset(); isCollection = true; }
Example 2
Source File: ClamlClassProcessor.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
protected static String getPreferredRubricLabel(Element classElement, String lang) { Iterator<Element> it = classElement.getChildren(ClamlConstants.RUBRIC_ELEMENT).iterator(); String label = null; while (it.hasNext() && label == null) { Element rubric = it.next(); if (ClamlConstants.RUBRIC_KIND_PREFFERD_ATTR.equals(rubric.getAttributeValue(ClamlConstants.KIND_ATTR))) { Element labelElement = rubric.getChild(ClamlConstants.LABEL_ELEMENT); if (labelElement != null) { if (CommonUtil.isEmptyString(lang) || lang.equals(labelElement.getAttributeValue(ClamlConstants.XML_LANG, Namespace.XML_NAMESPACE))) { label = labelElement.getTextTrim(); } } else { throw new IllegalArgumentException(getKind(classElement) + " " + getCode(classElement) + ": " + ClamlConstants.RUBRIC_ELEMENT + " without " + ClamlConstants.LABEL_ELEMENT); } } } return label; }
Example 3
Source File: MCRMODSDateHelper.java From mycore with GNU General Public License v3.0 | 6 votes |
public static Date getDate(Element element) { if (element == null) { return null; } String text = element.getTextTrim(); if ((text == null) || text.isEmpty()) { return null; } String encoding = element.getAttributeValue("encoding", "unknown").toLowerCase(DATE_LOCALE); String key = encoding + "-" + text.length(); MCRMODSDateFormat format = firstNonNull(MCRMODSDateFormat.getFormat(key), MCRMODSDateFormat.getFormat(encoding)); if (format == null) { throw reportParseException(encoding, text, null); } try { return format.parseDate(text); } catch (ParseException ex) { throw reportParseException(encoding, text, ex); } }
Example 4
Source File: MCRLayoutUtilities.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * Returns all labels of the ancestor axis for the given item within * navigation.xml * * @param item a navigation item * @return Label as String, like "labelRoot > labelChild > * labelChildOfChild" */ public static String getAncestorLabels(Element item) { StringBuilder label = new StringBuilder(); String lang = MCRSessionMgr.getCurrentSession().getCurrentLanguage().trim(); XPathExpression<Element> xpath; Element ic = null; xpath = XPATH_FACTORY.compile("//.[@href='" + getWebpageID(item) + "']", Filters.element()); ic = xpath.evaluateFirst(getNavi()); while (ic.getName().equals("item")) { ic = ic.getParentElement(); String webpageID = getWebpageID(ic); Element labelEl = null; xpath = XPATH_FACTORY.compile("//.[@href='" + webpageID + "']/label[@xml:lang='" + lang + "']", Filters.element()); labelEl = xpath.evaluateFirst(getNavi()); if (labelEl != null) { if (label.length() == 0) { label = new StringBuilder(labelEl.getTextTrim()); } else { label.insert(0, labelEl.getTextTrim() + " > "); } } } return label.toString(); }
Example 5
Source File: MCREditorOutValidator.java From mycore with GNU General Public License v3.0 | 6 votes |
public String checkDataSubTag(Element datasubtag) { Element[] children = datasubtag.getChildren("text").toArray(Element[]::new); int textCount = children.length; for (int i = 0; i < children.length; i++) { Element child = children[i]; String text = child.getTextTrim(); if (text == null || text.length() == 0) { child.detach(); textCount--; continue; } if (child.getAttribute("lang") != null) { child.getAttribute("lang").setNamespace(XML_NAMESPACE); LOGGER.warn("namespace add for xml:lang attribute in {}", datasubtag.getName()); } } if (textCount == 0) { return "history date is empty"; } return checkMetaObjectWithLang(datasubtag, MCRMetaHistoryDate.class); }
Example 6
Source File: XmlIoViewInterestPoints.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public ViewInterestPoints fromXml( final Element allInterestPointLists, final File basePath, final Map< ViewId, ViewDescription > viewDescriptions ) throws SpimDataException { final ViewInterestPoints viewsInterestPoints = super.fromXml( allInterestPointLists ); viewsInterestPoints.createViewInterestPoints( viewDescriptions ); for ( final Element viewInterestPointsElement : allInterestPointLists.getChildren( VIEWINTERESTPOINTSFILE_TAG ) ) { final int timepointId = Integer.parseInt( viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_TIMEPOINT_ATTRIBUTE_NAME ) ); final int setupId = Integer.parseInt( viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_SETUP_ATTRIBUTE_NAME ) ); final String label = viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_LABEL_ATTRIBUTE_NAME ); final String parameters = viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_PARAMETERS_ATTRIBUTE_NAME ); final String interestPointFileName = viewInterestPointsElement.getTextTrim(); final ViewId viewId = new ViewId( timepointId, setupId ); final ViewInterestPointLists collection = viewsInterestPoints.getViewInterestPointLists( viewId ); // we do not load the interestpoints nor the correspondinginterestpoints, we just do that once it is requested final InterestPointList list = new InterestPointList( basePath, new File( interestPointFileName ) ); list.setParameters( parameters ); collection.addInterestPointList( label, list ); } return viewsInterestPoints; }
Example 7
Source File: MCREditorOutValidator.java From mycore with GNU General Public License v3.0 | 5 votes |
public static String checkMetaObjectWithLangNotEmpty(Element datasubtag, Class<? extends MCRMetaInterface> metaClass) { String text = datasubtag.getTextTrim(); if (text == null || text.length() == 0) { return "Element " + datasubtag.getName() + " has no text."; } return checkMetaObjectWithLang(datasubtag, metaClass); }
Example 8
Source File: MCRSimpleContentStoreSelector.java From mycore with GNU General Public License v3.0 | 5 votes |
public MCRSimpleContentStoreSelector() { String file = MCRConfiguration2.getStringOrThrow("MCR.IFS.ContentStoreSelector.ConfigFile"); Element xml = MCRURIResolver.instance().resolve("resource:" + file); if (xml == null) { throw new MCRConfigurationException("Could not load configuration file from resource:" + file); } typeStoreMap = new HashMap<>(); List<Element> stores = xml.getChildren("store"); storeIDs = new String[stores.size() + 1]; for (int i = 0; i < stores.size(); i++) { Element store = stores.get(i); String storeID = store.getAttributeValue("ID"); storeIDs[i] = storeID; List<Element> types = store.getChildren(); for (Object type1 : types) { Element type = (Element) type1; String typeID = type.getTextTrim(); typeStoreMap.put(typeID, storeID); } } defaultID = xml.getAttributeValue("default"); // NOTE: if defaultID is listed as a <store> it's inserted twice here storeIDs[storeIDs.length - 1] = defaultID; }
Example 9
Source File: MediaModuleParser.java From rome with Apache License 2.0 | 5 votes |
/** * @param e element to parse * @param md metadata to fill in */ private void parseCommunity(final Element e, final Metadata md) { final Element communityElement = e.getChild("community", getNS()); if (communityElement != null) { final Community community = new Community(); final Element starRatingElement = communityElement.getChild("starRating", getNS()); if (starRatingElement != null) { final StarRating starRating = new StarRating(); starRating.setAverage(Doubles.parse(starRatingElement.getAttributeValue("average"))); starRating.setCount(Integers.parse(starRatingElement.getAttributeValue("count"))); starRating.setMax(Integers.parse(starRatingElement.getAttributeValue("max"))); starRating.setMin(Integers.parse(starRatingElement.getAttributeValue("min"))); community.setStarRating(starRating); } final Element statisticsElement = communityElement.getChild("statistics", getNS()); if (statisticsElement != null) { final Statistics statistics = new Statistics(); statistics.setFavorites(Integers.parse(statisticsElement.getAttributeValue("favorites"))); statistics.setViews(Integers.parse(statisticsElement.getAttributeValue("views"))); community.setStatistics(statistics); } final Element tagsElement = communityElement.getChild("tags", getNS()); if (tagsElement != null) { final String tagsText = tagsElement.getTextTrim(); final String[] tags = tagsText.split("\\s*,\\s*"); for (String tagText : tags) { final String[] tagParts = tagText.split("\\s*:\\s*"); final Tag tag = new Tag(tagParts[0]); if (tagParts.length > 1) { tag.setWeight(Integers.parse(tagParts[1])); } community.getTags().add(tag); } } md.setCommunity(community); } }
Example 10
Source File: MediaModuleParser.java From rome with Apache License 2.0 | 5 votes |
/** * @param e element to parse * @param md metadata to fill in */ private void parseRestrictions(final Element e, final Metadata md) { final List<Element> restrictions = e.getChildren("restriction", getNS()); final ArrayList<Restriction> values = new ArrayList<Restriction>(); for (int i = 0; i < restrictions.size(); i++) { final Element r = restrictions.get(i); Restriction.Type type = null; String restrictionType = r.getAttributeValue("type"); if (restrictionType != null) { if (restrictionType.equalsIgnoreCase(Restriction.Type.URI.toString())){ type = Restriction.Type.URI; } else if (restrictionType.equalsIgnoreCase(Restriction.Type.COUNTRY.toString())) { type = Restriction.Type.COUNTRY; } else if (restrictionType.equalsIgnoreCase(Restriction.Type.SHARING.toString())) { type = Restriction.Type.SHARING; } } Restriction.Relationship relationship = null; if (r.getAttributeValue("relationship").equalsIgnoreCase("allow")) { relationship = Restriction.Relationship.ALLOW; } else if (r.getAttributeValue("relationship").equalsIgnoreCase("deny")) { relationship = Restriction.Relationship.DENY; } final Restriction value = new Restriction(relationship, type, r.getTextTrim()); values.add(value); } md.setRestrictions(values.toArray(new Restriction[values.size()])); }
Example 11
Source File: MCRMODSWrapper.java From mycore with GNU General Public License v3.0 | 4 votes |
public String getElementValue(String xPath) { Element element = getElement(xPath); return (element == null ? null : element.getTextTrim()); }
Example 12
Source File: MCRRealmFactory.java From mycore with GNU General Public License v3.0 | 4 votes |
/** * */ private static void loadRealms() { Element root; try { root = getRealms().getRootElement(); } catch (SAXException | JDOMException | TransformerException | IOException e) { throw new MCRException("Could not load realms from URI: " + realmsURI); } String localRealmID = root.getAttributeValue("local"); HashMap<String, MCRRealm> realmsMap = new HashMap<>(); HashMap<String, MCRUserAttributeMapper> attributeMapper = new HashMap<>(); List<MCRRealm> realmsList = new ArrayList<>(); List<Element> realms = root.getChildren("realm"); for (Element child : realms) { String id = child.getAttributeValue("id"); MCRRealm realm = new MCRRealm(id); List<Element> labels = child.getChildren("label"); for (Element label : labels) { String text = label.getTextTrim(); String lang = label.getAttributeValue("lang", Namespace.XML_NAMESPACE); realm.setLabel(lang, text); } realm.setPasswordChangeURL(child.getChildTextTrim("passwordChangeURL")); Element login = child.getChild("login"); if (login != null) { realm.setLoginURL(login.getAttributeValue("url")); realm.setRedirectParameter(login.getAttributeValue("redirectParameter")); realm.setRealmParameter(login.getAttributeValue("realmParameter")); } Element createElement = child.getChild("create"); if (createElement != null) { realm.setCreateURL(createElement.getAttributeValue("url")); } attributeMapper.put(id, MCRUserAttributeMapper.instance(child)); realmsMap.put(id, realm); realmsList.add(realm); if (localRealmID.equals(id)) { localRealm = realm; } } MCRRealmFactory.realmsDocument = root.getDocument(); MCRRealmFactory.realmsMap = realmsMap; MCRRealmFactory.realmsList = realmsList; MCRRealmFactory.attributeMapper = attributeMapper; }
Example 13
Source File: MCRQuery.java From mycore with GNU General Public License v3.0 | 4 votes |
/** * Parses a XML representation of a query. * * @param doc * the XML document * @return the parsed MCRQuery */ public static MCRQuery parseXML(Document doc) { Element xml = doc.getRootElement(); Element conditions = xml.getChild("conditions"); MCRQuery query = null; if (conditions.getAttributeValue("format", "xml").equals("xml")) { Element condElem = conditions.getChildren().get(0); query = new MCRQuery(new MCRQueryParser().parse(condElem)); } else { String queryString = conditions.getTextTrim(); query = new MCRQuery(new MCRQueryParser().parse(queryString)); } String max = xml.getAttributeValue("maxResults", ""); query.setMaxResults(max); String num = xml.getAttributeValue("numPerPage", ""); query.setNumPerPage(num); List<MCRSortBy> sortBy = null; Element sortByElem = xml.getChild("sortBy"); if (sortByElem != null) { List children = sortByElem.getChildren(); sortBy = new ArrayList<>(children.size()); for (Object aChildren : children) { Element sortByChild = (Element) aChildren; String name = sortByChild.getAttributeValue("name"); String ad = sortByChild.getAttributeValue("order"); boolean direction = "ascending".equals(ad) ? MCRSortBy.ASCENDING : MCRSortBy.DESCENDING; sortBy.add(new MCRSortBy(name, direction)); } } if (sortBy != null) { query.setSortBy(sortBy); } Element returns = xml.getChild("returnFields"); if (returns != null) { query.setReturnFields(returns.getText()); } return query; }
Example 14
Source File: MCRWorksSection.java From mycore with GNU General Public License v3.0 | 4 votes |
private String buildIdentifierKey(Element modsIdentifier) { return modsIdentifier.getAttributeValue("type") + ":" + modsIdentifier.getTextTrim(); }