Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public void updateCoordinateMenu(boolean isClassicViewCoordinate) {
}

if (menuItems != null) {
// TODO creating a new ViewCalculator causes XML and negative nids to be rendered in the view coordinate menu
// TODO reusing the existing ViewCalculator causes the Spanish language to not be rendered, remains in English
// (rather than Spanish: Ingles y Espanol)
ViewCalculatorWithCache viewCalculator = ViewCalculatorWithCache.getCalculator(this.viewProperties.nodeView().getValue());
var viewMenuTask = new ViewMenuTask(viewCalculator, viewProperties.nodeView(), whichMenu);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
import dev.ikm.tinkar.coordinate.view.calculator.ViewCalculator;
import dev.ikm.tinkar.entity.Entity;
import dev.ikm.tinkar.entity.StampService;
import dev.ikm.tinkar.terms.*;
import dev.ikm.tinkar.terms.ConceptFacade;
import dev.ikm.tinkar.terms.EntityFacade;
import dev.ikm.tinkar.terms.EntityProxy;
import dev.ikm.tinkar.terms.PatternFacade;
import dev.ikm.tinkar.terms.TinkarTerm;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
Expand All @@ -50,9 +54,19 @@
import org.eclipse.collections.impl.factory.primitive.IntObjectMaps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.LongConsumer;

import static dev.ikm.tinkar.common.service.PrimitiveData.PREMUNDANE_TIME;
Expand Down Expand Up @@ -744,11 +758,58 @@ private static String getNameAndValueString(ViewCalculator viewCalculator, Prope
return sb.toString();
}

/// Extracts the "desc" attribute from the XML stirng provided, if the string provides is actually in
/// XML and if the XML contains the "desc" attribute.
private static String extractDescAttribute(String xmlStr) {
final String DESC_ATTR = "desc";
String extractedStr = xmlStr;

if (xmlStr != null && xmlStr.startsWith("<") && xmlStr.endsWith("/>") && xmlStr.contains(DESC_ATTR)) {
LOG.debug("The viewCalculator returned XML for the preferred name: {}", xmlStr);

try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new ByteArrayInputStream(xmlStr.getBytes()));
doc.normalizeDocument();

// first get the element name from the XML string
int spaceIndex = xmlStr.indexOf(" ");
String elementName = xmlStr.substring(1, spaceIndex);

// next get the element node from the document
NodeList nodeList = doc.getElementsByTagName(elementName);
Element element = (Element) nodeList.item(0);

// finally get the attribute value from the element
String attributeValue = element.getAttribute(DESC_ATTR);

if (attributeValue != null) {
extractedStr = attributeValue;
}
} catch (Exception e) {
LOG.error("An exception occurred parsing XML", e);
}
}

return extractedStr;
}

/// Gets the property name from either the PropertyWithOverride or from the ViewCalculator.
private static String getPropertyNameWithOverride(ViewCalculator viewCalculator, Property<?> baseProperty) {
String prefString;

if (baseProperty instanceof PropertyWithOverride propertyWithOverride) {
return propertyWithOverride.getOverrideName(viewCalculator);
prefString = propertyWithOverride.getOverrideName(viewCalculator);
} else {
var name = baseProperty.getName();
prefString = viewCalculator.toPreferredEntityStringOrInputString(name);
}
return viewCalculator.toPreferredEntityStringOrInputString(baseProperty.getName());

// extract the "desc" attribute if the prefString is in XML
prefString = extractDescAttribute(prefString);

return prefString;
}

@Override
Expand Down Expand Up @@ -781,6 +842,7 @@ private void makeCoordinateDisplayMenu(ViewCalculator viewCalculator,
makeRecursiveOverrideMenu(viewCalculator, menuItems,
observableCoordinate);

// TODO the XML that appears in the view coordinate menu comes from the baseProperties
for (Property<?> baseProperty : observableCoordinate.getBaseProperties()) {
// variables added for simpler debugging
var basePropStr = baseProperty.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ public void setup(KometPreferences nodePreferences) {
}));

windowSettings.getView().addListener((observable, oldValue, newValue) -> {
// TODO creating a new ViewCalculator causes XML and negative nids to be rendered in the view coordinate menu
// TODO reusing the existing ViewCalculator causes the Spanish language to not be rendered, remains in English
// (rather than Spanish: Ingles y Espanol)
ViewCalculatorWithCache listenerViewCalculator = ViewCalculatorWithCache.getCalculator(windowView.toViewCoordinateRecord());
TinkExecutor.threadPool().execute(TaskWrapper.make(new ViewMenuTask(listenerViewCalculator, windowView, "JournalController"),
(List<MenuItem> result) ->
Expand Down