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:org.jahia.services.importexport.DocumentViewImportHandler.java

private void setAttributes(JCRNodeWrapper child, Attributes atts) throws RepositoryException {
    String lang = null;/*from   w  ww  .j  a v  a  2 s .  c o  m*/
    if (child.getPrimaryNodeTypeName().equals(Constants.JAHIANT_TRANSLATION)) {
        lang = atts.getValue(Constants.JCR_LANGUAGE);
        child.setProperty(Constants.JCR_LANGUAGE, lang);
    }

    for (int i = 0; i < atts.getLength(); i++) {
        if (atts.getURI(i).equals("http://www.w3.org/2000/xmlns/")) {
            continue;
        }

        String attrName = ISO9075.decode(atts.getQName(i));
        String attrValue = atts.getValue(i);

        boolean processed = false;
        for (AttributeProcessor processor : attributeProcessors) {
            if (processor.process(child, attrName, attrValue)) {
                processed = true;
                break;
            }
        }
        if (processed) {
            continue;
        }

        for (String placeHolder : placeHoldersMap.keySet()) {
            if (attrValue.contains(placeHolder)) {
                attrValue = attrValue.replace(placeHolder, placeHoldersMap.get(placeHolder));
            }
        }

        if (propertiesToSkip.contains(attrName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Skipping property {}", attrName);
            }
        } else {
            for (Map.Entry<Pattern, String> entry : replacements.entrySet()) {
                attrValue = entry.getKey().matcher(attrValue).replaceAll(entry.getValue());
            }

            if (attrName.equals("j:privileges") && child.isNodeType("jnt:ace")) {
                attrName = "j:roles";
                attrValue = mapAclAttributes(child, attrValue);
                if (StringUtils.isEmpty(attrValue)) {
                    // Value is mandatory, set a fake role to allow import to continue
                    attrValue = "dummy-role";
                }
            }

            if ((attrName.equals(Constants.JCR_TITLE) || attrName.equals("jcr:description"))
                    && !child.isNodeType(Constants.MIX_TITLE)) {
                child.addMixin(Constants.MIX_TITLE);
            } else if (attrName.equals("j:defaultCategory")
                    && !child.isNodeType(Constants.JAHIAMIX_CATEGORIZED)) {
                child.addMixin(Constants.JAHIAMIX_CATEGORIZED);
            }
            ExtendedPropertyDefinition propDef;
            propDef = child.getApplicablePropertyDefinition(attrName);
            if (propDef == null) {
                logger.error("Couldn't find definition for property " + attrName + " in "
                        + child.getPrimaryNodeTypeName() + getLocation());
                continue;
            }

            if (propDef.getRequiredType() == PropertyType.UNDEFINED) {
                // avoid illegal type 0
                //...getValueFactory().createValue(value, 0) throw a illegal type 0 exception
                logger.error("Couldn't resolve property type for property " + attrName + " in "
                        + child.getPrimaryNodeTypeName() + getLocation());
                continue;
            }

            if (propDef.getRequiredType() == PropertyType.REFERENCE
                    || propDef.getRequiredType() == ExtendedPropertyType.WEAKREFERENCE) {
                if (attrValue.length() > 0) {
                    String[] values = propDef.isMultiple() ? Patterns.SPACE.split(attrValue)
                            : new String[] { attrValue };
                    for (String value : values) {
                        value = JCRMultipleValueUtils.decode(value);
                        if (!StringUtils.isEmpty(value)) {
                            value = getReferenceValue(value);
                            if (attrName.equals("j:defaultCategory") && value.startsWith("/root")) {
                                // Map categories from legacy imports
                                value = JCRContentUtils.getSystemSitePath() + "/categories"
                                        + StringUtils.substringAfter(value, "/root");
                            }
                            if (!references.containsKey(value)) {
                                references.put(value, new ArrayList<String>());
                            }
                            references.get(value).add(child.getIdentifier() + "/" + attrName);
                        }
                    }
                }
            } else {
                if (propDef.isMultiple()) {
                    String[] s = "".equals(attrValue) ? new String[0] : Patterns.SPACE.split(attrValue);
                    List<Value> oldvalues = new ArrayList<Value>();

                    if (child.getRealNode().hasProperty(attrName)) {
                        Value[] oldValues = child.getRealNode().getProperty(attrName).getValues();
                        for (Value oldValue : oldValues) {
                            oldvalues.add(oldValue);
                        }
                    }

                    if (replaceMultipleValues) {
                        List<Value> values = new ArrayList<Value>();
                        for (int j = 0; j < s.length; j++) {
                            values.add(child.getRealNode().getSession().getValueFactory().createValue(
                                    JCRMultipleValueUtils.decode(s[j]), propDef.getRequiredType()));
                        }
                        if (!values.equals(oldvalues)) {
                            child.getRealNode().setProperty(attrName, values.toArray(new Value[values.size()]));
                        }
                    } else {
                        List<Value> values = new ArrayList<Value>(oldvalues);
                        for (int j = 0; j < s.length; j++) {
                            final Value value = child.getRealNode().getSession().getValueFactory()
                                    .createValue(JCRMultipleValueUtils.decode(s[j]), propDef.getRequiredType());
                            if (!oldvalues.contains(value)) {
                                values.add(value);
                            }
                        }
                        try {
                            if (!values.equals(oldvalues)) {
                                child.getRealNode().setProperty(attrName,
                                        values.toArray(new Value[values.size()]));
                            }
                        } catch (RepositoryException e) {
                            logger.error(e.getMessage(), e); //To change body of catch statement use File | Settings | File Templates.
                        }
                    }
                } else {
                    if (!child.getRealNode().hasProperty(attrName)
                            || !child.getRealNode().getProperty(attrName).getString().equals(attrValue)) {
                        child.getRealNode().setProperty(attrName, attrValue, propDef.getRequiredType());
                    }
                }
            }
        }
    }
}

