/*
* @author : Elangovan
* @version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ExternRequest.java
*
* Creation / Modification History
* Elangovan 12-Dec-2002 Created
*
*/
package oracle.otnsamples.cmsxdb.admin;
import org.w3c.dom.Element;
import java.sql.SQLException;
import oracle.xdb.XMLType;
import oracle.otnsamples.cmsxdb.ConnParams;
/**
* This class encapsulates a Externalize request.
*/
public class ExternRequest {
private String resourceUrl = null;
private String xslLocation = null;
private String contentType = null;
// Message Id of message in request queue
private String messageId = null;
private String url = null;
// Status of extern
private String status = null;
/**
* Constructs a new ExternRequest object with the specified resource url,
* content type, xsl location and message id.
*
* @param resUrl XDBUri of Resource
* @param contentType Content type of resource after applying XSL
* @param xslLocation XDBUri of XSL to be applied on resource
* @param messageId Message Id of this Externalization request
*/
public ExternRequest(String resUrl, String contentType, String xslLocation,
String messageId ) {
this.resourceUrl = resUrl;
this.contentType = contentType;
this.xslLocation = xslLocation;
this.messageId = messageId;
makeUrl();
}
/**
* Constructs a new ExternRequest with message id and externalization details
* from requestXML.
*
* @param msgId Message Id of this Externalization request
* @param requestXML XMLType instance that contains externalization details
*/
public ExternRequest( String msgId, XMLType requestXML )
throws SQLException {
Element rootElement = requestXML.getDOM().getDocumentElement();
this.resourceUrl = getNodeValue( rootElement, "ResourceURL");
this.xslLocation = getNodeValue( rootElement, "XSLLocation" );
this.contentType = getNodeValue( rootElement, "ContentType");
this.messageId = msgId;
makeUrl();
}
/**
* Returns the String representation of Resource XDBUri.
*
* @return String representation of Resource XDBUri
*/
public String getResourceUrl( ) {
return resourceUrl;
}
/**
* Returns the String representation of XSL XDBUri.
*
* @return String representation of XSL XDBUri
*/
public String getXSLLocation( ) {
return xslLocation;
}
/**
* Returns the Content type.
*
* @return content type of resource after applying XSL
*/
public String getContentType( ) {
return contentType;
}
/**
* Returns the Message of this request.
*
* @return message if this request
*/
public String getMessageId( ) {
return messageId;
}
/**
* Returns the status of externalization.
*
* @return the status of externalization
*/
public String getStatus( ) {
return status;
}
/**
* Updates the status of this externalization request.
*
* @param status status of this externalization request
*/
public void setStatus(String status) {
this.status = status;
}
/**
* Returns the complete url for this resource, which includes XSL and content
* type.
*
* @return the url for TransformServlet
*/
public String getUrl( ) {
return url;
}
/**
* Constructs a url for TransformServlet.
*/
private void makeUrl( ) {
StringBuffer servletUrl = new StringBuffer(ConnParams.dbTransServlet)
.append("?resource=")
.append(resourceUrl);
// Generate file to relative path specified by the resource
if( contentType != null && contentType != "" ) {
servletUrl.append( "&contenttype=" ).append( contentType );
}
if( xslLocation != null && xslLocation != "" ) {
servletUrl.append( "&transform=" ).append( xslLocation );
}
url = servletUrl.toString( );
}
/**
* Return the String representation of this Class. This method overrides the
* toString() method in java.lang.Object
*
* @return String representation of this Class.
*/
public String toString( ) {
return new StringBuffer( ).append( resourceUrl + "," + xslLocation + "," +
"," + contentType ).toString( );
}
/**
* Returns the value of the Node under the given Element.
*
* @param elem XML Element to be parsed
* @param nodeName Node name for which value is required
*
* @return value of Node under the specified Element.
*/
private String getNodeValue( Element elem, String nodeName ) {
String retVal = "";
try {
retVal = elem.getElementsByTagName(nodeName).item(0).getFirstChild().getNodeValue();
} catch( Exception ex ) { }
return retVal;
}
}