📄 mmirightsmanager.java
字号:
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If
* applicable, add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced
* with your own identifying information:
* Portions Copyright [yyyy]
* [name of copyright owner]
*/
/*
* $(@)MMIRightsManager.java $Revision: 1.1.1.1 $ $Date: 2006/07/31 17:36:31 $
*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*/
package org.omc.dream.mmi.client;
import java.util.Properties;
import java.util.logging.*;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import org.omc.dream.mmi.common.*;
/**
* Rights Manager translates rights requests from caller into MMIRightsRequest
* messages. It may also implement storage for rights on the client system.
*/
public class MMIRightsManager {
private static final String CONFIG_FILE = "configure.txt";
/* Keys in the config file */
private static final String LICENSE_SERVER = "LicenseServer";
private static final String PRIVATE_KEY_FILE = "PrivateKeyFile";
private static final String LICENSE_NAME = "LicenseName";
private static final String PORT_NUMBER = "PortNumber";
private static final String ACTION = "Action";
private static final String REPO_PATH = "RepoPath";
private static final String CONTENT_ID_FIELD = "ContentIdField";
private static final String DEBUG = "Debug";
/* other hardcodes */
private static final String DEFAULT_REPO_PATH = "~/.mmirepo";
private static final String DEF_CON_ID_FIELD = "content_id";
private static final int RIGHTS_REQUEST = 0;
private static final int RIGHTS_RELEASE = 1;
private static final String MMI_RIGHTS_REQUEST_STR = "MMIRightsRequest";
private static final String MMI_RIGHTS_RELEASE_STR = "MMIRightsRelease";
/* logging */
private static final Logger logger =
Logger.getLogger( MMIRightsManager.class.getName() );
/* member variables */
private RightsRepository _repo;
private Properties _props;
private MMIClient _mmiClient;
public MMIRightsManager() {
logger.entering("MMIRightsManager", "<init>");
_props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream( CONFIG_FILE );
_props.load( fis );
logger.finest("loaded config file");
} catch ( IOException ex ) {
logger.warning("Cannot open " + CONFIG_FILE );
ex.printStackTrace();
return;
}
_repo = new RightsRepository( _props.getProperty( REPO_PATH,
DEFAULT_REPO_PATH ) );
_mmiClient = new MMIClient();
}
/**
* parses the url to get content id.
*/
/*
private String getContentId( String mediaUrl ) {
String contentId;
try {
String conField = "&" + _props.getProperty( CONTENT_ID_FIELD,
DEF_CON_ID_FIELD ) + "=";
int index = mediaUrl.lastIndexOf( conField );
logger.finest("confield is " + conField);
// look for first "&" in url from index, not counting the "&" before
// content id field
int endField = mediaUrl.indexOf( "&", index + 1 );
logger.finest("endfield is " + endField);
if( endField == -1 ) {
endField = mediaUrl.length();
}
contentId = mediaUrl.substring( index + conField.length(), endField );
logger.fine("content id is " + contentId);
} catch( StringIndexOutOfBoundsException ex ) {
logger.warning("content_id field probably not present in URL");
ex.printStackTrace();
return null;
}
return contentId;
}
*/
/**
* Extracts contentId from the media url.
*/
private String getContentId( String mediaUrl ) {
// General algo: Look for .mpg, look for last slash before .mpg.
// substring between the two indices is the tentative contentId.
// Final check to see if there is a ".en" at the end. If so, trim it
// off.
String contentId;
int l = mediaUrl.lastIndexOf(".mpg");
if( l == -1 ) {
System.err.println("Invalid mediaUrl");
return null;
}
String tempUrl = mediaUrl.substring( 0, l );
int m = tempUrl.lastIndexOf("/");
if( m == -1 )
m = 0;
String mediaName = mediaUrl.substring( m+1, l );
int e = mediaName.lastIndexOf(".en");
if( e != -1 ) {
contentId = mediaName.substring( 0, e );
} else {
contentId = mediaName;
}
logger.finest("ContentId is " + contentId);
try {
} catch ( Exception ex ) {
ex.printStackTrace();
}
return contentId;
}
/**
* Gets an appropriate verb for the actionId specified.
String getVerbString( int actionId ) {
// XXX take care. This mapping comes from rights_xface.h
// cross referenced with verbs allowed in the spec.
// XXX
switch( actionId ) {
case 0: // PLAY
return "SimplePlay";
case 1: // RECORD
return "Record";
case 2: // FFWD
return "ForwardPlay";
case 3: // RWND
return "ReversePlay";
case 4: // CLEAR_COPY
return "ClearCopy";
case 5: // ADAPT
return "Adapt";
}
return null;
}
*/
/**
* Makes a MMImessage from ActionStat
*/
private MMIPlainTextMessage prepareMMIPlainTextMessage( int mesgType,
String conId, ActionId actionId, ActionStat inStat ) {
// XXX I should be looking at the actionId and then changing various
// fields in the MMIRequest on that basis. However for now, I only
// manipulate the count.
MMIMessageFactory mmf = MMIMessageFactory.PLAINTEXT;
MMIPlainTextMessage mptm = (MMIPlainTextMessage)mmf.createMMIMessage();
mptm.setMMIVersion("1.0");
MMIRequest mmiRequest = new MMIRequest();
try {
if( mesgType == RIGHTS_REQUEST ) {
mmiRequest.setMMIMessageType( MMI_RIGHTS_REQUEST_STR );
} else {
mmiRequest.setMMIMessageType( MMI_RIGHTS_RELEASE_STR );
}
IdentitySegment identitySegment = new IdentitySegment(new AuthServiceId("null"), null);
mmiRequest.setIdentitySegment(identitySegment);
DeviceSegment deviceSegment = new DeviceSegment();
DeviceId[] deviceId = new DeviceId[1];
deviceId[0] = new DeviceId("123456abc");
deviceSegment.setDeviceId(deviceId);
mmiRequest.setDeviceSegment(deviceSegment);
RightsSegment rightsSegment = new RightsSegment();
rightsSegment.setProfileId(new ProfileId("org.omc.dream.profiles.media"));
MMIRightsRequestElement[] mmiRightsRequestElement =
new MMIRightsRequestElement[1]; // Made this a single element.
mmiRightsRequestElement[0] = new MMIRightsRequestElement();
mmiRightsRequestElement[0].setReqElemId(new ReqElemId("23"));
ContentId[] contentId = new ContentId[1];
contentId[0] = new ContentId( conId ); // added conId here
mmiRightsRequestElement[0].setContentId(contentId);
VerbElement[] verbElement = new VerbElement[1];
verbElement[0] = new VerbElement();
verbElement[0].setVerbElementId(new VerbElementId("1"));
verbElement[0].setVerb(new Verb( actionId.toMMIVerbString() )); //get verb string here
verbElement[0].setCount(new Count("" + inStat.num)); //set count here
/* Special case for clear copy. setting a verb specific arg */
VerbSpecificArgs [] spec = null;
if ( actionId.equals( ActionId.CLEAR_COPY ) ) { /* XXX */
spec = new VerbSpecificArgs[1];
spec[0] = new VerbSpecificArgs("Target", inStat.target );
verbElement[0].setVerbSpecificArgs( spec );
}
mmiRightsRequestElement[0].setVerbElement(verbElement);
rightsSegment.setMMIRightsRequestElement(mmiRightsRequestElement);
mmiRequest.setRightsSegment(rightsSegment);
mptm.setMMIDataObject(mmiRequest);
} catch (InvalidMMIObjectException imoe) {
imoe.printStackTrace();
}
return mptm;
}
/**
* Given an MMIMessage this function will create an ActionStat that
* contains the necessary information.
*/
private ActionStat extractActionStat( MMIMessage mesg, ActionStat inStat ) {
MMIResponse response = null;
try {
response = (MMIResponse)mesg.getMMIDataObject();
} catch( RuntimeException rex ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -