-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding source files for 3rd party module to CVS
- Loading branch information
Showing
5 changed files
with
2,361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package it.eng.jhove.module.odf; | ||
|
||
import com.thaiopensource.util.PropertyMapBuilder; | ||
import com.thaiopensource.validate.SchemaReader; | ||
import com.thaiopensource.validate.ValidateProperty; | ||
import com.thaiopensource.validate.ValidationDriver; | ||
import com.thaiopensource.validate.rng.RngProperty; | ||
import com.thaiopensource.xml.sax.ErrorHandlerImpl; | ||
import java.io.IOException; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
import java.io.OutputStream; | ||
|
||
import java.io.InputStream; | ||
|
||
|
||
/** | ||
* JingDriver is a wrapper to use Jing as a library and not as an | ||
* application without changing jing own source code. | ||
* | ||
* Created: Fri Oct 20 14:22:14 2006 | ||
* | ||
* @author <a href="mailto:saint@eng.it">Gian Uberto Lauri</a> | ||
* @version $Revision$ | ||
*/ | ||
public class JingDriver { | ||
|
||
/** | ||
* <code>doValidation</code> preform a relaxed ng validation using jing | ||
* code (-i option, since we had some barfing with Oasis nrg during | ||
* pre-tests) | ||
* | ||
* @param schema a <code>String</code> relaxed nrg schema against who | ||
* the file is to be validated. | ||
* @param xmlFileName a <code>String</code> xml file to validate | ||
* @param boust a <code>ByteArrayOutputStream</code> byte output stream | ||
* to collect jing barfing... | ||
* @return a <code>boolean</code> true if the file is valid, false | ||
* otherwise. | ||
*/ | ||
public boolean doValidation(InputStream schema, | ||
String xmlFileName, | ||
OutputStream boust) { | ||
ErrorHandlerImpl eh = new ErrorHandlerImpl(System.out); | ||
PropertyMapBuilder properties = new PropertyMapBuilder(); | ||
ValidateProperty.ERROR_HANDLER.put(properties, eh); | ||
RngProperty.CHECK_ID_IDREF.add(properties); | ||
SchemaReader sr = null; | ||
|
||
// Simulate -i option, since without the program barfs on | ||
// Oasis Open Document nrg. | ||
properties.put(RngProperty.CHECK_ID_IDREF, null); | ||
|
||
boolean hadError = false; | ||
try { | ||
ValidationDriver driver = new ValidationDriver(properties.toPropertyMap(), sr); | ||
InputSource in = new InputSource(schema); | ||
if (driver.loadSchema(in)) { | ||
|
||
if (!driver.validate(ValidationDriver.uriOrFileInputSource(xmlFileName))) | ||
hadError = true; | ||
} | ||
else | ||
hadError = true; | ||
} | ||
catch (SAXException e) { | ||
hadError = true; | ||
eh.printException(e); | ||
} | ||
catch (IOException e) { | ||
hadError = true; | ||
eh.printException(e); | ||
} | ||
return ! hadError; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package it.eng.jhove.module.odf; | ||
|
||
import org.xml.sax.helpers.DefaultHandler; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import java.util.List; | ||
import it.eng.jhove.Booolean; | ||
|
||
/** | ||
* Describe class ManifestHandler here. | ||
* | ||
* | ||
* Created: Mon Oct 23 08:45:53 2006 | ||
* | ||
* @author <a href="mailto:saint@eng.it">Gian Uberto Lauri</a> | ||
* @version $Revision$ | ||
*/ | ||
public class ManifestHandler extends DefaultHandler { | ||
|
||
private Booolean isEncrypted; | ||
private List entries; | ||
|
||
/** | ||
* Crea una nuova istanza di <code>ManifestHandler</code> . | ||
* | ||
*/ | ||
public ManifestHandler(List entries, | ||
Booolean isEncrypted) { | ||
this.entries = entries; | ||
this.isEncrypted = isEncrypted; | ||
} | ||
|
||
/** | ||
* <code>startElement</code> | ||
* | ||
* @param nameSpaceUri a <code>String</code> | ||
* @param localName a <code>String</code> | ||
* @param rawName a <code>String</code> | ||
* @param attributes an <code>Attributes</code> | ||
* @exception SAXException | ||
*/ | ||
public final void startElement(final String nameSpaceUri, | ||
final String localName, | ||
final String rawName, | ||
final Attributes attributes) | ||
throws SAXException { | ||
|
||
if (rawName.equals(FILE_ENTRY)) { | ||
String type=""; | ||
String path=""; | ||
int size=0; | ||
|
||
for (int i = 0; i < attributes.getLength(); i++) { | ||
if (attributes.getQName(i).equals(ATTR_MEDIA)) { | ||
type = attributes.getValue(i); | ||
} | ||
if (attributes.getQName(i).equals(ATTR_PATH)) { | ||
path = attributes.getValue(i); | ||
} | ||
if (attributes.getQName(i).equals(ATTR_SIZE)) { | ||
size = Integer.parseInt(attributes.getValue(i)); | ||
} | ||
|
||
|
||
} | ||
ManifestEntry entry = new ManifestEntry(type, path, size); | ||
entries.add(entry); | ||
} | ||
else if (rawName.equals(CRYP_ENTRT)) { | ||
isEncrypted.setFlag(true); | ||
} | ||
|
||
} | ||
|
||
private final static String FILE_ENTRY = "manifest:file-entry"; | ||
|
||
private final static String CRYP_ENTRT = "manifest:encryption-data"; | ||
|
||
private final static String ATTR_MEDIA = "manifest:media-type"; | ||
private final static String ATTR_PATH = "manifest:full-path"; | ||
private final static String ATTR_SIZE = "manifest:size"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package it.eng.jhove.module.odf; | ||
|
||
import org.xml.sax.helpers.DefaultHandler; | ||
import edu.harvard.hul.ois.jhove.RepInfo; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.Attributes; | ||
import java.text.SimpleDateFormat; | ||
import java.text.ParsePosition; | ||
import java.util.Date; | ||
|
||
/** | ||
* Describe class MetaHandler here. | ||
* | ||
* | ||
* Created: Mon Oct 23 13:25:46 2006 | ||
* | ||
* @author <a href="mailto:saint@eng.it">Gian Uberto Lauri</a> | ||
* @version $Revision$ | ||
*/ | ||
public class MetaHandler extends DefaultHandler { | ||
protected RepInfo info; | ||
protected StringBuffer tagContent; | ||
protected boolean isInDate=false; | ||
protected boolean isInCreationDate=false; | ||
protected SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); | ||
/** | ||
* Cretes a new instance of <code>MetaHandler</code> . | ||
* | ||
*/ | ||
public MetaHandler(RepInfo info) { | ||
this.info= info; | ||
} | ||
|
||
/** | ||
* SAX parser callback method. | ||
*/ | ||
public void startElement (String namespaceURI, String localName, | ||
String rawName, Attributes atts) | ||
throws SAXException | ||
{ | ||
tagContent = new StringBuffer (); | ||
if (rawName.equals(TAG_DATE)) { | ||
isInDate=true; | ||
} | ||
if (rawName.equals(TAG_CREATION)) { | ||
isInCreationDate=true; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* SAX parser callback method. | ||
*/ | ||
public void characters (char [] ch, int start, int length) | ||
throws SAXException | ||
{ | ||
tagContent.append (ch, start, length); | ||
|
||
} | ||
|
||
/** | ||
* SAX parser callback method. | ||
*/ | ||
public void endElement (String namespaceURI, String localName, | ||
String rawName) | ||
throws SAXException | ||
{ | ||
if ( isInDate ) { | ||
info.setLastModified(contentToDate()); | ||
isInDate=false; | ||
} | ||
if ( isInCreationDate ) { | ||
info.setCreated(contentToDate()); | ||
isInCreationDate=false; | ||
} | ||
|
||
|
||
} | ||
|
||
private final Date contentToDate() { | ||
// Open document date format is yyyy-mm-ddThh:mm:ss | ||
return sdf1.parse(tagContent.toString(), new ParsePosition(0)); | ||
|
||
} | ||
private final static String TAG_DATE="dc:date"; | ||
private final static String TAG_CREATION="meta:creation-date"; | ||
} |
Oops, something went wrong.