private static YAttribute extractOneReferenceTextAttributeScNode(YAttribute ya) { if(! ll.contains(ya.getKey())) return ya; for(Part p:ya.getRichValue().toParts()){ if(p instanceof Node){ if("sc".equals(((Node)p).getTag())) return new YAttribute(ya.getKey(),new YRichText(((Node)p).getParts().get(0).toString())); }else if(p instanceof Leaf) return new YAttribute(ya.getKey(),new YRichText(((Leaf)p).toPlainText())); } return ya; }
private boolean isHtmlText(YRichText descriptionText) { if (descriptionText == null || descriptionText.isEmpty() || descriptionText.toParts().size() > 1) { return false; } Part part = descriptionText.toParts().get(0); if (!(part instanceof Node)) { return false; } Node node = (Node) part; return BaseYModelUtils.HTML_TAG.equals(node.getTag()) && BaseYModelUtils.XHTML_NAMESPACE.equals(node.getNS()); }
private String toText(final YRichText richText, final boolean flattenText) { if (richText == null) { return ""; } else if (flattenText) { return richText.toText(); } else { return YRTHelper.toXmlFragment(richText, "\n"); } }
protected YRichText convertText(List<Serializable> content) { List<Part> parts = convertToParts(content); YRichText text = new YRichText(parts); return text; }
private boolean isSimple(YRichText yRichText){ List<YRichText.Part> parts = yRichText.toParts(); if(parts.size()==1){ return parts.get(0) instanceof YRichText.Leaf; } return false; }
/** * Checks if rich text is empty or null. * * @param t the rich text to test * @return true if s is null or empty, false otherwise */ private boolean empty(YRichText t) { return t==null || t.isEmpty(); }
/** * Returns the content of an element as {@link YRichText}. If the element is null, returns empty text. * * @param e the element to get the text value from, may be null * @return text extracted from the element content */ private YRichText textOfElement(org.jdom.Element e) { if (e == null) { return new YRichText(); } return YRTHelper.buildYrichText(e); }
@Override public Object convert(YRichText text) { Object result = StringUtils.EMPTY; List<Part> parts = text.toParts(); if (CollectionUtils.isNotEmpty(parts)) { if (parts.size() == 1) { result = convertPart(parts.get(0)); } else { result = new BasicDBObject(YRichTextDbFields.F_CONTENT, convertParts(parts)); } } return result; }
private void storeElementTextInAttribute(org.jdom.Element element, String elementName, YRelation relation, String attributeName) { // String text = elementJDOMHelper.getChildTextTrim(elementName); YRichText text = extractNodeFromElement(element, elementName); if (text != null && !text.isEmpty()) { relation.addAttribute(attributeName, text); } }
private static YAttribute extractOneReferenceTextAttributeScNode(YAttribute ya) { if(! ll.contains(ya.getKey())) return ya; for(Part p:ya.getRichValue().toParts()){ if(p instanceof Node){ if("sc".equals(((Node)p).getTag())) return new YAttribute(ya.getKey(),new YRichText(((Node)p).getParts().get(0).toString())); }else if(p instanceof Leaf) // if(p.toPlainText()!=null && !p.toPlainText().matches("[\\s]+")) return new YAttribute(ya.getKey(),new YRichText(((Leaf)p).toPlainText())); } return ya; } }
@Override public pl.edu.icm.model.bwmeta.y.YRichText convert(Object dbo) { YRichText result; if (isSimpleText(dbo)) { result = new YRichText((String) dbo); } else{ DBObject record = (DBObject) dbo; result = new YRichText(); if(record.containsField(YRichTextDbFields.F_TAG) || record.containsField(YRichTextDbFields.F_NAMESPACE)){ result = new YRichText(Arrays.asList(convertPart(record))); } else { List<?> parts = (List<?>) record.get(YRichTextDbFields.F_CONTENT); result = new YRichText(convertParts(parts)); } } return result; }
private static YElement correctNamesByScRemoval(YElement yelement) { for(YName yn : yelement.getNames()){ removeGivenTag("sc", yn.getRichText().toParts()); } return yelement; }
private KeywordsData makeLocalizedKeywordsData(final YTagList yTagList, final YLanguage yLanguage, Locale locale) { if (yTagList.getType().equals(TG_KEYWORD)) { List<String> tags = new ArrayList<String>(); for (YRichText richTag : yTagList.getRichValues()) { tags.add(richTag.toText().replaceAll(YModelUtils.LF_CR, YModelUtils.CR)); } String longDesc = languageDictionary.getLongDescription(yLanguage.getBibliographicCode(), locale); LanguageData data = new LanguageData(yLanguage, yLanguage.getShortCode(), longDesc); return new KeywordsData(data).setStringData(tags); } return null; }
static YRichText buildYRichTextFromElementContent(Element element){ NodeList nl=element.getChildNodes(); List<YRichText.Part> parts=new ArrayList<>(); StringBuilder lastString=new StringBuilder(); for (int i=0; i<nl.getLength();i++){ Node n=nl.item(i); if (n instanceof CharacterData) { lastString.append(n.getTextContent()); } else if (n instanceof Element) { Element e=(Element) n; if (acceptedHtmlTags.contains(e.getTagName())) { if (lastString.length()>0) { parts.add(new YRichText.Leaf(lastString.toString())); } List<YRichText.Part> li=Collections.singletonList((YRichText.Part)new YRichText.Leaf(e.getTextContent())); YRichText.Node newNode=new YRichText.Node("http://www.w3.org/TR/html4/", e.getTagName(), li); parts.add(newNode); lastString=new StringBuilder(); } else { lastString.append(n.getTextContent()); } } } if (lastString.length()>0) { parts.add(new YRichText.Leaf(lastString.toString())); } return new YRichText(parts); } }
private static YElement correctDescriptionsByScRemoval(YElement yelement) { for(YDescription yd : yelement.getDescriptions()){ removeGivenTag("sc", yd.getRichText().toParts()); } return yelement; }
private void updateCategoryRefs(YElement article, org.jdom.Element kg, String type) { List<org.jdom.Element> ks = JDOMHelper.getChildren(kg, "kwd"); for (org.jdom.Element k : ks) { String codeText = JDOMHelper.textOfElement(k).toText(); for (String code : findAllCategoryCodes(codeText, type)) { YCategoryRef ref = new YCategoryRef(type, code); article.addCategoryRef(ref); } } }
/** * Creates a name with type "canonical" given its language and text. * If the text is empty or null uses the value of <code>canonicalNameDefault</code> * property. * * @param lang language of the name * @param text text of the name, may be null * @return created name */ public YName canonicalName(YLanguage lang, YRichText text) { if (empty(text)) { text = new YRichText(canonicalNameDefault); } return new YName(lang, text, NM_CANONICAL); }
private static YElement correctNamesByScRemoval(YElement yelement) { for(YName yn : yelement.getNames()){ removeGivenTag("sc", yn.getRichText().toParts()); } return yelement; }