@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (qName != null && qName.length() > 0) localName = qName; level++; L.d(tab() + "<" + localName + ">"); currentAttributes = attributes; elements.push(localName); // String currentElement = elements.peek(); if (!insideFeed && "feed".equals(localName)) { insideFeed = true; } else if ("entry".equals(localName)) { if (!insideFeed) { insideFeed = true; singleEntry = true; } insideEntry = true; entryInfo = new EntryInfo(); } else if ("category".equals(localName)) { if (insideEntry) { String category = attributes.getValue("label"); if (category != null) entryInfo.categories.add(category); } } else if ("id".equals(localName)) { } else if ("updated".equals(localName)) { } else if ("title".equals(localName)) { } else if ("link".equals(localName)) { LinkInfo link = new LinkInfo(url, attributes); if (link.isValid() && insideFeed) { L.d(tab() + link.toString()); if (insideEntry) { if (link.type != null) { entryInfo.links.add(link); int priority = link.getPriority(); if (link.type.startsWith("application/atom+xml")) { entryInfo.link = link; } else if (priority > 0 && (entryInfo.link == null || entryInfo.link.getPriority() < priority)) { entryInfo.link = link; } } } else { if ("self".equals(link.rel)) docInfo.selfLink = link; else if ("alternate".equals(link.rel)) docInfo.alternateLink = link; } } } else if ("author".equals(localName)) { authorInfo = new AuthorInfo(); } }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if (qName != null && qName.length() > 0) localName = qName; L.d(tab() + "</" + localName + ">"); // String currentElement = elements.peek(); if (insideFeed && "feed".equals(localName)) { insideFeed = false; } else if ("entry".equals(localName)) { if (!insideFeed || !insideEntry) throw new SAXException("unexpected element " + localName); if (entryInfo.link != null || entryInfo.getBestAcquisitionLink() != null) { entries.add(entryInfo); } insideEntry = false; entryInfo = null; } else if ("author".equals(localName)) { if (authorInfo != null && authorInfo.name != null) entryInfo.authors.add(authorInfo); authorInfo = null; } currentAttributes = null; if (level > 0) level--; }
@Override public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); String s = new String(ch, start, length); s = s.trim(); if (s.length() == 0 || (s.length() == 1 && s.charAt(0) == '\n')) return; // ignore empty line L.d(tab() + " {" + s + "}"); String currentElement = elements.peek(); if (currentElement == null) return; if (insideFeed) { if ("id".equals(currentElement)) { if (insideEntry) entryInfo.id = s; else docInfo.id = s; } else if ("updated".equals(currentElement)) { long ts = parseTimestamp(s); if (insideEntry) entryInfo.updated = ts; else docInfo.updated = ts; } else if ("title".equals(currentElement)) { if (!insideEntry) docInfo.title = s; else entryInfo.title = entryInfo.title + s; } else if ("summary".equals(currentElement)) { if (insideEntry) entryInfo.summary = entryInfo.summary + s; } else if ("name".equals(currentElement)) { if (authorInfo != null) authorInfo.name = s; } else if ("uri".equals(currentElement)) { if (authorInfo != null) authorInfo.uri = s; } else if ("icon".equals(currentElement)) { if (!insideEntry) docInfo.icon = s; else entryInfo.icon = s; } else if ("link".equals(currentElement)) { // rel, type, title, href if (!insideEntry) docInfo.icon = s; else entryInfo.icon = s; } else if ("content".equals(currentElement)) { if (insideEntry) entryInfo.content = entryInfo.content + s; } else if ("subtitle".equals(currentElement)) { if (!insideEntry) docInfo.subtitle = s; } } }
/** This reader collects stats about the log entry. */ @Override protected boolean processEntry(ByteBuffer entryBuffer) { byte currentType = currentEntryHeader.getType(); int itemSize = currentEntryHeader.getItemSize(); int headerSize = currentEntryHeader.getSize(); /* * Record various stats based on the entry header, then move the buffer * forward to skip ahead. */ LogEntryType lastEntryType = LogEntryType.findType(currentType); int nextEntryPosition = entryBuffer.position() + itemSize; /* * Get the info object for it, if this is the first time it's seen, * create an info object and insert it. */ EntryInfo info = entryInfoMap.get(lastEntryType); if (info == null) { info = new EntryInfo(); entryInfoMap.put(lastEntryType, info); } /* Update counts. */ info.count++; totalCount++; if (currentEntryHeader.getProvisional() == Provisional.YES) { info.provisionalCount++; } int size = itemSize + headerSize; info.totalBytes += size; info.headerBytes += headerSize; totalLogBytes += size; if ((info.minBytes == 0) || (info.minBytes > size)) { info.minBytes = size; } if (info.maxBytes < size) { info.maxBytes = size; } if (verbose) { if (firstLsnRead == DbLsn.NULL_LSN) { firstLsnRead = getLastLsn(); } if (currentType == LogEntryType.LOG_CKPT_END.getTypeNum()) { /* Start counting a new interval. */ ckptCounter.endCkptLsn = getLastLsn(); ckptCounter = new CheckpointCounter(); ckptList.add(ckptCounter); } else { ckptCounter.increment(this, currentType); } } if (lastEntryType.isUserLNType()) { /* Read the entry into the ByteBuffer. */ LNLogEntry<?> entry = (LNLogEntry<?>) lastEntryType.getSharedLogEntry(); entry.readEntry(envImpl, currentEntryHeader, entryBuffer); /* * The getUnconvertedXxx methods are used because we don't have a * DatabaseImpl for calling LNLogEntry.postFetchInit, and we can * tolerate statistics that use the old duplicates format. */ int keyLen = entry.getUnconvertedKeyLength(); realTotalKeyBytes += keyLen; if (!entry.isDeleted()) { int dataLen = entry.getUnconvertedDataLength(); realTotalDataBytes += dataLen; } } entryBuffer.position(nextEntryPosition); return true; }
/** * Writes the header for the next entry stream. * * @param info Some info, should be some sort of serialization information. * @param size The size of the stream. * @throws IOException */ public void nextEntry(EntryInfo info) throws IOException { mDataOutputStream.writeUTF(info.getInfo()); mDataOutputStream.writeLong(info.getSize()); }