From source file:org.jahia.services.importexport.FilesAclImportHandler.java

public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    if ("file".equals(localName) && ImportExportBaseService.JAHIA_URI.equals(uri)) {
        String path = attributes.getValue(ImportExportBaseService.JAHIA_URI, "path");
        String acl = attributes.getValue(ImportExportBaseService.JAHIA_URI, "fileacl");

        InputStream content = null;

        try {//w  w w  .  j  a  v a2s . c o  m
            boolean contentFound = false;
            if (this.filePath != null) {
                content = findExtractedContent(path);
            } else {
                contentFound = findContent(path);
            }

            if (path.startsWith("/shared") || path.startsWith("/users")) {
                path = "/sites/" + site.getSiteKey() + "/files" + path;
            } /*
              // DB-HOT-28
              else if (path.startsWith("/users/")) {
              Matcher m = Pattern.compile("/users/([^/]+)(/.*)?").matcher(path);
              if (m.matches()) {
                  path = ServicesRegistry.getInstance().getJahiaUserManagerService().getUserSplittingRule().getPathForUsername(m.group(1));
                  path = path + "/files" + ((m.group(2) != null) ? m.group(2) : "");
              }
              }*/

            if (session.itemExists(path)) {
                return;
            }
            JCRNodeWrapper f;
            path = JCRContentUtils.escapeNodePath(path);
            path = Patterns.COLON.matcher(path).replaceAll("_");

            String parentPath = StringUtils.substringBeforeLast(path, "/");
            try {
                f = session.getNode(parentPath);
            } catch (PathNotFoundException e) {
                f = ImportExportBaseService.getInstance().ensureDir(session, parentPath, site);
            }

            Calendar created = new GregorianCalendar();
            String creationDate = attributes.getValue("dav:creationdate");
            if (creationDate != null) {
                if (creationDate.endsWith("Z")) {
                    created.setTime(DATE_FORMAT_Z.parseDateTime(creationDate).toDate());
                } else {
                    created.setTime(DATE_FORMAT.parseDateTime(creationDate).toDate());
                }
            }
            Calendar lastModified = new GregorianCalendar();
            String modificationDate = attributes.getValue("dav:modificationdate");
            if (modificationDate != null) {
                if (modificationDate.endsWith("Z")) {
                    lastModified.setTime(DATE_FORMAT_Z.parseDateTime(modificationDate).toDate());
                } else {
                    lastModified.setTime(DATE_FORMAT.parseDateTime(modificationDate).toDate());
                }
            }
            String createdBy = attributes.getValue("dav:creationuser");
            String lastModifiedBy = attributes.getValue("dav:modificationuser");
            final String itemType = "file".equals(attributes.getValue("jahia:itemType"))
                    || StringUtils.isNotBlank(attributes.getValue("dav:getcontenttype")) ? "file" : "folder";
            final boolean binaryAvailable = content != null && !contentFound;
            final boolean isCorruptedFile = !binaryAvailable && "file".equals(itemType);

            if (isCorruptedFile) {
                logger.error(MessageFormat.format("Impossible to import the file {0} as its binary is missing",
                        path));
                corruptedFilesLogger.error(path);
            } else {
                checkoutNode(f);
                if (!binaryAvailable) {
                    f = f.addNode(StringUtils.substringAfterLast(path, "/"), "jnt:folder", null, created,
                            createdBy, lastModified, lastModifiedBy);
                } else {
                    f = f.addNode(StringUtils.substringAfterLast(path, "/"), "jnt:file", null, created,
                            createdBy, lastModified, lastModifiedBy);
                    String contentType = attributes.getValue("dav:getcontenttype");
                    if (content != null) {
                        if (contentType == null || contentType.length() == 0
                                || "application/binary".equals(contentType)) {
                            if (logger.isDebugEnabled()) {
                                logger.debug(
                                        "We don't have a proper content type for file content {}, let's force its detection",
                                        f.getPath());
                            }
                            // We don't have a proper content type, let's force its detection
                            contentType = null;
                        }
                        f.getFileContent().uploadFile(content, contentType);
                    } else {
                        f.getFileContent().uploadFile(zis, contentType);
                    }
                }
                if (acl != null && acl.length() > 0) {
                    StringTokenizer st = new StringTokenizer(acl, "|");
                    while (st.hasMoreElements()) {
                        String s = st.nextToken();
                        int beginIndex = s.lastIndexOf(":");

                        String principal = s.substring(0, beginIndex);

                        Set<String> grantedRoles = new HashSet<String>();
                        Set<String> removedRoles = new HashSet<String>();
                        String perm = s.substring(beginIndex + 1);
                        if (perm.charAt(0) == 'r') {
                            if (CollectionUtils.isEmpty(LegacyImportHandler.CUSTOM_FILES_READ_ROLES)) {
                                grantedRoles.addAll(LegacyImportHandler.READ_ROLES);
                            } else {
                                grantedRoles.addAll(LegacyImportHandler.CUSTOM_FILES_READ_ROLES);
                            }
                        } else {
                            if (CollectionUtils.isEmpty(LegacyImportHandler.CUSTOM_FILES_READ_ROLES)) {
                                removedRoles.addAll(LegacyImportHandler.READ_ROLES);
                            } else {
                                removedRoles.addAll(LegacyImportHandler.CUSTOM_FILES_READ_ROLES);
                            }
                        }
                        if (perm.charAt(1) == 'w') {
                            if (CollectionUtils.isEmpty(LegacyImportHandler.CUSTOM_FILES_WRITE_ROLES)) {
                                grantedRoles.addAll(LegacyImportHandler.WRITE_ROLES);
                            } else {
                                grantedRoles.addAll(LegacyImportHandler.CUSTOM_FILES_WRITE_ROLES);
                            }
                        } else {
                            if (CollectionUtils.isEmpty(LegacyImportHandler.CUSTOM_FILES_WRITE_ROLES)) {
                                removedRoles.addAll(LegacyImportHandler.WRITE_ROLES);
                            } else {
                                removedRoles.addAll(LegacyImportHandler.CUSTOM_FILES_WRITE_ROLES);
                            }
                        }

                        if (!grantedRoles.isEmpty()) {
                            f.grantRoles(principal, grantedRoles);
                        }
                        if (!removedRoles.isEmpty()) {
                            f.denyRoles(principal, removedRoles);
                        }
                    }
                }
                for (int i = 0; i < attributes.getLength(); i++) {
                    String attUri = attributes.getURI(i);
                    String attName = attributes.getLocalName(i);
                    if (!ImportExportBaseService.JAHIA_URI.equals(attUri) || (!"path".equals(attName)
                            && !"fileacl".equals(attName) && !"lastModification".equals(attName))) {
                        try {
                            setPropertyField(f.getPrimaryNodeType(), localName, f,
                                    getMappedProperty(f.getPrimaryNodeType(), attributes.getQName(i)),
                                    attributes.getValue(i));
                        } catch (RepositoryException e) {
                            logger.warn("Error importing " + localName + " " + path, e);
                        }
                    }
                }
                session.save(JCRObservationManager.IMPORT);
            }
        } catch (Exception e) {
            logger.error("error", e);
        } finally {
            IOUtils.closeQuietly(content);
        }
    }
}

From source file:org.jahia.services.importexport.LegacyImportHandler.java

private Map<String, String> convertToProperties(Attributes attributes) {
    Map<String, String> properties = new HashMap<String, String>();
    int l = attributes.getLength();
    for (int i = 0; i < l; i++) {
        properties.put(attributes.getQName(i), attributes.getValue(i));
    }/*  w w  w . j  a va 2s . co  m*/
    return properties;
}

From source file:org.jahia.services.importexport.LegacyImportHandler.java

private void setMetadata(Attributes attributes) throws RepositoryException {
    int l = attributes.getLength();
    for (int i = 0; i < l; i++) {
        String name = attributes.getQName(i);
        setPropertyField(null, name, attributes.getValue(i), getMetadataForNodeCreation(attributes));
    }//from  w w  w  .  ja v a 2s  .co  m
}

From source file:org.jahia.services.importexport.XMLWriter.java

/**
 * Write out an attribute list, escaping values.
 *
 * The names will have prefixes added to them.
 *
 * @param atts The attribute list to write.
 * @exception SAXException If there is an error writing
 *            the attribute list, this method will throw an
 *            IOException wrapped in a SAXException.
 *//*from   ww w . j  av a2  s. c o m*/
private void writeAttributes(Attributes atts) throws SAXException {
    int len = atts.getLength();
    for (int i = 0; i < len; i++) {
        char ch[] = atts.getValue(i).toCharArray();
        write(' ');
        writeName(atts.getURI(i), atts.getLocalName(i), atts.getQName(i), false);
        write("=\"");
        writeEsc(ch, 0, ch.length, true);
        write('"');
    }
}

