Search in sources :

Example 1 with CMEntityDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration in project webtools.sourceediting by eclipse.

the class DocumentImpl method getCharValue.

/**
 * getCharValue method
 *
 * @return java.lang.String
 * @param name
 *            java.lang.String
 */
protected String getCharValue(String name) {
    if (name == null)
        return null;
    int length = name.length();
    if (length == 0)
        return null;
    if (name.charAt(0) == '#') {
        // character reference
        if (length == 1)
            return null;
        int radix = 10;
        String s = null;
        // now allow hexadecimal also for non XML document
        if (name.charAt(1) == 'x') {
            // hexadecimal
            radix = 16;
            s = name.substring(2);
        } else {
            // decimal
            s = name.substring(1);
        }
        if (s == null || s.length() == 0)
            return null;
        if (s.charAt(0) == '-')
            // no minus accepted
            return null;
        char c = 0;
        try {
            c = (char) Integer.parseInt(s, radix);
        } catch (NumberFormatException ex) {
        }
        if (c == 0)
            return null;
        return String.valueOf(c);
    }
    // implicit character entities for XML
    if (name.equals(IXMLCharEntity.LT_NAME))
        return IXMLCharEntity.LT_VALUE;
    if (name.equals(IXMLCharEntity.GT_NAME))
        return IXMLCharEntity.GT_VALUE;
    if (name.equals(IXMLCharEntity.AMP_NAME))
        return IXMLCharEntity.AMP_VALUE;
    if (name.equals(IXMLCharEntity.QUOT_NAME))
        return IXMLCharEntity.QUOT_VALUE;
    if (isXMLType()) {
        if (name.equals(IXMLCharEntity.APOS_NAME))
            return IXMLCharEntity.APOS_VALUE;
    }
    CMDocument cm = getCMDocument();
    if (cm != null) {
        CMNamedNodeMap map = cm.getEntities();
        if (map != null) {
            CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
            if (decl != null) {
                String value = decl.getValue();
                if (value == null)
                    return null;
                int valueLength = value.length();
                if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
                    // character reference
                    return getCharValue(value.substring(1, valueLength - 1));
                }
                return value;
            }
        }
    }
    return null;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 2 with CMEntityDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method mapToProperties.

protected Properties mapToProperties(CMNamedNodeMap map) {
    Properties p = new Properties();
    for (int i = 0; i < map.getLength(); i++) {
        CMEntityDeclaration decl = (CMEntityDeclaration) map.item(i);
        p.put(decl.getName(), decl.getValue());
    }
    return p;
}
Also used : CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) Properties(java.util.Properties)

Example 3 with CMEntityDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method mapToProperties.

private Properties mapToProperties(CMNamedNodeMap map) {
    Properties p = new Properties();
    for (int i = 0; i < map.getLength(); i++) {
        CMEntityDeclaration decl = (CMEntityDeclaration) map.item(i);
        p.put(decl.getName(), decl.getValue());
    }
    return p;
}
Also used : CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) Properties(java.util.Properties)

Example 4 with CMEntityDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration in project webtools.sourceediting by eclipse.

the class CMPrinter method printEntities.

public void printEntities(StringBuffer sb, CMNamedNodeMap entities) {
    if ((entities != null) && (entities.getLength() > 0)) {
        // $NON-NLS-1$
        sb.append(indent + "<Entities>\n");
        incrementIndent();
        for (Iterator i = entities.iterator(); i.hasNext(); ) {
            CMEntityDeclaration entity = (CMEntityDeclaration) i.next();
            // $NON-NLS-1$
            sb.append(indent + "<Entity");
            printAttributes(sb, entity);
            // $NON-NLS-1$
            sb.append("/>\n");
        }
        decrementIndent();
        // $NON-NLS-1$
        sb.append(indent + "</Entities>\n");
    }
}
Also used : CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) Iterator(java.util.Iterator)

Aggregations

CMEntityDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration)4 Properties (java.util.Properties)2 Iterator (java.util.Iterator)1 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1