removed obsolete scratchpad files

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@776937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-05-21 03:06:25 +00:00
parent 5fb78707f7
commit 5a4ac88a81
8 changed files with 0 additions and 637 deletions

View File

@ -1,157 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.generator;
/**
* <p>For iterating through our fields.</p>
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class FieldIterator
{
protected int offset;
public FieldIterator()
{
}
/**
* This utility function returns a fill method entry for a given field
*
* @param size - how big of an "int" or the name of the size field for a string
* @param type - int or string
*/
public String fillDecoder(String size, String type)
{
String javaType = RecordUtil.getType(size, type, 0);
String result = "";
if (javaType.equals("short"))
result = "LittleEndian.getShort(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("short[]"))
result = "LittleEndian.getShortArray(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("int"))
result = "LittleEndian.getInt(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("byte"))
result = "data[ pos + 0x" + Integer.toHexString(offset) + " + offset ]";
else if (javaType.equals("double"))
result = "LittleEndian.getDouble(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("String") && !type.equals("hbstring"))
result = "StringUtil.getFromUnicode(data, pos + 0x" + Integer.toHexString(offset) + " + offset,("+ size + "-1)/2)";
else if (javaType.equals("String") && type.equals("hbstring"))
result = "StringUtil.getFromUnicodeHigh(data, pos + 0x" + Integer.toHexString(offset) + " + offset, ("+ size+"/2))";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
}
public String fillDecoder2(int position, String name, String size, String type)
{
if (type.startsWith("custom:"))
{
StringBuffer result = new StringBuffer();
result.append( RecordUtil.getFieldName( position, name, 0 ) );
result.append( " = new " );
String javaType = type.substring( 7 );
result.append(javaType);
result.append( "();\n");
result.append( " pos += " );
result.append(RecordUtil.getFieldName(position, name, 0))
.append(".fillField(data,size,pos + offset + ")
.append(offset)
.append(")");
return result.toString();
}
else
{
return RecordUtil.getFieldName(position, name, 30) +
" = " + fillDecoder(size, type);
}
}
//position(),@name,@size,@type
public String serialiseEncoder( int fieldNumber, String fieldName, String size, String type)
{
String javaType = RecordUtil.getType(size, type, 0);
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
String result = "";
if (type.startsWith("custom:"))
result = "pos += " + javaFieldName + ".serializeField( pos + " + (offset+4) + " + offset, data );";
else if (javaType.equals("short"))
result = "LittleEndian.putShort(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("short[]"))
result = "LittleEndian.putShortArray(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("int"))
result = "LittleEndian.putInt(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("byte"))
result = "data[ " + (offset+4) + " + offset + pos ] = " + javaFieldName + ";";
else if (javaType.equals("double"))
result = "LittleEndian.putDouble(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("String") && !type.equals("hbstring"))
result = "StringUtil.putUncompressedUnicode("+ javaFieldName +", data, offset + pos + 4);";
else if (javaType.equals("String") && type.equals("hbstring"))
result = "StringUtil.putUncompressedUnicodeHigh("+ javaFieldName +", data, "+(offset+4)+" + offset + pos);";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
}
public String calcSize( int fieldNumber, String fieldName, String size, String type)
{
String result = " + ";
if (type.startsWith("custom:"))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber, fieldName, 0);
return result + javaFieldName + ".getSize()";
}
else if ("var".equals(size))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
return result + " ("+javaFieldName + ".length() *2)";
}
else if ("varword".equals(size))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
return result + javaFieldName + ".length * 2 + 2";
} else
{
return result + size;
}
}
}

View File