From source file:org.jajuk.base.Collection.java

/**
 * Called when we start an element intern() method use policy : we use this
 * method when adding a new string into JVM that will probably be referenced
 * by several objects like the Genre ID that is referenced by many tracks. In
 * this case, all the String objects share the same char[]. On another hand,
 * it musn't be used for strings that have low probability to be used several
 * times (like raw names) as it uses a lot of CPU (equals() is called) and we
 * want startup to be as fast as possible. Note that the use of intern() save
 * around 1/4 of overall heap memory/*from w  w w. j a  v  a 2s  .  c  o  m*/
 *
 * We use sax-interning for the main items sections (<styles> for ie). For all
 * raw items, we don't perform equals on item name but we compare the string
 * hashcode
 *
 * @param sUri 
 * @param s 
 * @param sQName 
 * @param attributes 
 *
 * @throws SAXException the SAX exception
 */
@Override
public void startElement(String sUri, String s, String sQName, Attributes attributes) throws SAXException {
    try {
        int idIndex = attributes.getIndex(Const.XML_ID);
        // [PERF] Manage top tags to set current stage. Manages 'properties'
        // tags as well
        if (idIndex == -1) {
            // Note that we compare string with '==' for performance reasons and it is safe here.
            if (Const.XML_DEVICES == sQName) { //NOSONAR
                manager = DeviceManager.getInstance();
                stage = Stage.STAGE_DEVICES;
                needCheckID = true;
            } else if (Const.XML_ALBUMS == sQName) {//NOSONAR
                manager = AlbumManager.getInstance();
                stage = Stage.STAGE_ALBUMS;
                needCheckID = true;
            } else if (Const.XML_ARTISTS == sQName) {//NOSONAR
                manager = ArtistManager.getInstance();
                stage = Stage.STAGE_ARTISTS;
                needCheckID = true;
            } else if (Const.XML_ALBUM_ARTISTS == sQName) {//NOSONAR
                manager = AlbumArtistManager.getInstance();
                stage = Stage.STAGE_ALBUM_ARTIST;
                needCheckID = true;
            } else if (Const.XML_DIRECTORIES == sQName) {//NOSONAR
                manager = DirectoryManager.getInstance();
                stage = Stage.STAGE_DIRECTORIES;
                needCheckID = true;
            } else if (Const.XML_FILES == sQName) {//NOSONAR
                manager = FileManager.getInstance();
                stage = Stage.STAGE_FILES;
                needCheckID = true;
            } else if (Const.XML_PLAYLISTS == sQName) {//NOSONAR
                // This code is here for Jajuk < 1.6 compatibility
                manager = PlaylistManager.getInstance();
                stage = Stage.STAGE_PLAYLISTS;
                needCheckID = true;
            } else if (Const.XML_PLAYLIST_FILES == sQName) {//NOSONAR
                manager = PlaylistManager.getInstance();
                stage = Stage.STAGE_PLAYLIST_FILES;
                needCheckID = true;
            } else if (Const.XML_GENRES == sQName) {//NOSONAR
                manager = GenreManager.getInstance();
                stage = Stage.STAGE_GENRES;
                needCheckID = true;
            } else if (Const.XML_TRACKS == sQName) {//NOSONAR
                manager = TrackManager.getInstance();
                stage = Stage.STAGE_TRACKS;
                needCheckID = true;
            } else if (Const.XML_YEARS == sQName) {//NOSONAR
                manager = YearManager.getInstance();
                stage = Stage.STAGE_YEARS;
                needCheckID = true;
            } else if (Const.XML_TYPES == sQName) {//NOSONAR
                // This is here for pre-1.7 collections, after we don't commit types
                // anymore (they are set programmatically)
                manager = TypeManager.getInstance();
                stage = Stage.STAGE_TYPES;
                needCheckID = false;
            } else if (Const.XML_PROPERTY == sQName) {//NOSONAR
                // A property description
                boolean bCustom = Boolean
                        .parseBoolean(attributes.getValue(attributes.getIndex(Const.XML_CUSTOM)));
                boolean bConstructor = Boolean
                        .parseBoolean(attributes.getValue(attributes.getIndex(Const.XML_CONSTRUCTOR)));
                boolean bShouldBeDisplayed = Boolean
                        .parseBoolean(attributes.getValue(attributes.getIndex(Const.XML_VISIBLE)));
                boolean bEditable = Boolean
                        .parseBoolean(attributes.getValue(attributes.getIndex(Const.XML_EDITABLE)));
                boolean bUnique = Boolean
                        .parseBoolean(attributes.getValue(attributes.getIndex(Const.XML_UNIQUE)));
                Class<?> cType = Class.forName(attributes.getValue(Const.XML_TYPE));
                String sDefaultValue = attributes.getValue(Const.XML_DEFAULT_VALUE).intern();
                Object oDefaultValue = null;
                if (sDefaultValue != null && sDefaultValue.length() > 0) {
                    try {
                        // Date format has changed from 1.3 (only yyyyMMdd
                        // addition format is used)
                        // so an exception will be thrown when upgrading
                        // from 1.2
                        // we reset default value to "today"
                        oDefaultValue = UtilString.parse(sDefaultValue, cType);
                    } catch (ParseException e) {
                        oDefaultValue = new Date();
                    }
                }
                String sPropertyName = attributes.getValue(Const.XML_NAME).intern();
                if (manager.getMetaInformation(sPropertyName) == null) {
                    PropertyMetaInformation meta = new PropertyMetaInformation(sPropertyName, bCustom,
                            bConstructor, bShouldBeDisplayed, bEditable, bUnique, cType, oDefaultValue);
                    // standard properties are already loaded
                    manager.registerProperty(meta);
                }
            }
            if (Const.XML_PROPERTY == sQName) {//NOSONAR
                Log.debug("Found property: " + attributes.getValue(Const.XML_NAME));
            } else {
                Log.debug("Starting stage: '" + stage + "' with property: '" + sQName + "' manager: "
                        + (manager != null ? manager.getXMLTag() : "<null>"));
            }
        } else {
            // Manage elements themselves using a switch for performances
            switch (stage) {
            case STAGE_FILES:
                handleFiles(attributes, idIndex);
                break;
            case STAGE_DIRECTORIES:
                handleDirectories(attributes, idIndex);
                break;
            case STAGE_TRACKS:
                handleTracks(attributes, idIndex);
                break;
            case STAGE_ALBUMS:
                handleAlbums(attributes, idIndex);
                break;
            case STAGE_ARTISTS:
                handleArtists(attributes, idIndex);
                break;
            case STAGE_ALBUM_ARTIST:
                handleAlbumArtists(attributes, idIndex);
                break;
            case STAGE_GENRES:
                handleGenres(attributes, idIndex);
                break;
            case STAGE_PLAYLIST_FILES:
                handlePlaylistFiles(attributes, idIndex);
                break;
            case STAGE_DEVICES:
                handleDevices(attributes, idIndex);
                break;
            case STAGE_YEARS:
                handleYears(attributes, idIndex);
                break;
            case STAGE_TYPES:
                Log.warn("Unexpected Stage: STAGE_TYPES");
                break;
            default:
                Log.warn("Unexpected Stage: " + stage);
            }
        }
    } catch (Throwable e) {//NOSONAR
        // Make sure to catch every issue here (including runtime exceptions) so we make sure to start
        // jajuk
        StringBuilder sAttributes = new StringBuilder();
        for (int i = 0; i < attributes.getLength(); i++) {
            sAttributes.append('\n').append(attributes.getQName(i)).append('=').append(attributes.getValue(i));
        }
        Log.error(5, sAttributes.toString(), e);
    }
}

