Example usage for org.xml.sax Attributes getQName

List of usage examples for org.xml.sax Attributes getQName

Introduction

In this page you can find the example usage for org.xml.sax Attributes getQName.

Prototype

public abstract String getQName(int index);

Source Link

Document

Look up an attribute's XML qualified (prefixed) name by index.

Usage

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <field-transform>} element.
 *
 * @param attrs//  www  .j  a v a 2  s . c o  m
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processFieldTransform(Attributes attrs) throws SAXException {
    if (currTransform != null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration", FIELD_TRANSFORM_ELMT),
                currParseLocation);
    }

    if (currField == null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration4", FIELD_TRANSFORM_ELMT, FIELD_ELMT,
                EMBEDDED_ACTIVITY_ELMT, FIELD_LOC_ELMT), currParseLocation);
    }

    if (currTransform == null) {
        currTransform = new FieldTransformData();
    }

    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            currTransform.name = attValue;
        } else if (BEAN_REF_ATTR.equals(attName)) {
            currTransform.beanRef = attValue;
        } else if (LANG_ATTR.equals(attName)) {
            currTransform.scriptLang = attValue;
        }
    }

    if (StringUtils.isNoneEmpty(currTransform.beanRef, currTransform.scriptLang)) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.cannot.contain", FIELD_TRANSFORM_ELMT, BEAN_REF_ATTR, LANG_ATTR),
                currParseLocation);
    }

    handleFieldLocatorCDATA();

    elementData = new StringBuilder();
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <embedded-activity>} element.
 *
 * @param attrs/*w w  w. ja  v  a2s .c  o  m*/
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processEmbeddedActivity(Attributes attrs) throws SAXException {
    if (currField != null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration5", EMBEDDED_ACTIVITY_ELMT, FIELD_ELMT),
                currParseLocation);
    }
    if (currParser == null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", EMBEDDED_ACTIVITY_ELMT, PARSER_ELMT),
                currParseLocation);
    }
    String field = null;
    String locatorType = null;
    String locator = null;
    String reqVal = "";
    boolean transparent = true;
    boolean split = true;
    String id = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            field = attValue;
        } else if (LOC_TYPE_ATTR.equals(attName)) {
            locatorType = attValue;
        } else if (LOCATOR_ATTR.equals(attName)) {
            locator = attValue;
        } else if (REQUIRED_ATTR.equals(attName)) {
            reqVal = attValue;
        } else if (ID_ATTR.equals(attName)) {
            id = attValue;
        }
    }
    // make sure required fields are present
    notEmpty(field, EMBEDDED_ACTIVITY_ELMT, NAME_ATTR);
    notEmpty(locator, EMBEDDED_ACTIVITY_ELMT, LOCATOR_ATTR);
    notEmpty(locatorType, EMBEDDED_ACTIVITY_ELMT, LOC_TYPE_ATTR);

    ActivityFieldLocator afl;
    ActivityField af = new ActivityField(field);

    String[] locators = currParser.canHaveDelimitedLocators() ? locator.split(Pattern.quote(LOC_DELIM))
            : new String[] { locator };
    for (String loc : locators) {
        if (StringUtils.isNotEmpty(loc)) {
            afl = new ActivityFieldLocator(locatorType, loc);
            afl.setRequired(reqVal);
            if (StringUtils.isNotEmpty(id)) {
                afl.setId(id);
            }
            af.addLocator(afl);
        }
    }

    af.setRequired(reqVal);
    af.setTransparent(transparent);
    af.setSplitCollection(split);
    currField = af;
}

From source file:com.netspective.sparx.command.QueryResultDialogCommand.java

/**
 *
 * @param nc/* w w  w  .j av  a2  s  .c  om*/
 * @param dialog
 * @param rowCount
 * @throws SAXException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws ClassNotFoundException
 * @throws DataModelException
 */