@ -1,241 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.generator;
import java.util.StringTokenizer;
/**
* Helper functions for the record transformations.
*
* @author Glen Stampoultzis (glens at apache.org)
* @author Andrew C. Oliver (acoliver at apache dot org)
*/
public class RecordUtil
{
private static final String CR = "\n";
public static String getFieldName(int position, String name, int padTo)
{
StringBuffer fieldName = new StringBuffer("field_" + position + "_");
toIdentifier(name, fieldName);
pad(fieldName, padTo);
return fieldName.toString();
}
protected static StringBuffer pad(StringBuffer fieldName, int padTo)
{
for (int i = fieldName.length(); i < padTo; i++)
fieldName.append(' ');
return fieldName;
}
public static String getFieldName(String name, int padTo)
{
StringBuffer fieldName = new StringBuffer();
toIdentifier(name, fieldName);
pad(fieldName, padTo);
return fieldName.toString();
}
public static String getFieldName1stCap(String name, int padTo)
{
StringBuffer fieldName = new StringBuffer();
toIdentifier(name, fieldName);
fieldName.setCharAt(0, Character.toUpperCase(fieldName.charAt(0)));
pad(fieldName, padTo);
return fieldName.toString();
}
public static String clone(String name, String type, int pos) {
StringBuffer fieldName = new StringBuffer();
toIdentifier(name, fieldName);
String javaFieldName = getFieldName(pos, name, 0);
if (type.startsWith("custom:"))
{
String javaType = type.substring(7);
return "rec." + javaFieldName + " = ((" + javaType + ")" + javaFieldName + ".clone());";
}
else
{
return "rec." + javaFieldName + " = " + javaFieldName;
}
}
public static String initializeText(String size, String type)
{
// Removed because of wierdo initialization sequence in constructors.
// if (type.startsWith("custom:"))
// {
// String javaType = type.substring( 7 );
// return " = new " + javaType + "()";
// }
// else
// {
// return "";
// }
return "";
}
private static void toIdentifier(String name, StringBuffer fieldName)
{
for (int i = 0; i < name.length(); i++)
{
if (name.charAt(i) == ' ')
fieldName.append(Character.toUpperCase(name.charAt(++i)));
else
fieldName.append(name.charAt(i));
}
}
private static void toConstIdentifier(String name, StringBuffer fieldName)
{
for (int i = 0; i < name.length(); i++)
{
if (name.charAt(i) == ' ')
fieldName.append('_');
else
fieldName.append(Character.toUpperCase(name.charAt(i)));
}
}
public static String getType(String size, String type, int padTo)
{
boolean wholeNumber = type.equals("bits") || type.equals("int");
if (wholeNumber && "1".equals(size))
return pad(new StringBuffer("byte"), padTo).toString();
else if (wholeNumber && "2".equals(size))
return pad(new StringBuffer("short"), padTo).toString();
else if (type.equals("int") && "varword".equals(size))
return pad(new StringBuffer("short[]"), padTo).toString();
else if (wholeNumber && "4".equals(size))
return pad(new StringBuffer("int"), padTo).toString();
else if (type.equals("float") && "8".equals(size))
return pad(new StringBuffer("double"), padTo).toString();
else if (type.equals("string"))
return pad(new StringBuffer("String"), padTo).toString();
else if (type.equals("hbstring"))
return pad(new StringBuffer("String"), padTo).toString();
else if (type.startsWith("custom:"))
{
int pos = type.lastIndexOf('.');
return pad(new StringBuffer(type.substring(pos+1)), padTo)
.toString();
}
return "short"; // if we don't know, default to short
}
public static String getType1stCap(String size, String type, int padTo)
{
StringBuffer result;
boolean numeric = type.equals("bits") || type.equals("int");
if (numeric && "1".equals(size))
result = pad(new StringBuffer("byte"), padTo);
else if (type.equals("int") && "varword".equals(size))
result = pad(new StringBuffer("short[]"), padTo);
else if (numeric && "2".equals(size))
result = pad(new StringBuffer("short"), padTo);
else if (type.equals("string"))
result = pad(new StringBuffer("String"), padTo);
else if (type.equals("hbstring"))
result = pad(new StringBuffer("HighByteString"), padTo);
else
return "";
result.setCharAt(0, Character.toUpperCase(result.charAt(0)));
return result.toString();
}
public static String getMask(int bit)
{
//if (bit > 1) bit--;
int mask = (int)Math.pow(2, bit);
return "0x" + Integer.toHexString(mask);
}
public static String getConstName(String parentName, String constName, int padTo)
{
StringBuffer fieldName = new StringBuffer();
toConstIdentifier(parentName, fieldName);
fieldName.append('_');
toConstIdentifier(constName, fieldName);
pad(fieldName, padTo);
return fieldName.toString();
}
/**
* @return a byte array formatted string from a HexDump formatted string
* for example (byte)0x00,(byte)0x01 instead of 00 01
*/
public static String getByteArrayString(String data) {
StringTokenizer tokenizer = new StringTokenizer(data);
StringBuffer retval = new StringBuffer();
while (tokenizer.hasMoreTokens()) {
retval.append("(byte)0x").append(tokenizer.nextToken());
if (tokenizer.hasMoreTokens()) {
retval.append(",");
}
}
return retval.toString();
}
public static String getToString(String fieldName, String type, String size) {
StringBuffer result = new StringBuffer();
result.append(" buffer.append(\" .");
result.append(getFieldName(fieldName, 20));
result.append(" = \")" + CR);
if (type.equals("string") == false
&& type.equals("hbstring") == false
&& type.equals("float") == false
// && type.equals("varword") == false
&& size.equals("varword") == false
&& type.startsWith("custom:") == false)
{
result.append(" .append(\"0x\")");
result.append(".append(HexDump.toHex( ");
// result.append(getType(size, type, 0));
result.append(" get");
result.append(getFieldName1stCap(fieldName, 0));
result.append(" ()))" + CR);
}
result.append(" .append(\" (\").append( get");
result.append(getFieldName1stCap(fieldName,0));
result.append("() ).append(\" )\");");
return result.toString();
}
public static String getRecordId(String recordName, String excelName)
{
if (excelName == null || excelName.equals(""))
return recordName;
else
return excelName;
}
}

