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;
}
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;
}
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;
}
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");
}
}
Aggregations