private void createDialogFields(NavigationContext nc, Dialog dialog, int rowCount) throws SAXException,
        InstantiationException, IllegalAccessException, ClassNotFoundException, DataModelException {
    QueryResultDialog.RowFieldTemplate rowFieldTemplate = ((QueryResultDialog) dialog).getRowFieldTemplate();

    TemplateProducer templateProducer = ((QueryResultDialog) dialog).getTemplateProducers().getByIndex(0);
    final List templateInstances = templateProducer.getInstances();
    if (templateInstances.size() == 0) {
        log.error("There were no <row> template registered.");
    }

    // make sure to get the last template only because inheritance may have create multiples
    Template rowTemplate = (Template) templateInstances.get(templateInstances.size() - 1);
    List childFieldElements = rowTemplate.getChildren();

    DialogField field = null;
    int fieldCount = childFieldElements.size();

    GridField gridField = new GridField();
    gridField.setName(QueryResultDialog.GRID_FIELD_PREFIX);
    dialog.addGrid(gridField);

    Project.DialogFieldTypeTemplate fieldTypesTemplate = nc.getProject().getFieldTypes();
    Map fieldTypeInstancesMap = fieldTypesTemplate.getInstancesMap();
    for (int j = 0; j < rowCount; j++) {
        GridFieldRow row = new GridFieldRow();
        row.setName(QueryResultDialog.ROW_FIELD_PREFIX + j);
        gridField.addField(row);

        for (int k = 0; k < fieldCount; k++) {
            TemplateNode childFieldNode = (TemplateNode) childFieldElements.get(k);
            if (childFieldNode instanceof TemplateElement) {
                TemplateElement fieldElement = (TemplateElement) childFieldNode;
                String elementName = fieldElement.getElementName();
                Attributes attributes = fieldElement.getAttributes();
                String alternateClassName = attributes.getValue(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME);

                String fieldType = fieldElement.getAttributes().getValue("type");
                Template fieldTemplate = (Template) fieldTypeInstancesMap.get(fieldType);
                XdmHandler xdmHandler = ((XdmHandler) fieldTemplate.getDefnContentHandler());
                XdmParseContext pContext = (XdmParseContext) xdmHandler.getParseContext();
                TemplateApplyContext applyContext = fieldTemplate.createApplyContext(
                        fieldTemplate.getDefnContentHandler(), fieldElement.getElementName(),
                        fieldElement.getAttributes());

                // can't do a XmlDataModelSchema.createElement() since the <row> element doesn't have an actual
                // class implementation that would have had an createField() method so do a manual instantiation
                // of the dialog field class
                field = (DialogField) Class.forName(fieldTemplate.getAlternateClassName()).newInstance();
                TemplateConsumerDefn fieldTemplateConsumer = field.getTemplateConsumerDefn();

                // see if we have any templates that need to be applied                    
                XdmHandlerNodeStackEntry childEntry = new XdmHandlerNodeStackEntry(elementName, attributes,
                        field);
                xdmHandler.getNodeStack().push(childEntry);
                String[] attrNamesToSet = fieldTemplateConsumer.getAttrNamesToApplyBeforeConsuming();
                if (attrNamesToSet != null) {
                    for (int i = 0; i < attrNamesToSet.length; i++) {
                        String attrValue = attributes.getValue(attrNamesToSet[i]);
                        String lowerCaseAttrName = attrNamesToSet[i].toLowerCase();
                        childEntry.getSchema().setAttribute(((XdmParseContext) xdmHandler.getParseContext()),
                                childEntry.getInstance(), lowerCaseAttrName, attrValue, false);
                    }
                }

                // create the temporary list and add the dialog-field-type template to pass to the consume call
                List templatesToConsume = new ArrayList();
                templatesToConsume.add(fieldTemplate);
                fieldTemplateConsumer.consume(fieldTemplate.getDefnContentHandler(), templatesToConsume,
                        fieldElement.getElementName(), fieldElement.getAttributes());
                for (int i = 0; i < attributes.getLength(); i++) {
                    String origAttrName = attributes.getQName(i);
                    String lowerCaseAttrName = origAttrName.toLowerCase();
                    if (!childEntry.getOptions().ignoreAttribute(lowerCaseAttrName)
                            && !lowerCaseAttrName.equals(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME)
                            && !(xdmHandler.getNodeStack().size() < 3 && lowerCaseAttrName
                                    .startsWith(NodeIdentifiers.ATTRNAMEPREFIX_NAMESPACE_BINDING))
                            && !(fieldTemplateConsumer != null
                                    && fieldTemplateConsumer.isTemplateAttribute(origAttrName))
                            && !(origAttrName
                                    .startsWith(xdmHandler.getNodeIdentifiers().getXmlNameSpacePrefix())))

                        childEntry.getSchema().setAttribute(pContext, childEntry.getInstance(),
                                lowerCaseAttrName, attributes.getValue(i), false);
                }

                row.addField(field);
            }
        }
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <field-map>} element.
 *
 * @param attrs/*  w  w  w.j  a  v  a  2  s .c  om*/
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processFieldMap(Attributes attrs) throws SAXException {
    if (currField == null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration3", FIELD_MAP_ELMT, FIELD_ELMT, FIELD_LOC_ELMT),
                currParseLocation);
    }
    // if (currFieldHasLocElmt && currLocatorData == null) {
    // throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
    // "ConfigParserHandler.element.has.both2", FIELD_ELMT, FIELD_LOC_ELMT, FIELD_MAP_ELMT,
    // getLocationInfo()));
    // }
    if (CollectionUtils.isEmpty(currField.getLocators()) && currLocatorData == null) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.element.no.binding", FIELD_MAP_ELMT, FIELD_LOC_ELMT, getLocationInfo()));
    }
    String source = null;
    String target = null;
    String type = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (SOURCE_ATTR.equals(attName)) {
            source = attValue;
        } else if (TARGET_ATTR.equals(attName)) {
            target = attValue;
        } else if (TYPE_ATTR.equals(attName)) {
            type = attValue;
        }
    }
    notNull(source, FIELD_MAP_ELMT, SOURCE_ATTR);
    notNull(target, FIELD_MAP_ELMT, TARGET_ATTR);

    if (currLocatorData != null) {
        currLocatorData.valueMapItems.add(new FieldLocatorData.ValueMapData(source, target,
                StringUtils.isEmpty(type) ? null : ActivityFieldMappingType.valueOf(type)));
    } else {
        // currFieldHasMapElmt = true;
        List<ActivityFieldLocator> locators = currField.getLocators();
        if (locators != null) {
            for (ActivityFieldLocator loc : locators) {
                loc.addValueMap(source, target,
                        StringUtils.isEmpty(type) ? null : ActivityFieldMappingType.valueOf(type));
            }
        }
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <field-locator>} element.
 *
 * @param attrs// ww w .j  a  v  a  2 s .co m
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processFieldLocator(Attributes attrs) throws SAXException {
    if (currLocatorData != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", FIELD_LOC_ELMT), currParseLocation);
    }
    if (currField == null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration3", FIELD_LOC_ELMT, FIELD_ELMT,
                EMBEDDED_ACTIVITY_ELMT), currParseLocation);
    }
    if (!currField.hasDynamicAttrs() && currFieldHasLocValAttr) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.element.has.both", FIELD_ELMT, LOCATOR_ATTR, VALUE_ATTR, FIELD_LOC_ELMT,
                getLocationInfo()));
    }
    // if (currFieldHasMapElmt) {
    // throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
    // "ConfigParserHandler.element.has.both2", FIELD_ELMT, FIELD_LOC_ELMT, FIELD_MAP_ELMT,
    // getLocationInfo()));
    // }

    currLocatorData = new FieldLocatorData();

    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (DATA_TYPE_ATTR.equals(attName)) {
            currLocatorData.dataType = ActivityFieldDataType.valueOf(attValue);
        } else if (LOC_TYPE_ATTR.equals(attName)) {
            currLocatorData.locatorType = attValue;
        } else if (LOCATOR_ATTR.equals(attName)) {
            currLocatorData.locator = attValue;
        } else if (RADIX_ATTR.equals(attName)) {
            currLocatorData.radix = Integer.parseInt(attValue);
        } else if (UNITS_ATTR.equals(attName)) {
            currLocatorData.units = attValue;
        } else if (FORMAT_ATTR.equals(attName)) {
            currLocatorData.format = attValue;
        } else if (LOCALE_ATTR.equals(attName)) {
            currLocatorData.locale = attValue;
        } else if (TIMEZONE_ATTR.equals(attName)) {
            currLocatorData.timeZone = attValue;
        } else if (VALUE_ATTR.equals(attName)) {
            currLocatorData.value = attValue;
        } else if (REQUIRED_ATTR.equals(attName)) {
            currLocatorData.reqVal = attValue;
        } else if (ID_ATTR.equals(attName)) {
            currLocatorData.id = attValue;
        }
    }

    if (currLocatorData.value != null && currLocatorData.value.isEmpty()) {
        currLocatorData.value = null;
    }

    // make sure any fields that are required based on other fields are
    // specified
    if (ActivityFieldDataType.DateTime == currLocatorData.dataType) {
        if (currLocatorData.format == null) {
            throw new SAXParseException(StreamsResources.getStringFormatted(
                    StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.missing.attribute2",
                    FIELD_LOC_ELMT, FORMAT_ATTR, currLocatorData.dataType), currParseLocation);
        }
        // if (locale == null)
        // {
        //
        // }
    } else if (ActivityFieldDataType.Timestamp == currLocatorData.dataType) {
        if (currLocatorData.units == null) {
            throw new SAXParseException(StreamsResources.getStringFormatted(
                    StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.missing.attribute2",
                    FIELD_LOC_ELMT, UNITS_ATTR, currLocatorData.dataType), currParseLocation);
        }
    }
    // currFieldHasLocElmt = true;

    elementData = new StringBuilder();
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <field>} element.
 *
 * @param attrs//from  ww w.ja  v a  2 s .c  o  m
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processField(Attributes attrs) throws SAXException {
    if (currField != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", FIELD_ELMT), currParseLocation);
    }
    if (currParser == null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", FIELD_ELMT, PARSER_ELMT),
                currParseLocation);
    }
    currFieldHasLocValAttr = false;
    // currFieldHasLocElmt = false;
    // currFieldHasMapElmt = false;
    String field = null;
    ActivityFieldDataType dataType = null;
    String locatorType = null;
    String locator = null;
    String valueType = null;
    String separator = null;
    String pattern = null;
    String units = null;
    String format = null;
    String locale = null;
    String timeZone = null;
    String value = null;
    int radix = 10;
    String reqVal = "";
    boolean transparent = false;
    boolean split = false;
    String id = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            field = attValue;
        } else if (DATA_TYPE_ATTR.equals(attName)) {
            dataType = ActivityFieldDataType.valueOf(attValue);
        } else if (LOC_TYPE_ATTR.equals(attName)) {
            locatorType = attValue;
        } else if (LOCATOR_ATTR.equals(attName)) {
            locator = attValue;
        } else if (VALUE_TYPE_ATTR.equals(attName)) {
            valueType = attValue;
        } else if (SEPARATOR_ATTR.equals(attName)) {
            separator = attValue;
        } else if (FORMATTING_PATTERN_ATTR.equals(attName))
            pattern = attValue;
        else if (RADIX_ATTR.equals(attName)) {
            radix = Integer.parseInt(attValue);
        } else if (UNITS_ATTR.equals(attName)) {
            units = attValue;
        } else if (FORMAT_ATTR.equals(attName)) {
            format = attValue;
        } else if (LOCALE_ATTR.equals(attName)) {
            locale = attValue;
        } else if (TIMEZONE_ATTR.equals(attName)) {
            timeZone = attValue;
        } else if (VALUE_ATTR.equals(attName)) {
            value = attValue;
        } else if (REQUIRED_ATTR.equals(attName)) {
            reqVal = attValue;
        } else if (TRANSPARENT_ATTR.equals(attName)) {
            transparent = Boolean.parseBoolean(attValue);
        } else if (SPLIT_ATTR.equals(attName)) {
            split = Boolean.parseBoolean(attValue);
        } else if (ID_ATTR.equals(attName)) {
            id = attValue;
        }
    }
    // make sure required fields are present
    notEmpty(field, FIELD_ELMT, NAME_ATTR);

    if (separator != null && pattern != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.cannot.contain", FIELD_ELMT, SEPARATOR_ATTR, FORMATTING_PATTERN_ATTR),
                currParseLocation);
    }

    ActivityFieldLocator afl;
    ActivityField af = new ActivityField(field);

    if (value != null) {
        currFieldHasLocValAttr = true;
        afl = new ActivityFieldLocator(value);
        afl.setRadix(radix);
        afl.setRequired(reqVal);
        if (dataType != null) {
            afl.setDataType(dataType);
        }
        if (StringUtils.isNotEmpty(units)) {
            afl.setUnits(units);
        }
        if (StringUtils.isNotEmpty(format)) {
            afl.setFormat(format, locale);
        }
        if (StringUtils.isNotEmpty(timeZone)) {
            afl.setTimeZone(timeZone);
        }
        if (StringUtils.isNotEmpty(id)) {
            afl.setId(id);
        }
        af.addLocator(afl);
    } else if (StringUtils.isNotEmpty(locator)) {
        currFieldHasLocValAttr = true;
        String[] locators = currParser.canHaveDelimitedLocators() ? locator.split(Pattern.quote(LOC_DELIM))
                : new String[] { locator };
        for (String loc : locators) {
            if (StringUtils.isNotEmpty(loc)) {
                afl = new ActivityFieldLocator(locatorType, loc);
                afl.setRadix(radix);
                afl.setRequired(reqVal);
                if (dataType != null) {
                    afl.setDataType(dataType);
                }
                if (StringUtils.isNotEmpty(units)) {
                    afl.setUnits(units);
                }
                if (StringUtils.isNotEmpty(format)) {
                    afl.setFormat(format, locale);
                }
                if (StringUtils.isNotEmpty(timeZone)) {
                    afl.setTimeZone(timeZone);
                }
                if (StringUtils.isNotEmpty(id)) {
                    afl.setId(id);
                }
                af.addLocator(afl);
            }
        }
    } else if (StringUtils.isEmpty(locator)) {
        af.setGroupLocator(radix, reqVal, dataType, units, format, locale, timeZone);
    }

    if (separator != null) {
        af.setSeparator(separator);
    }
    if (StringUtils.isNotEmpty(pattern)) {
        af.setFormattingPattern(pattern);
    }
    if (StringUtils.isNotEmpty(valueType)) {
        af.setValueType(valueType);
    }
    af.setRequired(reqVal);
    af.setTransparent(transparent);
    af.setSplitCollection(split);
    currField = af;
}

