forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.java
More file actions
126 lines (114 loc) · 4.02 KB
/
Copy pathOptions.java
File metadata and controls
126 lines (114 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*-*- mode: Java; tab-width:8 -*-*/
package php.java.bridge;
/*
* Copyright (C) 2003-2007 Jost Boekemeier
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Exposes the request options. There is one Options instance for each request, but certain options may change for each packet.
* For example if a user calls java_set_file_encoding(enc), the new file encoding becomes available in the next packet.
* @author jostb
*
*/
class Options {
protected byte options = 0;
/**
* Default encoding: UTF-8
*/
private String encoding = null;
/**
* Returns the file encoding, see java_set_file_encoding(). This option may change for each packet.
* @return The file encoding
*/
public String getEncoding() {
if(encoding!=null) return encoding;
return encoding=Util.DEFAULT_ENCODING;
}
/**
* Return a byte array using the current file encoding (see java_set_file_encoding()).
* @param s The string
* @return The encoded bytes.
*/
public byte[] getBytes(String s) {
try {
return s.getBytes(getEncoding());
} catch (java.io.UnsupportedEncodingException e) {
Util.printStackTrace(e);
return s.getBytes();
}
}
private boolean valuesCache, valuesCacheSet=false;
/**
* Returns true when the bridge must destroy object identity (see PROTOCOL.TXT) due
* to limitations in the client (for PHP4 for example).
* This option stays the same for all packets.
* @return the appropriate value from the request header.
*/
public boolean preferValues() {
if(!valuesCacheSet) {
int options = 3 & this.options;
valuesCacheSet = true;
return valuesCache = options==2 || options==1;
}
return valuesCache;
}
/** re-initialize for keep alive */
protected void recycle() {
encoding = null;
}
/**
* Set the new file encoding.
* @param symbol The new file encoding, for example "UTF-8".
*/
public void setEncoding(String symbol) {
this.encoding = symbol;
}
/**
* Update the current request options
* @param b The options from the request header.
*/
public void updateOptions(byte b) {
encoding = null;
this.options = b;
}
private boolean base64Cache, base64CacheSet=false;
/**
* Return true if we must return a base 64 encoded string
* due to limitations in the client's XML parser.
* This option stays the same for all packets.
* @return true if the bridge must return strings as cdata, false otherwise.
*/
public boolean base64Data() {
if(!base64CacheSet) {
int options = 2 & this.options;
base64CacheSet = true;
return base64Cache = options==2;
}
return base64Cache;
}
/**
* Return true, if the client cannot keep a back-pointer to its own data structures.
* This option stays the same for all packets.
* @return true if the bridge must accept and pass a context ID, false otherwise.
*/
public boolean passContext() {
return false;
}
}