jdk.internal.org.xml.sax.Attributes Java Examples

The following examples show how to use jdk.internal.org.xml.sax.Attributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JFCParserHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName.toLowerCase()) {
    case ELEMENT_CONFIGURATION:
        String version = attributes.getValue(ATTRIBUTE_VERSION);
        if (version == null || !version.startsWith("2.")) {
           throw new SAXException("This version of Flight Recorder can only read JFC file format version 2.x");
        }
        label = attributes.getValue(ATTRIBUTE_LABEL);
        description = getOptional(attributes, ATTRIBUTE_DESCRIPTION, "");
        provider = getOptional(attributes, ATTRIBUTE_PROVIDER, "");
        break;
    case ELEMENT_EVENT_TYPE:
        currentEventPath = attributes.getValue(ATTRIBUTE_NAME);
        break;
    case ELEMENT_SETTING:
        currentSettingsName = attributes.getValue(ATTRIBUTE_NAME);
        break;
    }
    currentCharacters = null;
}
 
Example #2
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private long builtInId(Attributes attributes) {
    String t = attributes.getValue(ATTRIBUTE_ID);
    if ("Thread".equals(t)) {
        return Type.THREAD.getId();
    }
    if ("STRING".equals(t)) {
        return Type.STRING.getId();
    }
    if ("Class".equals(t)) {
        return Type.CLASS.getId();
    }
    for (Type type : Type.getKnownTypes()) {
        if (type.getName().equals(Type.ORACLE_TYPE_PREFIX + t)) {
           return type.getId();
        }
    }
    throw new IllegalStateException("Built-in type " + t + " not defined in Java");
}
 
Example #3
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void addTypedef(Attributes attributes) {
    String symbol = attributes.getValue(ATTRIBUTE_SYMBOL);
    String contentType = attributes.getValue(ATTRIBUTE_CONTENTTYPE);
    String dataType = attributes.getValue(ATTRIBUTE_DATATYPE);
    if (unsignedTypes.containsKey(dataType)) {
        unsignedTypes.put(symbol, unsignedTypes.get(dataType));
    }
    if (annotationTypes.containsKey(contentType)) {
        typedef.put(symbol, dataType);
        return;
    }
    if (typedef.containsKey(symbol)) {
        return;
    }
    typedef.put(symbol, ATTRIBUTE_VALUE_NONE.equals(contentType) ? dataType : contentType);
}
 
Example #4
Source File: JFCParserHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName.toLowerCase()) {
    case ELEMENT_CONFIGURATION:
        String version = attributes.getValue(ATTRIBUTE_VERSION);
        if (version == null || !version.startsWith("2.")) {
           throw new SAXException("This version of Flight Recorder can only read JFC file format version 2.x");
        }
        label = attributes.getValue(ATTRIBUTE_LABEL);
        description = getOptional(attributes, ATTRIBUTE_DESCRIPTION, "");
        provider = getOptional(attributes, ATTRIBUTE_PROVIDER, "");
        break;
    case ELEMENT_EVENT_TYPE:
        currentEventPath = attributes.getValue(ATTRIBUTE_NAME);
        break;
    case ELEMENT_SETTING:
        currentSettingsName = attributes.getValue(ATTRIBUTE_NAME);
        break;
    }
    currentCharacters = null;
}
 
Example #5
Source File: JFCParserHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName.toLowerCase()) {
    case ELEMENT_CONFIGURATION:
        String version = attributes.getValue(ATTRIBUTE_VERSION);
        if (version == null || !version.startsWith("2.")) {
           throw new SAXException("This version of Flight Recorder can only read JFC file format version 2.x");
        }
        label = attributes.getValue(ATTRIBUTE_LABEL);
        description = getOptional(attributes, ATTRIBUTE_DESCRIPTION, "");
        provider = getOptional(attributes, ATTRIBUTE_PROVIDER, "");
        break;
    case ELEMENT_EVENT_TYPE:
        currentEventPath = attributes.getValue(ATTRIBUTE_NAME);
        break;
    case ELEMENT_SETTING:
        currentSettingsName = attributes.getValue(ATTRIBUTE_NAME);
        break;
    }
    currentCharacters = null;
}
 
Example #6
Source File: PropertiesDefaultHandler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #7
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ValueDeclaration(Type type, int dimension, Attributes attributes) {
    typeName = attributes.getValue(ATTRIBUTE_TYPE);
    field = attributes.getValue(ATTRIBUTE_FIELD);
    label = attributes.getValue(ATTRIBUTE_LABEL);
    experimental = "true".equals(attributes.getValue(ATTRIBUTE_EXPERIMENTAL));
    description = attributes.getValue(ATTRIBUTE_DESCRIPTION);
    String t = attributes.getValue(ATTRIBUTE_RELATION);
    relation = "NOT_AVAILABLE".equals(t) ? null : t;
    String transition = attributes.getValue(ATTRIBUTE_TRANSITION);
    transitionFrom = "FROM".equals(transition);
    transitionTo = "TO".equals(transition);
    this.dimension = dimension;
    this.type = type;
}
 
Example #8
Source File: PropertiesDefaultHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #9
Source File: PropertiesDefaultHandler.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (sawRoot) {
        if (!ALLOWED_ELEMENTS.contains(qName)) {
            fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
        }
    } else {
        // check whether the root has been declared in the DTD
        if (rootElm == null) {
            fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
        }

        // check whether the element name matches the declaration
        if (!rootElm.equals(qName)) {
            fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
        }

        // this is a valid root element
        sawRoot = true;
    }

    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and " +
                "must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #10
Source File: PropertiesDefaultHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #11
Source File: PropertiesDefaultHandler.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #12
Source File: PropertiesDefaultHandler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #13
Source File: PropertiesDefaultHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #14
Source File: PropertiesDefaultHandler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #15
Source File: PropertiesDefaultHandler.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #16
Source File: PropertiesDefaultHandler.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #17
Source File: PropertiesDefaultHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #18
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Type createType(Attributes attributes, boolean eventType, long typeId, boolean contantPool) {
    String labelAttribute = ATTRIBUTE_LABEL;
    String id = attributes.getValue(ATTRIBUTE_ID);
    String path = attributes.getValue(ATTRIBUTE_PATH);
    String builtInType = attributes.getValue(ATTRIBUTE_BUILTIN_TYPE);
    String jvmType = attributes.getValue(ATTRIBUTE_JVM_TYPE);

    String typeName = makeTypeName(id, path);
    Type t;
    if (eventType) {
        t = new PlatformEventType(typeName, typeId, false, true);
    } else {
        t = new Type(typeName, null, typeId, contantPool);
    }
    typedef.put(id, typeName);
    if (contantPool) {
        labelAttribute = ATTRIBUTE_HR_NAME; // not "label" for some reason?
        if (builtInType != null) {
            typedef.put(builtInType, typeName);
        }
        if (jvmType != null) {
            typedef.put(jvmType, typeName);
        }
    }
    ArrayList<AnnotationElement> aes = new ArrayList<>();
    if (path != null) {
        aes.add(new AnnotationElement(Category.class, makeCategory(path)));
    }
    String label = attributes.getValue(labelAttribute);
    if (label != null) {
        aes.add(new AnnotationElement(Label.class, label));
    }
    String description = attributes.getValue(ATTRIBUTE_DESCRIPTION);
    if (description != null) {
        aes.add(new AnnotationElement(Description.class, description));
    }
    aes.trimToSize();
    t.setAnnotations(aes);
    return t;
}
 
Example #19
Source File: PropertiesDefaultHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #20
Source File: PropertiesDefaultHandler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #21
Source File: PropertiesDefaultHandler.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #22
Source File: JFCParserHandler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private String getOptional(Attributes attributes, String name, String defaultValue) {
    String value = attributes.getValue(name);
    return value == null ? defaultValue : value;
}
 