From source file:edu.virginia.speclab.juxta.author.model.JuxtaXMLParser.java

@Override
public void startElement(String uri, String localName, String qname, Attributes attr) {
    if (root == null) {
        // this is the root node. exciting.
        root = new JuxtaXMLNode(qname, flatTextPosition + 1);
        current = root;/*  w  w  w . ja va2  s.c  o  m*/
    } else {
        JuxtaXMLNode newNode = new JuxtaXMLNode(qname, flatTextPosition + 1);
        current.addChild(newNode);
        current = newNode;
    }

    // When dealing with revised modes, only keep revison
    // tags that we have been explicitly told to. Note the nify
    // inverted logic...
    if (isDocumentRevised() && isRevisionTag(qname)) {
        if (this.revisionsToAccept.contains(Integer.valueOf(this.currentRevisionIndex))) {
            if (this.current.getName().equals("del") || this.current.getName().equals("delSpan")) {
                current.setExcluded(true);
            }
        } else {
            if (this.current.getName().equals("add") || this.current.getName().equals("addSpan")) {
                current.setExcluded(true);
            }
        }
    }

    // set the start offset of the current node to the LAST xml position we read
    // then reset lastXMLPosition to be the current position given by locator.
    //
    // When these callbacks are called, the locator element points to the line and column number
    // of the current position, which is usually just after the thing that was just processed.
    // So for instance in this case, the locator points to the end of the opening tag.
    // The LAST time we read the location pointer and shoved it into lastXMLPosition corresponds
    // to either 1) the beginning of the document or 2) the end of the last end tag or character read.
    // This means that it already points to the offset we want to record, with the caveat that
    // the root tag will have offsets that also encompass the <?xml?> directive and anything that comes
    // between the beginning of the file and the open root tag, since we aren't ever infomed of an
    // event that happens when the root tag is getting ready to be opened. 
    current.setXMLStartOffset(lastXMLPosition);
    int openTagStartOffset = lastXMLPosition;
    int openTagEndOffset = lastXMLPosition = mapLineAndColumnToOffset(locator.getLineNumber(),
            locator.getColumnNumber());

    // Keep track of all of the element names that we see in the text.
    elementsEncountered.add(qname);

    // If our parent node is an excluded node, then
    // we ourselves are excluded.  When we called addChild our excluded
    // flag was set to be whatever the parent node's flag was set to.
    // If we AREN'T set as excluded from that event, then we check
    // to see if the current element name is set to be excluded
    if (!current.isExcluded()) {
        current.setExcluded(excludeElements.contains(qname));
    }

    // Check to see if we are an element to be noted
    current.setIsNotable(notableElements.contains(qname));

    // are we a newline tag?
    if (!current.isExcluded() && newlineElements.contains(qname)) {
        insertCharacterFromSource('\n');
        openTagStartOffset++;
    }

    for (int i = openTagStartOffset; i < openTagEndOffset; i++)
        skipCharacterFromSource();

    for (int i = 0; i < attr.getLength(); ++i) {
        String name = attr.getQName(i);
        String value = attr.getValue(i);
        current.setAttribute(name, value);
    }
}

