java.fedora.client.bmech.xml.ServiceProfileSerializer 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: ServiceProfileSerializer.java
* Description:
*
* @author [email protected]
* @version $Id: ServiceProfileSerializer.java 3965 2005-04-21 12:52:40Z rlw $
*/
public class ServiceProfileSerializer
{
private static final String FSVP =
"http://fedora.comm.nsdlib.org/service/profile";
private static final String XMLNS = "http://www.w3.org/2000/xmlns/";
private Document document;
public ServiceProfileSerializer(BMechTemplate newBMech) throws BMechBuilderException
{
createDOM();
genServiceProfile(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("ServiceProfileGenerator: error configuring parser."
+ "Underlying exception: " + pce.getMessage());
}
}
private void genServiceProfile(BMechTemplate newBMech)
{
ServiceProfile profile = newBMech.getServiceProfile();
Element root = (Element)document.createElementNS(FSVP, "fsvp:serviceProfile");
root.setAttributeNS(XMLNS, "xmlns:fsvp", FSVP);
String bDefPID = (newBMech.getbDefContractPID() == null) ? "" : newBMech.getbDefContractPID();
root.setAttribute("bDefPID", bDefPID);
String name = (profile.serviceName == null) ? "" : profile.serviceName;
root.setAttribute("name", name);
document.appendChild(root);
Element serviceLabel = document.createElementNS(FSVP, "fsvp:serviceDescription");
String label = (profile.serviceLabel == null) ? "" : profile.serviceLabel;
serviceLabel.appendChild(document.createTextNode(label));
Element serviceTestURL = document.createElementNS(FSVP, "fsvp:serviceLiveTestURL");
String testURL = (profile.serviceTestURL == null) ? "" : profile.serviceTestURL;
serviceTestURL.appendChild(document.createTextNode(testURL));
Element serviceMsgProtocol = document.createElementNS(FSVP, "fsvp:serviceMessagingProtocol");
String msgProtocol = (profile.msgProtocol == null) ? "" : profile.msgProtocol;
serviceMsgProtocol.appendChild(document.createTextNode(msgProtocol));
Element serviceInputs = document.createElementNS(FSVP, "fsvp:serviceInputFormats");
for (int i=0; i