/** * Set the value of dir attribute */ public static <T extends Element> void setDirection(Direction direction, T element) { if (direction != Direction.UNSPECIFIED) element.setAttributeValue(DIR, direction.toString().toLowerCase()); else if (direction == Direction.UNSPECIFIED) element.setAttributeValue(DIR, ""); else if (direction == null) element.removeAttribute(DIR); }
/** * Get the in-scope direction for an element. */ public static <T extends Element> Direction getDirection(T element) { Direction direction = Direction.UNSPECIFIED; String dir = element.getAttributeValue("dir"); if (dir != null && dir.length() > 0) direction = Direction.valueOf(dir.toUpperCase()); else if (dir == null) { // if the direction is unspecified on this element, // let's see if we've inherited it Base parent = element.getParentElement(); if (parent != null && parent instanceof Element) direction = getDirection((Element)parent); } return direction; }
private static void writeLanguageFields(Element element, JSONStream jstream) throws IOException { if (needToWriteLang(element)) { String lang = element.getLanguage(); jstream.writeField("lang", lang); } if (needToWriteDir(element)) { Direction dir = BidiHelper.getDirection(element); jstream.writeField("dir", dir.name().toLowerCase()); } }
private static boolean needToWriteDir(Element element) { Direction parentdir = Direction.UNSPECIFIED; Direction dir = BidiHelper.getDirection(element); if (element.getParentElement() != null) { Base parent = element.getParentElement(); if (parent instanceof Element) parentdir = BidiHelper.getDirection((Element)parent); } return dir != Direction.UNSPECIFIED && !dir.equals(parentdir); }