From source file:com.aurel.track.exchange.docx.importer.HTMLParser.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (qName.equalsIgnoreCase(ELEMENT_NAME.STYLE.getElementName())) {
        insideStyle = true;/*from   w w  w . ja  va  2  s.c  o m*/
        contentBuffer = new StringBuilder();
    } else {
        if (qName.equalsIgnoreCase(ELEMENT_NAME.P.getElementName())) {
            String clazz = attributes.getValue(ATTRIBUTE_NAME.CLASS.getElementName());
            if (clazz != null && !"".equals(clazz)) {
                if (clazz.contains(localizedHeading)) {
                    for (int i = 1; i <= MAX_HEADING_LEVEL; i++) {
                        if (clazz.contains(localizedHeading + i)) {
                            if (insideContent) {
                                //not the first heading: add the gathered description of the previous item when the new heading begins
                                currentNode.setDescription(contentBuffer.toString());
                            }
                            currentNode = new ItemNode();
                            //currentNode.setElementType(ELEMENT_NAME.HEADING);
                            currentNode.setHeadingLevel(i);
                            if (!stack.isEmpty()) {
                                ItemNode itemNode = stack.peek();
                                if (i > itemNode.getHeadingLevel()) {
                                    //current heading level > stack heading level: first sub-chapter
                                    List<ItemNode> children = itemNode.getChildren();
                                    if (children == null) {
                                        children = new ArrayList<ItemNode>();
                                        itemNode.setChildren(children);
                                    }
                                    //add as child to the peek
                                    children.add(currentNode);
                                } else {
                                    if (i == itemNode.getHeadingLevel()) {
                                        //sibling sub-chapter: remove sibling
                                        itemNode = stack.pop();
                                        //get the parent chapter
                                        itemNode = stack.peek();
                                        List<ItemNode> children = itemNode.getChildren();
                                        if (children == null) {
                                            //should never happen
                                            children = new ArrayList<ItemNode>();
                                            itemNode.setChildren(children);
                                        }
                                        //add as child to the peek
                                        children.add(currentNode);
                                    } else {
                                        if (i < itemNode.getHeadingLevel()) {
                                            //new parent chapter starts
                                            while (!stack.isEmpty()) {
                                                //remove all children/descendants of the new parent's previous sibling
                                                itemNode = stack.pop();
                                                if (itemNode.getHeadingLevel() == i) {
                                                    break;
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                            if (stack.isEmpty()) {
                                htmlContent.getChapters().add(currentNode);
                            }
                            stack.push(currentNode);
                            insideHeadingParagraph = true;
                            insideContent = true;
                            //gather the paragraph title
                            contentBuffer = new StringBuilder();
                            break;
                        }
                    }
                }
            }
        }
    }

    if (insideContent && !insideHeadingParagraph) {
        //gather the description content
        String eName = localName; // element name
        if ("".equals(eName)) {
            eName = qName; // not namespaceAware
        }
        contentBuffer.append("<" + eName);
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                String aName = attributes.getLocalName(i); // Attr name 
                if ("".equals(aName)) {
                    aName = attributes.getQName(i);
                }
                contentBuffer.append(" ");
                contentBuffer.append(aName + "=\"" + attributes.getValue(i) + "\"");
            }
        }
        contentBuffer.append(">");
    }

}

From source file:com.netspective.commons.xdm.XdmHandler.java

public void startElement(String url, String localName, String qName, Attributes attributes)
        throws SAXException {
    //System.out.println(getStackDepthPrefix() + qName + " " + getAttributeNames(attributes));

    if (handleDefaultStartElement(url, localName, qName, attributes))
        return;/*from w ww .jav a  2  s. c  o m*/

    String elementName = qName.toLowerCase();
    XdmHandlerNodeStackEntry activeEntry = (XdmHandlerNodeStackEntry) getNodeStack().peek();

    if (!unmarshallingTemplate && handleTemplateStartElement(activeEntry, url, localName, qName, attributes))
        return;

    if (elementName.equals(getNodeIdentifiers().getIncludeElementName())) {
        try {
            includeInputSource(activeEntry, attributes);
            setInInclude(true);
            return;
        } catch (Exception e) {
            throw new SAXException(e);
        }
    }

    if (activeEntry.getInstance() instanceof XmlDataModelSchema.InputSourceTrackerListener) {
        try {
            ((XmlDataModelSchema.InputSourceTrackerListener) activeEntry.getInstance())
                    .setInputSourceTracker(getParseContext().getInputSrcTracker());
        } catch (Exception e) {
            throw new SAXException(e.getMessage() + " " + getStateText(), e);
        }
    }

    if (!getIgnoreStack().isEmpty() || activeEntry.getOptions().ignoreNestedElement(elementName)) {
        getIgnoreStack().push(elementName);
    } else {
        Object childInstance = null;
        XmlDataModelSchema activeSchema = activeEntry.getSchema();
        TemplateConsumerDefn templateConsumer = null;
        List templatesToConsume = null;

        try {
            String alternateClassName = attributes.getValue(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME);
            childInstance = activeSchema.createElement(((XdmParseContext) getParseContext()),
                    alternateClassName, activeEntry.getInstance(), elementName, false);

            boolean inAttrSetterText = childInstance == activeEntry.getInstance();

            if (childInstance != null && !inAttrSetterText) {
                // see if we have any templates that need to be applied
                if (childInstance instanceof TemplateConsumer) {
                    // check to see if we don't have our own alternate class but one of our the templates we're about to apply want to override our class
                    templateConsumer = ((TemplateConsumer) childInstance).getTemplateConsumerDefn();
                    templatesToConsume = templateConsumer.getTemplatesToApply(this, elementName, attributes);
                    if (alternateClassName == null) {
                        alternateClassName = templateConsumer.getAlternateClassName(this, templatesToConsume,
                                elementName, attributes);
                        if (alternateClassName != null)
                            childInstance = activeSchema.createElement(((XdmParseContext) getParseContext()),
                                    alternateClassName, activeEntry.getInstance(), elementName, false);
                    }
                }
            }

            if (childInstance == null) {
                getIgnoreStack().push(elementName);
                return;
            }

            if (inAttrSetterText) {
                inAttrSetterTextEntry = new XdmHandlerNodeStackEntry(elementName, attributes, childInstance);
                return;
            }
        } catch (DataModelException e) {
            log.error(e.getMessage() + " " + getStateText(), e);
            throw new SAXException(e.getMessage() + " " + getStateText(), e);
        }

        if (childInstance != null) {
            if (childInstance instanceof XmlDataModelSchema.InputSourceLocatorListener) {
                final Locator locator = getParseContext().getLocator();
                ((XmlDataModelSchema.InputSourceLocatorListener) childInstance)
                        .setInputSourceLocator(new InputSourceLocator(getParseContext().getInputSrcTracker(),
                                locator.getLineNumber(), locator.getColumnNumber()));
            }

            XdmHandlerNodeStackEntry childEntry = null;
            try {
                childEntry = new XdmHandlerNodeStackEntry(elementName, attributes, childInstance);
                getNodeStack().push(childEntry);

                // if we're already inside a template, then check to see if we have any attributes that need their
                // expressions replaced
                TemplateApplyContext activeApplyTemplateContext = activeEntry.getActiveApplyContext();
                if (activeApplyTemplateContext != null) {
                    TemplateApplyContext.StackEntry atcEntry = activeApplyTemplateContext.getActiveEntry();
                    if (atcEntry != null && atcEntry.isReplacementExprsFoundInAttrs())
                        attributes = atcEntry.getActiveTemplate()
                                .replaceAttributeExpressions(activeApplyTemplateContext);
                }

                // if the current element indicates the start of a template, apply it now
                if (templateConsumer != null && templatesToConsume != null) {
                    String[] attrNamesToSet = templateConsumer.getAttrNamesToApplyBeforeConsuming();
                    if (attrNamesToSet != null) {
                        for (int i = 0; i < attrNamesToSet.length; i++) {
                            String attrValue = attributes.getValue(attrNamesToSet[i]);
                            String lowerCaseAttrName = attrNamesToSet[i].toLowerCase();
                            childEntry.getSchema().setAttribute(((XdmParseContext) getParseContext()),
                                    childEntry.getInstance(), lowerCaseAttrName, attrValue, false);
                        }
                    }

                    templateConsumer.consume(this, templatesToConsume, elementName, attributes);
                }

                for (int i = 0; i < attributes.getLength(); i++) {
                    String origAttrName = attributes.getQName(i);
                    String lowerCaseAttrName = origAttrName.toLowerCase();
                    if (!childEntry.getOptions().ignoreAttribute(lowerCaseAttrName)
                            && !lowerCaseAttrName.equals(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME)
                            && !(getNodeStack().size() < 3 && lowerCaseAttrName
                                    .startsWith(NodeIdentifiers.ATTRNAMEPREFIX_NAMESPACE_BINDING))
                            && !(templateConsumer != null && templateConsumer.isTemplateAttribute(origAttrName))
                            && !(origAttrName.startsWith(getNodeIdentifiers().getXmlNameSpacePrefix())))

                        childEntry.getSchema().setAttribute(((XdmParseContext) getParseContext()),
                                childEntry.getInstance(), lowerCaseAttrName, attributes.getValue(i), false);
                }
            } catch (Exception e) {
                log.error(e.getMessage() + " " + getStateText(), e);
                throw new SAXException(e.getMessage() + " " + getStateText(), e);
            }

            try {
                activeEntry.getSchema().storeElement(((XdmParseContext) getParseContext()),
                        activeEntry.getInstance(), childEntry.getInstance(), elementName, false);
            } catch (DataModelException e) {
                log.error(e.getMessage() + " " + getStateText(), e);
                throw new SAXException(e.getMessage() + " " + getStateText(), e);
            }
        }
    }
}

From source file:ee.sk.digidoc.factory.SAXDigiDocFactory.java

/**
 * Start Element handler// w  w  w .j  av  a  2s  .  c o  m
 * @param namespaceURI namespace URI
 * @param lName local name
 * @param qName qualified name
 * @param attrs attributes
 */
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs)
        throws SAXDigiDocException {
    if (m_logger.isDebugEnabled())
        m_logger.debug("Start Element: " + qName + " lname: " + lName + " uri: " + namespaceURI);
    String tag = qName;
    if (tag.indexOf(':') != -1) {
        tag = qName.substring(qName.indexOf(':') + 1);
        if (m_nsDsPref == null) {
            m_nsDsPref = findNsPrefForUri(attrs, xmlnsDs);
            if (m_logger.isDebugEnabled())
                m_logger.debug(
                        "Element: " + qName + " xmldsig pref: " + ((m_nsDsPref != null) ? m_nsDsPref : "NULL"));
        }
        if (m_nsXadesPref == null) {
            m_nsXadesPref = findNsPrefForUri(attrs, xmlnsEtsi);
            if (m_logger.isDebugEnabled())
                m_logger.debug("Element: " + qName + " xades pref: "
                        + ((m_nsXadesPref != null) ? m_nsXadesPref : "NULL"));
        }
        if (m_nsAsicPref == null) {
            m_nsAsicPref = findNsPrefForUri(attrs, xmlnsAsic);
            if (m_logger.isDebugEnabled())
                m_logger.debug("Element: " + qName + " asic pref: "
                        + ((m_nsAsicPref != null) ? m_nsAsicPref : "NULL"));
        }
    }
    // record elements found
    XmlElemInfo e = new XmlElemInfo(tag, findAttrValueByName(attrs, "id"),
            (tag.equals("XAdESSignatures") || tag.equals("SignedDoc")) ? null : m_elemCurrent);
    // <XAdESSignatures> and <SignedDoc> cannot be child of another element, must be root elements
    if (m_elemCurrent != null && !tag.equals("XAdESSignatures") && !tag.equals("SignedDoc"))
        m_elemCurrent.addChild(e);
    m_elemCurrent = e;
    if (m_elemRoot == null || tag.equals("XAdESSignatures") || tag.equals("SignedDoc"))
        m_elemRoot = e;
    DigiDocException exv = DigiDocStructureValidator.validateElementPath(m_elemCurrent);
    if (exv != null)
        handleSAXError(exv);

    m_tags.push(tag);
    if (tag.equals("SigningTime") || tag.equals("IssuerSerial") || tag.equals("X509SerialNumber")
            || tag.equals("X509IssuerName") || tag.equals("ClaimedRole") || tag.equals("City")
            || tag.equals("StateOrProvince") || tag.equals("CountryName") || tag.equals("PostalCode")
            || tag.equals("SignatureValue") || tag.equals("DigestValue") ||
            //qName.equals("EncapsulatedX509Certificate") ||
            tag.equals("IssuerSerial")
            || (tag.equals("ResponderID") && !m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC))
            || (tag.equals("ByName") && m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC))
            || (tag.equals("ByKey") && m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC))
            || tag.equals("X509SerialNumber") || tag.equals("ProducedAt") || tag.equals("EncapsulatedTimeStamp")
            || tag.equals("Identifier") || tag.equals("SPURI") || tag.equals("NonceAlgorithm")
            || tag.equals("MimeType") || tag.equals("EncapsulatedOCSPValue")) {
        if (m_logger.isDebugEnabled())
            m_logger.debug("Start collecting tag: " + tag);
        m_sbCollectItem = new StringBuffer();
    }
    // <XAdESSignatures>
    if (tag.equals("XAdESSignatures")) {
        try {
            if (m_logger.isDebugEnabled())
                m_logger.debug("BDOC 2.0 - ASIC-E");
            m_doc.setFormatAndVersion(SignedDoc.FORMAT_BDOC, SignedDoc.BDOC_VERSION_2_1);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }

    // <X509Certificate>
    // Prepare CertValue object
    if (tag.equals("X509Certificate")) {
        Signature sig = getLastSignature();
        CertValue cval = null;
        try {
            if (m_logger.isDebugEnabled())
                m_logger.debug("Adding signers cert to: " + sig.getId());
            cval = sig.getOrCreateCertValueOfType(CertValue.CERTVAL_TYPE_SIGNER);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
        m_sbCollectItem = new StringBuffer();
    }
    // <EncapsulatedX509Certificate>
    // Prepare CertValue object and record it's id
    if (tag.equals("EncapsulatedX509Certificate")) {
        Signature sig = getLastSignature();
        String id = null;
        for (int i = 0; i < attrs.getLength(); i++) {
            String key = attrs.getQName(i);
            if (key.equalsIgnoreCase("Id")) {
                id = attrs.getValue(i);
            }
        }
        CertValue cval = new CertValue();
        if (id != null) {
            cval.setId(id);
            try {
                if (id.indexOf("RESPONDER_CERT") != -1 || id.indexOf("RESPONDER-CERT") != -1)
                    cval.setType(CertValue.CERTVAL_TYPE_RESPONDER);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        if (m_logger.isDebugEnabled() && cval != null)
            m_logger.debug("Adding cval " + cval.getId() + " type: " + cval.getType() + " to: " + sig.getId());
        sig.addCertValue(cval);
        m_sbCollectItem = new StringBuffer();
    }
    // the following elements switch collect mode
    // in and out
    // <DataFile>
    boolean bDfDdoc13Bad = false;
    if (tag.equals("DataFile")) {
        String ContentType = null, Filename = null, Id = null, MimeType = null, Size = null, DigestType = null,
                Codepage = null;
        byte[] DigestValue = null;
        m_digest = null; // init to null
        if (m_doc != null && m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML)
                && m_doc.getVersion().equals(SignedDoc.VERSION_1_3)) {
            m_xmlnsAttr = SignedDoc.xmlns_digidoc13;
            bDfDdoc13Bad = true; // possible case for ddoc 1.3 invalid namespace problem
        } else
            m_xmlnsAttr = null;
        ArrayList dfAttrs = new ArrayList();
        for (int i = 0; i < attrs.getLength(); i++) {
            String key = attrs.getQName(i);
            if (key.equals("ContentType")) {
                ContentType = attrs.getValue(i);
            } else if (key.equals("Filename")) {
                Filename = attrs.getValue(i);
                if (Filename.indexOf('/') != -1 || Filename.indexOf('\\') != -1) {
                    DigiDocException ex = new DigiDocException(DigiDocException.ERR_DF_NAME,
                            "Failed to parse DataFile name. Invalid file name!", null);
                    handleSAXError(ex);
                }
            } else if (key.equals("Id")) {
                Id = attrs.getValue(i);
            } else if (key.equals("MimeType")) {
                MimeType = attrs.getValue(i);
            } else if (key.equals("Size")) {
                Size = attrs.getValue(i);
            } else if (key.equals("DigestType")) {
                DigestType = attrs.getValue(i);
            } else if (key.equals("Codepage")) {
                Codepage = attrs.getValue(i);
            } else if (key.equals("DigestValue")) {
                DigestValue = Base64Util.decode(attrs.getValue(i));
            } else {
                try {
                    if (!key.equals("xmlns")) {
                        DataFileAttribute attr = new DataFileAttribute(key, attrs.getValue(i));
                        dfAttrs.add(attr);
                    } else {
                        bDfDdoc13Bad = false; // nope, this one has it's own xmlns
                    }
                } catch (DigiDocException ex) {
                    handleSAXError(ex);
                }
            } // else
        } // for
        if (m_nCollectMode == 0) {
            try {
                DataFile df = new DataFile(Id, ContentType, Filename, MimeType, m_doc);
                m_dfCacheOutStream = null; // default is don't use cache file
                if (Size != null)
                    df.setSize(Long.parseLong(Size));
                if (DigestValue != null) {
                    if (m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML))
                        df.setAltDigest(DigestValue);
                    else if (ContentType != null && ContentType.equals(DataFile.CONTENT_HASHCODE))
                        df.setDigestValue(DigestValue);
                }
                if (Codepage != null)
                    df.setInitialCodepage(Codepage);
                for (int i = 0; i < dfAttrs.size(); i++)
                    df.addAttribute((DataFileAttribute) dfAttrs.get(i));
                // enable caching if requested
                if (m_tempDir != null) {
                    File fCache = new File(m_tempDir + File.separator + df.getFileName());
                    if (m_logger.isDebugEnabled())
                        m_logger.debug("Parser temp DF: " + Id + " size: " + df.getSize() + " cache-file: "
                                + fCache.getAbsolutePath());
                    m_dfCacheOutStream = new FileOutputStream(fCache);
                    df.setCacheFile(fCache);
                } else if (df.schouldUseTempFile()) {
                    File fCache = df.createCacheFile();
                    if (m_logger.isDebugEnabled())
                        m_logger.debug("Df-temp DF: " + Id + " size: " + df.getSize() + " cache-file: "
                                + fCache.getAbsolutePath());
                    df.setCacheFile(fCache);
                    m_dfCacheOutStream = new FileOutputStream(fCache);
                }
                m_doc.addDataFile(df);
            } catch (IOException ex) {
                handleSAXError(ex);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        m_nCollectMode++;
        // try to anticipate how much memory we need for collecting this <DataFile>
        try {
            if (Size != null) {
                int nSize = Integer.parseInt(Size);
                if (!ContentType.equals(DataFile.CONTENT_HASHCODE)) {
                    if (ContentType.equals(DataFile.CONTENT_EMBEDDED_BASE64)) {
                        nSize *= 2;
                        m_bCollectDigest = true;
                        if (m_logger.isDebugEnabled())
                            m_logger.debug("Start collecting digest");
                    }
                    if (m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML))
                        m_bCollectDigest = false;
                    if (m_logger.isDebugEnabled())
                        m_logger.debug("Allocating buf: " + nSize + " Element: " + qName + " lname: " + lName
                                + " uri: " + namespaceURI);
                    if (m_dfCacheOutStream == null) // if we use temp files then we don't cache in memory 
                        m_sbCollectChars = new StringBuffer(nSize);
                }
            }
        } catch (Exception ex) {
            m_logger.error("Error: " + ex);
        }
    }

    //  
    if (tag.equals("SignedInfo")) {
        if (m_nCollectMode == 0) {
            try {
                if (m_doc != null && (m_doc.getVersion().equals(SignedDoc.VERSION_1_3)
                        || m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC)
                        || m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML)))
                    m_xmlnsAttr = null;
                else
                    m_xmlnsAttr = SignedDoc.xmlns_xmldsig;
                Signature sig = getLastSignature();
                SignedInfo si = new SignedInfo(sig);
                if (sig != null) {
                    sig.setSignedInfo(si);
                    String Id = attrs.getValue("Id");
                    if (Id != null)
                        si.setId(Id);
                }
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        m_nCollectMode++;
        m_sbCollectChars = new StringBuffer(1024);
    }
    // <SignedProperties>
    if (tag.equals("SignedProperties")) {
        String Id = attrs.getValue("Id");
        String Target = attrs.getValue("Target");
        if (m_nCollectMode == 0) {
            try {
                if (m_doc != null && (m_doc.getVersion().equals(SignedDoc.VERSION_1_3)
                        || m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC)))
                    m_xmlnsAttr = null;
                else
                    m_xmlnsAttr = SignedDoc.xmlns_xmldsig;
                Signature sig = getLastSignature();
                SignedProperties sp = new SignedProperties(sig);
                sp.setId(Id);
                if (Target != null)
                    sp.setTarget(Target);
                sig.setSignedProperties(sp);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        m_nCollectMode++;
        m_sbCollectChars = new StringBuffer(2048);
    }
    // <XAdESSignatures>
    if (tag.equals("XAdESSignatures") && m_nCollectMode == 0) {
        if (m_logger.isDebugEnabled())
            m_logger.debug("Start collecting <XAdESSignatures>");
        m_sbCollectSignature = new StringBuffer();
    }
    // <Signature>
    if (tag.equals("Signature") && m_nCollectMode == 0) {
        if (m_logger.isDebugEnabled())
            m_logger.debug("Start collecting <Signature>");
        if (m_doc == null) {
            DigiDocException ex = new DigiDocException(DigiDocException.ERR_PARSE_XML,
                    "Invalid signature format. Missing signed container root element.", null);
            handleSAXError(ex); // now stop parsing
            SAXDigiDocException sex1 = new SAXDigiDocException(
                    "Invalid signature format. Missing signed container root element.");
            throw sex1;
        }
        String str1 = attrs.getValue("Id");
        Signature sig = null;
        // in case of ddoc-s try find existing signature but not in case of bdoc-s.
        // to support libc++ buggy implementation with non-unique id atributes
        if (m_doc != null && !m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC))
            sig = m_doc.findSignatureById(str1);
        if (m_doc != null && m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC)
                && m_doc.getVersion().equals(SignedDoc.BDOC_VERSION_2_1)) {
            m_doc.addSignatureProfile(str1, SignedDoc.BDOC_PROFILE_TM);
            if (m_doc.getProfile() == null || !m_doc.getProfile().equals(SignedDoc.BDOC_PROFILE_TM))
                m_doc.setProfile(SignedDoc.BDOC_PROFILE_TM);
        }
        if (sig == null || (sig.getId() != null && !sig.getId().equals(str1))) {
            if (m_logger.isDebugEnabled())
                m_logger.debug("Create signature: " + str1);
            if (m_doc != null) {
                sig = new Signature(m_doc);
                try {
                    sig.setId(str1);
                } catch (DigiDocException ex) {
                    handleSAXError(ex);
                }
                sig.setPath(m_fileName);
                sig.setComment(m_sigComment);
                String sProfile = m_doc.findSignatureProfile(m_fileName);
                if (sProfile == null)
                    sProfile = m_doc.findSignatureProfile(sig.getId());
                if (sProfile != null)
                    sig.setProfile(sProfile);
                /*if(sProfile == null && 
                      (m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML) ||
                   m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML)))
                   sig.setProfile(SignedDoc.BDOC_PROFILE_TM);*/
                m_doc.addSignature(sig);
                if (m_logger.isDebugEnabled())
                    m_logger.debug("Sig1: " + m_fileName + " profile: " + sProfile + " doc: "
                            + ((m_doc != null) ? "OK" : "NULL"));
            } else {
                m_sig = new Signature(null);
                m_sig.setPath(m_fileName);
                m_sig.setComment(m_sigComment);
                String sProfile = null;
                if (m_doc != null && m_fileName != null)
                    sProfile = m_doc.findSignatureProfile(m_fileName);
                if (sProfile != null)
                    m_sig.setProfile(sProfile);
                if (m_logger.isDebugEnabled())
                    m_logger.debug("Sig2: " + m_fileName + " profile: " + sProfile);
                sig = m_sig;
            }
            for (int j = 0; (m_doc != null) && (j < m_doc.countSignatures()); j++) {
                Signature sig2 = m_doc.getSignature(j);
                if (sig2 != null && sig != null && m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC)
                        && sig2.getId() != null && sig.getId() != null && !sig2.getId().equals(sig.getId())
                        && sig2.getPath() != null && sig.getPath() != null
                        && sig2.getPath().equals(sig.getPath())) {
                    m_logger.error("Signatures: " + sig.getId() + " and " + sig2.getId() + " are in same file: "
                            + sig.getPath());
                    DigiDocException ex = new DigiDocException(DigiDocException.ERR_PARSE_XML,
                            "More than one signature in signatures.xml file is unsupported", null);
                    handleSAXError(ex);
                }
            }
        }
        if (m_sbCollectSignature == null)
            m_sbCollectSignature = new StringBuffer();
    }
    // <SignatureValue>
    if (tag.equals("SignatureValue") && m_nCollectMode == 0) {
        m_strSigValTs = null;
        m_nCollectMode++;
        m_sbCollectChars = new StringBuffer(1024);
    }
    // <SignatureTimeStamp>
    if (tag.equals("SignatureTimeStamp") && m_nCollectMode == 0) {
        if (m_sig != null)
            m_sig.setProfile(SignedDoc.BDOC_PROFILE_TS);
        m_doc.setProfile(SignedDoc.BDOC_PROFILE_TS);
        m_strSigAndRefsTs = null;
        m_nCollectMode++;
        m_sbCollectChars = new StringBuffer(2048);
    }
    // collect <Signature> data
    if (m_sbCollectSignature != null) {
        m_sbCollectSignature.append("<");
        m_sbCollectSignature.append(qName);
        for (int i = 0; i < attrs.getLength(); i++) {
            m_sbCollectSignature.append(" ");
            m_sbCollectSignature.append(attrs.getQName(i));
            m_sbCollectSignature.append("=\"");
            String s = attrs.getValue(i);
            s = s.replaceAll("&", "&amp;");
            m_sbCollectSignature.append(s);
            m_sbCollectSignature.append("\"");
        }
        m_sbCollectSignature.append(">");
    }
    // if we just switched to collect-mode
    // collect SAX event data to original XML data
    // for <DataFile> we don't collect the begin and
    // end tags unless this an embedded <DataFile>
    if (m_nCollectMode > 0 || m_sbCollectChars != null) {
        StringBuffer sb = new StringBuffer();
        String sDfTagBad = null;
        sb.append("<");
        sb.append(qName);
        for (int i = 0; i < attrs.getLength(); i++) {
            if (attrs.getQName(i).equals("xmlns")) {
                m_xmlnsAttr = null; // allready have it from document
                bDfDdoc13Bad = false;
            }
            sb.append(" ");
            sb.append(attrs.getQName(i));
            sb.append("=\"");
            if (m_logger.isDebugEnabled())
                m_logger.debug("Attr: " + attrs.getQName(i) + " =\'" + attrs.getValue(i) + "\'");

            if (!m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML)) {
                sb.append(ConvertUtils.escapeXmlSymbols(attrs.getValue(i)));
            } else {
                String sv = attrs.getValue(i);
                if (attrs.getQName(i).equals("DigestValue") && sv.endsWith(" "))
                    sv = sv.replaceAll(" ", "\n");
                sb.append(sv);
            }
            sb.append("\"");
        }
        if (bDfDdoc13Bad)
            sDfTagBad = sb.toString() + ">";
        if (m_xmlnsAttr != null) {
            sb.append(" xmlns=\"" + m_xmlnsAttr + "\"");
            m_xmlnsAttr = null;
        }
        sb.append(">");
        //canonicalize & calculate digest over DataFile begin-tag without content
        if (tag.equals("DataFile") && m_nCollectMode == 1) {
            String strCan = null;
            if (!m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML)) {
                strCan = sb.toString() + "</DataFile>";
                strCan = canonicalizeXml(strCan);
                strCan = strCan.substring(0, strCan.length() - 11);
                if (m_logger.isDebugEnabled())
                    m_logger.debug("Canonicalized: \'" + strCan + "\'");
                if (sDfTagBad != null) {
                    strCan = sDfTagBad + "</DataFile>";
                    strCan = canonicalizeXml(strCan);
                    sDfTagBad = strCan.substring(0, strCan.length() - 11);
                    if (m_logger.isDebugEnabled())
                        m_logger.debug("Canonicalized alternative: \'" + sDfTagBad + "\'");
                }
                try {
                    updateDigest(ConvertUtils.str2data(strCan));
                    if (sDfTagBad != null)
                        updateAltDigest(ConvertUtils.str2data(sDfTagBad));
                } catch (DigiDocException ex) {
                    handleSAXError(ex);
                }
            }
        } // we don't collect <DataFile> begin and end - tags and we don't collect if we use temp files 
        else {
            if (m_sbCollectChars != null)
                m_sbCollectChars.append(sb.toString());
            try {
                if (m_dfCacheOutStream != null)
                    m_dfCacheOutStream.write(ConvertUtils.str2data(sb.toString()));
            } catch (IOException ex) {
                handleSAXError(ex);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
    }

    // the following stuff is used also on level 1
    // because it can be part of SignedInfo or SignedProperties
    if (m_nCollectMode == 1) {
        // <CanonicalizationMethod>
        if (tag.equals("CanonicalizationMethod")) {
            String Algorithm = attrs.getValue("Algorithm");
            try {
                Signature sig = getLastSignature();
                SignedInfo si = sig.getSignedInfo();
                si.setCanonicalizationMethod(Algorithm);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <SignatureMethod>
        if (tag.equals("SignatureMethod")) {
            String Algorithm = attrs.getValue("Algorithm");
            try {
                Signature sig = getLastSignature();
                SignedInfo si = sig.getSignedInfo();
                si.setSignatureMethod(Algorithm);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <Reference>
        if (tag.equals("Reference")) {
            String URI = attrs.getValue("URI");
            try {
                Signature sig = getLastSignature();
                SignedInfo si = sig.getSignedInfo();
                Reference ref = new Reference(si);
                String Id = attrs.getValue("Id");
                if (Id != null)
                    ref.setId(Id);
                ref.setUri(ConvertUtils.unescapeXmlSymbols(ConvertUtils.uriDecode(URI)));
                String sType = attrs.getValue("Type");
                if (sType != null)
                    ref.setType(sType);
                si.addReference(ref);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <Transform>
        /*if(tag.equals("Transform")) {
           String Algorithm = attrs.getValue("Algorithm");
           if(m_doc.getFormat().equals(SignedDoc.FORMAT_BDOC) ||
              m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML)) {
           DigiDocException ex = new DigiDocException(DigiDocException.ERR_TRANSFORMS, "Transform elements are currently not supported ", null);
           handleSAXError(ex);
           }
        }*/
        // <X509SerialNumber>
        if (tag.equals("X509SerialNumber") && m_doc != null
                && m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML)) {
            String sXmlns = attrs.getValue("xmlns");
            if (sXmlns == null || !sXmlns.equals(SignedDoc.xmlns_xmldsig)) {
                if (m_logger.isDebugEnabled())
                    m_logger.debug("X509SerialNumber has none or invalid namespace: " + sXmlns);
                DigiDocException ex = new DigiDocException(DigiDocException.ERR_ISSUER_XMLNS,
                        "X509SerialNumber has none or invalid namespace: " + sXmlns, null);
                handleSAXError(ex);
            }
        }
        // <X509IssuerName>
        if (tag.equals("X509IssuerName") && m_doc != null
                && m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML)) {
            String sXmlns = attrs.getValue("xmlns");
            if (sXmlns == null || !sXmlns.equals(SignedDoc.xmlns_xmldsig)) {
                if (m_logger.isDebugEnabled())
                    m_logger.debug("X509IssuerName has none or invalid namespace: " + sXmlns);
                DigiDocException ex = new DigiDocException(DigiDocException.ERR_ISSUER_XMLNS,
                        "X509IssuerName has none or invalid namespace: " + sXmlns, null);
                handleSAXError(ex);
            }
        }
        // <SignatureProductionPlace>
        if (tag.equals("SignatureProductionPlace")) {
            try {
                Signature sig = getLastSignature();
                SignedProperties sp = sig.getSignedProperties();
                SignatureProductionPlace spp = new SignatureProductionPlace();
                sp.setSignatureProductionPlace(spp);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
    }
    // the following is collected anyway independent of collect mode
    // <SignatureValue>
    if (tag.equals("SignatureValue")) {
        String Id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            SignatureValue sv = new SignatureValue(sig, Id);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <OCSPRef>
    if (tag.equals("OCSPRef")) {
        OcspRef orf = new OcspRef();
        Signature sig = getLastSignature();
        UnsignedProperties usp = sig.getUnsignedProperties();
        CompleteRevocationRefs rrefs = usp.getCompleteRevocationRefs();
        rrefs.addOcspRef(orf);
    }
    // <DigestMethod>
    if (tag.equals("DigestMethod")) {
        String Algorithm = attrs.getValue("Algorithm");
        try {
            if (m_tags.search("Reference") != -1) {
                Signature sig = getLastSignature();
                SignedInfo si = sig.getSignedInfo();
                Reference ref = si.getLastReference();
                ref.setDigestAlgorithm(Algorithm);
            } else if (m_tags.search("SigningCertificate") != -1) {
                Signature sig = getLastSignature();
                CertID cid = sig.getOrCreateCertIdOfType(CertID.CERTID_TYPE_SIGNER);
                cid.setDigestAlgorithm(Algorithm);
            } else if (m_tags.search("CompleteCertificateRefs") != -1) {
                Signature sig = getLastSignature();
                CertID cid = sig.getLastCertId(); // initially set to unknown type !
                cid.setDigestAlgorithm(Algorithm);
            } else if (m_tags.search("CompleteRevocationRefs") != -1) {
                Signature sig = getLastSignature();
                UnsignedProperties up = sig.getUnsignedProperties();
                CompleteRevocationRefs rrefs = up.getCompleteRevocationRefs();
                OcspRef orf = rrefs.getLastOcspRef();
                if (orf != null)
                    orf.setDigestAlgorithm(Algorithm);
            } else if (m_tags.search("SigPolicyHash") != -1) {
                Signature sig = getLastSignature();
                SignedProperties sp = sig.getSignedProperties();
                SignaturePolicyIdentifier spi = sp.getSignaturePolicyIdentifier();
                SignaturePolicyId sppi = spi.getSignaturePolicyId();
                sppi.setDigestAlgorithm(Algorithm);
            }
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <Cert>
    if (tag.equals("Cert")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            if (m_tags.search("SigningCertificate") != -1) {
                CertID cid = sig.getOrCreateCertIdOfType(CertID.CERTID_TYPE_SIGNER);
                if (id != null)
                    cid.setId(id);
            }
            if (m_tags.search("CompleteCertificateRefs") != -1) {
                //CertID cid = new CertID();
                CertID cid = sig.getOrCreateCertIdOfType(CertID.CERTID_TYPE_RESPONDER);
                if (id != null)
                    cid.setId(id);
                sig.addCertID(cid);
            }
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <AllDataObjectsTimeStamp>
    if (tag.equals("AllDataObjectsTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_ALL_DATA_OBJECTS);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <IndividualDataObjectsTimeStamp>
    if (tag.equals("IndividualDataObjectsTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_INDIVIDUAL_DATA_OBJECTS);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SignatureTimeStamp>
    if (tag.equals("SignatureTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_SIGNATURE);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SigAndRefsTimeStamp>
    if (tag.equals("SigAndRefsTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_SIG_AND_REFS);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <RefsOnlyTimeStamp>
    if (tag.equals("RefsOnlyTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_REFS_ONLY);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <ArchiveTimeStamp>
    if (tag.equals("ArchiveTimeStamp")) {
        String id = attrs.getValue("Id");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = new TimestampInfo(id, TimestampInfo.TIMESTAMP_TYPE_ARCHIVE);
            sig.addTimestampInfo(ts);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <Include>
    if (tag.equals("Include")) {
        String uri = attrs.getValue("URI");
        try {
            Signature sig = getLastSignature();
            TimestampInfo ts = sig.getLastTimestampInfo();
            IncludeInfo inc = new IncludeInfo(uri);
            ts.addIncludeInfo(inc);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <CompleteCertificateRefs>
    if (tag.equals("CompleteCertificateRefs")) {
        String Target = attrs.getValue("Target");
        try {
            Signature sig = getLastSignature();
            UnsignedProperties up = sig.getUnsignedProperties();
            CompleteCertificateRefs crefs = new CompleteCertificateRefs();
            up.setCompleteCertificateRefs(crefs);
            crefs.setUnsignedProperties(up);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <CompleteRevocationRefs>
    if (tag.equals("CompleteRevocationRefs")) {
        try {
            Signature sig = getLastSignature();
            UnsignedProperties up = sig.getUnsignedProperties();
            CompleteRevocationRefs rrefs = new CompleteRevocationRefs();
            up.setCompleteRevocationRefs(rrefs);
            rrefs.setUnsignedProperties(up);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <OCSPIdentifier>
    if (tag.equals("OCSPIdentifier")) {
        String URI = attrs.getValue("URI");
        try {
            Signature sig = getLastSignature();
            UnsignedProperties up = sig.getUnsignedProperties();
            CompleteRevocationRefs rrefs = up.getCompleteRevocationRefs();
            OcspRef orf = rrefs.getLastOcspRef();
            orf.setUri(URI);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SignaturePolicyIdentifier>
    if (tag.equals("SignaturePolicyIdentifier")) {
        try {
            Signature sig = getLastSignature();
            SignedProperties sp = sig.getSignedProperties();
            SignaturePolicyIdentifier spid = sp.getSignaturePolicyIdentifier();
            if (spid == null) {
                spid = new SignaturePolicyIdentifier(null);
                sp.setSignaturePolicyIdentifier(spid);
            }
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SignaturePolicyId>
    if (tag.equals("SignaturePolicyId")) {
        try {
            Signature sig = getLastSignature();
            SignedProperties sp = sig.getSignedProperties();
            SignaturePolicyIdentifier spid = sp.getSignaturePolicyIdentifier();
            if (spid == null) {
                spid = new SignaturePolicyIdentifier(null);
                sp.setSignaturePolicyIdentifier(spid);
            }
            SignaturePolicyId spi = spid.getSignaturePolicyId();
            if (spi == null) {
                spi = new SignaturePolicyId(null);
                spid.setSignaturePolicyId(spi);
            }
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SigPolicyId>
    // cannot handle alone because we need mandatory Identifier value
    // <Identifier>
    if (tag.equals("Identifier")) {
        try {
            Signature sig = getLastSignature();
            SignedProperties sp = sig.getSignedProperties();
            SignaturePolicyIdentifier spid = sp.getSignaturePolicyIdentifier();
            if (spid == null) {
                spid = new SignaturePolicyIdentifier(null);
                sp.setSignaturePolicyIdentifier(spid);
            }
            SignaturePolicyId spi = spid.getSignaturePolicyId();
            if (spi == null) {
                spi = new SignaturePolicyId(null);
                spid.setSignaturePolicyId(spi);
            }
            String sQualifier = attrs.getValue("Qualifier");
            Identifier id = new Identifier(sQualifier);
            ObjectIdentifier oi = spi.getSigPolicyId();
            if (oi == null)
                oi = new ObjectIdentifier(id);
            else
                oi.setIdentifier(id);
            spi.setSigPolicyId(oi);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <SigPolicyQualifier>
    if (tag.equals("SigPolicyQualifier")) {
        try {
            Signature sig = getLastSignature();
            SignedProperties sp = sig.getSignedProperties();
            SignaturePolicyIdentifier spid = sp.getSignaturePolicyIdentifier();
            if (spid == null) {
                spid = new SignaturePolicyIdentifier(null);
                sp.setSignaturePolicyIdentifier(spid);
            }
            SignaturePolicyId spi = spid.getSignaturePolicyId();
            if (spi == null) {
                spi = new SignaturePolicyId(null);
                spid.setSignaturePolicyId(spi);
            }
            SigPolicyQualifier spq = new SigPolicyQualifier();
            spi.addSigPolicyQualifier(spq);
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }

    // <DataObjectFormat>
    if (tag.equals("DataObjectFormat")) {
        Signature sig = getLastSignature();
        try {
            if (sig != null) {
                SignedProperties sp = sig.getSignedProperties();
                if (sp != null) {
                    SignedDataObjectProperties sdps = sp.getSignedDataObjectProperties();
                    if (sdps == null) {
                        sdps = new SignedDataObjectProperties();
                        sp.setSignedDataObjectProperties(sdps);
                    }
                    String sObjectReference = attrs.getValue("ObjectReference");
                    DataObjectFormat dof = new DataObjectFormat(sObjectReference);
                    sdps.addDataObjectFormat(dof);
                }
            }
        } catch (DigiDocException ex) {
            handleSAXError(ex);
        }
    }
    // <NonceAlgorithm> - give error?
    if (tag.equals("NonceAlgorithm")) {

    }
    // the following stuff is ignored in collect mode
    // because it can only be the content of a higher element
    if (m_nCollectMode == 0) {
        // <SignedDoc>
        if (tag.equals("SignedDoc")) {
            String format = null, version = null;
            for (int i = 0; i < attrs.getLength(); i++) {
                String key = attrs.getQName(i);
                if (key.equals("format"))
                    format = attrs.getValue(i);
                if (key.equals("version"))
                    version = attrs.getValue(i);
            }
            try {
                m_doc = new SignedDoc();
                m_doc.setFormat(format);
                m_doc.setVersion(version);
                if (format != null && (format.equals(SignedDoc.FORMAT_SK_XML)
                        || format.equals(SignedDoc.FORMAT_DIGIDOC_XML))) {
                    m_doc.setProfile(SignedDoc.BDOC_PROFILE_TM); // in ddoc format we used only TM
                }
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <Signature>
        /*if(qName.equals("Signature")) {
           String Id = attrs.getValue("Id");
           try {
              Signature sig = new Signature(m_doc);
              if(Id != null)
          sig.setId(Id);
              m_doc.addSignature(sig);
           } catch (DigiDocException ex) {
              handleSAXError(ex);
           }
        }*/
        // <KeyInfo>
        if (tag.equals("KeyInfo")) {
            try {
                KeyInfo ki = new KeyInfo();
                String Id = attrs.getValue("Id");
                if (Id != null)
                    ki.setId(Id);
                Signature sig = getLastSignature();
                sig.setKeyInfo(ki);
                ki.setSignature(sig);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <UnsignedProperties>
        if (tag.equals("UnsignedProperties")) {
            String Target = attrs.getValue("Target");
            try {
                Signature sig = getLastSignature();
                UnsignedProperties up = new UnsignedProperties(sig);
                sig.setUnsignedProperties(up);
            } catch (DigiDocException ex) {
                handleSAXError(ex);
            }
        }
        // <EncapsulatedOCSPValue>
        if (tag.equals("EncapsulatedOCSPValue")) {
            String Id = attrs.getValue("Id");
            Signature sig = getLastSignature();
            UnsignedProperties up = sig.getUnsignedProperties();
            Notary not = new Notary();
            if (Id != null)
                not.setId(Id);
            not.setId(Id);
            up.addNotary(not);
            if (sig.getProfile() == null && (m_doc.getFormat().equals(SignedDoc.FORMAT_DIGIDOC_XML)
                    || m_doc.getFormat().equals(SignedDoc.FORMAT_SK_XML)))
                sig.setProfile(SignedDoc.BDOC_PROFILE_TM);
        }
    } // if(m_nCollectMode == 0)
}