2013年 2月
JAVA でファイル名を分解するクラス
JAVA でファイル名を分解するクラス
[text]
package jp.computer-system.util.file;
public class FileString
{
private String filePath = “”;
private String drive;
private String folder;
private String fileName;
private String ext;
public FileString()
{
}
public FileString(String filePath)
{
this.filePath = filePath;
String[] strs = filePath.split(“[/,\\\\]”);
if(strs.length == 0 ) return;
int six = 0;
if(!(strs[0].indexOf(“:”)==-1))
{
six=1;
drive = strs[0];
}
folder = “”;
for(int i=six;i<(strs.length – 1);i++)
{
if(folder.length()!=0)
{
folder += "/" + strs[i];
}
else
{
folder = strs[i];
}
}
fileName = strs[strs.length -1];
int ip = fileName.lastIndexOf(".");
if(ip==-1)
{
ext = "";
}
else
{
if((ip+1)==fileName.length())
{
ext = "";
}
else
{
ext = fileName.substring(ip + 1);
}
}
}
public String getDrive() {
return drive;
}
public void setDrive(String drive) {
this.drive = drive;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getExt() {
return ext;
}
public void setExt(String ext) {
this.ext = ext;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
}
[/text]
OpenLdapにLINUXユーザーアカウントを作ったけどその他の情報もLDAPに入れておきたかったので作ったSchema
/etc/openldap/schema フォルダーに ldapusers.schema を作成した。
[text]
attributetype ( 1.1.2.1.1.500.1
NAME ‘userName’
DESC ‘jp.compsys user name UTF8’
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch <—- filter の部分文字列検索するためには必要か?!
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{200} )
attributetype ( 1.1.2.1.1.500.2
NAME 'mailAddress'
DESC 'jp.compsys email address'
EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
attributetype ( 1.1.2.1.1.500.3
NAME 'mailAddressMobile'
DESC 'jp.compsys mobile email address'
EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )
objectclass ( 1.1.2.1.1.100.1
NAME 'personalInfo'
DESC 'jp.compsys personal information'
SUP top AUXILIARY
MAY ( userName $ mailAddress $ mailAddressMobile ) )
[/text]
/etc/openldap/slapd.conf にldapusers.schema を追加する。修正したら slapd を再起動する。
[text]
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/collective.schema
include /etc/openldap/schema/ldapusers.schema <—–ここ
[/text]
javaで使うときは
[text]
// objectClass(必須)
Attribute attrObjClass = new BasicAttribute(“objectClass”);
attrObjClass.add(0, “top”);
attrObjClass.add(1, “account”);
attrObjClass.add(2, “posixAccount”);
attrObjClass.add(3, “personalInfo”);
attrs.put(attrObjClass);
[/text]