Example #23
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName) {
    case ELEMENT_RELATION_DECL:
        String relationalURI = attributes.getValue(ATTRIBUTE_URI);
        String id = attributes.getValue(ATTRIBUTE_ID);
        typedef.put(id, relationalURI);
        break;
    case ELEMENT_PRIMARY_TYPE:
        addTypedef(attributes);
        break;
    case ELEMENT_STRUCT_ARRAY:
        valueDeclarations.add(new ValueDeclaration(type, 1, attributes));
        break;
    case ELEMENT_VALUE:
    case ELEMENT_STRUCT_VALUE:
        valueDeclarations.add(new ValueDeclaration(type, 0, attributes));
        break;
    case ELEMENT_EVENT:
        type = createType(attributes, true, structTypeId++, false);
        boolean stackTrace = getBoolean(attributes, ATTRIBUTE_HAS_STACKTRACE);
        boolean thread = getBoolean(attributes, (ATTRIBUTE_HAS_THREAD));
        boolean instant = getBoolean(attributes, (ATTRIBUTE_IS_INSTANT));
        boolean requestable = getBoolean(attributes, (ATTRIBUTE_IS_REQUESTABLE));
        boolean constant = getBoolean(attributes, (ATTRIBUTE_IS_CONSTANT));
        boolean duration = !requestable && !instant;
        boolean experimental = getBoolean(attributes, ATTRIBUTE_EXPERIMENTAL);
        boolean cutoff =  getBoolean(attributes, ATTRIBUTE_CUTOFF);
        TypeLibrary.addImplicitFields(type, requestable, duration, thread, stackTrace, cutoff);
        ArrayList<AnnotationElement> aes = new ArrayList<>();
        aes.addAll(type.getAnnotationElements());
        if (requestable) {
            String period = constant ? "endChunk" : "everyChunk";
            aes.add(new AnnotationElement(Period.class, period));
        } else {
            if (!instant) {
                aes.add(new AnnotationElement(Threshold.class, "0 ns"));
            }
            if (stackTrace) {
                aes.add(new AnnotationElement(StackTrace.class, true));
            }
        }
        if (cutoff) {
            aes.add(new AnnotationElement(Cutoff.class, Cutoff.INIFITY));
        }
        if (experimental) {
            aes.add(new AnnotationElement(Experimental.class));
        }
        aes.add(new AnnotationElement(Enabled.class, false));
        aes.trimToSize();
        type.setAnnotations(aes);
        break;
    case ELEMENT_CONTENT_TYPE:
        if (attributes.getValue(ATTRIBUTE_BUILTIN_TYPE) != null) {
            type = createType(attributes, false, builtInId(attributes), true);
        } else {
            type = createType(attributes, false, jvmTypeId++, true);
        }
        break;
    case ELEMENT_STRUCT_TYPE:
    case ELEMENT_STRUCT:
        type = createType(attributes, false, structTypeId++, false);
        break;
    }
}
 
Example #24
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean getBoolean(Attributes attributes, String attribute) {
    return "true".equals(attributes.getValue(attribute));
}
 
Example #25
Source File: JFCParserHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private String getOptional(Attributes attributes, String name, String defaultValue) {
    String value = attributes.getValue(name);
    return value == null ? defaultValue : value;
}
 
Example #26
Source File: MetadataHandler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean getBoolean(Attributes attributes, String name, boolean defaultValue) {
    String value = attributes.getValue(name);
    return value == null ? defaultValue : Boolean.valueOf(value);
}
 
Example #27
Source File: MetadataHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private boolean getBoolean(Attributes attributes, String name, boolean defaultValue) {
    String value = attributes.getValue(name);
    return value == null ? defaultValue : Boolean.valueOf(value);
}
 
Example #28
Source File: JFCParserHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private String getOptional(Attributes attributes, String name, String defaultValue) {
    String value = attributes.getValue(name);
    return value == null ? defaultValue : value;
}
 
Example #29
Source File: DefaultHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Receive notification of the start of an element.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to take specific actions at the start of
 * each element (such as allocating a new tree node or writing
 * output to a file).</p>
 *
 * @param uri The Namespace URI, or the empty string if the
 *        element has no Namespace URI or if Namespace
 *        processing is not being performed.
 * @param localName The local name (without prefix), or the
 *        empty string if Namespace processing is not being
 *        performed.
 * @param qName The qualified name (with prefix), or the
 *        empty string if qualified names are not available.
 * @param attributes The attributes attached to the element.  If
 *        there are no attributes, it shall be an empty
 *        Attributes object.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.ContentHandler#startElement
 */
public void startElement (String uri, String localName,
                          String qName, Attributes attributes)
    throws SAXException
{
    // no op
}
 
Example #30
Source File: DefaultHandler.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Receive notification of the start of an element.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to take specific actions at the start of
 * each element (such as allocating a new tree node or writing
 * output to a file).</p>
 *
 * @param uri The Namespace URI, or the empty string if the
 *        element has no Namespace URI or if Namespace
 *        processing is not being performed.
 * @param localName The local name (without prefix), or the
 *        empty string if Namespace processing is not being
 *        performed.
 * @param qName The qualified name (with prefix), or the
 *        empty string if qualified names are not available.
 * @param attributes The attributes attached to the element.  If
 *        there are no attributes, it shall be an empty
 *        Attributes object.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.ContentHandler#startElement
 */
public void startElement (String uri, String localName,
                          String qName, Attributes attributes)
    throws SAXException
{
    // no op
}