EMMA Coverage Report (generated Mon Nov 01 16:48:29 PDT 2010)
[all classes][com.google.caja.parser.html]

COVERAGE SUMMARY FOR SOURCE FILE [AttrStub.java]

nameclass, %method, %block, %line, %
AttrStub.java100% (1/1)100% (3/3)84%  (89/106)95%  (20/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AttrStub100% (1/1)100% (3/3)84%  (89/106)95%  (20/21)
AttrStub (Token, Token, String): void 100% (1/1)100% (12/12)100% (5/5)
toAttr (Document, String, String): Attr 100% (1/1)100% (26/26)100% (6/6)
toNamespace (Namespaces, MessageQueue): Namespaces 100% (1/1)75%  (51/68)90%  (9/10)

1// Copyright (C) 2009 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package com.google.caja.parser.html;
16 
17import com.google.caja.lexer.HtmlTokenType;
18import com.google.caja.lexer.Token;
19import com.google.caja.reporting.MessagePart;
20import com.google.caja.reporting.MessageQueue;
21import com.google.caja.reporting.MessageType;
22 
23import org.w3c.dom.Attr;
24import org.w3c.dom.Document;
25 
26final class AttrStub {
27  final Token<HtmlTokenType> nameTok;
28  final Token<HtmlTokenType> valueTok;
29  final String value;
30 
31  AttrStub(Token<HtmlTokenType> nameTok,
32           Token<HtmlTokenType> valueTok, String value) {
33    this.nameTok = nameTok;
34    this.valueTok = valueTok;
35    this.value = value;
36  }
37 
38  Namespaces toNamespace(Namespaces ns, MessageQueue mq) {
39    String rawName = nameTok.text;
40    if (rawName.startsWith("xmlns")) {
41      if (rawName.length() == 5) {
42        return new Namespaces(ns, "", value);
43      } else if (':' == rawName.charAt(5)) {
44        String prefix = rawName.substring(6);
45        if ("".equals(prefix) || "xml".equals(prefix)
46            || "xmlns".equals(prefix)) {
47          mq.addMessage(
48              MessageType.ILLEGAL_NAMESPACE_NAME, nameTok.pos,
49              MessagePart.Factory.valueOf(prefix));
50        } else {
51          return new Namespaces(ns, prefix, value);
52        }
53      }
54    }
55    return null;
56  }
57 
58  Attr toAttr(Document doc, String attrUri, String attrQName) {
59    Attr attrNode = doc.createAttributeNS(attrUri, attrQName);
60    attrNode.setValue(value);
61    Nodes.setFilePositionFor(attrNode, nameTok.pos);
62    Nodes.setFilePositionForValue(attrNode, valueTok.pos);
63    Nodes.setRawValue(attrNode, valueTok.text);
64    return attrNode;
65  }
66}

[all classes][com.google.caja.parser.html]
EMMA 2.0.5312 (C) Vladimir Roubtsov