Пример #1
0
 @JRubyMethod(required = 1, optional = 4)
 public IRubyObject create_entity(ThreadContext context, IRubyObject[] argv) {
   // FIXME: Entity node should be create by some right way.
   // this impl passes tests, but entity doesn't exists in DTD, which
   // would cause validation failure.
   if (argv.length == 0) throw context.getRuntime().newRuntimeError("Could not create entity");
   String tagName = (String) argv[0].toJava(String.class);
   Node n = this.getOwnerDocument().createElement(tagName);
   return XmlEntityDecl.create(context, n, argv);
 }
Пример #2
0
    @Nullable
    private static Object getLookupItem(@Nullable final XmlEntityDecl decl) {
      if (decl == null) {
        return null;
      }

      final String name = decl.getName();
      if (name == null) {
        return null;
      }

      final XmlAttributeValue value = decl.getValueElement();
      final ASTNode node = value.getNode();
      if (node != null) {
        final ASTNode[] nodes = node.getChildren(TokenSet.create(XmlTokenType.XML_CHAR_ENTITY_REF));
        if (nodes.length == 1) {
          final String valueText = nodes[0].getText();
          final int i = valueText.indexOf('#');
          if (i > 0) {
            String s = valueText.substring(i + 1);
            if (s.endsWith(";")) {
              s = s.substring(0, s.length() - 1);
            }

            try {
              final int unicodeChar = Integer.valueOf(s).intValue();
              return LookupValueFactory.createLookupValueWithHint(
                  name, null, new String(Character.toChars(unicodeChar)));
            } catch (NumberFormatException e) {
              return null;
            }
          }
        }
      }

      return null;
    }