use of com.codename1.rad.attributes.Condition in project CodenameOne by codenameone.
the class TextArea method initRowString.
private void initRowString() {
if (!Display.getInstance().isEdt()) {
if (rowStrings == null) {
rowStrings = new ArrayList();
rowStrings.add(getText());
return;
}
}
Style style = getUnselectedStyle();
rowStrings = new ArrayList();
widthForRowCalculations = getWidth() - style.getHorizontalPadding();
// to allow subclasses to override it
if (isSingleLineTextArea()) {
rowStrings.add(getText());
return;
}
if (widthForRowCalculations <= 0) {
rowStrings.add(getText());
setShouldCalcPreferredSize(true);
return;
}
if (text == null || text.equals("")) {
return;
}
Font font = style.getFont();
if (actAsLabel && text.length() <= columns && text.indexOf('\n') < 0) {
int w = font.stringWidth(text);
if (w <= getWidth()) {
if (rowStrings == null) {
rowStrings = new ArrayList();
rowStrings.add(getText());
return;
} else {
rowStrings.clear();
rowStrings.add(getText());
return;
}
}
}
char[] text = preprocess(getText());
int rows = this.rows;
if (growByContent) {
rows = Math.max(rows, getLines());
}
int charWidth = font.charWidth(widestChar);
Style selectedStyle = getSelectedStyle();
if (selectedStyle.getFont() != style.getFont()) {
int cw = selectedStyle.getFont().charWidth(widestChar);
if (cw > charWidth) {
charWidth = cw;
font = selectedStyle.getFont();
}
}
style = getStyle();
int tPadding = style.getHorizontalPadding();
int textAreaWidth = getWidth() - tPadding;
/*if(textAreaWidth <= 0) {
if(columns < 1) {
textAreaWidth = Math.min(Display.getInstance().getDisplayWidth() - tPadding, getText().length()) * charWidth;
} else {
textAreaWidth = Math.min(Display.getInstance().getDisplayWidth() - tPadding, columns) * charWidth;
}
}*/
if (textAreaWidth <= charWidth) {
if (!isInitialized()) {
rowStrings.add(getText());
} else {
// special case for the edge case of "no room".
// Its important since sometimes this case occurs in the GUI builder by accident
int tlen = text.length;
for (int iter = 0; iter < tlen; iter++) {
rowStrings.add("" + text[iter]);
}
}
return;
}
int minCharactersInRow = Math.max(1, textAreaWidth / charWidth);
int from = 0;
int to = from + minCharactersInRow;
int textLength = text.length;
String rowText = null;
int i, spaceIndex;
// width to accommodate it
if (textLength / minCharactersInRow > Math.max(2, rows)) {
textAreaWidth -= getUIManager().getLookAndFeel().getVerticalScrollWidth();
textAreaWidth -= charWidth / 2;
}
String unsupported = getUnsupportedChars();
/*
iteration over the string using indexes, from - the beginning of the row , to - end of a row
for each row we will try to search for a "space" character at the end of the row ( row is text area available width)
indorder to improve the efficiency we do not search an entire row but we start from minCharactersInRow which indicates
what is the minimum amount of characters that can feet in the text area width.
if we dont find we will go backwards and search for the first space available,
if there is no space in the entire row we will cut the line inorder to fit in.
*/
// Don't rely on the fact that short text has no newline character. we always have to parse the text.
to = Math.max(Math.min(textLength - 1, to), 0);
while (to < textLength) {
if (to > textLength) {
to = textLength;
}
spaceIndex = -1;
rowText = "";
int maxLength = to;
if (useStringWidth || actAsLabel) {
// fix for an infinite loop issue: http://forums.java.net/jive/thread.jspa?messageID=482802
// currentRowWidth = 0;
String currentRow = "";
// search for "space" character at close as possible to the end of the row
for (i = to; i < textLength && fastCharWidthCheck(text, from, i - from + 1, textAreaWidth, charWidth, font); i++) {
char c = text[i];
/*if(updateRowWidth(c, font) >= textAreaWidth) {
break;
}*/
currentRow += c;
if (i < textLength - 1 && Character.isSurrogatePair(c, text[i + 1])) {
// Surrogate pairs (e.g. emojis) shouldn't be split up.
currentRow += text[++i];
maxLength += 2;
if (font.stringWidth(currentRow) >= textAreaWidth) {
break;
}
continue;
}
if (font.stringWidth(currentRow) >= textAreaWidth) {
break;
}
if (unsupported.indexOf(c) > -1) {
text[i] = ' ';
c = ' ';
}
if (c == ' ' || c == '\n') {
spaceIndex = i;
// newline has been found. We can end the loop here as the line cannot grow more
if (c == '\n')
break;
}
maxLength++;
}
} else {
currentRowWidth = 0;
if (to != from) {
currentRowWidth = font.charsWidth(text, from, to - from);
}
// search for "space" character at close as possible to the end of the row
for (i = to; i < textLength; i++) {
char c = text[i];
if (i < textLength - 1 && Character.isSurrogatePair(c, text[i + 1])) {
// Surrogate pairs (e.g. emojis) shouldn't be split up.
String testStr = new String(new char[] { text[i], text[i + 1] });
i++;
if (updateRowWidth(testStr, font) >= textAreaWidth) {
break;
}
maxLength += 2;
continue;
}
if (updateRowWidth(c, font) >= textAreaWidth) {
break;
}
if (unsupported.indexOf(c) > -1) {
text[i] = ' ';
c = ' ';
}
if (c == ' ' || c == '\n') {
spaceIndex = i;
// newline has been found. We can end the loop here as the line cannot grow more
if (c == '\n')
break;
}
maxLength++;
}
}
// also if space is next character (in the next row) we can cut the line
if (i == textLength || text[i] == ' ' || text[i] == '\n') {
spaceIndex = i;
}
// if we found space in the limit width of the row (searched only from minCharactersInRow)
if (spaceIndex != -1) {
// make sure that if we have a newline character before the end of the line we should
// break there instead
int newLine = indexOf(text, '\n', from, spaceIndex - from);
if (newLine > -1 && newLine < spaceIndex) {
spaceIndex = newLine;
}
rowText = new String(text, from, spaceIndex - from);
from = spaceIndex + 1;
} else // if there is no space from minCharactersInRow to limit need to search backwards
{
for (i = to; spaceIndex == -1 && i >= from; i--) {
char chr = text[i];
if (chr == ' ' || chr == '\n' || chr == '\t') {
spaceIndex = i;
// don't forget to search for line breaks in the
// remaining part. otherwise we overlook possible
// line breaks!
int newLine = indexOf(text, '\n', from, i - from);
if (newLine > -1 && newLine < spaceIndex) {
spaceIndex = newLine;
}
rowText = new String(text, from, spaceIndex - from);
from = spaceIndex + 1;
}
}
if (spaceIndex == -1) {
// from = to + 1;
if (maxLength <= 0) {
maxLength = 1;
}
spaceIndex = maxLength;
if (spaceIndex > 0 && spaceIndex < textLength && Character.isSurrogatePair(text[spaceIndex - 1], text[spaceIndex])) {
// Make sure the space index isn't on the 2nd char of a surrogate pair (e.g. for emojis).
spaceIndex++;
maxLength++;
}
rowText = new String(text, from, spaceIndex - from);
from = spaceIndex;
}
}
if (rowText.length() == 0) {
// This happens due to a race condition or something, no idea why???
if (textAreaWidth <= charWidth) {
if (!isInitialized()) {
rowStrings.add(getText());
} else {
// special case for the edge case of "no room".
// Its important since sometimes this case occurs in the GUI builder by accident
int tlen = text.length;
for (int iter = 0; iter < tlen; iter++) {
rowStrings.add("" + text[iter]);
}
}
return;
}
}
rowStrings.add(rowText);
// adding minCharactersInRow doesn't work if what is left is less
// then minCharactersInRow
// +minCharactersInRow;
to = from;
}
if (text[text.length - 1] == '\n') {
rowStrings.add("");
}
}
use of com.codename1.rad.attributes.Condition in project CodeRAD by shannah.
the class DefaultActionViewFactory method update.
public static void update(Button btn, Entity entity, ActionNode action) {
boolean repaint = false;
boolean revalidate = false;
Condition cond = action.getCondition();
if (cond != null) {
boolean hidden = !cond.getValue().test(entity);
if (hidden != btn.isHidden()) {
btn.setHidden(hidden);
btn.setVisible(!hidden);
revalidate = true;
}
}
EnabledCondition enabledCond = action.getEnabledCondition();
if (enabledCond != null) {
boolean enabled = enabledCond.getValue().test(entity);
if (enabled != btn.isEnabled()) {
btn.setEnabled(enabled);
repaint = true;
}
}
if (action.getLabel() != null) {
String currTextVal = btn.getText();
String newTextVal = action.getLabelText(entity);
if (!Objects.equals(currTextVal, newTextVal)) {
btn.setText(newTextVal);
repaint = true;
}
}
if (!action.isTextStyle() && !"".equals(btn.getText().trim())) {
btn.setText("");
repaint = true;
}
if (action.getUIID() != null) {
String currUiid = btn.getUIID();
String newUiid = action.getUIID(entity, "Button");
if (!Objects.equals(currUiid, newUiid)) {
btn.setUIID(newUiid);
repaint = true;
}
}
if (btn instanceof CheckBox) {
SelectedCondition selectedCond = action.getSelectedCondition();
if (selectedCond != null) {
boolean selected = selectedCond.getValue().test(entity);
if (selected != btn.isSelected()) {
((CheckBox) btn).setSelected(selected);
repaint = true;
ActionNode newState = selected ? action.getSelected() : action.getUnselected();
ActionNode oldState = selected ? action.getUnselected() : action.getSelected();
if (oldState != newState) {
String currText = btn.getText();
String newText = newState.getLabelText(entity);
if (!newState.isTextStyle()) {
newText = "";
}
if (!Objects.equals(newText, currText)) {
btn.setText(newText);
}
}
}
}
}
Badge badge = action.getBadge();
if (badge != null) {
btn.setBadgeText(badge.getValue(entity));
BadgeUIID badgeUiid = action.getBadgeUIID();
if (badgeUiid != null) {
btn.setBadgeUIID(badgeUiid.getValue());
}
}
if (revalidate || repaint) {
Form f = btn.getComponentForm();
if (f != null) {
if (revalidate) {
Component entityView = findEntityViewParent(btn);
if (entityView instanceof Container) {
((Container) entityView).revalidateLater();
} else {
entityView.repaint();
}
} else {
btn.repaint();
}
}
}
}
use of com.codename1.rad.attributes.Condition in project CodeRAD by shannah.
the class XMLSchemaGenerator method writeSchema.
public StringBuilder writeSchema(StringBuilder sb, boolean writeHeader) throws IOException {
if (writeHeader) {
sb.append("<?xml version=\"1.0\"?>\n");
alreadyIncludedSet.clear();
}
if (writeElements) {
sb.append("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n");
}
if (checksum != null)
sb.append("<!-- ").append(checksum).append(" -->\n");
indent += 2;
for (File includeFile : includes) {
// String id = includeFile.getAbsolutePath().replace(".", "_").replace(File.separatorChar, '_').replace("/", "_");
String content;
try (FileInputStream fis = new FileInputStream(includeFile)) {
byte[] bytes = new byte[(int) includeFile.length()];
fis.read(bytes);
content = new String(bytes, "UTF-8");
}
content = content.trim();
if (content.startsWith("====\n")) {
// There is head matter
int headMatterEndPos = content.indexOf("====\n", 5);
if (headMatterEndPos < 0) {
throw new IOException("Invalid content found in file " + includeFile + ". Found head matter with no end separator.");
}
String headMatter = content.substring(5, headMatterEndPos + 5).trim();
content = content.substring(headMatterEndPos + 5).trim();
if (content.startsWith("<?xml")) {
content = content.substring(content.indexOf("?>") + 2).trim();
}
StringTokenizer strtok = new StringTokenizer(headMatter, "\n");
while (strtok.hasMoreTokens()) {
String nextTok = strtok.nextToken().trim();
if (nextTok.startsWith("requireAttributeGroup ")) {
String attGroupCoords = nextTok.substring(nextTok.indexOf(" ") + 1);
String prefix = attGroupCoords.substring(0, attGroupCoords.indexOf(":"));
String type = attGroupCoords.substring(prefix.length() + 1, attGroupCoords.indexOf(":", prefix.length() + 1));
String depth = attGroupCoords.substring(attGroupCoords.lastIndexOf(":") + 1);
File attgroupFile = getAttributeGroupFile(new AttributeGroup(prefix, type, Integer.parseInt(depth)));
if (!attgroupFile.exists()) {
throw new IOException("Cannot find attribute group file at " + attgroupFile + " required by " + includeFile + " while processing schema for " + javaClass);
}
if (alreadyIncludedSet.contains(attgroupFile.getAbsolutePath())) {
continue;
}
alreadyIncludedSet.add(attgroupFile.getAbsolutePath());
try (FileInputStream fis = new FileInputStream(attgroupFile)) {
byte[] bytes = new byte[(int) attgroupFile.length()];
fis.read(bytes);
String tmp = new String(bytes, "UTF-8").trim();
if (tmp.startsWith("<?xml")) {
tmp = tmp.substring(tmp.indexOf("?>") + 2).trim();
}
content = tmp + "\n" + content;
}
} else if (nextTok.startsWith("require ")) {
TypeElement requiredType = processingEnvironment.getElementUtils().getTypeElement(nextTok.substring(nextTok.indexOf(" ") + 1).trim());
if (requiredType != null) {
File requiredTypeFile = getClassSchemaFile(requiredType);
if (!requiredTypeFile.exists()) {
throw new IOException("Cannot find type schema " + requiredTypeFile + " required by " + includeFile + " while processing schema for " + javaClass);
}
if (alreadyIncludedSet.contains(requiredType.getQualifiedName().toString())) {
continue;
}
alreadyIncludedSet.add(requiredType.getQualifiedName().toString());
// System.out.println("including "+requiredType);
try (FileInputStream fis = new FileInputStream(requiredTypeFile)) {
byte[] bytes = new byte[(int) requiredTypeFile.length()];
fis.read(bytes);
String tmp = new String(bytes, "UTF-8").trim();
if (tmp.startsWith("<?xml")) {
tmp = tmp.substring(tmp.indexOf("?>") + 2).trim();
}
content = tmp + "\n" + content;
}
}
}
}
} else {
if (content.startsWith("<?xml")) {
content = content.substring(content.indexOf("?>") + 2).trim();
}
}
indent(sb, indent).append(content).append("\n");
}
if (!writeElements) {
Set<Element> parentMembers = new HashSet<>();
String extensionBase = null;
TypeElement superType = null;
{
TypeMirror superclass = javaClass.getSuperclass();
if (superclass != null && superclass.getKind() == TypeKind.DECLARED) {
superType = (TypeElement) ((DeclaredType) superclass).asElement();
}
}
if (superType != null) {
extensionBase = superType.getQualifiedName().toString().replace('.', '_');
final TypeElement fSuperType = superType;
final DeclaredType fDeclaredSuperType = (DeclaredType) fSuperType.asType();
processingEnvironment.getElementUtils().getAllMembers(superType).forEach(e -> {
if (e.getKind() == ElementKind.METHOD && e.getSimpleName().toString().startsWith("get")) {
TypeMirror tm = processingEnvironment.getTypeUtils().asMemberOf(fDeclaredSuperType, e);
if (tm.getKind() == TypeKind.EXECUTABLE) {
ExecutableType methodMirror = (ExecutableType) tm;
TypeMirror methodReturnType = methodMirror.getReturnType();
if (methodReturnType.getKind() == TypeKind.TYPEVAR || methodReturnType.getKind() == TypeKind.WILDCARD) {
return;
}
}
}
parentMembers.add(e);
});
}
String complexTypeName = javaClass.getQualifiedName().toString().replace('.', '_');
Set<String> attributeNames = new HashSet<>();
for (TypeElement clazz : new TypeElement[] { javaClass, builderClass }) {
if (clazz == null) {
// The builder class is null
indent(sb, indent).append("<xs:complexType name=\"").append(complexTypeName).append("-impl\">\n");
indent(sb, indent).append(" <xs:complexContent>\n");
indent(sb, indent).append(" <xs:extension base=\"").append(complexTypeName).append("\"/>\n");
indent(sb, indent).append(" </xs:complexContent>\n");
indent(sb, indent).append("</xs:complexType>\n");
continue;
}
if (clazz == builderClass) {
indent(sb, indent).append("<xs:complexType name=\"").append(complexTypeName).append("-impl\">\n");
indent += 2;
indent(sb, indent).append("<xs:complexContent>\n");
indent += 2;
indent(sb, indent).append("<xs:extension base=\"").append(complexTypeName).append("\">\n");
indent += 2;
} else {
String mixed = extensionBase != null ? "" : " mixed=\"true\"";
indent(sb, indent).append("<xs:complexType name=\"").append(complexTypeName).append("\"").append(mixed).append(">\n");
indent += 2;
if (extensionBase != null) {
indent(sb, indent).append("<xs:complexContent>\n");
indent += 2;
indent(sb, indent).append("<xs:extension base=\"").append(extensionBase).append("\">\n");
indent += 2;
} else {
indent(sb, indent).append("<xs:sequence><xs:any minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"lax\"/></xs:sequence>");
indent(sb, indent).append("<xs:attribute name=\"layout-constraint\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"layout-rows\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"layout-columns\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-transition\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-leadComponent\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-implements\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-href\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-href-trigger\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"view-model\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"view-controller\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-extends\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-model\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-var\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-property\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"rad-condition\" type=\"xs:string\"/>\n");
}
}
if (clazz.getQualifiedName().contentEquals("com.codename1.ui.Component")) {
TypeElement componentBinder = processingEnvironment.getElementUtils().getTypeElement("com.codename1.rad.ui.builders.ComponentBinder");
for (Element member : processingEnvironment.getElementUtils().getAllMembers(componentBinder)) {
if (member.getKind() == ElementKind.METHOD && member.getSimpleName().toString().startsWith("bind")) {
String propertyName = toCamelCase(member.getSimpleName().toString().substring(4));
indent(sb, indent).append("<xs:attribute name=\"bind-").append(propertyName).append("\" type=\"xs:string\"/>\n");
}
}
}
for (Element member : processingEnvironment.getElementUtils().getAllMembers(clazz)) {
if (extensionBase != null && parentMembers.contains(member))
continue;
if (member.getKind() == ElementKind.METHOD) {
ExecutableElement methodEl = (ExecutableElement) member;
if (methodEl.getParameters().size() == 1) {
// Could be a setter
String methodName = methodEl.getSimpleName().toString();
String propertyName = methodName;
if (clazz == javaClass && !methodName.startsWith("set")) {
continue;
}
if (clazz == builderClass && !methodName.startsWith("set")) {
ExecutableType methodType = (ExecutableType) processingEnvironment.getTypeUtils().asMemberOf((DeclaredType) builderClass.asType(), methodEl);
if (!env.isA(methodType.getReturnType(), "com.codename1.rad.ui.ComponentBuilder")) {
// a builder style method that returns the builder for chaining.
continue;
}
}
if (methodName.startsWith("set")) {
propertyName = propertyName.substring(3);
}
if (propertyName.isEmpty())
continue;
propertyName = toCamelCase(propertyName);
if (attributeNames.contains(propertyName.toLowerCase()))
continue;
attributeNames.add(propertyName.toLowerCase());
TypeMirror paramTypeMirror = methodEl.getParameters().get(0).asType();
List<String> enumValues = null;
TypeElement parameterType = null;
if (paramTypeMirror.getKind() == TypeKind.DECLARED) {
parameterType = (TypeElement) ((DeclaredType) paramTypeMirror).asElement();
enumValues = parameterType.getEnclosedElements().stream().filter(element -> element.getKind().equals(ElementKind.ENUM_CONSTANT)).map(Object::toString).collect(Collectors.toList());
}
String type = "xs:string";
if (enumValues != null && !enumValues.isEmpty()) {
type = parameterType.getQualifiedName().toString().replace('.', '_');
enumTypes.add(parameterType);
}
indent(sb, indent).append("<xs:attribute name=\"").append(propertyName).append("\" type=\"").append(type).append("\"/>\n");
if (clazz == javaClass) {
indent(sb, indent).append("<xs:attribute name=\"").append("bind-" + propertyName).append("\" type=\"xs:string\"/>\n");
}
} else if (clazz == javaClass && methodEl.getParameters().size() == 0 && methodEl.getSimpleName().toString().startsWith("get")) {
boolean useAttributeGroups = true;
ExecutableType methodType = (ExecutableType) processingEnvironment.getTypeUtils().asMemberOf((DeclaredType) clazz.asType(), methodEl);
String propertyName = toCamelCase(methodEl.getSimpleName().toString().substring(3));
if (methodType != null && methodType.getReturnType() != null) {
if (env.isA(methodType.getReturnType(), "com.codename1.ui.plaf.Style") || methodEl.getSimpleName().contentEquals("getComponentForm") || methodEl.getSimpleName().contentEquals("getParent") || env.isA(methodType.getReturnType(), "com.codename1.rad.nodes.ActionNode.Builder") || (methodEl.getAnnotation(RADDoc.class) != null && methodEl.getAnnotation(RADDoc.class).generateSubattributeHints() && methodType.getReturnType().getKind() == TypeKind.DECLARED)) {
TypeMirror retTypeMirror = methodType.getReturnType();
if (retTypeMirror.getKind() == TypeKind.DECLARED) {
// processingEnvironment.getElementUtils().getTypeElement("com.codename1.ui.plaf.Style");
TypeElement retType = (TypeElement) ((DeclaredType) retTypeMirror).asElement();
if (useAttributeGroups) {
indent(sb, indent).append("<xs:attributeGroup ref=\"").append(getAttributeGroupName((DeclaredType) retTypeMirror, propertyName + ".", 1)).append("\" />\n");
addRequiredAttributeGroup(new AttributeGroup(propertyName + ".", retType.getQualifiedName().toString(), 1));
} else {
for (Element subMember : processingEnvironment.getElementUtils().getAllMembers(retType)) {
String subMethodName = subMember.getSimpleName().toString();
if (subMember.getKind() != ElementKind.METHOD)
continue;
if (!subMethodName.startsWith("set"))
continue;
if (((ExecutableElement) subMember).getParameters().size() != 1)
continue;
List<String> enumValues = null;
TypeElement parameterType = null;
TypeMirror parameterTypeMirror = ((ExecutableElement) subMember).getParameters().get(0).asType();
if (parameterTypeMirror.getKind() == TypeKind.DECLARED) {
parameterType = (TypeElement) ((DeclaredType) parameterTypeMirror).asElement();
enumValues = parameterType.getEnclosedElements().stream().filter(element -> element.getKind().equals(ElementKind.ENUM_CONSTANT)).map(Object::toString).collect(Collectors.toList());
}
String type = "xs:string";
if (enumValues != null && !enumValues.isEmpty()) {
type = parameterType.toString().replace('.', '_');
enumTypes.add(parameterType);
}
indent(sb, indent).append("<xs:attribute name=\"").append(propertyName).append(".").append(toCamelCase(subMethodName.toString().substring(3))).append("\" type=\"").append(type).append("\"/>\n");
indent(sb, indent).append("<xs:attribute name=\"bind-").append(propertyName).append(".").append(toCamelCase(subMethodName.toString().substring(3))).append("\" type=\"xs:string\"/>\n");
}
}
}
}
}
}
}
}
if (clazz == builderClass || extensionBase != null) {
indent -= 2;
indent(sb, indent).append("</xs:extension>\n");
indent -= 2;
indent(sb, indent).append("</xs:complexContent>\n");
}
indent -= 2;
indent(sb, indent).append("</xs:complexType>\n");
}
for (XMLSchemaGenerator subGenerator : subGenerators) {
subGenerator.writeSchema(sb, false);
}
}
if (writeElements) {
indent(sb, indent).append("<xs:element name=\"script\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:element name=\"import\" type=\"xs:string\"/>\n");
indent(sb, indent).append("<xs:element name=\"view-model\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:sequence>\n");
indent(sb, indent).append(" <xs:element ref=\"define-property\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n");
indent(sb, indent).append(" </xs:sequence>\n");
indent(sb, indent).append(" <xs:attribute name=\"extends\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"implements\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"form-controller\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"extends\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"implements\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"view-controller\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"extends\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"bind-action\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"category\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"inherit\" type=\"xs:boolean\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"on\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"define-tag\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"name\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"value\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"type\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"initialValue\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"use-taglib\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"package\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"class\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"define-property\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"name\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"type\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"initialValue\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"define-category\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"name\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"value\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"var\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:attribute name=\"value\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"lookup\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"name\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" <xs:attribute name=\"type\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"define-slot\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:sequence>\n");
indent(sb, indent).append(" <xs:any minOccurs=\"0\" maxOccurs=\"1\" />\n");
indent(sb, indent).append(" </xs:sequence>\n");
indent(sb, indent).append(" <xs:attribute name=\"id\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"fill-slot\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:sequence>\n");
indent(sb, indent).append(" <xs:any minOccurs=\"0\" maxOccurs=\"1\"/>\n");
indent(sb, indent).append(" </xs:sequence>\n");
indent(sb, indent).append(" <xs:attribute name=\"id\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
indent(sb, indent).append("<xs:element name=\"row-template\">\n");
indent(sb, indent).append(" <xs:complexType>\n");
indent(sb, indent).append(" <xs:sequence>\n");
indent(sb, indent).append(" <xs:any minOccurs=\"0\" maxOccurs=\"1\"/>\n");
indent(sb, indent).append(" </xs:sequence>\n");
indent(sb, indent).append(" <xs:attribute name=\"case\" type=\"xs:string\"/>\n");
indent(sb, indent).append(" </xs:complexType>\n");
indent(sb, indent).append("</xs:element>\n");
for (Map.Entry<String, TypeElement> e : allTags.entrySet()) {
if (e.getValue().getModifiers().contains(Modifier.PUBLIC) && !e.getValue().getModifiers().contains(Modifier.ABSTRACT)) {
indent(sb, indent).append("<xs:element name=\"").append(e.getKey()).append("\" type=\"").append(e.getValue().getQualifiedName().toString().replace('.', '_')).append("-impl\"/>\n");
}
}
}
if (writeElements) {
indent -= 2;
indent(sb, indent).append("</xs:schema>\n");
} else {
boolean includeHeadmatter = !requiredAttributeGroups.isEmpty() || !enumTypes.isEmpty();
StringBuilder headMatter = includeHeadmatter ? new StringBuilder() : null;
if (includeHeadmatter) {
headMatter.append("====\n");
}
if (!requiredAttributeGroups.isEmpty()) {
HashSet<AttributeGroup> currentRound = new HashSet<>(requiredAttributeGroups);
while (!currentRound.isEmpty()) {
for (AttributeGroup group : currentRound) {
headMatter.append("requireAttributeGroup ").append(group.prefix).append(":").append(group.type).append(":").append(group.depth).append("\n");
File attGroupFile = getAttributeGroupFile(group);
if (!attGroupFile.exists()) {
StringBuilder attGroupContent = new StringBuilder();
writeAttributeGroup(attGroupContent, (DeclaredType) env.lookupClass(group.type).asType(), group.prefix, group.depth);
attGroupFile.getParentFile().mkdirs();
try (FileOutputStream fos = new FileOutputStream(attGroupFile)) {
fos.write(attGroupContent.toString().getBytes("UTF-8"));
}
}
writtenAttributeGroups.add(group);
}
currentRound.clear();
currentRound.addAll(requiredAttributeGroups);
currentRound.removeAll(writtenAttributeGroups);
}
}
if (!enumTypes.isEmpty()) {
for (TypeElement enumType : enumTypes) {
headMatter.append("require ").append(enumType.getQualifiedName()).append("\n");
File enumSchemaFile = getClassSchemaFile(enumType);
if (!enumSchemaFile.exists()) {
enumSchemaFile.getParentFile().mkdirs();
StringBuilder enumSchemaContent = new StringBuilder();
writeEnumType(enumSchemaContent, enumType);
try (FileOutputStream fos = new FileOutputStream(enumSchemaFile)) {
fos.write(enumSchemaContent.toString().getBytes("UTF-8"));
}
}
}
}
if (includeHeadmatter) {
headMatter.append("====\n");
sb.insert(0, headMatter);
}
}
return sb;
}
Aggregations