View File

@ -1,103 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hdf.generator;
import org.apache.poi.generator.FieldIterator;
import org.apache.poi.generator.RecordUtil;
/**
* This class overrides FieldIterator to handle HDF specific types
*/
public class HDFFieldIterator extends FieldIterator
{
public HDFFieldIterator()
{
}
public String fillDecoder(String size, String type)
{
String result = "";
if (type.equals("short[]"))
result = "LittleEndian.getSimpleShortArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")";
else if (type.equals("byte[]"))
result = "LittleEndian.getByteArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")";
else if (type.equals("BorderCode"))
result = "new BorderCode(data, 0x" + Integer.toHexString(offset) + " + offset)";
else if (type.equals("DateAndTime"))
result = "new DateAndTime(data, 0x" + Integer.toHexString(offset) + " + offset)";
else if (size.equals("2"))
result = "LittleEndian.getShort(data, 0x" + Integer.toHexString(offset) + " + offset)";
else if (size.equals("4"))
result = "LittleEndian.getInt(data, 0x" + Integer.toHexString(offset) + " + offset)";
else if (size.equals("1"))
result = "data[ 0x" + Integer.toHexString(offset) + " + offset ]";
else if (type.equals("double"))
result = "LittleEndian.getDouble(data, 0x" + Integer.toHexString(offset) + " + offset)";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
}
public String serialiseEncoder( int fieldNumber, String fieldName, String size, String type)
{
//String javaType = RecordUtil.getType(size, type, 0);
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
String result = "";
if (type.equals("short[]"))
result = "LittleEndian.putShortArray(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
else if (type.equals("byte[]"))
result = "System.arraycopy(" + javaFieldName + ", 0, data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ".length);";
else if (type.equals("BorderCode"))
result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);";
else if (type.equals("DateAndTime"))
result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);";
else if (size.equals("2"))
result = "LittleEndian.putShort(data, 0x" + Integer.toHexString(offset) + " + offset, (short)" + javaFieldName + ");";
else if (size.equals("4"))
result = "LittleEndian.putInt(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
else if (size.equals("1"))
result = "data[ 0x" + Integer.toHexString(offset) + " + offset] = " + javaFieldName + ";";
else if (type.equals("double"))
result = "LittleEndian.putDouble(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
}
}

View File

@ -1,136 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hdf.generator;
import org.apache.poi.generator.RecordUtil;
/**
* This class overrides RecordUtil to handle HDF specific types
*/
public class HDFRecordUtil extends RecordUtil
{
public HDFRecordUtil()
{
}
public static String getType(String size, String type, int padTo)
{
return type;
}
public static String getType1stCap(String size, String type, int padTo)
{
StringBuffer result = new StringBuffer();
result.append(type);
result = pad(result, padTo);
result.setCharAt(0, Character.toUpperCase(result.charAt(0)));
return result.toString();
}
public static String getBitFieldFunction(String name, String bitMask, String parentType, String withType)
{
String type = getBitFieldType(name, bitMask, parentType);
String retVal = new String();
if(withType.equals("true"))
{
retVal = type + " ";
}
if(type.equals("boolean"))
{
retVal += "is" + getFieldName1stCap(name, 0);
}
else
{
retVal +="get" + getFieldName1stCap(name, 0);
}
return retVal;
}
public static String getBitFieldGet(String name, String bitMask, String parentType, String parentField)
{
String type = getBitFieldType(name, bitMask, parentType);
String retVal = null;
if(type.equals("boolean"))
retVal = name + ".isSet(" + parentField + ");";
else
retVal = "( " + type + " )" + name + ".getValue(" + parentField + ");";
return retVal;
}
public static String getBitFieldSet(String name, String bitMask, String parentType, String parentField)
{
String type = getBitFieldType(name, bitMask, parentType);
String retVal = null;
if(type.equals("boolean"))
retVal = "(" + parentType + ")" + getFieldName(name, 0) + ".setBoolean(" + parentField + ", value)";
else
retVal = "(" + parentType + ")" + getFieldName(name, 0) + ".setValue(" + parentField + ", value)";
return retVal;
}
public static String getBitFieldType(String name, String bitMask, String parentType)
{
byte parentSize = 0;
byte numBits = 0;
int mask = (int)Long.parseLong(bitMask.substring(2), 16);
if (parentType.equals("byte"))
parentSize = 8;
else if (parentType.equals("short"))
parentSize = 16;
else if (parentType.equals("int"))
parentSize = 32;
for (int x = 0; x < parentSize; x++)
{
int temp = mask;
numBits += (temp >> x) & 0x1;
}
if(numBits == 1)
{
return "boolean";
}
else if (numBits < 8)
{
return "byte";
}
else if (numBits < 16)
{
return "short";
}
else
{
return "int";
}
}
}