Search in sources :

Example 1 with IContent

use of org.whole.lang.xml.model.IContent in project whole by wholeplatform.

the class XmlPrettyPrinterVisitor method visit.

public void visit(Content entity) {
    IEntity prevChild = null;
    for (int i = 0; i < entity.size(); i++) {
        IContent child = entity.get(i);
        if (prevChild != null && !Matcher.match(XmlEntityDescriptorEnum.CharData, prevChild) && !Matcher.match(XmlEntityDescriptorEnum.CharData, child)) {
            out.println();
        }
        child.accept(this);
        prevChild = child;
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IContent(org.whole.lang.xml.model.IContent)

Example 2 with IContent

use of org.whole.lang.xml.model.IContent in project whole by wholeplatform.

the class XmlNormalizerVisitor method visit.

@Override
public void visit(Content entity) {
    // recursively normalize nested composite entities
    IEntityIterator<IEntity> iterator = IteratorFactory.childMatcherIterator().withPattern(EntityKinds.COMPOSITE);
    iterator.reset(entity);
    while (iterator.hasNext()) {
        IEntity composite = iterator.next();
        ((IXmlEntity) composite).accept(this);
        // move Content's children in place of Content entity
        if (Matcher.match(Content, composite)) {
            for (int i = composite.wSize() - 1; i >= 0; i--) {
                IEntity child = composite.wGet(i);
                composite.wRemove(i);
                iterator.add(child);
            }
            iterator.remove();
        }
    }
    for (int i = 0; i < entity.wSize(); i++) {
        IContent child = (IContent) entity.wGet(i);
        if (Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, child)) {
            IEntity nextChild;
            if (i + 1 < entity.wSize() && Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, nextChild = entity.wGet(i + 1))) {
                StringBuilder sb = getStringBuilder();
                sb.append(child.wStringValue());
                do {
                    sb.append(nextChild.wStringValue());
                    entity.wRemove(i + 1);
                } while (i + 1 < entity.wSize() && Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, nextChild = entity.wGet(i + 1)));
                child.wSetValue(sb.toString());
            }
            if (XmlUtils.isIgnorableWhitespace(child.wStringValue()))
                entity.wRemove(i--);
        }
        child.accept(this);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IContent(org.whole.lang.xml.model.IContent) IXmlEntity(org.whole.lang.xml.model.IXmlEntity)

Example 3 with IContent

use of org.whole.lang.xml.model.IContent in project whole by wholeplatform.

the class XmlNormalizerVisitor method visit.

@Override
public void visit(Element entity) {
    IContent content = entity.getContent();
    if (!EntityUtils.isResolver(content) && !Matcher.match(Content, content)) {
        entity.wRemove(content);
        entity.setContent(XmlEntityFactory.instance.createContent(content));
    }
    super.visit(entity);
}
Also used : IContent(org.whole.lang.xml.model.IContent)

Example 4 with IContent

use of org.whole.lang.xml.model.IContent in project whole by wholeplatform.

the class XmlPrettyPrinterVisitor method visit.

public void visit(Element entity) {
    out.printRaw("<");
    entity.getTag().accept(this);
    entity.getAttributes().accept(this);
    IContent content = entity.getContent();
    int contentSize = content.wSize();
    final int NO_CONTENT = 0;
    final int INLINE_CONTENT = 1;
    final int NESTED_CONTENT = 2;
    int contentCase = NESTED_CONTENT;
    if (Matcher.match(XmlEntityDescriptorEnum.Content, content)) {
        if (EntityUtils.isResolver(content))
            contentCase = NO_CONTENT;
        else {
            switch(contentSize) {
                case 0:
                    contentCase = NO_CONTENT;
                    break;
                case 1:
                    IEntity contentChild = content.wGet(0);
                    if (EntityUtils.isResolver(contentChild))
                        contentCase = NO_CONTENT;
                    else if (!Matcher.match(XmlEntityDescriptorEnum.Element, contentChild))
                        contentCase = INLINE_CONTENT;
                    break;
            }
        }
    } else {
        contentCase = INLINE_CONTENT;
    }
    switch(contentCase) {
        case NO_CONTENT:
            out.printRaw("/>");
            break;
        case INLINE_CONTENT:
            out.printRaw(">");
            out.setInlined(true);
            content.accept(this);
            out.setInlined(false);
            out.printRaw("</");
            entity.getTag().accept(this);
            out.printRaw(">");
            break;
        case NESTED_CONTENT:
            out.printRaw(">");
            out.setRelativeIndentation(+1);
            if (!Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, content.wGet(0))) {
                out.println();
            }
            content.accept(this);
            out.setRelativeIndentation(-1);
            if (!Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, content.wGet(contentSize - 1))) {
                out.println();
            }
            out.printRaw("</");
            entity.getTag().accept(this);
            out.printRaw(">");
            break;
    }
}
Also used : IContent(org.whole.lang.xml.model.IContent) IEntity(org.whole.lang.model.IEntity)

Example 5 with IContent

use of org.whole.lang.xml.model.IContent in project whole by wholeplatform.

the class ElementOutlinePart method createFigure.

protected IFigure createFigure() {
    Element entity = getModelEntity();
    IContent content = entity.getContent();
    boolean startOpened = !EntityUtils.isResolver(content) && !(EntityUtils.isComposite(content) && content.wIsEmpty());
    return new ElementOutlineFigure(startOpened);
}
Also used : IContent(org.whole.lang.xml.model.IContent) Element(org.whole.lang.xml.model.Element) ElementOutlineFigure(org.whole.lang.xml.ui.figures.ElementOutlineFigure)

Aggregations

IContent (org.whole.lang.xml.model.IContent)5 IEntity (org.whole.lang.model.IEntity)3 Element (org.whole.lang.xml.model.Element)1 IXmlEntity (org.whole.lang.xml.model.IXmlEntity)1 ElementOutlineFigure (org.whole.lang.xml.ui.figures.ElementOutlineFigure)1