From source file:org.jajuk.base.Device.java

/**
 * Set all personal properties of an XML file for an item (doesn't overwrite
 * existing properties for perfs).//  w  ww . jav  a 2s  .c  o m
 * 
 * @param attributes :
 * list of attributes for this XML item
 */
@Override
public void populateProperties(final Attributes attributes) {
    for (int i = 0; i < attributes.getLength(); i++) {
        final String sProperty = attributes.getQName(i);
        if (!getProperties().containsKey(sProperty)) {
            String sValue = attributes.getValue(i);
            final PropertyMetaInformation meta = getMeta(sProperty);
            // compatibility code for <1.1 : auto-refresh is now a double,
            // no more a boolean
            if (meta.getName().equals(Const.XML_DEVICE_AUTO_REFRESH)
                    && (sValue.equalsIgnoreCase(Const.TRUE) || sValue.equalsIgnoreCase(Const.FALSE))) {
                if (getType() == Type.DIRECTORY) {
                    sValue = "0.5d";
                }
                if (getType() == Type.FILES_CD) {
                    sValue = "0d";
                }
                if (getType() == Type.NETWORK_DRIVE) {
                    sValue = "0d";
                }
                if (getType() == Type.EXTDD) {
                    sValue = "3d";
                }
                if (getType() == Type.PLAYER) {
                    sValue = "3d";
                }
            }
            try {
                setProperty(sProperty, UtilString.parse(sValue, meta.getType()));
            } catch (final Exception e) {
                Log.error(137, sProperty, e);
            }
        }
    }
}

From source file:org.jamwiki.migrate.MediaWikiXmlImporter.java

/**
 * start of xml-tag/*from   w  w w .  j  av  a2  s .c  o  m*/
 *
 * @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 attrs The attributes attached to the element. If there are no attributes, it shall be an
 *  empty Attributes object.
 */
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    this.currentElementBuffer = new StringBuilder();
    this.currentAttributeMap = new HashMap<String, String>();
    String key;
    if (attrs != null) {
        // populate the attribute map
        for (int i = 0; i < attrs.getLength(); i++) {
            key = attrs.getQName(i);
            if (!StringUtils.isBlank(key)) {
                this.currentAttributeMap.put(key, attrs.getValue(i));
            }
        }
    }
    if (MediaWikiConstants.MEDIAWIKI_ELEMENT_TOPIC_VERSION.equals(qName)) {
        this.currentTopicVersion = new TopicVersion();
        this.currentTopicVersion.setEditType(TopicVersion.EDIT_IMPORT);
    } else if (MediaWikiConstants.MEDIAWIKI_ELEMENT_TOPIC.equals(qName)) {
        this.currentTopicVersions = new TreeMap<Date, Integer>();
    }
}

From source file:org.jamwiki.utils.XMLTopicFactory.java

/**
 * start of xml-tag//from   ww w. j a  v a 2  s.c  o m
 *
 * @param lName Local name.
 * @param qName Qualified name.
 */
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs)
        throws SAXException {
    indentLevel++;
    nl();
    emit("ELEMENT: ");
    String eName = lName;
    if ("".equals(eName)) {
        eName = qName;
    }
    emit("<" + eName);
    lastStr = new StringBuffer();
    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            String aName = attrs.getLocalName(i); // Attr name
            if ("".equals(aName)) {
                aName = attrs.getQName(i);
            }
            nl();
            emit("   ATTR: ");
            emit(aName);
            emit("\t\"");
            emit(attrs.getValue(i));
            emit("\"");
        }
    }
    if (attrs.getLength() > 0) {
        nl();
    }
    emit(">");
    if ("namespace".equals(eName)) { // mapping of namespaces from imported file
        nsKey = new Integer(attrs.getValue("key"));
    }
    if ("page".equals(eName)) {
        pageName = "";
        pageText = "";
    }
}

From source file:org.jboss.windup.util.xml.LocationAwareContentHandler.java

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attrs)
        throws SAXException {
    Element e = null;//from  ww  w.  j a v  a2s. c o m
    if (localName != null && !"".equals(localName)) {
        e = doc.createElementNS(uri, localName);
    } else {
        e = doc.createElement(qName);
    }

    storeLineInformation(e);
    if (StringUtils.isNotBlank(uri)) {
        namespaceURIs.add(uri);
    }

    if (doc.getUserData(NAMESPACE_KEY_NAME) == null) {
        doc.setUserData(NAMESPACE_KEY_NAME, namespaceURIs, null);
    }

    if (current == null) {
        doc.appendChild(e);
    } else {
        current.appendChild(e);
    }
    current = e;

    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            Attr attr = null;
            if (attrs.getLocalName(i) != null && !"".equals(attrs.getLocalName(i))) {
                attr = doc.createAttributeNS(attrs.getURI(i), attrs.getLocalName(i));
                attr.setValue(attrs.getValue(i));
                storeLineInformation(attr);
                current.setAttributeNodeNS(attr);
            } else {
                attr = doc.createAttribute(attrs.getQName(i));
                attr.setValue(attrs.getValue(i));
                storeLineInformation(attr);
                current.setAttributeNode(attr);
            }
        }
    }
}