private void reformat()

in eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java [201:238]


    private void reformat() {
        List<Attribute> list = domElement.getAttributes();
        if (list.size()==0) {
            // then there are no attributes at all - nothing to format
            return;
        } else if (list.size()==1) {
            // only one attribute - make sure it has no preSpace
            Attribute first = list.get(0);
            first.setPreSpace("");
        } else {
            final String NL = System.getProperty("line.separator");
            final String INDENT = "    ";
            // otherwise, make sure each element has the correct preSpace
            final String correctPreSpace;
            Element parent = domElement.getParentElement();
            if (parent!=null) {
                List<Node> nodes = parent.getNodes();
                if (nodes.size()>1 && (nodes.get(0) instanceof Text) && (nodes.get(0).toXML().startsWith(NL))) {
                    correctPreSpace = nodes.get(0).toXML() + INDENT;
                } else {
                    String totalIndent = INDENT;
                    while(parent!=null) {
                        totalIndent = totalIndent + INDENT;
                        parent = parent.getParentElement();
                    }
                    correctPreSpace = NL + totalIndent;
                }
            } else {
                // guestimate
                correctPreSpace = NL + INDENT;
            }
            for (Attribute attribute : list) {
                if (!attribute.getName().startsWith("xmlns:")) {
                    attribute.setPreSpace(correctPreSpace);
                }
            }
        }
    }