1 package org.codehaus.plexus.components.io.attributes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import javax.annotation.Nullable;
20
21
22
23
24 public class SimpleResourceAttributes implements PlexusIoResourceAttributes {
25
26 private Integer gid;
27
28 private Integer uid;
29
30 private String userName;
31
32 private String groupName;
33
34 private int mode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
35
36 private boolean isSymbolicLink;
37
38 public SimpleResourceAttributes(Integer uid, String userName, Integer gid, String groupName, int mode) {
39 this.uid = uid;
40 this.userName = userName;
41 this.gid = gid;
42 this.groupName = groupName;
43 this.mode = mode;
44 }
45
46 public SimpleResourceAttributes(
47 Integer uid, String userName, Integer gid, String groupName, int mode, boolean isSymbolicLink) {
48 this.uid = uid;
49 this.userName = userName;
50 this.gid = gid;
51 this.groupName = groupName;
52 this.mode = mode;
53 this.isSymbolicLink = isSymbolicLink;
54 }
55
56 public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS() {
57 return new SimpleResourceAttributes();
58 }
59
60 SimpleResourceAttributes() {}
61
62 public int getOctalMode() {
63 return mode;
64 }
65
66 @Nullable
67 public Integer getGroupId() {
68 return gid;
69 }
70
71 @Nullable
72 public String getGroupName() {
73 return groupName;
74 }
75
76 public Integer getUserId() {
77 return uid;
78 }
79
80 public String getUserName() {
81 return userName;
82 }
83
84 public boolean isGroupExecutable() {
85 return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal(mode);
86 }
87
88 public boolean isGroupReadable() {
89 return PlexusIoResourceAttributeUtils.isGroupReadableInOctal(mode);
90 }
91
92 public boolean isGroupWritable() {
93 return PlexusIoResourceAttributeUtils.isGroupWritableInOctal(mode);
94 }
95
96 public boolean isOwnerExecutable() {
97 return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal(mode);
98 }
99
100 public boolean isOwnerReadable() {
101 return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal(mode);
102 }
103
104 public boolean isOwnerWritable() {
105 return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal(mode);
106 }
107
108 public boolean isWorldExecutable() {
109 return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal(mode);
110 }
111
112 public boolean isWorldReadable() {
113 return PlexusIoResourceAttributeUtils.isWorldReadableInOctal(mode);
114 }
115
116 public boolean isWorldWritable() {
117 return PlexusIoResourceAttributeUtils.isWorldWritableInOctal(mode);
118 }
119
120 public String getOctalModeString() {
121 return Integer.toString(mode, 8);
122 }
123
124 public PlexusIoResourceAttributes setOctalMode(int mode) {
125 this.mode = mode;
126 return this;
127 }
128
129 public PlexusIoResourceAttributes setGroupId(Integer gid) {
130 this.gid = gid;
131 return this;
132 }
133
134 public PlexusIoResourceAttributes setGroupName(String name) {
135 this.groupName = name;
136 return this;
137 }
138
139 public PlexusIoResourceAttributes setUserId(Integer uid) {
140 this.uid = uid;
141 return this;
142 }
143
144 public PlexusIoResourceAttributes setUserName(String name) {
145 this.userName = name;
146 return this;
147 }
148
149 public PlexusIoResourceAttributes setOctalModeString(String mode) {
150 setOctalMode(Integer.parseInt(mode, 8));
151 return this;
152 }
153
154 public String toString() {
155 return String.format(
156 "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o",
157 userName == null ? "" : userName,
158 groupName == null ? "" : groupName,
159 uid != null ? uid : 0,
160 gid != null ? gid : 0,
161 mode);
162 }
163
164 public void setSymbolicLink(boolean isSymbolicLink) {
165 this.isSymbolicLink = isSymbolicLink;
166 }
167
168 public boolean isSymbolicLink() {
169 return isSymbolicLink;
170 }
171 }