java.fedora.client.bmech.xml.DSInputSpecGenerator Maven / Gradle / Ivy
Show all versions of fcrepo-client Show documentation
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to 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.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.client.bmech.xml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.transform.dom.DOMResult;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import fedora.client.bmech.data.*;
import fedora.client.bmech.BMechBuilderException;
/**
*
* Title: DSInputSpecGenerator.java
* Description:
*
* @author [email protected]
* @version $Id: DSInputSpecGenerator.java 4984 2006-07-17 16:59:13Z rlw $
*/
public class DSInputSpecGenerator
{
private static final String FBS =
"http://fedora.comm.nsdlib.org/service/bindspec";
private static final String XMLNS = "http://www.w3.org/2000/xmlns/";
private Document document;
public DSInputSpecGenerator(BMechTemplate newBMech) throws BMechBuilderException
{
createDOM();
genDSInputSpec(newBMech);
}
private void createDOM() throws BMechBuilderException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
}
catch (ParserConfigurationException pce)
{
// Parser with specified options can't be built
pce.printStackTrace();
throw new BMechBuilderException("DSInputSpecGenerator: error configuring parser."
+ "Underlying exception: " + pce.getMessage());
}
}
private void genDSInputSpec(BMechTemplate newBMech)
{
DSInputRule[] rules = newBMech.getDSInputSpec();
Element root = (Element)document.createElementNS(FBS, "fbs:DSInputSpec");
root.setAttributeNS(XMLNS, "xmlns:fbs", FBS);
String bmlabel = (newBMech.getbObjLabel() == null) ? "" : newBMech.getbObjLabel();
root.setAttribute("label", ("Datastream Input Specification for " + bmlabel));
String bDefPID = (newBMech.getbDefContractPID() == null) ? "" : newBMech.getbDefContractPID();
root.setAttribute("bDefPID", bDefPID);
document.appendChild(root);
for (int i=0; i