view src/de/mpg/mpiwg/itgroup/indexMeta/Utils/ParseIndexMeta.java @ 9:e63a64652f4d

added comments
author dwinter
date Mon, 03 Jan 2011 16:53:48 +0100
parents 83c58ea33792
children
line wrap: on
line source

package de.mpg.mpiwg.itgroup.indexMeta.Utils;

import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;

/**
 * 
 * Utilities to parse index.meta files following the standards of the MPIWG
 * @author dwinter
 *
 */
public class ParseIndexMeta {

	private Document dom;

	public ParseIndexMeta(IFile indexMetaFile) throws JDOMException, IOException, CoreException {
		 SAXBuilder builder = new SAXBuilder();
		 InputStream is = indexMetaFile.getContents();
		 dom = builder.build(is);
	}

	/**
	 * @return the content of the archive-path tag.
	 * @throws JDOMException
	 */
	public String getPath() throws JDOMException {
		
		XPath xpath = XPath.newInstance("//archive-path");
		Element el = (Element)xpath.selectSingleNode(dom);
		if (el==null)
			return null;
		return el.getTextTrim();
	}
	
	/**
	 * @return the content of //texttool/image
	 * @throws JDOMException
	 */
	public String getImagePath() throws JDOMException{
		String path = getPath();
		
		XPath xpath = XPath.newInstance("//texttool/image");
		Element el = (Element)xpath.selectSingleNode(dom);
		if (el==null)
			return null;
		String imagePath =el.getTextTrim();
		
		return(path+"/"+imagePath);
		
	}

}