com.github.fscheffer.arras.test.services.MusicLibraryParser Maven / Gradle / Ivy
// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.github.fscheffer.arras.test.services;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.util.Stack;
import org.slf4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import com.github.fscheffer.arras.test.Track;
import static java.lang.String.format;
/**
* Reads an iTunes music library file into a list of {@link Track} elements.
*/
public class MusicLibraryParser {
private final Logger logger;
private static final int STATE_START = 0;
private static final int STATE_PLIST = 1;
private static final int STATE_DICT1 = 2;
private static final int STATE_IGNORE = 3;
private static final int STATE_DICT2 = 4;
private static final int STATE_DICT_TRACK = 5;
private static final int STATE_COLLECT_KEY = 6;
private static final int STATE_COLLECT_VALUE = 7;
private static class Item {
StringBuilder _buffer;
boolean _ignoreCharacterData;
int _priorState;
void addContent(char buffer[], int start, int length) {
if (this._ignoreCharacterData) {
return;
}
if (this._buffer == null) {
this._buffer = new StringBuilder(length);
}
this._buffer.append(buffer, start, length);
}
String getContent() {
if (this._buffer != null) {
return this._buffer.toString().trim();
}
else {
return null;
}
}
Item(int priorState, boolean ignoreCharacterData) {
this._priorState = priorState;
this._ignoreCharacterData = ignoreCharacterData;
}
}
private class Handler extends DefaultHandler {
private final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy