file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
ITableFocusListener.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/ITableFocusListener.java
/* * File: ITableFocusListener.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model; import de.jaret.util.ui.table.JaretTable; /** * Interface for listeners listening to the focus move on a jaret table. * * @author Peter Kliem * @version $Id: ITableFocusListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $ */ public interface ITableFocusListener { /** * Focus has been moved or has been initially set. * * @param source JaretTable that is the source for the event. * @param row new focussed row. * @param column new focussed column. */ void tableFocusChanged(JaretTable source, IRow row, IColumn column); }
1,056
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IHierarchicalTableViewState.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IHierarchicalTableViewState.java
/* * File: IHierarchicalTableViewState.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model; /** * Interface describing a hierarchical tabel viewstate. Extends the falt table viewstate. * * @author Peter Kliem * @version $Id: IHierarchicalTableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $ */ public interface IHierarchicalTableViewState extends ITableViewState { /** * Check whether a node is expanded. * * @param node node to check * @return true for expanded */ boolean isExpanded(ITableNode node); /** * Set the expanded state for a single node. * * @param node node * @param expanded true for expanded */ void setExpanded(ITableNode node, boolean expanded); /** * Set the expanded state for a node and all of it's children. * * @param node node to begin with * @param expanded expanded state */ void setExpandedRecursive(ITableNode node, boolean expanded); /** * Add a view state listener. * * @param htvsListener listener to add */ void addHierarchicalViewstateListener(IHierarchicalTableViewStateListener htvsListener); /** * Remove a view state listener. * * @param htvsListener listener to remove */ void remHierarchicalViewStateListener(IHierarchicalTableViewStateListener htvsListener); }
1,807
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IPropColAccessor.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IPropColAccessor.java
/* * File: IPropColAccessor.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model; /** * Interface describing an accessor to be used together with the PropCol. * * @author kliem * @version $Id: IPropColAccessor.java,v 1.1 2012-05-07 01:34:37 jason Exp $ */ public interface IPropColAccessor { /** * Retrieve the value from the base object. * * @param base base object * @return value */ Object getValue(Object base); /** * Set a value on the base object. * * @param base base object * @param value value to be set */ void setValue(Object base, Object value); }
1,043
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ITableNodeListener.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/ITableNodeListener.java
/* * File: ITableNodeListener.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model; /** * Interface for listening on jaret table nodes in a hierarchical model. * * @author Peter Kliem * @version $Id: ITableNodeListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $ */ public interface ITableNodeListener { /** * Called when a node has been added. * * @param parent Parent of the new node. * @param newChild the new node. */ void nodeAdded(ITableNode parent, ITableNode newChild); /** * Called whenever a node is removed. * * @param parent parent of the removed node. * @param removedChild the removed node. */ void nodeRemoved(ITableNode parent, ITableNode removedChild); }
1,154
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
DefaultJaretTableModel.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/DefaultJaretTableModel.java
/* * File: DefaultJaretTableModel.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model; import java.util.ArrayList; import java.util.List; /** * Default Jaret table model. * * @author Peter Kliem * @version $Id: DefaultJaretTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $ */ public class DefaultJaretTableModel extends AbstractJaretTableModel implements IJaretTableModel { /** rows. */ protected List<IRow> _rows = new ArrayList<IRow>(); /** columns. */ protected List<IColumn> _cols = new ArrayList<IColumn>(); /** * {@inheritDoc} */ public int getRowCount() { return _rows.size(); } /** * {@inheritDoc} */ public IRow getRow(int idx) { return _rows.get(idx); } /** * Add a row to the model. * * @param row row to add */ public void addRow(IRow row) { _rows.add(row); fireRowAdded(_rows.size() - 1, row); } /** * Add a row to the model at a specified index. * * @param index index the row will be inserted * @param row row to add */ public void addRow(int index, IRow row) { _rows.add(index, row); fireRowAdded(index, row); } /** * Remove row from the model. * * @param row row to remove */ public void remRow(IRow row) { if (_rows.contains(row)) { _rows.remove(row); fireRowRemoved(row); } } /** * {@inheritDoc} */ public int getColumnCount() { return _cols.size(); } /** * {@inheritDoc} */ public IColumn getColumn(int idx) { return _cols.get(idx); } /** * Retrieve a column by it's ID. * * @param id id of the column to look for * @return the column or <code>null</code> if no Column with the id could be found. */ public IColumn getColumn(String id) { for (IColumn col : _cols) { if (col.getId().equals(id)) { return col; } } return null; } /** * Add a column to the model. * * @param column col to add */ public void addColumn(IColumn column) { _cols.add(column); fireColumnAdded(_cols.size() - 1, column); } /** * Remove a column from the model. * * @param column col to remove */ public void remColumn(IColumn column) { if (_cols.contains(column)) { _cols.remove(column); fireColumnRemoved(column); } } }
3,072
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SimpleRow.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/simple/SimpleRow.java
/* * File: SimpleRow.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model.simple; import de.jaret.util.ui.table.model.IRow; /** * Simple row implementation based on it's index, used as a marker in the SimpleJaretTableModel. * * @author kliem * @version $Id: SimpleRow.java,v 1.1 2012-05-07 01:34:39 jason Exp $ */ public class SimpleRow implements IRow { /** index of the column. */ private int _index; /** * Constructor. * * @param idx index */ public SimpleRow(int idx) { _index = idx; } /** * {@inheritDoc} */ public String getId() { return Integer.toString(_index); } /** * Retrieve the index of the row. * * @return index of the row */ public int getIndex() { return _index; } /** * {@inheritDoc} Equals based on the index of the row. */ public boolean equals(Object obj) { if (obj == null) { return false; } if (obj instanceof SimpleRow) { SimpleRow r = (SimpleRow) obj; return _index == r.getIndex(); } else { return false; } } /** * {@inheritDoc} hashcode based on the index of the column. */ public int hashCode() { return _index; } }
1,762
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SimpleJaretTableModel.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/simple/SimpleJaretTableModel.java
/* * File: SimpleJaretTableModel.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model.simple; import java.util.HashMap; import java.util.Map; import de.jaret.util.ui.table.model.AbstractJaretTableModel; import de.jaret.util.ui.table.model.IColumn; import de.jaret.util.ui.table.model.IRow; /** * Imlpementation of a very simple table model for the jaret table. The model is formed of hash maps holding objects, * allowing storage of values at arbitrary indizes. * * @author kliem * @version $Id: SimpleJaretTableModel.java,v 1.1 2012-05-07 01:34:39 jason Exp $ */ public class SimpleJaretTableModel extends AbstractJaretTableModel { /** map holding the columns. */ private Map<Integer, SimpleColumn> _cols = new HashMap<Integer, SimpleColumn>(); /** map holding the rows. */ private Map<Integer, SimpleRow> _rows = new HashMap<Integer, SimpleRow>(); /** current maximum of the col indizes. */ private int _colCount = -1; /** current maximum of the row indizes. */ private int _rowCount = -1; /** * Set a value. * * @param colIdx index of the column (x) * @param rowIdx index of the row (y) * @param value value */ public void setValueAt(int colIdx, int rowIdx, Object value) { IColumn col = getColumn(colIdx); IRow row = getRow(rowIdx); col.setValue(row, value); } /** * Get a value. * * @param colIdx index of the column (x) * @param rowIdx index of the row (y) * @return value at the given index or <code>null</code> if none present */ public Object getValueAt(int colIdx, int rowIdx) { IColumn col = getColumn(colIdx); return col.getValue(getRow(rowIdx)); } /** * Set the header label for a column. * * @param colIdx index * @param label label to set */ public void setHeaderLabel(int colIdx, String label) { ((SimpleColumn) getColumn(colIdx)).setHeaderLabel(label); } /** * {@inheritDoc} */ public IColumn getColumn(int idx) { SimpleColumn col = _cols.get(idx); if (col == null) { col = new SimpleColumn(idx, this); _cols.put(idx, col); // fireColumnAdded(idx, col); _colCount = Math.max(_colCount, idx); } return col; } /** * {@inheritDoc} */ public int getColumnCount() { return _colCount + 1; } /** * {@inheritDoc} */ public IRow getRow(int idx) { SimpleRow row = _rows.get(idx); if (row == null) { row = new SimpleRow(idx); _rows.put(idx, row); // fireRowAdded(idx, row); _rowCount = Math.max(_rowCount, idx); } return row; } /** * {@inheritDoc} */ public int getRowCount() { return _rowCount + 1; } /** * {@inheritDoc} */ public void cellChanged(IRow row, SimpleColumn column, Object value) { fireCellChanged(row, column); } /** * {@inheritDoc} addColumn is not implementable for the SimpleModel; does nothing. */ public void addColumn(IColumn column) { // do nothing } }
3,739
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
SimpleColumn.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/simple/SimpleColumn.java
/* * File: SimpleColumn.java * Copyright (c) 2004-2007 Peter Kliem ([email protected]) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ package de.jaret.util.ui.table.model.simple; import java.util.HashMap; import java.util.Map; import de.jaret.util.ui.table.model.AbstractColumn; import de.jaret.util.ui.table.model.IRow; /** * Simple implementation of a column for use in the SimpleJaretTableModel. * * @author kliem * @version $Id: SimpleColumn.java,v 1.1 2012-05-07 01:34:39 jason Exp $ */ public class SimpleColumn extends AbstractColumn { /** Map holding the column values. */ private Map<Integer, Object> _values = new HashMap<Integer, Object>(); /** header label. */ private String _headerLabel = ""; /** index of the column. */ private int _index; /** * Tablemodel the column is part of. */ private SimpleJaretTableModel _model; /** * Construct a column. * * @param index index * @param model table model the column is part of */ public SimpleColumn(int index, SimpleJaretTableModel model) { _index = index; _model = model; } /** * Allow setting of the header label. * * @param label the label */ public void setHeaderLabel(String label) { _headerLabel = label; } /** * {@inheritDoc} Always assume different classes and rely on the object tht is the value. */ public Class<?> getContentClass() { return null; } /** * {@inheritDoc} */ public String getHeaderLabel() { return _headerLabel; } /** * {@inheritDoc} */ public String getId() { return Integer.toString(_index); } /** * {@inheritDoc} */ public Object getValue(IRow row) { return _values.get(((SimpleRow) row).getIndex()); } /** * {@inheritDoc} */ public void setValue(IRow row, Object value) { Object oldVal = getValue(row); _values.put(((SimpleRow) row).getIndex(), value); fireValueChanged(row, this, oldVal, value); _model.cellChanged(row, this, value); } /** * {@inheritDoc} */ public boolean supportsSorting() { return true; } /** * {@inheritDoc} Sorting set null &lt; non-null, non comparables are equal. */ @SuppressWarnings("unchecked") public int compare(IRow o1, IRow o2) { Object v1 = getValue(o1); Object v2 = getValue(o2); if (v1 == null && v2 != null) { return -1; } if (v2 == null && v1 != null) { return 1; } if (v1 instanceof Comparable) { Comparable c1 = (Comparable) v1; try { return c1.compareTo(v2); } catch (Exception e) { // ignore } } return 0; } }
3,306
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TableCombo.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/org.eclipse.nebula.widgets.tablecombo/src/org/eclipse/nebula/widgets/tablecombo/TableCombo.java
/**************************************************************************** * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Marty Jones <[email protected]> - initial API and implementation * Enrico Schnepel <[email protected]> - clear selectedImage bug 297209 * Enrico Schnepel <[email protected]> - disable selectedImage bug 297327 * Wolfgang Schramm <[email protected]> - added vertical alignment of text for selected table item. * Enrico Schnepel <[email protected]> - help event listener bug 326285 *****************************************************************************/ package org.eclipse.nebula.widgets.tablecombo; import java.lang.reflect.InvocationTargetException; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; import org.eclipse.swt.accessibility.ACC; import org.eclipse.swt.accessibility.AccessibleAdapter; import org.eclipse.swt.accessibility.AccessibleControlAdapter; import org.eclipse.swt.accessibility.AccessibleControlEvent; import org.eclipse.swt.accessibility.AccessibleEvent; import org.eclipse.swt.accessibility.AccessibleTextAdapter; import org.eclipse.swt.accessibility.AccessibleTextEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.TypedListener; import org.eclipse.swt.widgets.Widget; /** * The TableCombo class represents a selectable user interface object that combines a label, textfield, and a table and * issues notification when an item is selected from the table. Note: This widget is basically a extension of the CCombo * widget. The list control was replaced by a Table control and a Label control was added so that images can be * displayed when a value from the drop down items has a image associated to it. * <p> * TableCombo was written to allow the user to be able to display multiple columns of data in the "Drop Down" portion of * the combo. * </p> * <p> * Special Note: Although this class is a subclass of <code>Composite</code>, it does not make sense to add children to * it, or set a layout on it. * </p> * <dl> * <dt><b>Styles:</b> * <dd>BORDER, READ_ONLY, FLAT</dd> * <dt><b>Events:</b> * <dd>DefaultSelection, Modify, Selection, Verify</dd> * </dl> */ public class TableCombo extends Composite { private Shell popup; private Button arrow; private Label selectedImage; private Text text; private Table table; private Font font; private boolean hasFocus; private int visibleItemCount = 7; private Listener listener; private Listener focusFilter; private int displayColumnIndex = 0; private Color foreground; private Color background; private int[] columnWidths; private int tableWidthPercentage = 100; private boolean showImageWithinSelection = true; private boolean showColorWithinSelection = true; private boolean showFontWithinSelection = true; /** * Constructs a new instance of this class given its parent and a style value describing its behavior and * appearance. * <p> * The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to * instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the * <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists * the style constants that are applicable to the class. Style bits are also inherited from superclasses. * </p> * @param parent * a widget which will be the parent of the new instance (cannot be null) * @param style * the style of widget to construct * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> * </ul> * @see SWT#BORDER * @see SWT#READ_ONLY * @see SWT#FLAT * @see Widget#getStyle() */ public TableCombo(Composite parent, int style) { super(parent, style = checkStyle(style)); // set the label style int textStyle = SWT.SINGLE; if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY; if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT; // set control background to white setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); // create label to hold image if necessary. selectedImage = new Label(this, SWT.NONE); selectedImage.setAlignment(SWT.RIGHT); selectedImage.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); getLayout(); // create the control to hold the display text of what the user // selected. text = new Text(this, textStyle); text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); // set the arrow style. int arrowStyle = SWT.ARROW | SWT.DOWN; if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT; // create the down arrow button arrow = new Button(this, arrowStyle); // now add a listener to listen to the events we are interested in. listener = new Listener() { public void handleEvent(Event event) { if (isDisposed()) return; // check for a popup event if (popup == event.widget) { popupEvent(event); return; } if (text == event.widget) { textEvent(event); return; } // check for a table event if (table == event.widget) { tableEvent(event); return; } // check for arrow event if (arrow == event.widget) { arrowEvent(event); return; } // check for this widget's event if (TableCombo.this == event.widget) { comboEvent(event); return; } // check for shell event if (getShell() == event.widget) { getDisplay().asyncExec(new Runnable() { public void run() { if (isDisposed()) return; handleFocus(SWT.FocusOut); } }); } } }; // create new focus listener focusFilter = new Listener() { public void handleEvent(Event event) { if (isDisposed()) return; Shell shell = ((Control) event.widget).getShell(); if (shell == TableCombo.this.getShell()) { handleFocus(SWT.FocusOut); } } }; // set the listeners for this control int[] comboEvents = { SWT.Dispose, SWT.FocusIn, SWT.Move, SWT.Resize }; for (int i = 0; i < comboEvents.length; i++) this.addListener(comboEvents[i], listener); int[] textEvents = { SWT.DefaultSelection, SWT.KeyDown, SWT.KeyUp, SWT.MenuDetect, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.MouseDoubleClick, SWT.MouseWheel, SWT.Traverse, SWT.FocusIn, SWT.Verify }; for (int i = 0; i < textEvents.length; i++) text.addListener(textEvents[i], listener); // set the listeners for the arrow image int[] arrowEvents = { SWT.Selection, SWT.FocusIn }; for (int i = 0; i < arrowEvents.length; i++) arrow.addListener(arrowEvents[i], listener); // initialize the drop down createPopup(-1); initAccessible(); } /** * @param style * @return */ private static int checkStyle(int style) { int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; return SWT.NO_FOCUS | (style & mask); } /** * Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by * sending it one of the messages defined in the <code>ModifyListener</code> interface. * @param listener * the listener which should be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see ModifyListener * @see #removeModifyListener */ public void addModifyListener(ModifyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener(listener); addListener(SWT.Modify, typedListener); } /** * Adds the listener to the collection of listeners who will be notified when the user changes the receiver's * selection, by sending it one of the messages defined in the <code>SelectionListener</code> interface. * <p> * <code>widgetSelected</code> is called when the combo's list selection changes. <code>widgetDefaultSelected</code> * is typically called when ENTER is pressed the combo's text area. * </p> * @param listener * the listener which should be notified when the user changes the receiver's selection * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see SelectionListener * @see #removeSelectionListener * @see SelectionEvent */ public void addSelectionListener(SelectionListener listener) { checkWidget(); if (listener == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } TypedListener typedListener = new TypedListener(listener); addListener(SWT.Selection, typedListener); addListener(SWT.DefaultSelection, typedListener); } /** * Adds the listener to the collection of listeners who will be notified when the user presses keys in the text * field. interface. * @param listener * the listener which should be notified when the user presses keys in the text control. * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void addTextControlKeyListener(KeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); text.addKeyListener(listener); } /** * Removes the listener from the collection of listeners who will be notified when the user presses keys in the text * control. * @param listener * the listener which should no longer be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void removeTextControlKeyListener(KeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); text.removeKeyListener(listener); } /** * Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by * sending it one of the messages defined in the <code>VerifyListener</code> interface. * @param listener * the listener which should be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see VerifyListener * @see #removeVerifyListener * @since 3.3 */ public void addVerifyListener(VerifyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener(listener); addListener(SWT.Verify, typedListener); } /** * Handle Arrow Event * @param event */ private void arrowEvent(Event event) { switch (event.type) { case SWT.FocusIn: { handleFocus(SWT.FocusIn); break; } case SWT.MouseDown: { Event mouseEvent = new Event(); mouseEvent.button = event.button; mouseEvent.count = event.count; mouseEvent.stateMask = event.stateMask; mouseEvent.time = event.time; mouseEvent.x = event.x; mouseEvent.y = event.y; notifyListeners(SWT.MouseDown, mouseEvent); event.doit = mouseEvent.doit; break; } case SWT.MouseUp: { Event mouseEvent = new Event(); mouseEvent.button = event.button; mouseEvent.count = event.count; mouseEvent.stateMask = event.stateMask; mouseEvent.time = event.time; mouseEvent.x = event.x; mouseEvent.y = event.y; notifyListeners(SWT.MouseUp, mouseEvent); event.doit = mouseEvent.doit; break; } case SWT.Selection: { text.setFocus(); dropDown(!isDropped()); break; } } } /** * Sets the selection in the receiver's text field to an empty selection starting just before the first character. * If the text field is editable, this has the effect of placing the i-beam at the start of the text. * <p> * Note: To clear the selected items in the receiver's list, use <code>deselectAll()</code>. * </p> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see #deselectAll */ public void clearSelection() { checkWidget(); text.clearSelection(); table.deselectAll(); } /** * Handle Combo events * @param event */ private void comboEvent(Event event) { switch (event.type) { case SWT.Dispose: removeListener(SWT.Dispose, listener); notifyListeners(SWT.Dispose, event); event.type = SWT.None; if (popup != null && !popup.isDisposed()) { table.removeListener(SWT.Dispose, listener); popup.dispose(); } Shell shell = getShell(); shell.removeListener(SWT.Deactivate, listener); Display display = getDisplay(); display.removeFilter(SWT.FocusIn, focusFilter); popup = null; text = null; table = null; arrow = null; selectedImage = null; break; case SWT.FocusIn: Control focusControl = getDisplay().getFocusControl(); if (focusControl == arrow || focusControl == table) return; if (isDropped()) { table.setFocus(); } else { text.setFocus(); } break; case SWT.Move: dropDown(false); break; case SWT.Resize: internalLayout(false); break; } } /** * {@inheritDoc} */ public Point computeSize(int wHint, int hHint, boolean changed) { checkWidget(); int overallWidth = 0; int overallHeight = 0; int borderWidth = getBorderWidth(); // use user defined values if they are specified. if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { overallWidth = wHint; overallHeight = hHint; } else { TableItem[] tableItems = table.getItems(); GC gc = new GC(text); int spacer = gc.stringExtent(" ").x; //$NON-NLS-1$ int maxTextWidth = gc.stringExtent(text.getText()).x; int colIndex = getDisplayColumnIndex(); int maxImageHeight = 0; int currTextWidth = 0; // calculate the maximum text width and image height. for (int i = 0; i < tableItems.length; i++) { currTextWidth = gc.stringExtent(tableItems[i].getText(colIndex)).x; // take image into account if there is one for the tableitem. if (tableItems[i].getImage() != null) { currTextWidth += tableItems[i].getImage().getBounds().width; maxImageHeight = Math.max(tableItems[i].getImage().getBounds().height, maxImageHeight); } maxTextWidth = Math.max(currTextWidth, maxTextWidth); } gc.dispose(); Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); Point tableSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); overallHeight = Math.max(textSize.y, arrowSize.y); overallHeight = Math.max(maxImageHeight, overallHeight); overallWidth = Math.max(maxTextWidth + 2 * spacer + arrowSize.x + 2 * borderWidth, tableSize.x); // use user specified if they were entered. if (wHint != SWT.DEFAULT) overallWidth = wHint; if (hHint != SWT.DEFAULT) overallHeight = hHint; } return new Point(overallWidth + 2 * borderWidth, overallHeight + 2 * borderWidth); } /** * Copies the selected text. * <p> * The current selection is copied to the clipboard. * </p> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.3 */ public void copy() { checkWidget(); text.copy(); } /** * creates the popup shell. * @param selectionIndex */ void createPopup(int selectionIndex) { // create shell and table popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP); // set style int style = getStyle(); int tableStyle = SWT.SINGLE | SWT.V_SCROLL; if ((style & SWT.FLAT) != 0) tableStyle |= SWT.FLAT; if ((style & SWT.RIGHT_TO_LEFT) != 0) tableStyle |= SWT.RIGHT_TO_LEFT; if ((style & SWT.LEFT_TO_RIGHT) != 0) tableStyle |= SWT.LEFT_TO_RIGHT; // create table table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION); if (font != null) table.setFont(font); if (foreground != null) table.setForeground(foreground); if (background != null) table.setBackground(background); // Add popup listeners int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help }; for (int i = 0; i < popupEvents.length; i++) { popup.addListener(popupEvents[i], listener); } // add table listeners int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose }; for (int i = 0; i < tableEvents.length; i++) { table.addListener(tableEvents[i], listener); } // set the selection if (selectionIndex != -1) { table.setSelection(selectionIndex); } } /** * Cuts the selected text. * <p> * The current selection is first copied to the clipboard and then deleted from the widget. * </p> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.3 */ public void cut() { checkWidget(); text.cut(); } /** * handle DropDown request * @param drop */ void dropDown(boolean drop) { // if already dropped then return if (drop == isDropped()) return; // closing the dropDown if (!drop) { popup.setVisible(false); if (!isDisposed() && isFocusControl()) { text.setFocus(); } return; } // if not visible then return if (!isVisible()) return; // create a new popup if needed. if (getShell() != popup.getParent()) { int selectionIndex = table.getSelectionIndex(); table.removeListener(SWT.Dispose, listener); popup.dispose(); popup = null; table = null; createPopup(selectionIndex); } // get the size of the TableCombo. Point tableComboSize = getSize(); // calculate the table height. int itemCount = table.getItemCount(); itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount); int itemHeight = (table.getItemHeight() * itemCount); // add 1 to the table height if the table item count is less than the // visible item count. if (table.getItemCount() <= visibleItemCount) { itemHeight += 1; } // add height of header if the header is being displayed. if (table.getHeaderVisible()) { itemHeight += table.getHeaderHeight(); } // get table column references TableColumn[] tableColumns = table.getColumns(); int totalColumns = (tableColumns == null ? 0 : tableColumns.length); // check to make sure at least one column has been specified. if it // hasn't // then just create a blank one. if (table.getColumnCount() == 0) { new TableColumn(table, SWT.NONE); totalColumns = 1; tableColumns = table.getColumns(); } int totalColumnWidth = 0; // now pack any columns that do not have a explicit value set for them. for (int colIndex = 0; colIndex < totalColumns; colIndex++) { if (!wasColumnWidthSpecified(colIndex)) { tableColumns[colIndex].pack(); } totalColumnWidth += tableColumns[colIndex].getWidth(); } // reset the last column's width to the preferred size if it has a // explicit value. int lastColIndex = totalColumns - 1; if (wasColumnWidthSpecified(lastColIndex)) { tableColumns[lastColIndex].setWidth(columnWidths[lastColIndex]); } // calculate the table size after making adjustments. Point tableSize = table.computeSize(SWT.DEFAULT, itemHeight, false); // calculate the table width and table height. double pct = tableWidthPercentage / 100d; int tableWidth = (int) (Math.max(tableComboSize.x - 2, tableSize.x) * pct); int tableHeight = tableSize.y; // add the width of a horizontal scrollbar to the table height if we are // not viewing the full table. if (tableWidthPercentage < 100) { tableHeight += table.getHorizontalBar().getSize().y; } // set the bounds on the table. table.setBounds(1, 1, tableWidth, tableHeight); // check to see if we can adjust the table width to by the amount the // vertical // scrollbar would have taken since the table auto allocates the space // whether // it is needed or not. if (!table.getVerticalBar().getVisible() && tableSize.x - table.getVerticalBar().getSize().x >= tableComboSize.x - 2) { tableWidth = tableWidth - table.getVerticalBar().getSize().x; // reset the bounds on the table. table.setBounds(1, 1, tableWidth, tableHeight); } table.getHorizontalBar().setVisible(false); // adjust the last column to make sure that there is no empty space. autoAdjustColumnWidthsIfNeeded(tableColumns, tableWidth, totalColumnWidth); // set the table top index if there is a valid selection. String indexStr = (String) text.getData(); if (indexStr != null && !indexStr.equals("")) { int index = Integer.parseInt(indexStr); table.setSelection(index); table.setTopIndex(index); } // calculate popup dimensions. Display display = getDisplay(); Rectangle tableRect = table.getBounds(); Rectangle parentRect = display.map(getParent(), null, getBounds()); Point comboSize = getSize(); Rectangle displayRect = getMonitor().getClientArea(); int overallWidth = 0; // now set what the overall width should be. if (tableWidthPercentage < 100) { overallWidth = tableRect.width + 2; } else { overallWidth = Math.max(comboSize.x, tableRect.width + 2); } int overallHeight = tableRect.height + 2; int x = parentRect.x; int y = parentRect.y + comboSize.y; if (y + overallHeight > displayRect.y + displayRect.height) y = parentRect.y - overallHeight; if (x + overallWidth > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - tableRect.width; // set the bounds of the popup popup.setBounds(x, y, overallWidth, overallHeight); // set the popup visible popup.setVisible(true); // set focus on the table. table.setFocus(); } /* * Return the Label immediately preceding the receiver in the z-order, or null if none. */ private Label getAssociatedLabel() { Control[] siblings = getParent().getChildren(); for (int i = 0; i < siblings.length; i++) { if (siblings[i] == TableCombo.this) { if (i > 0 && siblings[i - 1] instanceof Label) { return (Label) siblings[i - 1]; } } } return null; } /** * {@inheritDoc} */ public Control[] getChildren() { checkWidget(); return new Control[0]; } /** * Gets the editable state. * @return whether or not the receiver is editable * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.0 */ public boolean getEditable() { checkWidget(); return text.getEditable(); } /** * Returns the item at the given, zero-relative index in the receiver's list. Throws an exception if the index is * out of range. * @param index * the index of the item to return * @return the item at the given index * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list * minus 1 (inclusive)</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public String getItem(int index) { checkWidget(); return table.getItem(index).getText(getDisplayColumnIndex()); } /** * Returns the number of items contained in the receiver's list. * @return the number of items * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int getItemCount() { checkWidget(); return table.getItemCount(); } /** * Returns the height of the area which would be used to display <em>one</em> of the items in the receiver's list. * @return the height of one item * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int getItemHeight() { checkWidget(); return table.getItemHeight(); } /** * Returns an array of <code>String</code>s which are the items in the receiver's list. * <p> * Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array * will not affect the receiver. * </p> * @return the items in the receiver's list * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public String[] getItems() { checkWidget(); // get a list of the table items. TableItem[] tableItems = table.getItems(); int totalItems = (tableItems == null ? 0 : tableItems.length); // create string array to hold the total number of items. String[] stringItems = new String[totalItems]; int colIndex = getDisplayColumnIndex(); // now copy the display string from the tableitems. for (int index = 0; index < totalItems; index++) { stringItems[index] = tableItems[index].getText(colIndex); } return stringItems; } /** * Returns a <code>Point</code> whose x coordinate is the start of the selection in the receiver's text field, and * whose y coordinate is the end of the selection. The returned values are zero-relative. An "empty" selection as * indicated by the the x and y coordinates having the same value. * @return a point representing the selection start and end * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public Point getSelection() { checkWidget(); return text.getSelection(); } /** * Returns the zero-relative index of the item which is currently selected in the receiver's list, or -1 if no item * is selected. * @return the index of the selected item * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int getSelectionIndex() { checkWidget(); return table.getSelectionIndex(); } /** * {@inheritDoc} */ public int getStyle() { checkWidget(); int style = super.getStyle(); style &= ~SWT.READ_ONLY; if (!text.getEditable()) style |= SWT.READ_ONLY; return style; } /** * Returns a string containing a copy of the contents of the receiver's text field. * @return the receiver's text * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public String getText() { checkWidget(); return text.getText(); } /** * Returns the height of the receivers's text field. * @return the text height * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int getTextHeight() { checkWidget(); return text.getLineHeight(); } /** * Gets the number of items that are visible in the drop down portion of the receiver's list. * @return the number of items that are visible * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.0 */ public int getVisibleItemCount() { checkWidget(); return visibleItemCount; } /** * Handle Focus event * @param type */ private void handleFocus(int type) { switch (type) { case SWT.FocusIn: { if (hasFocus) return; if (getEditable()) { text.selectAll(); } hasFocus = true; Shell shell = getShell(); shell.removeListener(SWT.Deactivate, listener); shell.addListener(SWT.Deactivate, listener); Display display = getDisplay(); display.removeFilter(SWT.FocusIn, focusFilter); display.addFilter(SWT.FocusIn, focusFilter); Event e = new Event(); notifyListeners(SWT.FocusIn, e); break; } case SWT.FocusOut: { if (!hasFocus) return; Control focusControl = getDisplay().getFocusControl(); if (focusControl == arrow || focusControl == table || focusControl == text) return; hasFocus = false; Shell shell = getShell(); shell.removeListener(SWT.Deactivate, listener); Display display = getDisplay(); display.removeFilter(SWT.FocusIn, focusFilter); Event e = new Event(); notifyListeners(SWT.FocusOut, e); break; } } } /** * Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the * argument, and returns the index of that item. If no item is found, returns -1. * @param string * the search item * @return the index of the item * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int indexOf(String string) { checkWidget(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); // get a list of the table items. TableItem[] tableItems = table.getItems(); int totalItems = (tableItems == null ? 0 : tableItems.length); int colIndex = getDisplayColumnIndex(); // now copy the display string from the tableitems. for (int index = 0; index < totalItems; index++) { if (string.equals(tableItems[index].getText(colIndex))) { return index; } } return -1; } /** * Searches the receiver's list starting at the given, zero-relative index until an item is found that is equal to * the argument, and returns the index of that item. If no item is found or the starting index is out of range, * returns -1. * @param string * the search item * @param start * the zero-relative index at which to begin the search * @return the index of the item * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int indexOf(String string, int start) { checkWidget(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); // get a list of the table items. TableItem[] tableItems = table.getItems(); int totalItems = (tableItems == null ? 0 : tableItems.length); if (start < totalItems) { int colIndex = getDisplayColumnIndex(); // now copy the display string from the tableitems. for (int index = start; index < totalItems; index++) { if (string.equals(tableItems[index].getText(colIndex))) { return index; } } } return -1; } /** * sets whether or not to show table lines * @param showTableLines */ public void setShowTableLines(boolean showTableLines) { checkWidget(); table.setLinesVisible(showTableLines); } /** * sets whether or not to show table header. * @param showTableHeader */ public void setShowTableHeader(boolean showTableHeader) { checkWidget(); table.setHeaderVisible(showTableHeader); } /** * Add Accessbile listeners to label and table. */ void initAccessible() { AccessibleAdapter accessibleAdapter = new AccessibleAdapter() { public void getName(AccessibleEvent e) { String name = null; Label label = getAssociatedLabel(); if (label != null) { name = stripMnemonic(text.getText()); } e.result = name; } public void getKeyboardShortcut(AccessibleEvent e) { String shortcut = null; Label label = getAssociatedLabel(); if (label != null) { String text = label.getText(); if (text != null) { char mnemonic = _findMnemonic(text); if (mnemonic != '\0') { shortcut = "Alt+" + mnemonic; //$NON-NLS-1$ } } } e.result = shortcut; } public void getHelp(AccessibleEvent e) { e.result = getToolTipText(); } }; getAccessible().addAccessibleListener(accessibleAdapter); text.getAccessible().addAccessibleListener(accessibleAdapter); table.getAccessible().addAccessibleListener(accessibleAdapter); arrow.getAccessible().addAccessibleListener(new AccessibleAdapter() { public void getName(AccessibleEvent e) { e.result = isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$ } public void getKeyboardShortcut(AccessibleEvent e) { e.result = "Alt+Down Arrow"; //$NON-NLS-1$ } public void getHelp(AccessibleEvent e) { e.result = getToolTipText(); } }); getAccessible().addAccessibleTextListener(new AccessibleTextAdapter() { public void getCaretOffset(AccessibleTextEvent e) { e.offset = text.getCaretPosition(); } public void getSelectionRange(AccessibleTextEvent e) { Point sel = text.getSelection(); e.offset = sel.x; e.length = sel.y - sel.x; } }); getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() { public void getChildAtPoint(AccessibleControlEvent e) { Point testPoint = toControl(e.x, e.y); if (getBounds().contains(testPoint)) { e.childID = ACC.CHILDID_SELF; } } public void getLocation(AccessibleControlEvent e) { Rectangle location = getBounds(); Point pt = getParent().toDisplay(location.x, location.y); e.x = pt.x; e.y = pt.y; e.width = location.width; e.height = location.height; } public void getChildCount(AccessibleControlEvent e) { e.detail = 0; } public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_COMBOBOX; } public void getState(AccessibleControlEvent e) { e.detail = ACC.STATE_NORMAL; } public void getValue(AccessibleControlEvent e) { e.result = text.getText(); } }); text.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() { public void getRole(AccessibleControlEvent e) { e.detail = text.getEditable() ? ACC.ROLE_TEXT : ACC.ROLE_LABEL; } }); arrow.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() { public void getDefaultAction(AccessibleControlEvent e) { e.result = isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"); //$NON-NLS-1$ //$NON-NLS-2$ } }); } /** * returns if the drop down is currently open * @return */ private boolean isDropped() { return popup.getVisible(); } /** * {@inheritDoc} */ public boolean isFocusControl() { checkWidget(); // if (label.isFocusControl () || arrow.isFocusControl () || // table.isFocusControl () || popup.isFocusControl ()) { if (arrow.isFocusControl() || table.isFocusControl() || popup.isFocusControl()) { return true; } return super.isFocusControl(); } /** * This method is invoked when a resize event occurs. * @param changed */ private void internalLayout(boolean changed) { if (isDropped()) dropDown(false); Rectangle rect = getClientArea(); int width = rect.width; int height = rect.height; Point arrowSize = arrow.computeSize(SWT.DEFAULT, height, changed); // calculate text vertical alignment. int textYPos = 0; Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT); if (textSize.y < height) { textYPos = (height - textSize.y) / 2; } // does the selected entry have a image associated with it? if (selectedImage.getImage() == null) { // set image, text, and arrow boundaries selectedImage.setBounds(0, 0, 0, 0); text.setBounds(0, textYPos, width - arrowSize.x, textSize.y); arrow.setBounds(width - arrowSize.x, 0, arrowSize.x, arrowSize.y); } else { // calculate the amount of width left in the control after taking // into account the arrow selector int remainingWidth = width - arrowSize.x; Point imageSize = selectedImage.computeSize(SWT.DEFAULT, height, changed); int imageWidth = imageSize.x + 2; // handle the case where the image is larger than the available // space in the control. if (imageWidth > remainingWidth) { imageWidth = remainingWidth; remainingWidth = 0; } else { remainingWidth = remainingWidth - imageWidth; } // set the width of the text. int textWidth = remainingWidth; // set image, text, and arrow boundaries selectedImage.setBounds(0, 0, imageWidth, imageSize.y); text.setBounds(imageWidth, textYPos, textWidth, textSize.y); arrow.setBounds(imageWidth + textWidth, 0, arrowSize.x, arrowSize.y); } } /** * Handles Table Events. * @param event * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ private void tableEvent(Event event) { switch (event.type) { case SWT.Dispose: if (getShell() != popup.getParent()) { int selectionIndex = table.getSelectionIndex(); popup = null; table = null; createPopup(selectionIndex); } break; case SWT.FocusIn: { handleFocus(SWT.FocusIn); break; } case SWT.MouseMove: { TableItem item = table.getItem(new Point(event.x, event.y)); if (item != null) { table.setSelection(item); } break; } case SWT.MouseUp: { if (event.button != 1) return; dropDown(false); int index = table.getSelectionIndex(); if (index == -1) return; // refresh the text. refreshText(index); // set the selection in the table. table.setSelection(index); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; e.doit = event.doit; notifyListeners(SWT.Selection, e); event.doit = e.doit; break; } case SWT.Traverse: { switch (event.detail) { case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_ARROW_PREVIOUS: case SWT.TRAVERSE_ARROW_NEXT: event.doit = false; break; case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: event.doit = text.traverse(event.detail); event.detail = SWT.TRAVERSE_NONE; if (event.doit) dropDown(false); return; } Event e = new Event(); e.time = event.time; e.detail = event.detail; e.doit = event.doit; e.character = event.character; e.keyCode = event.keyCode; notifyListeners(SWT.Traverse, e); event.doit = e.doit; event.detail = e.detail; break; } case SWT.KeyUp: { Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyUp, e); break; } case SWT.KeyDown: { if (event.character == SWT.ESC) { // Escape key cancels popup list dropDown(false); } if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { dropDown(false); } if (event.character == SWT.CR) { // // Enter causes default selection // System.out.println("test"); // dropDown(false); // Event e = new Event(); // e.time = event.time; // e.stateMask = event.stateMask; // notifyListeners(SWT.MouseDown, e); int index = table.getSelectionIndex(); if (index == -1) return; // refresh the text. refreshText(index); // set the selection in the table. table.setSelection(index); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; e.doit = event.doit; notifyListeners(SWT.Selection, e); event.doit = e.doit; } // At this point the widget may have been disposed. // If so, do not continue. if (isDisposed()) break; Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyDown, e); break; } } } /** * Pastes text from clipboard. * <p> * The selected text is deleted from the widget and new text inserted from the clipboard. * </p> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.3 */ public void paste() { checkWidget(); text.paste(); } /** * Handles Popup Events * @param event */ private void popupEvent(Event event) { switch (event.type) { case SWT.Paint: // draw rectangle around table Rectangle tableRect = table.getBounds(); event.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); event.gc.drawRectangle(0, 0, tableRect.width + 1, tableRect.height + 1); break; case SWT.Close: event.doit = false; dropDown(false); break; case SWT.Deactivate: /* * Bug in GTK. When the arrow button is pressed the popup control receives a deactivate event and then the * arrow button receives a selection event. If we hide the popup in the deactivate event, the selection * event will show it again. To prevent the popup from showing again, we will let the selection event of the * arrow button hide the popup. In Windows, hiding the popup during the deactivate causes the deactivate to * be called twice and the selection event to be disappear. */ if (!"carbon".equals(SWT.getPlatform())) { Point point = arrow.toControl(getDisplay().getCursorLocation()); Point size = arrow.getSize(); Rectangle rect = new Rectangle(0, 0, size.x, size.y); if (!rect.contains(point)) dropDown(false); } else { dropDown(false); } break; case SWT.Help: if (isDropped()) { dropDown(false); } Composite comp = TableCombo.this; do { if (comp.getListeners(event.type) != null && comp.getListeners(event.type).length > 0) { comp.notifyListeners(event.type, event); break; } comp = comp.getParent(); } while (null != comp); break; } } /** * {@inheritDoc} */ public void redraw() { super.redraw(); text.redraw(); arrow.redraw(); if (popup.isVisible()) table.redraw(); } /** * {@inheritDoc} */ public void redraw(int x, int y, int width, int height, boolean all) { super.redraw(x, y, width, height, true); } /** * Removes the listener from the collection of listeners who will be notified when the receiver's text is modified. * @param listener * the listener which should no longer be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see ModifyListener * @see #addModifyListener */ public void removeModifyListener(ModifyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); removeListener(SWT.Modify, listener); } /** * Removes the listener from the collection of listeners who will be notified when the user changes the receiver's * selection. * @param listener * the listener which should no longer be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see SelectionListener * @see #addSelectionListener */ public void removeSelectionListener(SelectionListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); removeListener(SWT.Selection, listener); removeListener(SWT.DefaultSelection, listener); } /** * Removes the listener from the collection of listeners who will be notified when the control is verified. * @param listener * the listener which should no longer be notified * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @see VerifyListener * @see #addVerifyListener * @since 3.3 */ public void removeVerifyListener(VerifyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); removeListener(SWT.Verify, listener); } /** * Selects the item at the given zero-relative index in the receiver's list. If the item at the index was already * selected, it remains selected. Indices that are out of range are ignored. * @param index * the index of the item to select * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void select(int index) { checkWidget(); // deselect if a value of -1 is passed in. if (index == -1) { table.deselectAll(); text.setText(""); selectedImage.setImage(null); return; } if (0 <= index && index < table.getItemCount()) { if (index != getSelectionIndex()) { // refresh the text field and image label refreshText(index); // select the row in the table. table.setSelection(index); } } } /** * {@inheritDoc} */ public void setBackground(Color color) { super.setBackground(color); background = color; if (text != null) text.setBackground(color); if (selectedImage != null) selectedImage.setBackground(color); if (table != null) table.setBackground(color); if (arrow != null) arrow.setBackground(color); } /** * Sets the editable state. * @param editable * the new editable state * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.0 */ public void setEditable(boolean editable) { checkWidget(); text.setEditable(editable); } /** * {@inheritDoc} */ public void setEnabled(boolean enabled) { super.setEnabled(enabled); if (popup != null) popup.setVisible(false); if (selectedImage != null) selectedImage.setEnabled(enabled); if (text != null) text.setEnabled(enabled); if (arrow != null) arrow.setEnabled(enabled); } /** * {@inheritDoc} */ public boolean setFocus() { checkWidget(); if (!isEnabled() || !isVisible()) return false; if (isFocusControl()) return true; return text.setFocus(); } /** * {@inheritDoc} */ public void setFont(Font font) { super.setFont(font); this.font = font; text.setFont(font); table.setFont(font); internalLayout(true); } /** * {@inheritDoc} */ public void setForeground(Color color) { super.setForeground(color); foreground = color; if (text != null) text.setForeground(color); if (table != null) table.setForeground(color); if (arrow != null) arrow.setForeground(color); } /** * Sets the layout which is associated with the receiver to be the argument which may be null. * <p> * Note : No Layout can be set on this Control because it already manages the size and position of its children. * </p> * @param layout * the receiver's new layout or null * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void setLayout(Layout layout) { checkWidget(); return; } /** * Marks the receiver's list as visible if the argument is <code>true</code> , and marks it invisible otherwise. * <p> * If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. * </p> * @param visible * the new visibility state * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.4 */ public void setTableVisible(boolean visible) { checkWidget(); dropDown(visible); } /** * Sets the selection in the receiver's text field to the range specified by the argument whose x coordinate is the * start of the selection and whose y coordinate is the end of the selection. * @param selection * a point representing the new selection start and end * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the point is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void setSelection(Point selection) { checkWidget(); if (selection == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); text.setSelection(selection.x, selection.y); } /** * Sets the contents of the receiver's text field to the given string. * <p> * Note: The text field in a <code>Combo</code> is typically only capable of displaying a single line of text. Thus, * setting the text to a string containing line breaks or other special characters will probably cause it to display * incorrectly. * </p> * @param string * the new text * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void setText(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } // find the index of the given string. int index = indexOf(string); if (index == -1) { table.deselectAll(); text.setText(string); return; } // select the text and table row. select(index); } /** * Sets the maximum number of characters that the receiver's text field is capable of holding to be the argument. * @param limit * new text limit * @exception IllegalArgumentException * <ul> * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> * </ul> * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public void setTextLimit(int limit) { checkWidget(); text.setTextLimit(limit); } /** * {@inheritDoc} */ public void setToolTipText(String tipText) { checkWidget(); super.setToolTipText(tipText); if (selectedImage != null) selectedImage.setToolTipText(tipText); if (text != null) text.setToolTipText(tipText); if (arrow != null) arrow.setToolTipText(tipText); } /** * {@inheritDoc} */ public void setVisible(boolean visible) { super.setVisible(visible); /* * At this point the widget may have been disposed in a FocusOut event. If so then do not continue. */ if (isDisposed()) return; // TEMPORARY CODE if (popup == null || popup.isDisposed()) return; if (!visible) popup.setVisible(false); } /** * Sets the number of items that are visible in the drop down portion of the receiver's list. * @param count * the new number of items to be visible * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @since 3.0 */ public void setVisibleItemCount(int count) { checkWidget(); if (count > 0) { visibleItemCount = count; } } /** * @param string * @return */ private String stripMnemonic(String string) { int index = 0; int length = string.length(); do { while ((index < length) && (string.charAt(index) != '&')) index++; if (++index >= length) return string; if (string.charAt(index) != '&') { return string.substring(0, index - 1) + string.substring(index, length); } index++; } while (index < length); return string; } /** * Defines what columns the drop down table will have. Use this method when you don't care about the width of the * columns but want to set the column header text. * @param columnHeaders * @param columnWidths */ public void defineColumns(String[] columnHeaders) { if (columnHeaders != null && columnHeaders.length > 0) { defineColumnsInternal(columnHeaders, null, columnHeaders.length); } } /** * Defines what columns the drop down table will have. Use this method when you don't care about the column header * text but you want the fields to be a specific width. * @param columnHeaders * @param columnBounds */ public void defineColumns(int[] columnBounds) { this.columnWidths = columnBounds; if (columnBounds != null && columnBounds.length > 0) { defineColumnsInternal(null, columnBounds, columnBounds.length); } } /** * Defines what columns the drop down table will have. Use this method when you don't care about the column headers * and you want the columns to be automatically sized based upon their content. * @param columnHeaders * @param columnWidths */ public void defineColumns(int numberOfColumnsToCreate) { if (numberOfColumnsToCreate > 0) { defineColumnsInternal(null, null, numberOfColumnsToCreate); } } /** * Defines what columns the drop down table will have. Use this method when you want to specify the column header * text and the column widths. * @param columnHeaders * @param columnBounds */ public void defineColumns(String[] columnHeaders, int[] columnBounds) { if (columnHeaders != null || columnBounds != null) { int total = columnHeaders == null ? 0 : columnHeaders.length; if (columnBounds != null && columnBounds.length > total) { total = columnBounds.length; } this.columnWidths = columnBounds; // define the columns defineColumnsInternal(columnHeaders, columnBounds, total); } } /** * Defines what columns the drop down table will have. * @param columnHeaders * @param columnBounds */ private void defineColumnsInternal(String[] columnHeaders, int[] columnBounds, int totalColumnsToBeCreated) { checkWidget(); int totalColumnHeaders = columnHeaders == null ? 0 : columnHeaders.length; int totalColBounds = columnBounds == null ? 0 : columnBounds.length; if (totalColumnsToBeCreated > 0) { for (int index = 0; index < totalColumnsToBeCreated; index++) { TableColumn column = new TableColumn(table, SWT.NONE); if (index < totalColumnHeaders) { column.setText(columnHeaders[index]); } if (index < totalColBounds) { column.setWidth(columnBounds[index]); } column.setResizable(true); column.setMoveable(true); } } } /** * Sets the table width percentage in relation to the width of the label control. The default value if 100% which * means that it will be the same size as the label control. If you want the table to be wider than the label then * just display a value higher than 100%. * @param ddWidthPct */ public void setTableWidthPercentage(int ddWidthPct) { checkWidget(); // don't accept invalid input. if (ddWidthPct > 0 && ddWidthPct <= 100) { this.tableWidthPercentage = ddWidthPct; } } /** * Sets the zero-relative column index that will be used to display the currently selected item in the label * control. * @param displayColumnIndex */ public void setDisplayColumnIndex(int displayColumnIndex) { checkWidget(); if (displayColumnIndex >= 0) { this.displayColumnIndex = displayColumnIndex; } } /** * returns the column index of the TableColumn to be displayed when selected. * @return */ private int getDisplayColumnIndex() { // make sure the requested column index is valid. return (displayColumnIndex <= (table.getColumnCount() - 1) ? displayColumnIndex : 0); } /* * Return the lowercase of the first non-'&' character following an '&' character in the given string. If there are * no '&' characters in the given string, return '\0'. */ private char _findMnemonic(String string) { if (string == null) return '\0'; int index = 0; int length = string.length(); do { while (index < length && string.charAt(index) != '&') index++; if (++index >= length) return '\0'; if (string.charAt(index) != '&') return Character.toLowerCase(string.charAt(index)); index++; } while (index < length); return '\0'; } /** * Refreshes the label control with the selected object's details. */ private void refreshText(int index) { // get a reference to the selected TableItem TableItem tableItem = table.getItem(index); // get the TableItem index to use for displaying the text. int colIndexToUse = getDisplayColumnIndex(); // set image if requested if (showImageWithinSelection) { // set the selected image selectedImage.setImage(tableItem.getImage(colIndexToUse)); // refresh the layout of the widget internalLayout(false); } // set color if requested if (showColorWithinSelection) { text.setForeground(tableItem.getForeground(colIndexToUse)); } // set font if requested if (showFontWithinSelection) { // set the selected font text.setFont(tableItem.getFont(colIndexToUse)); } // set the label text. String str = tableItem.getText(colIndexToUse); text.setText(str); text.setData(index + ""); // text.selectAll(); text.setSelection(str.length(), str.length()); } /** * @param showImageWithinSelection */ public void setShowImageWithinSelection(boolean showImageWithinSelection) { checkWidget(); this.showImageWithinSelection = showImageWithinSelection; } /** * @param showColorWithinSelection */ public void setShowColorWithinSelection(boolean showColorWithinSelection) { checkWidget(); this.showColorWithinSelection = showColorWithinSelection; } /** * @param showFontWithinSelection */ public void setShowFontWithinSelection(boolean showFontWithinSelection) { checkWidget(); this.showFontWithinSelection = showFontWithinSelection; } /** * returns the Table reference. NOTE: the access is public for now but will most likely be changed in a future * release. * @return */ public Table getTable() { checkWidget(); return table; } /** * determines if the user explicitly set a column width for a given column index. * @param columnIndex * @return */ private boolean wasColumnWidthSpecified(int columnIndex) { return (columnWidths != null && columnWidths.length > columnIndex && columnWidths[columnIndex] != SWT.DEFAULT); } void textEvent(Event event) { switch (event.type) { case SWT.FocusIn: { handleFocus(SWT.FocusIn); break; } case SWT.DefaultSelection: { dropDown(false); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; notifyListeners(SWT.DefaultSelection, e); break; } case SWT.KeyDown: { Event keyEvent = new Event(); keyEvent.time = event.time; keyEvent.character = event.character; keyEvent.keyCode = event.keyCode; keyEvent.stateMask = event.stateMask; notifyListeners(SWT.KeyDown, keyEvent); if (isDisposed()) break; event.doit = keyEvent.doit; if (!event.doit) break; if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) { event.doit = false; if ((event.stateMask & SWT.ALT) != 0) { boolean dropped = isDropped(); text.selectAll(); if (!dropped) setFocus(); dropDown(!dropped); break; } int oldIndex = table.getSelectionIndex(); if (event.keyCode == SWT.ARROW_UP) { select(Math.max(oldIndex - 1, 0)); } else { select(Math.min(oldIndex + 1, getItemCount() - 1)); } if (oldIndex != table.getSelectionIndex()) { Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; notifyListeners(SWT.Selection, e); } if (isDisposed()) break; } // Further work : Need to add support for incremental search in // pop up list as characters typed in text widget break; } case SWT.KeyUp: { Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyUp, e); event.doit = e.doit; break; } case SWT.MenuDetect: { Event e = new Event(); e.time = event.time; notifyListeners(SWT.MenuDetect, e); break; } case SWT.Modify: { table.deselectAll(); Event e = new Event(); e.time = event.time; notifyListeners(SWT.Modify, e); break; } case SWT.MouseDown: { Event mouseEvent = new Event(); mouseEvent.button = event.button; mouseEvent.count = event.count; mouseEvent.stateMask = event.stateMask; mouseEvent.time = event.time; mouseEvent.x = event.x; mouseEvent.y = event.y; notifyListeners(SWT.MouseDown, mouseEvent); if (isDisposed()) break; event.doit = mouseEvent.doit; if (!event.doit) break; if (event.button != 1) return; if (text.getEditable()) return; boolean dropped = isDropped(); text.selectAll(); if (!dropped) setFocus(); dropDown(!dropped); break; } case SWT.MouseUp: { Event mouseEvent = new Event(); mouseEvent.button = event.button; mouseEvent.count = event.count; mouseEvent.stateMask = event.stateMask; mouseEvent.time = event.time; mouseEvent.x = event.x; mouseEvent.y = event.y; notifyListeners(SWT.MouseUp, mouseEvent); if (isDisposed()) break; event.doit = mouseEvent.doit; if (!event.doit) break; if (event.button != 1) return; if (text.getEditable()) return; text.selectAll(); break; } case SWT.MouseDoubleClick: { Event mouseEvent = new Event(); mouseEvent.button = event.button; mouseEvent.count = event.count; mouseEvent.stateMask = event.stateMask; mouseEvent.time = event.time; mouseEvent.x = event.x; mouseEvent.y = event.y; notifyListeners(SWT.MouseDoubleClick, mouseEvent); break; } case SWT.MouseWheel: { Event keyEvent = new Event(); keyEvent.time = event.time; keyEvent.keyCode = event.count > 0 ? SWT.ARROW_UP : SWT.ARROW_DOWN; keyEvent.stateMask = event.stateMask; notifyListeners(SWT.KeyDown, keyEvent); if (isDisposed()) break; event.doit = keyEvent.doit; if (!event.doit) break; if (event.count != 0) { event.doit = false; int oldIndex = table.getSelectionIndex(); if (event.count > 0) { select(Math.max(oldIndex - 1, 0)); } else { select(Math.min(oldIndex + 1, getItemCount() - 1)); } if (oldIndex != table.getSelectionIndex()) { Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; notifyListeners(SWT.Selection, e); } if (isDisposed()) break; } break; } case SWT.Traverse: { switch (event.detail) { case SWT.TRAVERSE_ARROW_PREVIOUS: case SWT.TRAVERSE_ARROW_NEXT: // The enter causes default selection and // the arrow keys are used to manipulate the list contents so // do not use them for traversal. event.doit = false; break; case SWT.TRAVERSE_TAB_PREVIOUS: event.doit = traverse(SWT.TRAVERSE_TAB_PREVIOUS); event.detail = SWT.TRAVERSE_NONE; return; } Event e = new Event(); e.time = event.time; e.detail = event.detail; e.doit = event.doit; e.character = event.character; e.keyCode = event.keyCode; notifyListeners(SWT.Traverse, e); event.doit = e.doit; event.detail = e.detail; break; } case SWT.Verify: { Event e = new Event(); e.text = event.text; e.start = event.start; e.end = event.end; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.Verify, e); event.doit = e.doit; break; } } } /** * adjusts the last table column width to fit inside of the table if the table column data does not fill out the * table area. */ private void autoAdjustColumnWidthsIfNeeded(TableColumn[] tableColumns, int totalAvailWidth, int totalColumnWidthUsage) { int scrollBarSize = 0; int totalColumns = (tableColumns == null ? 0 : tableColumns.length); // determine if the vertical scroll bar needs to be taken into account if (table.getVerticalBar().getVisible()) { scrollBarSize = (table.getVerticalBar() == null ? 0 : table.getVerticalBar().getSize().x); } // is there any extra space that the table is not using? if (totalAvailWidth > totalColumnWidthUsage + scrollBarSize) { int totalAmtToBeAllocated = (totalAvailWidth - totalColumnWidthUsage - scrollBarSize); // add unused space to the last column. if (totalAmtToBeAllocated > 0) { tableColumns[totalColumns - 1].setWidth(tableColumns[totalColumns - 1].getWidth() + totalAmtToBeAllocated); } } } /** * Returns the Text control reference. * @return */ public Text getTextControl() { checkWidget(); return text; } }
71,877
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TableComboViewer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/org.eclipse.nebula.widgets.tablecombo/src/org/eclipse/nebula/jface/tablecomboviewer/TableComboViewer.java
/**************************************************************************** * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Marty Jones <[email protected]> - initial API and implementation * Enrico Schnepel <[email protected]> - added logic to fix bug 304353 *****************************************************************************/ package org.eclipse.nebula.jface.tablecomboviewer; import org.eclipse.jface.viewers.AbstractTableViewer; import org.eclipse.jface.viewers.ColumnViewerEditor; import org.eclipse.jface.viewers.LabelProviderChangedEvent; import org.eclipse.jface.viewers.ViewerRow; import org.eclipse.nebula.widgets.tablecombo.TableCombo; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Widget; /** * TableComboViewerRow is basically identical to the TableViewer class with a few modifications to reference the Table * within the TableCombo widget instead of a parent Table widget. */ public class TableComboViewer extends AbstractTableViewer { private TableCombo tableCombo; /** * The cached row which is reused all over */ private TableComboViewerRow cachedRow; public TableComboViewer(Composite parent) { this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); } /** * Creates a table viewer on a newly-created table control under the given parent. The table control is created * using the given style bits. The viewer has no input, no content provider, a default label provider, no sorter, * and no filters. The table has no columns. * @param parent * the parent control * @param style * SWT style bits */ public TableComboViewer(Composite parent, int style) { this(new TableCombo(parent, style)); } /** * Creates a table viewer on the given table control. The viewer has no input, no content provider, a default label * provider, no sorter, and no filters. * @param table * the table control */ public TableComboViewer(TableCombo tableCombo) { this.tableCombo = tableCombo; hookControl(tableCombo); } /** * {@inheritDoc} */ protected void doClear(int index) { tableCombo.getTable().clear(index); } /** * {@inheritDoc} */ protected void doClearAll() { tableCombo.getTable().clearAll(); } /** * {@inheritDoc} */ protected void doDeselectAll() { tableCombo.getTable().deselectAll(); } /** * {@inheritDoc} */ protected Widget doGetColumn(int index) { return tableCombo.getTable().getColumn(index); } /** * {@inheritDoc} */ protected Item doGetItem(int index) { return tableCombo.getTable().getItem(index); } /** * {@inheritDoc} */ protected int doGetItemCount() { return tableCombo.getTable().getItemCount(); } /** * {@inheritDoc} */ protected Item[] doGetItems() { return tableCombo.getTable().getItems(); } /** * {@inheritDoc} */ protected Item[] doGetSelection() { return tableCombo.getTable().getSelection(); } /** * {@inheritDoc} */ protected int[] doGetSelectionIndices() { return tableCombo.getTable().getSelectionIndices(); } /** * {@inheritDoc} */ protected int doIndexOf(Item item) { return tableCombo.getTable().indexOf((TableItem) item); } /** * {@inheritDoc} */ protected void doRemove(int[] indices) { tableCombo.getTable().remove(indices); } /** * {@inheritDoc} */ protected void doRemove(int start, int end) { tableCombo.getTable().remove(start, end); } /** * {@inheritDoc} */ protected void doRemoveAll() { tableCombo.getTable().removeAll(); } /** * {@inheritDoc} */ protected void doResetItem(Item item) { TableItem tableItem = (TableItem) item; int columnCount = Math.max(1, tableCombo.getTable().getColumnCount()); for (int i = 0; i < columnCount; i++) { tableItem.setText(i, ""); //$NON-NLS-1$ if (tableItem.getImage(i) != null) { tableItem.setImage(i, null); } } } /** * {@inheritDoc} */ protected void doSelect(int[] indices) { tableCombo.select(indices != null && indices.length > 0 ? indices[0] : -1); } /** * {@inheritDoc} */ protected void doSetItemCount(int count) { tableCombo.getTable().setItemCount(count); } /** * {@inheritDoc} */ protected void doSetSelection(Item[] items) { if (items != null && items.length > 0) { tableCombo.select(tableCombo.getTable().indexOf((TableItem) items[0])); } else { tableCombo.select(-1); } } /** * {@inheritDoc} */ protected void doSetSelection(int[] indices) { tableCombo.select(indices != null && indices.length > 0 ? indices[0] : -1); } /** * {@inheritDoc} */ protected void doShowItem(Item item) { tableCombo.getTable().showItem((TableItem) item); } /** * {@inheritDoc} */ protected void doShowSelection() { tableCombo.getTable().showSelection(); } /** * {@inheritDoc} */ protected ViewerRow internalCreateNewRowPart(int style, int rowIndex) { TableItem item; if (rowIndex >= 0) { item = new TableItem(tableCombo.getTable(), style, rowIndex); } else { item = new TableItem(tableCombo.getTable(), style); } return getViewerRowFromItem(item); } /** * {@inheritDoc} */ protected ColumnViewerEditor createViewerEditor() { return null; } /** * {@inheritDoc} */ protected int doGetColumnCount() { return tableCombo.getTable().getColumnCount(); } /** * {@inheritDoc} */ protected Item getItemAt(Point point) { return tableCombo.getTable().getItem(point); } /** * {@inheritDoc} */ protected ViewerRow getViewerRowFromItem(Widget item) { if (cachedRow == null) { cachedRow = new TableComboViewerRow((TableItem) item); } else { cachedRow.setItem((TableItem) item); } return cachedRow; } /** * {@inheritDoc} */ public Control getControl() { return tableCombo; } /** * returns the TableCombo reference. * @return */ public TableCombo getTableCombo() { return tableCombo; } /** * {@inheritDoc} */ protected void handleLabelProviderChanged(LabelProviderChangedEvent event) { super.handleLabelProviderChanged(event); setSelection(getSelection()); } }
6,583
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TableComboViewerRow.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/org.eclipse.nebula.widgets.tablecombo/src/org/eclipse/nebula/jface/tablecomboviewer/TableComboViewerRow.java
/**************************************************************************** * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Marty Jones <[email protected]> - initial API and implementation *****************************************************************************/ package org.eclipse.nebula.jface.tablecomboviewer; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.ViewerRow; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Widget; /** * TableComboViewerRow is basically identical to the TableRow class with a * few modifications to reference the TableComboViewer row instead of a standar * TableViewer row. * */ /** * @author martyj */ public class TableComboViewerRow extends ViewerRow { private TableItem item; /** * Create a new instance of the receiver from item. * @param item */ TableComboViewerRow(TableItem item) { this.item = item; } /** * {@inheritDoc} */ public Rectangle getBounds(int columnIndex) { return item.getBounds(columnIndex); } /** * {@inheritDoc} */ public Rectangle getBounds() { return item.getBounds(); } /** * {@inheritDoc} */ public Widget getItem() { return item; } void setItem(TableItem item) { this.item = item; } /** * {@inheritDoc} */ public int getColumnCount() { return item.getParent().getColumnCount(); } /** * {@inheritDoc} */ public Color getBackground(int columnIndex) { return item.getBackground(columnIndex); } /** * {@inheritDoc} */ public Font getFont(int columnIndex) { return item.getFont(columnIndex); } /** * {@inheritDoc} */ public Color getForeground(int columnIndex) { return item.getForeground(columnIndex); } /** * {@inheritDoc} */ public Image getImage(int columnIndex) { return item.getImage(columnIndex); } /** * {@inheritDoc} */ public String getText(int columnIndex) { return item.getText(columnIndex); } /** * {@inheritDoc} */ public void setBackground(int columnIndex, Color color) { item.setBackground(columnIndex, color); } /** * {@inheritDoc} */ public void setFont(int columnIndex, Font font) { item.setFont(columnIndex, font); } /** * {@inheritDoc} */ public void setForeground(int columnIndex, Color color) { item.setForeground(columnIndex, color); } /** * {@inheritDoc} */ public void setImage(int columnIndex, Image image) { Image oldImage = item.getImage(columnIndex); if (oldImage != image) { item.setImage(columnIndex, image); } } /** * {@inheritDoc} */ public void setText(int columnIndex, String text) { item.setText(columnIndex, text == null ? "" : text); //$NON-NLS-1$ } /** * {@inheritDoc} */ public Control getControl() { return item.getParent(); } /** * {@inheritDoc} */ public ViewerRow getNeighbor(int direction, boolean sameLevel) { if (direction == ViewerRow.ABOVE) { return getRowAbove(); } else if (direction == ViewerRow.BELOW) { return getRowBelow(); } else { throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$ } } private ViewerRow getRowAbove() { int index = item.getParent().indexOf(item) - 1; if (index >= 0) { return new TableComboViewerRow(item.getParent().getItem(index)); } return null; } private ViewerRow getRowBelow() { int index = item.getParent().indexOf(item) + 1; if (index < item.getParent().getItemCount()) { TableItem tmp = item.getParent().getItem(index); // TODO NULL can happen in case of VIRTUAL => How do we deal with that if (tmp != null) { return new TableComboViewerRow(tmp); } } return null; } /** * {@inheritDoc} */ public TreePath getTreePath() { return new TreePath(new Object[] { item.getData() }); } /** * {@inheritDoc} */ public Object clone() { return new TableComboViewerRow(item); } /** * {@inheritDoc} */ public Object getElement() { return item.getData(); } /** * {@inheritDoc} */ public int getVisualIndex(int creationIndex) { int[] order = item.getParent().getColumnOrder(); for (int i = 0; i < order.length; i++) { if (order[i] == creationIndex) { return i; } } return super.getVisualIndex(creationIndex); } /** * {@inheritDoc} */ public int getCreationIndex(int visualIndex) { if (item != null && !item.isDisposed() && hasColumns() && isValidOrderIndex(visualIndex)) { return item.getParent().getColumnOrder()[visualIndex]; } return super.getCreationIndex(visualIndex); } /** * {@inheritDoc} */ public Rectangle getTextBounds(int index) { return item.getTextBounds(index); } /** * {@inheritDoc} */ public Rectangle getImageBounds(int index) { return item.getImageBounds(index); } private boolean hasColumns() { return this.item.getParent().getColumnCount() != 0; } private boolean isValidOrderIndex(int currentIndex) { return currentIndex < this.item.getParent().getColumnOrder().length; } protected boolean scrollCellIntoView(int columnIndex) { item.getParent().showItem(item); if (hasColumns()) { item.getParent().showColumn(item.getParent().getColumn(columnIndex)); } return true; } }
5,670
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDUtilsTest.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/testSrc/net/heartsome/xml/vtdimpl/test/VTDUtilsTest.java
package net.heartsome.xml.vtdimpl.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import java.util.Hashtable; import java.util.Vector; import net.heartsome.xml.vtdimpl.VTDUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import com.ximpleware.AutoPilot; import com.ximpleware.NavException; import com.ximpleware.VTDGen; import com.ximpleware.VTDNav; import com.ximpleware.XPathEvalException; import com.ximpleware.XPathParseException; public class VTDUtilsTest { private final static String testFile = "testSrc/net/heartsome/xml/vtdimpl/test/Test_UTF16LE.txt.xlf"; private static VTDNav vn = null; private static VTDUtils vu = null; @BeforeClass public static void setUp() throws Exception { VTDGen vg = new VTDGen(); if (vg.parseFile(testFile, true)) { vn = vg.getNav(); vu = new VTDUtils(vn); } } @AfterClass public static void tearDown() throws Exception { vn = null; vu = null; } @Test(expected = NavException.class) public void testVTDUtils() throws NavException { vu = new VTDUtils(null); } @Test public void testVTDNavStatus(){ assertNotNull(vn); assertNotNull(vu); } @Test public void testGetChildContent() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=1]"); int inx = ap.evalXPath(); assertNotSame(-1, inx); assertEquals("This <ph id=\"1\">&lt;b&gt;</ph>is the first <ph id=\"2\">&lt;/b&gt;</ph>test.",vu.getChildContent("source")); ap.resetXPath(); ap.selectXPath("//trans-unit"); inx = ap.evalXPath(); assertNotSame(-1, inx); String txt = vu.getChildContent("note"); assertEquals("The note 1.", txt); } @Test public void testGetChildrenContent() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=2]"); ap.evalXPath(); Vector<String> notes = vu.getChildrenContent("note"); assertEquals(3, notes.size()); assertEquals("The 1 note.",notes.get(0)); assertEquals("The 2 note.",notes.get(1)); assertEquals("The 3 note.",notes.get(2)); } @Test public void testGetCurrentElementAttributsNoParams() throws XPathEvalException, NavException, XPathParseException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=2]"); ap.evalXPath(); Hashtable<String,String> eAtts = new Hashtable<String,String>(); eAtts.put("approved","yes"); eAtts.put("id","1"); eAtts.put("merged-trans","yes"); eAtts.put("reformat","yes"); eAtts.put("size-unit","pixel"); eAtts.put("translate","yes"); eAtts.put("xml:space","preserve"); eAtts.put("hs:ext","yes"); eAtts.put("xsi:test", "test"); Hashtable<String,String> aAtts = vu.getCurrentElementAttributs(); assertEquals(eAtts,aAtts); } @Test public void testGetCurrentElementAttributs1Param() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=2]"); ap.evalXPath(); Hashtable<String,String> eAtts = new Hashtable<String,String>(); eAtts.put("approved","yes"); eAtts.put("id","1"); eAtts.put("merged-trans","yes"); eAtts.put("reformat","yes"); eAtts.put("size-unit","pixel"); eAtts.put("translate","yes"); eAtts.put("xml:space","preserve"); eAtts.put("hs:ext","yes"); eAtts.put("xsi:test", "test"); Hashtable<String,String> aAtts = vu.getCurrentElementAttributs("es","http://www.heartsome.net.cn/2008/XLFExtension"); assertEquals(eAtts,aAtts); } @Test public void testGetCurrentElementAttributs2Params() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=2]"); ap.evalXPath(); Hashtable<String,String> eAtts = new Hashtable<String,String>(); eAtts.put("approved","yes"); eAtts.put("id","1"); eAtts.put("merged-trans","yes"); eAtts.put("reformat","yes"); eAtts.put("size-unit","pixel"); eAtts.put("translate","yes"); eAtts.put("xml:space","preserve"); eAtts.put("hs:ext","yes"); eAtts.put("xsi:test", "test"); Hashtable<String,String> ns = new Hashtable<String,String>(); ns.put("http://www.heartsome.net.cn/2008/XLFExtension", "es"); ns.put("http://www.w3.org/2001/XMLSchema-instance", "es"); Hashtable<String,String> aAtts = vu.getCurrentElementAttributs(ns); assertEquals(eAtts,aAtts); } @Test public void testGetElementContent() throws NavException, XPathParseException, XPathEvalException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit/note[position()=1]"); int inx = ap.evalXPath(); assertNotSame(-1, inx); String txt = vu.getElementContent(); assertEquals("The note 1.", txt); } @Test public void testGetElementContent1Param() throws NavException, XPathParseException, XPathEvalException{ String txt = vu.getElementContent("//trans-unit/note[position()=1]"); assertEquals("The note 1.", txt); } @Test public void testGetElementPureText() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=1]/source"); int inx = ap.evalXPath(); assertNotSame(-1, inx); String txt = vu.getElementPureText(); assertEquals("This is the first test.", txt); } @Test public void testGetVTDNav(){ assertNotNull(vu.getVTDNav()); assertSame(vn,vu.getVTDNav()); } @Test public void testGetCurrentElementName() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=1]/source"); int inx = ap.evalXPath(); String name = vu.getCurrentElementName(inx); assertEquals(name, "source"); } @Test public void testGetCurrentElementNameWithoutInx() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//trans-unit[position()=1]/source"); ap.evalXPath(); String name = vu.getCurrentElementName(); assertEquals(name, "source"); } @Test public void testGetChildElementsCount() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/xliff"); ap.evalXPath(); int count = vu.getChildElementsCount(); assertEquals(2, count); } @Test public void testGetChildElementsCount2() throws XPathParseException, XPathEvalException, NavException{ int count = vu.getChildElementsCount("/xliff"); assertEquals(2, count); } @Test public void testGetElementFragment() throws XPathParseException, XPathEvalException, NavException{ AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/xliff/file/header/tool"); ap.evalXPath(); String str = vu.getElementFragment(); assertEquals(str, "<tool tool-id=\"XLFEditor auto-Quick Translation\" tool-name=\"HSStudio\" />"); } }
7,035
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDLoader.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/net/heartsome/xml/vtdimpl/VTDLoader.java
/** * VTDLoader.java * * Version information : * * Date:2013-11-4 * * Copyright notice : * 本文件及其附带的相关文件包含机密信息,仅限瀚特盛科技有限公司指定的,与本项目有关的内部人员和客户联络人员查阅和使用。 * 如果您不是本保密声明中指定的收件者,请立即销毁本文件,禁止对本文件或根据本文件中的内容采取任何其他行动, * 包括但不限于:泄露本文件中的信息、以任何方式制作本文件全部或部分内容之副本、将本文件或其相关副本提供给任何其他人。 */ package net.heartsome.xml.vtdimpl; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.Arrays; import com.ximpleware.ParseException; import com.ximpleware.VTDGen; import com.ximpleware.parser.XMLChar; /** * @author Jason * @version * @since JDK1.6 */ public class VTDLoader { /** * 使用 VTD 解析 XML 文件,返回 VTDGen 对象<br> * 解析 XML 时忽略掉了 XML 标准中的非法字符 * @param file * @return * @throws ParseException * @throws IOException * @throws Exception * ; */ public static VTDGen loadVTDGen(File f, String fileEncoding) throws ParseException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), fileEncoding)); try { char[] cbuf = new char[8192]; int count = reader.read(cbuf); if (count < 20) {// Error Empty File throw new ParseException("Other Error: XML not starting properly"); } StringBuilder _sb = new StringBuilder(); _sb.append(cbuf, 0, count < 500 ? count : 500); // 取前500个字符进行判断 int stIdx = _sb.indexOf("<?xml"); if (stIdx != -1) { // is xml int endIdx = _sb.indexOf("?>"); if (endIdx != -1 && _sb.indexOf("encoding") != -1) { endIdx += 2; String s = "<?xml version=\"1.0\" ?>"; char[] temp = new char[cbuf.length - endIdx + s.length()]; char[] schar = s.toCharArray(); System.arraycopy(schar, 0, temp, 0, schar.length); System.arraycopy(cbuf, endIdx, temp, schar.length, cbuf.length - endIdx); cbuf = temp; count = count - endIdx + s.length(); } } else { throw new ParseException("Other Error: XML not starting properly"); } byte[] bArr = new byte[(int) f.length()]; int i = 0; int idx = 0; while (count > 0) { int tempIdx = 0; char[] tempChar = new char[count]; for (; i < count; i++) { char c = cbuf[i]; if (!XMLChar.isValidChar(c)) { continue; } else if (c == '&') { StringBuilder sb = new StringBuilder(); int val = 0; int j = i + 1; if (j >= count) { c = (char) reader.read(); } else { c = cbuf[j++]; } sb.append(c); if (c == '#') { if (j >= count) { c = (char) reader.read(); } else { c = cbuf[j++]; } sb.append(c); if (c == 'x') { while (true) { if (j >= count) { c = (char) reader.read(); } else { c = cbuf[j++]; } sb.append(c); if (c >= '0' && c <= '9') { val = (val << 4) + (c - '0'); } else if (c >= 'a' && c <= 'f') { val = (val << 4) + (c - 'a' + 10); } else if (c >= 'A' && c <= 'F') { val = (val << 4) + (c - 'A' + 10); } else if (c == ';') { break; } else { break; } } } else { while (true) { if (c >= '0' && c <= '9') { val = val * 10 + (c - '0'); } else if (c == ';') { break; } else { break; } if (j >= count) { c = (char) reader.read(); } else { c = cbuf[j++]; } sb.append(c); } } if (!XMLChar.isValidChar(val)) { if (j <= count) { i = j; } System.out.println((char) val + " " + val + " " + sb); continue; } else { c = cbuf[i]; tempChar[tempIdx++] = c; for (int t = 0; t < sb.length(); t++) { if (tempIdx >= tempChar.length) { tempChar = Arrays.copyOf(tempChar, tempChar.length + 1); count = tempChar.length; } tempChar[tempIdx++] = sb.charAt(t); i++; } } } else { c = cbuf[i]; tempChar[tempIdx++] = c; for (int t = 0; t < sb.length(); t++) { if (tempIdx >= tempChar.length) { tempChar = Arrays.copyOf(tempChar, tempChar.length + 1); count = tempChar.length; } tempChar[tempIdx++] = sb.charAt(t); i++; } } } else { tempChar[tempIdx++] = c; } } if (tempChar.length != 0) { byte[] temp = getBytes(tempChar, 0, tempIdx); System.arraycopy(temp, 0, bArr, idx, temp.length); idx += temp.length; } count = reader.read(cbuf); i = 0; } // FileOutputStream os = new FileOutputStream("C:\\Users\\Jason\\Desktop\\Trados 2007.tmxsasas"); // os.write(bArr, 0, idx); // os.close(); VTDGen vg = new VTDGen(); vg.setDoc(Arrays.copyOf(bArr, idx)); vg.parse(true); return vg; } finally { reader.close(); } } private static byte[] getBytes(char[] chars, int offset, int length) { Charset cs = Charset.defaultCharset(); CharBuffer cb = CharBuffer.wrap(chars, offset, length); ByteBuffer bb = cs.encode(cb); byte[] ba = bb.array(); return Arrays.copyOf(ba, bb.limit()); } }
5,957
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDUtils.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/net/heartsome/xml/vtdimpl/VTDUtils.java
package net.heartsome.xml.vtdimpl; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.StringTokenizer; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.heartsome.xml.resource.Messages; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ximpleware.AutoPilot; import com.ximpleware.ModifyException; import com.ximpleware.NavException; import com.ximpleware.ParseException; import com.ximpleware.TranscodeException; import com.ximpleware.VTDGen; import com.ximpleware.VTDNav; import com.ximpleware.XMLModifier; import com.ximpleware.XPathEvalException; import com.ximpleware.XPathParseException; /** * @author John * @version * @since JDK1.6 */ public class VTDUtils { private static final Logger LOGGER = LoggerFactory.getLogger(VTDUtils.class); /** * 前缀为“xml”的默认命名空间的 URL。 */ public static final String XML_NAMESPACE_URL = "http://www.w3.org/XML/1998/namespace"; /** VTD Navigator 对象 **/ private VTDNav vn; /** VTD Generator 对象 **/ private VTDGen vg; /** * 导航该 XPath 语句直到末尾。 */ public static final int PILOT_TO_END = 1 << 1; /** * 如果不存在该 XPath 对应的节点则创建。 */ public static final int CREATE_IF_NOT_EXIST = 1 << 2; /** * 注意:使用此构造方法,需要手动调用 bind(VTDNav vn) 方法绑定 VTDNav * @see #bind(VTDNav) */ public VTDUtils() { } /** * 使用指定的 XML 导航器对象构建一个 VTDUtils 实例。导航器为 null 时无法完成构建。 * @param vn * XML导航器 * @throws NavException */ public VTDUtils(VTDNav vn) throws NavException { bind(vn); } /** * 解析文件 * @param filePath * 文件路径 * @param useNamespase * 是否需要支持命名空间。如果确定所操作 XML 没有命名空间,可选择不支持(即 false),以提高解析速度。 * @throws ParseException * @throws IOException * ; */ public void parseFile(String filePath, boolean useNamespase) throws ParseException, IOException { if (vg == null) { vg = new VTDGen(); } FileInputStream fis = new FileInputStream(filePath); try { parseFile(fis, useNamespase); } finally { fis.close(); } } /** * 解析文件 * @param is * 文件的输入流 * @param useNamespase * 是否需要支持命名空间。如果确定所操作 XML 没有命名空间,可选择不支持(即 false),以提高解析速度。 * @throws ParseException * @throws IOException * ; */ public void parseFile(InputStream is, boolean useNamespase) throws ParseException, IOException { if (vg == null) { vg = new VTDGen(); } BufferedInputStream bis = new BufferedInputStream(is); try { int available = bis.available(); ByteArrayOutputStream out = new ByteArrayOutputStream(available); int bufferLength = available > 1048576 ? 10485760 : 1048576; // 1048576 = 1024 * 1024 byte[] buffer = new byte[bufferLength]; int len = -1; while ((len = bis.read(buffer)) > 0) { out.write(buffer, 0, len); } vg.setDoc(out.toByteArray()); out.close(); vg.parse(useNamespase); vn = vg.getNav(); } finally { bis.close(); } } /** * 将一个 VTDNav 实例附加到此 VTDUtils 实例,以便之后发生的所有操作都是基于这个 VTDNav 实例 * @param masterDocument * VTDNav 实例 * @throws NavException */ public void bind(VTDNav vn) throws NavException { if (vn == null) { throw new NavException(Messages.getString("vtdimpl.VTDUtils.logger1")); } this.vn = vn; } /** * 获取当前元素节点的某个属性值。如果当前节点没有该属性,返回默认值。 * @exception NavException */ public String getCurrentElementAttribut(String AttributName, String defaultValue) throws NavException { int index = vn.getAttrVal(AttributName); return index != -1 ? vn.toString(index) : defaultValue; } /** * 获取当前元素节点的全部属性。如果当前节点没有属性,返回 null。 * @exception XPathEvalException * ,XPathParseException,NavException */ public Hashtable<String, String> getCurrentElementAttributs() throws XPathParseException, XPathEvalException, NavException { vn.push(); Hashtable<String, String> attributes = new Hashtable<String, String>(); AutoPilot apAttributes = new AutoPilot(vn); apAttributes.selectXPath("@*"); int inx = -1; while ((inx = apAttributes.evalXPath()) != -1) { String name = vn.toString(inx); inx = vn.getAttrVal(name); String value = inx != -1 ? vn.toString(inx) : ""; attributes.put(name, value); } apAttributes.resetXPath(); if (attributes.isEmpty()) { attributes = null; } vn.pop(); return attributes; } /** * 获取所有当前元素节点的全部属性。如果当前节点没有属性,返回 null。 * @param nsPrefix * 需声明的名空间前缀,可与XML文件实际前缀不同。 * @param nsUrl * 需声明的名空间地址,必须与 XML 文件中声明的地址一致。 * @exception XPathEvalException * ,XPathParseException,NavException */ public Hashtable<String, String> getCurrentElementAttributs(String nsPrefix, String nsUrl) throws XPathParseException, XPathEvalException, NavException { Hashtable<String, String> attributes = new Hashtable<String, String>(); AutoPilot apAttributes = new AutoPilot(vn); apAttributes.declareXPathNameSpace(nsPrefix, nsUrl); apAttributes.selectXPath("@*"); int inx = -1; while ((inx = apAttributes.evalXPath()) != -1) { String name = vn.toString(inx); inx = vn.getAttrVal(name); String value = inx != -1 ? vn.toString(inx) : ""; attributes.put(name, value); } apAttributes.resetXPath(); if (attributes.isEmpty()) { attributes = null; } return attributes; } /** * 获取当前节点的名称 * @param index * 当前节点所在的索引 * @return * @throws NavException */ public String getCurrentElementName(int index) throws NavException { return vn.toString(index); } /** * 获取当前节点的名称 * @return * @throws NavException */ public String getCurrentElementName() throws NavException { return vn.toString(vn.getCurrentIndex()); } /** * 获取所有当前元素节点的全部属性。如果当前节点没有属性,返回 null。 * @param ns * 需声明的名空间,键为地址,必须与 XML 文件中声明的地址一致。值为前缀,可与XML文件实际前缀不同。 * @exception XPathEvalException * ,XPathParseException,NavException */ public Hashtable<String, String> getCurrentElementAttributs(Hashtable<String, String> ns) throws XPathParseException, XPathEvalException, NavException { Hashtable<String, String> attributes = new Hashtable<String, String>(); AutoPilot apAttributes = new AutoPilot(vn); if (ns != null) { Iterator<String> nsIt = ns.keySet().iterator(); while (nsIt.hasNext()) { String nsUrl = nsIt.next(); String nsPrefix = ns.get(nsUrl); apAttributes.declareXPathNameSpace(nsPrefix, nsUrl); } } apAttributes.selectXPath("@*"); int inx = -1; while ((inx = apAttributes.evalXPath()) != -1) { String name = vn.toString(inx); inx = vn.getAttrVal(name); String value = inx != -1 ? vn.toString(inx) : ""; attributes.put(name, value); } apAttributes.resetXPath(); if (attributes.isEmpty()) { attributes = null; } return attributes; } /** * 得到当前节点的纯文本。实体会被转义。若无文本内容返回 null。 * @exception XPathParseException * ,XPathEvalException,NavException */ public String getElementPureText() throws XPathParseException, XPathEvalException, NavException { String txtNode = "./text()"; AutoPilot ap = new AutoPilot(vn); StringBuilder result = new StringBuilder(); ap.selectXPath(txtNode); int txtIndex = -1; boolean isNull = true; while ((txtIndex = ap.evalXPath()) != -1) { result.append(vn.toString(txtIndex)); if (isNull) { isNull = false; } } return isNull ? null : result.toString(); } /** * 得到当前节点的纯文本。实体不会被转义。若无文本内容返回 null。 * @exception XPathParseException * ,XPathEvalException,NavException */ public String getElementRawPureText() throws XPathParseException, XPathEvalException, NavException { String txtNode = "./text()"; AutoPilot ap = new AutoPilot(vn); StringBuilder result = new StringBuilder(); ap.selectXPath(txtNode); int txtIndex = -1; while ((txtIndex = ap.evalXPath()) != -1) { result.append(vn.toRawString(txtIndex)); } if (result.length() == 0) { return null; } else { return result.toString(); } } /** * 得到当前节点的完整内容,包含子节点及文本。若无文本内容返回 null。 * @throws NavException */ public String getElementContent() throws NavException { String result = null; long l = vn.getContentFragment(); if (l == -1) { return null; } int offset = (int) l; int len = (int) (l >> 32); if (offset != -1 && len != -1) { if (vn.getEncoding() > VTDNav.FORMAT_WIN_1258) { offset = offset >> 1; len = len >> 1; } result = vn.toRawString(offset, len); } return result; } /** * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。 * @param elementName * 子节点名称 * @throws XPathParseException * @throws NavException * @throws XPathEvalException */ public Vector<String> getChildrenContent(String elementName) throws XPathParseException, XPathEvalException, NavException { Vector<String> texts = new Vector<String>(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("./" + elementName); while (ap.evalXPath() != -1) { vn.push(); texts.add(getElementContent()); vn.pop(); } if (texts.isEmpty()) { texts = null; } return texts; } /** * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。 * @param elementName * 子节点名称 * @return String 指定子节点内容,无内容返回 null。 * @throws XPathParseException * @throws NavException * @throws XPathEvalException */ public String getChildContent(String elementName) throws XPathParseException, XPathEvalException, NavException { String text = null; AutoPilot ap = new AutoPilot(vn); ap.selectXPath("./" + elementName); vn.push(); if (ap.evalXPath() != -1) { text = getElementContent(); } vn.pop(); return text; } /** * 返回当前节点下一级子节点的个数。 * @return * @throws XPathParseException * @throws XPathEvalException * @throws NavException * ; */ public int getChildElementsCount() throws XPathParseException, XPathEvalException, NavException { int result = 0; AutoPilot ap = new AutoPilot(vn); ap.selectXPath("./*"); vn.push(); while (ap.evalXPath() != -1) { result++; } vn.pop(); return result; } /** * 获得指定节点下一级子节点的个数 * @param xpath * 指定节点的 XPath * @return * @throws XPathParseException * @throws XPathEvalException * @throws NavException * ; */ public int getChildElementsCount(String xpath) throws XPathParseException, XPathEvalException, NavException { int result = 0; AutoPilot ap = new AutoPilot(vn); ap.selectXPath(xpath); vn.push(); if (ap.evalXPath() != -1) { result = getChildElementsCount(); } vn.pop(); return result; } /** * 得到指定节点的完整内容,包含子节点及文本。若无文本内容返回 null。 * @param xpath * 指定节点的XPath。 * @throws XPathParseException * @throws XPathEvalException * @throws NavException * @exception XPathParseException * ,XPathEvalException,NavException */ public String getElementContent(String xpath) throws NavException, XPathParseException, XPathEvalException { String text = null; if (xpath != null && !xpath.equals("")) { AutoPilot ap = new AutoPilot(vn); ap.selectXPath(xpath); vn.push(); if (ap.evalXPath() != -1) { text = getElementContent(); } vn.pop(); } return text; } /** * 获取绑定的 XML 导航器对象。 */ public VTDNav getVTDNav() { return vn; } /** * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。 * @param elementName * 子节点名称 * @return String 指定子节点内容,无内容返回 null。 * @throws XPathParseException * @throws XPathParseException * @throws NavException * @throws NavException * @throws XPathEvalException * @throws XPathEvalException */ public String getChildPureText(String elementName) throws XPathParseException, NavException, XPathEvalException { String text = null; AutoPilot ap = new AutoPilot(vn); ap.selectXPath("./" + elementName); vn.push(); if (ap.evalXPath() != -1) { text = getElementPureText(); } vn.pop(); return text; } /** * 获得元素的属性值 * @param elementXPath * 指定元素的 XPath * @param attributeName * 指定属性的名称 * @return * @throws XPathParseException * @throws XPathEvalException * @throws NavException * ; */ public String getElementAttribute(String elementXPath, String attributeName) throws XPathParseException, XPathEvalException, NavException { String text = null; AutoPilot ap = new AutoPilot(vn); ap.selectXPath(elementXPath); vn.push(); if (ap.evalXPath() != -1) { int inx = vn.getAttrVal(attributeName); if (inx != -1) { text = vn.toString(inx); } } vn.pop(); return text; } /** * 获得整个节点的段落 * @return 整个节点的段落,例如:&lt;ph id="1"&gt;a&lt;/ph&gt; * @throws NavException * ; */ public String getElementFragment() throws NavException { long l = vn.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); /* 区别编码。在解析 UTF-16 等部分编码的时候索引会变为2倍。 */ if (vn.getEncoding() > VTDGen.FORMAT_WIN_1258) { offset = offset >> 1; len = len >> 1; } // 处理这种情况下获取内容错误的情况 <ph>...</ph> 1><ph>...</ph> robert 2012-09-13 String fragment = ""; try { fragment = vn.toRawString(offset, len); } catch (NavException e) { if (e.getMessage().contains("encoding error")) { byte[] doc = vn.getXML().getBytes(); if (vn.getEncoding() == VTDNav.FORMAT_UTF_16LE || vn.getEncoding() == VTDNav.FORMAT_UTF_16BE) { offset = offset << 1; } String line = formatLineNumber(doc, offset, vn); throw new NavException("encoding error:" + line); } throw e; } int length = fragment.length(); int realEndIdx = fragment.indexOf(">", fragment.lastIndexOf("<")); if (realEndIdx != length - 1) { fragment = fragment.substring(0, fragment.indexOf(">", fragment.lastIndexOf("<")) + 1); } return fragment; } private String formatLineNumber(byte[] XMLDoc, int os, VTDNav vn) { int so = 0; int lineNumber = 0; int lineOffset = 0; if (vn.getEncoding() < VTDNav.FORMAT_UTF_16BE) { while (so <= os - 1) { if (XMLDoc[so] == '\n') { lineNumber++; lineOffset = so; } // lineOffset++; so++; } lineOffset = os - lineOffset; } else if (vn.getEncoding() == VTDNav.FORMAT_UTF_16BE) { while (so <= os - 2) { if (XMLDoc[so + 1] == '\n' && XMLDoc[so] == 0) { lineNumber++; lineOffset = so; } so += 2; } lineOffset = (os - lineOffset) >> 1; } else { while (so <= os - 2) { if (XMLDoc[so] == '\n' && XMLDoc[so + 1] == 0) { lineNumber++; lineOffset = so; } so += 2; } lineOffset = (os - lineOffset) >> 1; } return "\nLine Number: " + (lineNumber + 1) + " Offset: " + (lineOffset - 1); } private static final Pattern PATTERN = Pattern.compile("<[^>]+>"); /** * 获得节点的头部 * @return 节点头部,例如:&lt;ph id="1"&gt;a&lt;/ph&gt;,则返回&lt;ph id="1"&gt; * @throws NavException * ; */ public String getElementHead() throws NavException { String sourceFragment = getElementFragment(); // 节点的段落 Matcher matcher = PATTERN.matcher(sourceFragment); if (matcher.find()) { String elementHead = matcher.group(); if (elementHead.endsWith("/>")) { return elementHead.substring(0, elementHead.length() - 2) + ">"; } return elementHead; } return null; } /** * 得到一个节点的XML格式的文本 * @param name * 节点名 * @param content * 节点内容,值为null时表示独立节点。 * @param props * 节点属性 * @return ; */ public static String getNodeXML(String name, String content, Hashtable<String, String> props) { if (name == null || "".equals(name)) { return null; } StringBuffer xml = new StringBuffer("<"); xml.append(name); if (props != null && !props.isEmpty()) { for (Entry<String, String> entry : props.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key == null || "".equals(key) || value == null) { continue; } xml.append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); } } if (content == null) { xml.append(" />"); } else { xml.append(">").append(content).append("</").append(name).append(">"); } return xml.toString(); } /** * 获取非节点 XPath 表达式计算的值。<br/> * 非节点 XPath:导航到的位置不是简单的 XML 内容。 * <p> * 例如“count”等函数的返回值。 <br/> * <code>Double count = getEvalValue(Double.class, "count(//a)");</code> * </p> * @param <T> * 结果类型 * @param clazz * 结果类型 * @param xpath * XPath 表达式 * @return XPath 表达式计算的值; */ public <T> T getEvalValue(Class<T> clazz, String xpath) { return getEvalValue(clazz, null, xpath); } /** * 获取非节点 XPath 表达式计算的值。<br/> * 非节点 XPath:导航到的位置不是简单的 XML 内容。 * <p> * 例如“count”等函数的返回值。 <br/> * <code>Double count = getEvalValue(Double.class, "count(//a)");</code> * </p> * @param <T> * 结果类型 * @param clazz * 结果类型 * @param ap * AutoPilot 实例 * @param xpath * XPath 表达式 * @return XPath 表达式计算的值; */ @SuppressWarnings("unchecked") public <T> T getEvalValue(Class<T> clazz, AutoPilot ap, String xpath) { if (ap == null) { ap = new AutoPilot(vn); } try { vn.push(); ap.selectXPath(xpath); if (String.class.equals(clazz)) { String value; if ((value = ap.evalXPathToString()) != null) { return (T) value; } } else if (Double.class.equals(clazz)) { Double value; if ((value = ap.evalXPathToNumber()) != -1) { return (T) value; } } else if (Boolean.class.equals(clazz)) { Boolean value; if ((value = ap.evalXPathToBoolean()) != false) { return (T) value; } } } catch (XPathParseException e) { LOGGER.error("", e); } finally { vn.pop(); } return null; } /** * <p> * 根据 XPath 取值(XPath 支持相对定位)。<br/> * 使用此方法时,可以结合 {@link #pilot(String)} 或 {@link #pilot(AutoPilot, String)} 方法采用相对定位,可以大大提高导航效率 * </p> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param xpath * XPath 表达式 * @return XPath 得到的值; */ public String getValue(String xpath) { return getValue(null, xpath, null); } /** * <p> * 根据 XPath 取值(XPath 支持相对定位)。<br/> * 使用此方法时,可以结合 {@link #pilot(String)} 或 {@link #pilot(AutoPilot, String)} 方法采用相对定位,可以大大提高导航效率 * </p> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param xpath * XPath 表达式 * @param defaultValue * 默认值 * @return XPath 得到的值; */ public String getValue(String xpath, String defaultValue) { return getValue(null, xpath, defaultValue); } /** * <p> * 根据 XPath 取值(XPath 支持相对定位)。<br/> * 使用此方法时,可以结合 {@link #pilot(String)} 或 {@link #pilot(AutoPilot, String)} 方法采用相对定位,可以大大提高导航效率 * </p> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param ap * AutoPilot 实例 * @param xpath * XPath 表达式 * @return XPath 得到的值; */ public String getValue(AutoPilot ap, String xpath) { return getValue(ap, xpath, null); } /** * <p> * 根据 XPath 取值(XPath 支持相对定位)。<br/> * 使用此方法时,可以结合 {@link #pilot(String)} 或 {@link #pilot(AutoPilot, String)} 方法采用相对定位,可以大大提高导航效率 * </p> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param ap * AutoPilot 实例 * @param xpath * XPath 表达式 * @param defaultValue * 默认值 * @return XPath 得到的值; */ public String getValue(AutoPilot ap, String xpath, String defaultValue) { if (ap == null) { ap = new AutoPilot(vn); } String value = null; try { vn.push(); if (xpath.endsWith("/puretext()")) { xpath = xpath.substring(0, xpath.length() - "/puretext()".length()); ap.selectXPath(xpath); if (ap.evalXPath() != -1) { value = getElementPureText(); } } else if (xpath.endsWith("/text()")) { xpath = xpath.substring(0, xpath.length() - "/text()".length()); ap.selectXPath(xpath); if (ap.evalXPath() != -1) { value = getElementContent(); } } else { boolean isAttrName = false; // 是否是取属性名字 if (xpath.endsWith("[name]")) { xpath = xpath.substring(0, xpath.length() - "[name]".length()); isAttrName = true; } ap.selectXPath(xpath); if (ap.evalXPath() != -1) { int type = vn.getTokenType(vn.getCurrentIndex()); if (type == VTDNav.TOKEN_STARTING_TAG) { long l = vn.getElementFragment(); value = vn.toString((int) l, (int) (l >> 32)); } else if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { if (isAttrName) { value = vn.toString(vn.getCurrentIndex()); } else { value = vn.toString(vn.getCurrentIndex() + 1); } } else { value = vn.toString(vn.getCurrentIndex()); } } } } catch (XPathParseException e) { LOGGER.error("", e); } catch (XPathEvalException e) { LOGGER.error("", e); } catch (NavException e) { LOGGER.error("", e); } finally { vn.pop(); } return value == null ? defaultValue : value; } /** * 根据 XPath 取一个集合的值。<br/> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param ap * AutoPilot 对象 * @param xpath * XPath 表达式 * @param isAllowRepeat * 是否允许取值重复。 * @return XPath 得到的值,无匹配的值则为 null; */ public List<String> getValues(AutoPilot ap, String xpath, boolean isAllowRepeat) { if (ap == null) { ap = new AutoPilot(vn); } List<String> values = new Vector<String>(); try { vn.push(); if (xpath.endsWith("/puretext()")) { xpath = xpath.substring(0, xpath.length() - "/puretext()".length()); ap.selectXPath(xpath); if (ap.evalXPath() != -1) { String strTmpValue = getElementPureText(); if (isAllowRepeat) { values.add(strTmpValue); } else { if (!values.contains(strTmpValue)) { values.add(strTmpValue); } } } } else if (xpath.endsWith("/text()")) { xpath = xpath.substring(0, xpath.length() - "/text()".length()); ap.selectXPath(xpath); while (ap.evalXPath() != -1) { String strTmpValue = getElementContent(); if (isAllowRepeat) { values.add(strTmpValue); } else { if (!values.contains(strTmpValue)) { values.add(strTmpValue); } } } } else { boolean isAttrName = false; if (xpath.endsWith("[name]")) { xpath = xpath.substring(0, xpath.length() - "[name]".length()); isAttrName = true; } ap.selectXPath(xpath); while (ap.evalXPath() != -1) { int type = vn.getTokenType(vn.getCurrentIndex()); if (type == VTDNav.TOKEN_STARTING_TAG) { long l = vn.getElementFragment(); String strTmpValue = vn.toString((int) l, (int) (l >> 32)); if (isAllowRepeat) { values.add(strTmpValue); } else { if (!values.contains(strTmpValue)) { values.add(strTmpValue); } } } else if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { String strTmpValue; if (isAttrName) { strTmpValue = vn.toString(vn.getCurrentIndex()); } else { strTmpValue = vn.toString(vn.getCurrentIndex() + 1); } if (isAllowRepeat) { values.add(strTmpValue); } else { if (!values.contains(strTmpValue)) { values.add(strTmpValue); } } } else { String strTmpValue = vn.toString(vn.getCurrentIndex()); if (isAllowRepeat) { values.add(strTmpValue); } else { if (!values.contains(strTmpValue)) { values.add(strTmpValue); } } } } } } catch (XPathParseException e) { LOGGER.error("", e); } catch (XPathEvalException e) { LOGGER.error("", e); } catch (NavException e) { LOGGER.error("", e); } finally { vn.pop(); } if (values.size() == 0) { values = null; } return values; } /** * 根据 XPath 取一个不包含重复值的集合。<br/> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param ap * AutoPilot 对象 * @param xpath * XPath 表达式 * @return XPath 得到的值,无匹配的值则为 null; */ public List<String> getValues(AutoPilot ap, String xpath) { return getValues(ap, xpath, false); } /** * 根据 XPath 取一个不包含重复值的集合。<br/> * <b>注意</b>在XPath基础上,添加关键字“[name]”、“puretext()”的支持: <li>[name]:用于取得指定属性名称,例如,/a/@*[name] 取得 a 节点下所有属性的名字</li> <li> * puretext():用于取得指定节点的纯文本内容(排除子节点),例如,/a/puretext() 取得 a 节点的纯文本内容</li> * @param xpath * XPath 表达式 * @return XPath 得到的值,无匹配的值则为 null; */ public List<String> getValues(String xpath) { return getValues(null, xpath, false); } /** * 删除 XPath 表达式所定位到的内容 * @param xpath * xpath表达式 * @return XMLModifier 实例; */ public XMLModifier delete(String xpath) { return delete(null, null, xpath); } /** * 删除 XPath 表达式所定位到的内容 * @param xpath * xpath表达式 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier delete(String xpath, int condition) { return delete(null, null, xpath, condition); } /** * 删除 XPath 表达式所定位到的内容 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * xpath表达式 * @return XMLModifier 实例; */ public XMLModifier delete(AutoPilot ap, XMLModifier xm, String xpath) { return update(ap, xm, xpath, null, 0); // 默认只导航一次 } /** * 删除 XPath 表达式所定位到的内容 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * xpath表达式 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier delete(AutoPilot ap, XMLModifier xm, String xpath, int condition) { return update(ap, xm, xpath, null, condition); } /** * 修改 XPath 表达式所定位到的内容 * @param xpath * xpath表达式 * @param newValue * 要修改的新值 * @return XMLModifier 实例; */ public XMLModifier update(String xpath, String newValue) { return update(null, null, xpath, newValue); } /** * 修改 XPath 表达式所定位到的内容 * @param xpath * xpath表达式 * @param newValue * 要修改的新值 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier update(String xpath, String newValue, int condition) { return update(null, null, xpath, newValue, condition); } /** * 修改 XPath 表达式所定位到的内容 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * xpath表达式 * @param newValue * 要修改的新值 * @return XMLModifier 实例; */ public XMLModifier update(AutoPilot ap, XMLModifier xm, String xpath, String newValue) { return update(ap, xm, xpath, newValue, 0); // 默认只导航一次 } /** * 修改 XPath 表达式所定位到的内容 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * xpath表达式 * @param newValue * 要修改的新值 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier update(AutoPilot ap, XMLModifier xm, String xpath, String newValue, int condition) { return handleXML(ap, xm, xpath, newValue, condition, true); } /** * 处理 XPath 表达式所定位到的 XML 内容 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * xpath表达式 * @param newValue * 要修改的新值 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ private XMLModifier handleXML(AutoPilot ap, XMLModifier xm, String xpath, String newValue, int condition, boolean remove) { try { vn.push(); if (ap == null) { ap = new AutoPilot(vn); } if (xm == null) { xm = new XMLModifier(vn); } boolean pilotToEnd = (condition & PILOT_TO_END) != 0; boolean isContent = false; if (xpath.endsWith("/text()")) { // 操作的是内容节点。 xpath = xpath.substring(0, xpath.length() - "/text()".length()); isContent = true; } ap.selectXPath(xpath); boolean exist = false; while (ap.evalXPath() != -1) { exist = true; long contentFragment = vn.getContentFragment(); int currentIndex = vn.getCurrentIndex(); int type = vn.getTokenType(currentIndex); if (remove || newValue == null) { // newValue 为 null,执行移除操作 if (isContent) { if (contentFragment != -1) { // 执行删除 xm.remove(contentFragment); // 删除内容 } } else { // 属性节点不执行删除,除非调用 delete 方法(判断是否调用 delete 方法的依据是,newValue 是否为 null) if ((type != VTDNav.TOKEN_ATTR_NAME && type != VTDNav.TOKEN_ATTR_NS) || newValue == null) { xm.remove(); // 删除节点 } } } if (newValue != null) { // 执行修改 if (isContent) { xm.insertBeforeTail(newValue.getBytes(getCharsetByEncoding())); } else { if (type == VTDNav.TOKEN_STARTING_TAG) { xm.insertAfterElement(newValue); } else if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { xm.updateToken(currentIndex + 1, newValue); } else { xm.updateToken(currentIndex, newValue.getBytes()); } } } if (!pilotToEnd) { // 不需要导航到 XML 末尾,停止循环 break; } } boolean createIfNotExist = (condition & CREATE_IF_NOT_EXIST) != 0; if (!exist && createIfNotExist) { // 如果不存在并且需要创建 int lastSeperator = xpath.lastIndexOf("/"); String nodeName = xpath.substring(lastSeperator + 1); xpath = xpath.substring(0, lastSeperator); // 截掉最后一部分 if (nodeName.startsWith("@")) { nodeName = nodeName.substring(1); ap.selectXPath(xpath); while (ap.evalXPath() != -1) { insertAttribute(xm, nodeName, newValue); // 插入属性 if (!pilotToEnd) { // 不需要导航到 XML 末尾,停止循环 break; } } } else { if (isContent) { // 如果改动的是节点内容 newValue = getNodeXML(nodeName, newValue, null); ap.selectXPath(xpath); while (ap.evalXPath() != -1) { xm.insertAfterHead(newValue); if (!pilotToEnd) { // 不需要导航到 XML 末尾,停止循环 break; } } } } } } catch (XPathParseException e) { LOGGER.error("", e); } catch (XPathEvalException e) { LOGGER.error("", e); } catch (NavException e) { LOGGER.error("", e); } catch (ModifyException e) { LOGGER.error("", e); } catch (UnsupportedEncodingException e) { LOGGER.error("", e); } finally { vn.pop(); } return xm; } /** * 插入新属性(到最后的位置)。 * @param xm * @param attrName * @param attrValue * @throws ModifyException * ; */ private void insertAttribute(XMLModifier xm, String attrName, String attrValue) throws ModifyException { int startTagIndex = vn.getCurrentIndex(); int type = vn.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); String attrFragment = new StringBuffer(" ").append(attrName).append("=\"").append(attrValue).append("\"") .toString(); // 构建属性片段,“ attrName="attrValue" ” long i = vn.getOffsetAfterHead(); // 得到开始标记的结束位置 if (vn.getEncoding() < VTDNav.FORMAT_UTF_16BE) { xm.insertBytesAt((int) i - 1, attrFragment.getBytes()); } else { xm.insertBytesAt(((int) i - 1) << 1, attrFragment.getBytes()); } } /** * 将新值插入到 XPath 表达式所定位到的位置 * @param xpath * XPath 表达式 * @param newValue * 要修改的新值 * @return XMLModifier 实例; */ public XMLModifier insert(String xpath, String newValue) { return insert(null, null, xpath, newValue); } /** * 将新值插入到 XPath 表达式所定位到的位置 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * XPath 表达式 * @param newValue * 要修改的新值 * @return XMLModifier 实例; */ public XMLModifier insert(AutoPilot ap, XMLModifier xm, String xpath, String newValue) { return insert(ap, xm, xpath, newValue, 0); } /** * 将新值插入到 XPath 表达式所定位到的位置 * @param xpath * XPath 表达式 * @param newValue * 要修改的新值 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier insert(String xpath, String newValue, int condition) { return insert(null, null, xpath, newValue, condition); } /** * 将新值插入到 XPath 表达式所定位到的位置 * @param ap * AutoPilot 实例 * @param xm * XMLModifier 实例 * @param xpath * XPath 表达式 * @param newValue * 要修改的新值 * @param condition * 本次操作的限定条件 * @return XMLModifier 实例; */ public XMLModifier insert(AutoPilot ap, XMLModifier xm, String xpath, String newValue, int condition) { return handleXML(ap, xm, xpath, newValue, condition | CREATE_IF_NOT_EXIST, false); } /** * 导航 * @param xpath * XPath 表达式 * @return 导航到的位置索引(-1:导航失败); */ public int pilot(String xpath) { return pilot(null, xpath); } /** * 导航 * @param ap * AutoPilot 对象 * @param xpath * XPath 表达式 * @return 导航到的位置索引(-1:导航失败); */ public int pilot(AutoPilot ap, String xpath) { if (ap == null) { ap = new AutoPilot(vn); } try { ap.selectXPath(xpath); return ap.evalXPath(); } catch (XPathParseException e) { LOGGER.error("", e); } catch (XPathEvalException e) { LOGGER.error("", e); } catch (NavException e) { LOGGER.error("", e); } return -1; } /** * 在 XPath 中转义引号(解决在 XPath 中某个字符串同时含有单引号和双引号的情况) * @param xpath * @return ; */ public static String dealEscapeQuotes(String xpath) { StringBuffer sb = new StringBuffer(); if (xpath.indexOf('\'') != -1) { StringTokenizer st = new StringTokenizer(xpath, "'\"", true); sb.append("concat("); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equalsIgnoreCase("'")) { sb.append("\""); sb.append(token); sb.append("\""); } else { sb.append("'"); sb.append(token); sb.append("'"); } if (st.countTokens() != 0) { sb.append(","); } } sb.append(")"); } else { sb.append("'"); sb.append(xpath); sb.append("'"); } return sb.toString(); } /** * 保存修改并更新 VTDNav 实例 * @param xm * XMLModifier 实例 * @param filePath * 文件路径 * @return VTDNav 实例 */ public VTDNav updateVTDNav(XMLModifier xm, String filePath) { try { File file = new File(filePath); FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); xm.output(bos); bos.close(); fos.close(); VTDGen vg = new VTDGen(); if (vg.parseFile(filePath, true)) { // 重新加载 vn = vg.getNav(); } } catch (ModifyException e) { LOGGER.error("", e); } catch (TranscodeException e) { LOGGER.error("", e); } catch (IOException e) { LOGGER.error("", e); } return vn; } /** * 根据 vn 的 encoding 获取字符集编码(此方法与 XMLModifier 的 bind 方法中获取字符集的方式一致) * @return * @throws ModifyException * ; */ public String getCharsetByEncoding() throws ModifyException { int encoding = vn.getEncoding(); switch (encoding) { case VTDNav.FORMAT_ASCII: return "ASCII"; case VTDNav.FORMAT_ISO_8859_1: return "ISO8859_1"; case VTDNav.FORMAT_UTF8: return "UTF8"; case VTDNav.FORMAT_UTF_16BE: return "UnicodeBigUnmarked"; case VTDNav.FORMAT_UTF_16LE: return "UnicodeLittleUnmarked"; case VTDNav.FORMAT_ISO_8859_2: return "ISO8859_2"; case VTDNav.FORMAT_ISO_8859_3: return "ISO8859_3"; case VTDNav.FORMAT_ISO_8859_4: return "ISO8859_4"; case VTDNav.FORMAT_ISO_8859_5: return "ISO8859_5"; case VTDNav.FORMAT_ISO_8859_6: return "ISO8859_6"; case VTDNav.FORMAT_ISO_8859_7: return "ISO8859_7"; case VTDNav.FORMAT_ISO_8859_8: return "ISO8859_8"; case VTDNav.FORMAT_ISO_8859_9: return "ISO8859_9"; case VTDNav.FORMAT_ISO_8859_10: return "ISO8859_10"; case VTDNav.FORMAT_ISO_8859_11: return "x-iso-8859-11"; case VTDNav.FORMAT_ISO_8859_12: return "ISO8859_12"; case VTDNav.FORMAT_ISO_8859_13: return "ISO8859_13"; case VTDNav.FORMAT_ISO_8859_14: return "ISO8859_14"; case VTDNav.FORMAT_ISO_8859_15: return "ISO8859_15"; case VTDNav.FORMAT_WIN_1250: return "Cp1250"; case VTDNav.FORMAT_WIN_1251: return "Cp1251"; case VTDNav.FORMAT_WIN_1252: return "Cp1252"; case VTDNav.FORMAT_WIN_1253: return "Cp1253"; case VTDNav.FORMAT_WIN_1254: return "Cp1254"; case VTDNav.FORMAT_WIN_1255: return "Cp1255"; case VTDNav.FORMAT_WIN_1256: return "Cp1256"; case VTDNav.FORMAT_WIN_1257: return "Cp1257"; case VTDNav.FORMAT_WIN_1258: return "Cp1258"; default: throw new ModifyException(Messages.getString("vtdimpl.VTDUtils.logger2")); } } }
42,743
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Messages.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/net/heartsome/xml/resource/Messages.java
package net.heartsome.xml.resource; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * 国际化工具类 * @author peason * @version * @since JDK1.6 */ public class Messages { private static final String BUNDLE_NAME = "net.heartsome.xml.resource.message"; private static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); public static String getString(String key) { try { return BUNDLE.getString(key); } catch (MissingResourceException e) { return key; } } }
536
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NavException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/NavException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This exception is for any exception conditions during navigation phase. * Creation date: (11/19/03 11:42:28 AM) */ public class NavException extends VTDException { /** * NavException constructor comment. */ public NavException() { super(); } /** * NavException constructor comment. * @param s java.lang.String */ public NavException(String s) { super(s); } }
1,220
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Expr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/Expr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.*; /** * * This is the abstract class on which all XPath expressions * are based */ abstract public class Expr { abstract public boolean evalBoolean(VTDNav vn); abstract public double evalNumber(VTDNav vn); abstract public int evalNodeSet(VTDNav vn) throws XPathEvalException, NavException; abstract public String evalString(VTDNav vn); abstract public void reset(VTDNav vn); abstract public String toString(); abstract public boolean isNumerical(); abstract public boolean isNodeSet(); abstract public boolean isString(); abstract public boolean isBoolean(); abstract public boolean requireContextSize(); abstract public void setContextSize(int size); abstract public void setPosition(int pos); abstract public int adjust(int n); //protected boolean cacheable; abstract public boolean isFinal(); public void markCacheable(){} public void markCacheable2(){} //public boolean isConstant(){return false;} public void clearCache(){} // to support computer context size // needs to add //abstract public boolean needContextSize(); //abstract public boolean SetContextSize(int contextSize); /*final protected int getStringIndex(VTDNav vn){ int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { a++; } else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG) { a = -2; }else if (t == VTDNav.TOKEN_PI_NAME) { a++; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; }*/ protected int computeDataSize(VTDNav vn){ int i = vn.context[0]; if (vn.shallowDepth) switch (i) { case -1: case 0: return vn.vtdSize; case 1: return vn.vtdSize / vn.l1Buffer.size; case 2: return vn.vtdSize / vn.l2Buffer.size; default: return vn.vtdSize / vn.l3Buffer.size; } else { VTDNav_L5 vnl = (VTDNav_L5) vn; switch (i) { case 0: return vn.vtdSize; case 1: return vn.vtdSize / vn.l1Buffer.size; case 2: return vn.vtdSize / vn.l2Buffer.size; case 3: return vn.vtdSize / vnl.l3Buffer.size; case 4: return vnl.vtdSize / vnl.l4Buffer.size; default: return vnl.vtdSize / vnl.l5Buffer.size; } } } }
3,495
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FastLongBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FastLongBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.lang.IndexOutOfBoundsException; import java.lang.NullPointerException; import java.lang.IllegalArgumentException; import java.util.ArrayList; /** * A fast, unsynchronized, chunk-based long buffer for storing LCs and VTD. * Creation date: (7/17/03 6:07:46 PM) */ public class FastLongBuffer implements ILongBuffer { /* bufferArrayList is a resizable array list of int buffers * */ private arrayList bufferArrayList; /** * Total capacity of the IntBuffer */ private int capacity; /** * Page size of the incremental growth of the Int Buffer */ private int pageSize; /** * Total number of integers in the IntBuffer */ protected int size; private int exp; private int r; /** * FastLongBuffer constructor comment. */ public FastLongBuffer() { size = 0; capacity = 0; pageSize = 1024; exp = 10; r = 1023; bufferArrayList = new arrayList(); } /** * Construct a FastLongBuffer instance with specified page size * @param e int (so that pageSize = (1<<e)) */ public FastLongBuffer(int e) { if (e <= 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = (1<<e); exp = e; r = pageSize -1; bufferArrayList = new arrayList(); } /** * Construct a FastLongBuffer instance with specified page size * @param e int (so that pageSize = (1<<e)) * @param c int (suggest initial capacity of ArrayList */ public FastLongBuffer(int e,int c) { if (e <= 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = (1<<e); exp = e; r = pageSize -1; bufferArrayList = new arrayList(c); } /** * Append single long to the end of array buffer. * @param long_array long[] */ public void append(long[] long_array) { if (long_array == null) { throw new NullPointerException(); } // no additional buffer space needed int lastBufferIndex; long[] lastBuffer; if (bufferArrayList.size == 0) { lastBuffer = new long[pageSize]; bufferArrayList.add(lastBuffer); lastBufferIndex = 0; capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (long[]) bufferArrayList.oa[lastBufferIndex]; } if ((this.size + long_array.length) < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length if (this.size + long_array.length< ((lastBufferIndex+1)<<exp)){ System.arraycopy(long_array, 0, lastBuffer, size & r, long_array.length); } else { int offset = pageSize -(size&r); // copy the first part System.arraycopy(long_array, 0, lastBuffer, size & r, offset); // copy the middle part int l = long_array.length - offset; int k = (l)>> exp; int z; for (z=1;z<=k;z++){ System.arraycopy(long_array,offset,(long[]) bufferArrayList.oa[lastBufferIndex+z], 0, pageSize); offset += pageSize; } // copy the last part System.arraycopy(long_array,offset,(long[]) bufferArrayList.oa[lastBufferIndex+z], 0, l & r); } size += long_array.length; return; } else // new buffers needed { // compute the number of additional buffers needed // int n = // ((int) ((long_array.length + size) / pageSize)) // + (((long_array.length + size) % pageSize) > 0 ? 1 : 0) // - (int) (capacity / pageSize); int n = ((long_array.length + size) >> exp) + (((long_array.length + size)&r) > 0 ? 1 : 0) - (capacity >> exp); // create these buffers // add to bufferArrayList //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, capacity - size); System.arraycopy(long_array, 0, lastBuffer, size & r, capacity - size); for (int i = 0; i < n; i++) { long[] newBuffer = new long[pageSize]; if (i < n - 1) { // full copy System.arraycopy( long_array, pageSize * i + capacity - size, newBuffer, 0, pageSize); } else { // last page System.arraycopy( long_array, pageSize * i + capacity - size, newBuffer, 0, long_array.length+ size - pageSize*i - capacity); } bufferArrayList.add(newBuffer); } // update length size += long_array.length; // update capacity capacity += n * pageSize; // update } } /** * Append an integer to the end of this array buffer * @param i long */ public final void append(long i) { //long[] lastBuffer; //int lastBufferIndex; /*if (bufferArrayList.size == 0) { lastBuffer = new long[pageSize]; bufferArrayList.add(lastBuffer); capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (long[]) bufferArrayList.oa[lastBufferIndex]; //lastBuffer = (long[]) bufferArrayList.get(bufferArrayList.size() - 1); }*/ if (this.size < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, long_array.length); //lastBuffer[size % pageSize] = i; ((long[]) bufferArrayList.oa[size >> exp])[size & r] = i; //((long[])bufferArrayList.oa[bufferArrayList.size-1])[size & r] = i; size += 1; } else // new buffers needed { long[] newBuffer = new long[pageSize]; size++; capacity += pageSize; bufferArrayList.add(newBuffer); newBuffer[0] = i; } } /** * Get the capacity of the buffer. * @return int */ public final int getCapacity() { return capacity; } /** * Return a selected chuck of long buffer as a long array. * @return long[] * @param startingOffset int * @param len int */ public long[] getLongArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size) { throw (new IndexOutOfBoundsException()); } long[] result = new long[len]; // allocate result array int first_index = (startingOffset >> exp); int last_index = ((startingOffset + len) >>exp); //if ((startingOffset + len) % pageSize == 0) { if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (long[]) (bufferArrayList.oa[first_index]), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int long_array_offset = 0; for (int i = first_index; i <= last_index; i++) { long[] currentChunk = (long[]) bufferArrayList.oa[i]; if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % r)); pageSize - (startingOffset & r)); long_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, long_array_offset, len - long_array_offset); } else { System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize); long_array_offset += pageSize; } } } return result; } /** * Get the buffer page size. * @return int */ public final int getPageSize() { return pageSize; } /** * Get the long val at given index value. * @return long * @param index int */ public final long longAt(int index) { /*if (index >= size) { throw new IndexOutOfBoundsException(); }*/ int pageNum = (index >> exp); // int offset = index % r; int offset = index &r; return ((long[]) bufferArrayList.oa[pageNum])[offset]; } /** * Get the lower 32 bit of the integer at the given index. * @return int * @param index int */ public final int lower32At(int index) { /*if ( index > size) { throw new IndexOutOfBoundsException(); }*/ int pageNum = (index >> exp); // int offset = index % pageSize; int offset = index & r; return (int) ((long[]) bufferArrayList.oa[pageNum])[offset]; } /** * Modify the value at the index to a new val. * @param index int * @param newValue long */ public final void modifyEntry(int index, long newValue) { /*if ( index > size + 1) { throw new IndexOutOfBoundsException(); }*/ //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((long[]) bufferArrayList.oa[index >> exp])[index & r] = newValue; } /** * Get the total number of longs in the buffer. * @return int */ public final int size() { return size; } /** * Convert all longs into a long array. * @return long[] */ public long[] toLongArray() { if (size > 0) { int s = size; long[] resultArray = new long[size]; //copy all the content int into the resultArray int array_offset = 0; for (int i = 0; s>0; i++) { System.arraycopy( (long[]) bufferArrayList.oa[i], 0, resultArray, array_offset, (s<pageSize) ? s : pageSize); //(i == (bufferArrayList.size() - 1)) ? size - ((size>>exp)<<exp) : pageSize); //(i == (bufferArrayList.size() - 1)) ? (size & r) : pageSize); s = s - pageSize; array_offset += pageSize; } return resultArray; } return null; } /** * Return the upper 32 bit of the long at the index. * @return int * @param index int */ public final int upper32At(int index) { /*if ( index >= size) { throw new IndexOutOfBoundsException(); }*/ int pageNum = (index >>exp); int offset = index & r; return (int) ((((long[]) bufferArrayList.oa[pageNum])[offset] & (0xffffffffL << 32)) >> 32); } /** * set teh size of long buffer to zero, capacity * untouched so long buffer can be reused without * any unnecessary and additional allocation * */ public final void clear(){ size = 0; } /** * Set the size of FastLongBuffer to newSz if newSz is less than the * capacity, otherwise return false * @param newSz * @return status of resize * */ public final boolean resize(int newSz){ if (newSz <= capacity && newSz >=0){ size = newSz; return true; } else return false; } }
12,885
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EOFException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/EOFException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Signals the End of File exception during parsing (not the one in java.io). * Creation date: (2/15/04 1:41:08 PM) */ public class EOFException extends ParseException { /** * EOFException constructor comment. */ public EOFException() { super(); } /** * EOFException constructor comment. * @param s java.lang.String */ public EOFException(String s) { super(s); } }
1,223
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IndexReadException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IndexReadException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * * IndexReadException is thrown when there are exception * conditions during index loading */ public class IndexReadException extends VTDException { public IndexReadException(String s){ super(s); } public IndexReadException(){ } }
1,116
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ElementFragment.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ElementFragment.java
/* * Copyright (C) 2002-2010 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * ElementFragement represents a chunk of bytes in an XML document that * corresponds to an element, additionally this class includes an integer * array corresponds to all the name spaces declarations applicable to the * element fragement * So l is the length/offset of the fragment * vn is the VTDNav instance to which the fragment belongs * fib is the integer array containing the name space declarations applicable * to the element fragment */ package com.ximpleware; import java.io.*; public class ElementFragment { VTDNav vn; long l; FastIntBuffer fib; int stLen; // length of starting tag static byte[] ws; // a few byte patterns for white space and '=' static{ ws = new byte[5]; ws[0]=0; ws[1]=(byte)' '; ws[2]=0; ws[3]='='; ws[4]=0; } public ElementFragment(VTDNav vn1, long l1, FastIntBuffer fib1, int len){ vn = vn1; l = l1; fib = fib1; stLen = len; } /** * Return a byte array with namespace compensation * witht the orginal encoding format * @return * */ public final byte[] toBytes(){ byte[] ba = new byte[getSize()]; int os = (int)l; int len = (int)(l>>32); int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ System.arraycopy(xml,os,ba,0,len); return ba; } int enc = vn.getEncoding(); int temp = 0; switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } System.arraycopy(xml,os,ba,0,temp); //namespace compensation os1 += temp; int tos =0,tlen=0; for (int i = 0; i < fib.size(); i++) { System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws System.arraycopy(ws,0,ba,os1,2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; // write a 0 and = System.arraycopy(ws,2,ba,os1,2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 System.arraycopy(ws,1,ba,os1,2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; // write a = and 0 System.arraycopy(ws,3,ba,os1,2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; break; default: // write a ws System.arraycopy(ws, 1, ba, os1, 1); os1 ++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); System.arraycopy(xml, tos, ba, os1, tlen); os1 +=tlen; // write a = System.arraycopy(ws, 3, ba, os1, 1); os1 ++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; System.arraycopy(xml, tos, ba, os1, tlen); os1 +=tlen; } } //System.out.println(new String(ba)); switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } System.arraycopy(xml, os + temp, ba, os1, len - temp); //System.out.println(new String(ba)); return ba; } /** * getSize gets the fragment with ns compensation * @return * */ public final int getSize(){ //int encoding = vn.encoding; int len = (int) (l >> 32); if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); len += (vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4; } return len; } /** * * * */ public final int writeToByteArray(byte[] ba, int offset){ return 0; } /** * Write ns compensated fragments (bytes in original encoding format) to outputstream * @param ost * @throws IOException * */ public final void writeToOutputStream(OutputStream ost) throws IOException{ int os = (int)l; int len = (int)(l>>32); //int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ //System.arraycopy(xml,os,ba,0,len); ost.write(xml,os,len); //return ba; } int enc = vn.getEncoding(); int temp = 0; switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } ost.write(xml,os,temp); //System.arraycopy(xml,os,ba,0,temp); //namespace compensation //os1 += temp; int tos =0,tlen=0; for (int i = 0; i < fib.size(); i++) { System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws //System.arraycopy(ws,0,ba,os1,2); ost.write(ws,0,2); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a 0 and = //System.arraycopy(ws,2,ba,os1,2); ost.write(ws,2,2); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 //System.arraycopy(ws,1,ba,os1,2); ost.write(ws,1,2); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a = and 0 //System.arraycopy(ws,3,ba,os1,2); ost.write(ws,3,2); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; break; default: // write a ws //System.arraycopy(ws, 1, ba, os1, 1); ost.write(ws,1,1); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); //System.arraycopy(xml, tos, ba, os1, tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a = //System.arraycopy(ws, 3, ba, os1, 1); ost.write(ws,3,1); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; //System.arraycopy(xml, tos, ba, os1, tlen); ost.write(xml,tos,tlen); //os1 +=tlen; } } //System.out.println(new String(ba)); switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } //System.arraycopy(xml, os + temp, ba, os1, len - temp); ost.write(xml,os+temp,len-temp); } /** * * @return * */ public final long getOffsetLen(){ return l; } }
10,197
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UniByteBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/UniByteBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * A simple wrapper around monolithic byte array implementing IByteBuffer interface. * Creation date: (11/25/03 5:05:57 PM) */ public class UniByteBuffer implements IByteBuffer { private byte[] ba; /** * UniByteBuffer constructor comment. * @exception IllegalArguement when b is a null pointer */ public UniByteBuffer(byte[] b) { super(); if (b==null) throw new IllegalArgumentException(); ba = b; } /** * Get the byte at the index. * Creation date: (11/25/03 5:07:42 PM) * @return byte * @param index int */ public final byte byteAt(int index) { return (byte) ba[index]; } /** * Return the token in its original encoding format. * Creation date: (11/28/03 7:02:07 PM) * @return byte[] * @param offset int * @param len int */ public final byte[] getBytes(int offset, int len) { byte[] b = new byte[len]; System.arraycopy(ba, offset, b, 0, len); return b; } /** * Get total size in terms of # of bytes. * Creation date: (11/25/03 5:13:10 PM) * @return int */ public int length() { return ba.length; } /** * Return the byte array containing the original XML document * @return byte[] * */ public byte[] getBytes(){ return ba; } }
2,066
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TranscodeException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/TranscodeException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * TranscodeException is thrown when there is exception condition (in XMLModifier) * for transcoding characters * */ public class TranscodeException extends VTDException { public TranscodeException(String s){ super(s); } public TranscodeException(){ } }
1,116
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDNav_L5.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/VTDNav_L5.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class VTDNav_L5 extends VTDNav { protected int l4index; protected int l5index; protected int l4upper; protected int l4lower; protected int l5upper; protected int l5lower; protected FastLongBuffer l3Buffer; protected FastLongBuffer l4Buffer; protected FastIntBuffer l5Buffer; //protected static short maxLCDepth =5; /** * Initialize the VTD navigation object. * * @param RootIndex * int * @param maxDepth * int * @param encoding * int * @param NS * boolean * @param x * byte[] * @param vtd * com.ximpleware.ILongBuffer * @param l1 * com.ximpleware.ILongBuffer * @param l2 * com.ximpleware.ILongBuffer * @param l3 * com.ximpleware.IIntBuffer * @param so * int starting offset of the document(in byte) * @param length * int length of the document (in byte) */ protected VTDNav_L5( int RootIndex, int enc, boolean NS, int depth, IByteBuffer x, FastLongBuffer vtd, FastLongBuffer l1, FastLongBuffer l2, FastLongBuffer l3, FastLongBuffer l4, FastIntBuffer l5, int so, // start offset of the starting offset(in byte) int length) // lengnth of the XML document (in byte)) { //super(); // initialize all buffers if (l1 == null || l2 == null || l3 == null || vtd == null || x == null || depth < 0 || RootIndex < 0 //|| encoding <= FORMAT_UTF8 //|| encoding >= FORMAT_ISO_8859_1 || so < 0 || length < 0) { throw new IllegalArgumentException(); } count=0; l1Buffer = l1; l2Buffer = l2; l3Buffer = l3; l4Buffer = l4; l5Buffer = l5; vtdBuffer = vtd; XMLDoc = x; encoding = enc; //System.out.println("encoding " + encoding); rootIndex = RootIndex; nestingLevel = depth + 1; ns = NS; // namespace aware or not if (ns == false) MASK_TOKEN_OFFSET = 0x000000007fffffffL; // this allows xml size to // be 2GB else // if there is no namespace MASK_TOKEN_OFFSET = 0x000000003fffffffL; atTerminal = false; //this variable will only change value during XPath // eval // initialize the context object this.context = new int[nestingLevel]; //depth value is the first entry in the context because root is // singular. context[0] = 0; //set the value to zero for (int i = 1; i < nestingLevel; i++) { context[i] = -1; } //currentOffset = 0; //contextStack = new ContextBuffer(1024, nestingLevel + 7); contextStack = new ContextBuffer(10, nestingLevel + 15); contextStack2 = new ContextBuffer(10, nestingLevel + 15); stackTemp = new int[nestingLevel + 15]; // initial state of LC variables l1index = l2index = l3index = l4index = l5index= -1; l2lower = l3lower = l4lower = l5lower= -1; l2upper = l3upper = l4upper = l5upper= -1; docOffset = so; docLen = length; //System.out.println("offset " + offset + " length " + length); //printL2Buffer(); vtdSize = vtd.size; //writeOffsetAdjustment = false; //recentNS = -1; name = null; nameIndex = -1; localName = null; localNameIndex = -1; fib = new FastIntBuffer(5); // page size is 32 ints shallowDepth = false; maxLCDepthPlusOne =6; } /** * Clone the VTDNav instance to get with shared XML, VTD and LC buffers * The node position is also copied from the original instance * @return a new instance of VTDNav */ public VTDNav cloneNav(){ VTDNav_L5 vn = new VTDNav_L5(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, l4Buffer, l5Buffer, docOffset, docLen ); vn.atTerminal = this.atTerminal; vn.LN = this.LN; if (this.context[0]!=-1) System.arraycopy(this.context, 0, vn.context, 0, this.context[0]+1 ); else vn.context[0]=-1; vn.l1index = l1index; if (getCurrentDepth()>1){ vn.l2index = this.l2index; vn.l2upper = l2upper; vn.l2lower = l2lower; } if (getCurrentDepth() > 2) { vn.l3lower = l3lower; vn.l3index = l3index; vn.l3upper = l3upper; } if (getCurrentDepth() > 3) { vn.l4lower = l4lower; vn.l4index = l4index; vn.l4upper = l4upper; } if (getCurrentDepth() > 4) { vn.l5lower = l5lower; vn.l5index = l5index; vn.l5upper = l5upper; } return vn; } /** * Duplicate the VTDNav instance with shared XML, VTD and LC buffers * This method may be useful for parallel XPath evaluation * The node Position is at root element * @return a VTDNav instance * */ final public VTDNav duplicateNav(){ return new VTDNav_L5(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, l4Buffer, l5Buffer, docOffset, docLen ); } /** * This method is similar to getElementByName in DOM except it doesn't * return the nodeset, instead it iterates over those nodes . When URL is * "*" it will match any namespace if ns is false, return false immediately * * @return boolean * @param dp * int (The depth of the starting position before iterating) * @param URL * java.lang.String * @param ln * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because VTD records can be generated * by another machine from a load-balancer.. * @exception IllegalArguementException * if ln is null example * * int depth = nv.getCurrentDepth() while(iterateNS(depth, * "www.url.com","node_name")){ push(); // store the current position //move * position safely pop(); // load the position } */ final protected boolean iterateNS(int dp, String URL, String ln) throws NavException { if (ns == false) return false; int tokenType; int index = getCurrentIndex() + 1; while (index < vtdSize) { tokenType = getTokenType(index); if(tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS){ index = index+2; continue; } if (isElementOrDocument(index)) { int depth = getTokenDepth(index); if (depth > dp) { context[0] = depth; if (depth>0) context[depth] = index; if (matchElementNS(URL, ln)) { if (dp < 6) resolveLC(); return true; } } else { return false; } } index++; } return false; } /** * Sync up the current context with location cache. This operation includes * finding out l1index, l2index, l3index and restores upper and lower bound * info To improve efficieny this method employs some heuristic search * algorithm. The result is that it is quite close to direct access. * Creation date: (11/16/03 7:44:53 PM) * * @return int The index of the NS URL */ protected void resolveLC() { if (context[0]<=0) return; resolveLC_l1(); if (context[0] == 1) return; resolveLC_l2(); if (context[0] == 2) return; resolveLC_l3(); if (context[0] == 3) return; resolveLC_l4(); if (context[0] == 4) return; resolveLC_l5(); } /** * Sync L3 location Cache */ protected void resolveLC_l3(){ int temp = l2Buffer.lower32At(l2index); if (l3lower != temp) { l3lower = temp; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously l3index = l3lower; l3upper = l3Buffer.size - 1; for (int i = l2index + 1; i < l2Buffer.size; i++) { temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } // intelligent guess again ?? if (l3index < 0 || l3index >= l3Buffer.size || context[3] != l3Buffer.upper32At(l3index)) { if (l3index >= l3Buffer.size || l3index<0) l3index = l3lower; if (l3index+1< l3Buffer.size&& context[3] == l3Buffer.upper32At(l3index + 1)) l3index = l3index + 1; else if (l3upper - l3lower >= 16) { int init_guess = l3lower + (int) ((l3upper - l3lower) * ((float) context[3] - l3Buffer .upper32At(l3lower)) / (l3Buffer .upper32At(l3upper) - l3Buffer .upper32At(l3lower))); if (l3Buffer.upper32At(init_guess) > context[3]) { while (context[3] != l3Buffer.upper32At(init_guess)) init_guess--; } else if (l3Buffer.upper32At(init_guess) < context[3]) { while (context[3] != l3Buffer.upper32At(init_guess)) init_guess++; } l3index = init_guess; } else if (context[3]<l3Buffer.upper32At(l3index)){ while ( context[3] != l3Buffer.upper32At(l3index)) { l3index--; } } else { while(context[3]!=l3Buffer.upper32At(l3index)) l3index++; } } } private void resolveLC_l4(){ int temp = l3Buffer.lower32At(l3index); if (l4lower != temp) { l4lower = temp; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously l4index = l4lower; l4upper = l4Buffer.size - 1; for (int i = l3index + 1; i < l3Buffer.size; i++) { temp = l3Buffer.lower32At(i); if (temp != 0xffffffff) { l4upper = temp - 1; break; } } } // intelligent guess again ?? if (l4index < 0 || l4index >= l4Buffer.size || context[4] != l4Buffer.upper32At(l4index)) { if (l4index >= l4Buffer.size || l4index<0) l4index = l4lower; if (l4index+1< l4Buffer.size&& context[4] == l4Buffer.upper32At(l4index + 1)) l4index = l4index + 1; else if (l4upper - l4lower >= 16) { int init_guess = l4lower + (int) ((l4upper - l4lower) * ((float) context[4] - l4Buffer .upper32At(l4lower)) / (l4Buffer .upper32At(l4upper) - l4Buffer .upper32At(l4lower))); if (l4Buffer.upper32At(init_guess) > context[4]) { while (context[4] != l4Buffer.upper32At(init_guess)) init_guess--; } else if (l4Buffer.upper32At(init_guess) < context[4]) { while (context[4] != l4Buffer.upper32At(init_guess)) init_guess++; } l4index = init_guess; } else if (context[4]<l4Buffer.upper32At(l4index)){ while ( context[4] != l4Buffer.upper32At(l4index)) { l4index--; } } else { while(context[4]!=l4Buffer.upper32At(l4index)) l4index++; } } } /** * Sync L3 location Cache */ private void resolveLC_l5(){ int temp = l4Buffer.lower32At(l4index); if (l5lower != temp) { //l3lower and l3upper are always together l5lower = temp; // l3lower shouldn't be -1 l5index = l5lower; l5upper = l5Buffer.size - 1; for (int i = l4index + 1; i < l4Buffer.size; i++) { temp = l4Buffer.lower32At(i); if (temp != 0xffffffff) { l5upper = temp - 1; break; } } } if (l5index < 0 || l5index >= l5Buffer.size || context[5] != l5Buffer.intAt(l5index)) { if (l5index >= l5Buffer.size || l5index <0) l5index = l5lower; if (l5index+1 < l5Buffer.size && context[5] == l5Buffer.intAt(l5index + 1)) l5index = l5index + 1; else if (l5upper - l5lower >= 16) { int init_guess = l5lower + (int) ((l5upper - l5lower) * ((float) (context[5] - l5Buffer .intAt(l5lower)) / (l5Buffer.intAt(l5upper) - l5Buffer .intAt(l5lower)))); if (l5Buffer.intAt(init_guess) > context[5]) { while (context[5] != l5Buffer.intAt(init_guess)) init_guess--; } else if (l5Buffer.intAt(init_guess) < context[5]) { while (context[5] != l5Buffer.intAt(init_guess)) init_guess++; } l5index = init_guess; } else if (context[5]<l5Buffer.intAt(l5index)){ while (context[5] != l5Buffer.intAt(l5index)) { l5index--; } } else { while (context[5] != l5Buffer.intAt(l5index)) { l5index++; } } } } /** * Load the context info from ContextBuffer. Info saved including LC and * current state of the context * * @return boolean * */ public boolean pop() { boolean b = contextStack.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l4index = stackTemp[nestingLevel + 3]; l5index = stackTemp[nestingLevel + 4]; l2lower = stackTemp[nestingLevel + 5]; l2upper = stackTemp[nestingLevel + 6]; l3lower = stackTemp[nestingLevel + 7]; l3upper = stackTemp[nestingLevel + 8]; l4lower = stackTemp[nestingLevel + 9]; l4upper = stackTemp[nestingLevel + 10]; l5lower = stackTemp[nestingLevel + 11]; l5upper = stackTemp[nestingLevel + 12]; atTerminal = (stackTemp[nestingLevel + 13] == 1); LN = stackTemp[nestingLevel+14]; return true; } /** * Load the context info from contextStack2. This method is dedicated for * XPath evaluation. * * @return status of pop2 */ final protected boolean pop2(){ boolean b = contextStack2.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l4index = stackTemp[nestingLevel + 3]; l5index = stackTemp[nestingLevel + 4]; l2lower = stackTemp[nestingLevel + 5]; l2upper = stackTemp[nestingLevel + 6]; l3lower = stackTemp[nestingLevel + 7]; l3upper = stackTemp[nestingLevel + 8]; l4lower = stackTemp[nestingLevel + 9]; l4upper = stackTemp[nestingLevel + 10]; l5lower = stackTemp[nestingLevel + 11]; l5upper = stackTemp[nestingLevel + 12]; atTerminal = (stackTemp[nestingLevel + 13] == 1); LN = stackTemp[nestingLevel+14]; return true; } /** * Store the context info into the ContextBuffer. Info saved including LC * and current state of the context Creation date: (11/16/03 7:00:27 PM) */ final public void push() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l4index; stackTemp[nestingLevel + 4] = l5index; stackTemp[nestingLevel + 5] = l2lower; stackTemp[nestingLevel + 6] = l2upper; stackTemp[nestingLevel + 7] = l3lower; stackTemp[nestingLevel + 8] = l3upper; stackTemp[nestingLevel + 9] = l4lower; stackTemp[nestingLevel + 10] = l4upper; stackTemp[nestingLevel + 11] = l5lower; stackTemp[nestingLevel + 12] = l5upper; if (atTerminal) stackTemp[nestingLevel + 13] =1; else stackTemp[nestingLevel + 13] =0; stackTemp[nestingLevel+14] = LN; contextStack.store(stackTemp); } /** * Store the context info into the contextStack2. This method is reserved * for XPath Evaluation * */ final protected void push2() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l4index; stackTemp[nestingLevel + 4] = l5index; stackTemp[nestingLevel + 5] = l2lower; stackTemp[nestingLevel + 6] = l2upper; stackTemp[nestingLevel + 7] = l3lower; stackTemp[nestingLevel + 8] = l3upper; stackTemp[nestingLevel + 9] = l4lower; stackTemp[nestingLevel + 10] = l4upper; stackTemp[nestingLevel + 11] = l5lower; stackTemp[nestingLevel + 12] = l5upper; if (atTerminal) stackTemp[nestingLevel + 13] =1; else stackTemp[nestingLevel + 13] =0; stackTemp[nestingLevel+14] = LN; contextStack2.store(stackTemp); } private final void recoverNode_l3(int index){ int i = l2Buffer.lower32At(l2index); if (l3lower != i) { l3lower = i; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously //l2index = l2lower; l3upper = l3Buffer.size - 1; for (int k = l2index + 1; k < l2Buffer.size; k++) { i = l2Buffer.lower32At(k); if (i != 0xffffffff) { l3upper = i - 1; break; } } } // guess what i would be in l2 cache int t1=l3Buffer.upper32At(l3lower); int t2=l3Buffer.upper32At(l3upper); //System.out.print(" t2 ==>"+t2+" t1 ==>"+t1); i= Math.min(l3lower+ (int)(((float)(index-t1)/(t2-t1+1))*(l3upper-l3lower)),l3upper) ; //System.out.print(" i1 "+i); while(i<l3Buffer.size-1 && l3Buffer.upper32At(i)<index){ i++; } //System.out.println(" ==== i2 "+i+" index ==> "+index); while (l3Buffer.upper32At(i)>index && i>0) i--; context[3] = l3Buffer.upper32At(i); l3index = i; //System.out.println("l2lower ==>"+l2lower+" l2upper==>"+l2upper+" l2index==> "+l2index); } private final void recoverNode_l4(int index){ int i = l3Buffer.lower32At(l3index); if (l4lower != i) { l4lower = i; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously //l2index = l2lower; l4upper = l4Buffer.size - 1; for (int k = l3index + 1; k < l3Buffer.size; k++) { i = l3Buffer.lower32At(k); if (i != 0xffffffff) { l4upper = i - 1; break; } } } // guess what i would be in l2 cache int t1=l4Buffer.upper32At(l4lower); int t2=l4Buffer.upper32At(l4upper); //System.out.print(" t2 ==>"+t2+" t1 ==>"+t1); i= Math.min(l4lower+ (int)(((float)(index-t1)/(t2-t1+1))*(l4upper-l4lower)),l4upper) ; //System.out.print(" i1 "+i); while(i<l4Buffer.size-1 && l4Buffer.upper32At(i)<index){ i++; } //System.out.println(" ==== i2 "+i+" index ==> "+index); while (l4Buffer.upper32At(i)>index && i>0) i--; context[4] = l4Buffer.upper32At(i); l4index = i; //System.out.println("l2lower ==>"+l2lower+" l2upper==>"+l2upper+" l2index==> "+l2index); } private final void recoverNode_l5(int index){ //l3 int i = l4Buffer.lower32At(l4index); if (l5lower != i) { //l3lower and l3upper are always together l5lower = i; // l3lower shouldn't be -1 //l3index = l3lower; l5upper = l5Buffer.size - 1; for (int k = l4index + 1; k < l4Buffer.size; k++) { i = l4Buffer.lower32At(k); if (i != 0xffffffff) { l5upper = i - 1; break; } } } int t1=l5Buffer.intAt(l5lower); int t2=l5Buffer.intAt(l5upper); i= Math.min(l5lower+ (int)(((float)(index-t1)/(t2-t1+1))*(l5upper-l5lower)),l5upper) ; while(i<l5Buffer.size-1 && l5Buffer.intAt(i)<index){ i++; } while (l5Buffer.intAt(i)>index && i>0) i--; //System.out.println(" i ===> "+i); context[5] = l5Buffer.intAt(i); l5index = i; } protected void sync(int depth, int index){ // assumption is that this is always at terminal switch(depth){ case -1: return; case 0: if(l1Buffer.size!=0){ if (l1index==-1) l1index=0; if (index> l1Buffer.upper32At(l1Buffer.size-1)){ l1index = l1Buffer.size-1; return; } if (index > l1Buffer.upper32At(l1index)){ while (l1index < l1Buffer.size - 1 && l1Buffer.upper32At(l1index) < index) { l1index++; } //l1index--; } else{ while (l1index >0 && l1Buffer.upper32At(l1index-1) > index) { l1index--; } } //assert(index<l1Buffer.upper32At(l1index)); } break; case 1: if (l1Buffer.lower32At(l1index)!=-1){ if (l2lower!=l1Buffer.lower32At(l1index)){ l2lower = l2index=l1Buffer.lower32At(l1index); l2upper = l2Buffer.size - 1; int size = l1Buffer.size; for (int i = l1index + 1; i < size; i++) { int temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } //l2upper = l1Buffer.lower32At(l1index); } if (index>l2Buffer.upper32At(l2index)){ while (l2index < l2upper && l2Buffer.upper32At(l2index)< index){ l2index++; } } else { while(l2index > l2lower && l2Buffer.upper32At(l2index-1)> index){ l2index--; } } //assert(index<l2Buffer.upper32At(l2index)); } break; case 2: if (l2Buffer.lower32At(l2index)!=-1){ if (l3lower!=l2Buffer.lower32At(l2index)){ l3index = l3lower = l2Buffer.lower32At(l2index); l3upper = l3Buffer.size - 1; int size = l2Buffer.size; for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } if (index>l3Buffer.upper32At(l3index)){ while (l3index < l3upper && l3Buffer.upper32At(l3index)<index ){ l3index++; } }else { while(l3index > l3lower && l3Buffer.upper32At(l3index-1)> index){ l3index--; } } //assert(index<l3Buffer.intAt(l3index)); } break; case 3: if (l3Buffer.lower32At(l3index)!=-1){ if (l4lower!=l3Buffer.lower32At(l3index)){ l4index = l4lower = l3Buffer.lower32At(l3index); l4upper = l4Buffer.size - 1; int size = l3Buffer.size; for (int i = l3index + 1; i < size; i++) { int temp = l3Buffer.lower32At(i); if (temp != 0xffffffff) { l4upper = temp - 1; break; } } } if (index>l4Buffer.upper32At(l4index)){ while (l4index < l4upper && l4Buffer.upper32At(l4index)< index){ l4index++; } } else { while(l4index > l4lower && l4Buffer.upper32At(l4index-1)> index){ l4index--; } } //assert(index<l3Buffer.intAt(l3index)); } break; case 4: if (l4Buffer.lower32At(l4index)!=-1){ if (l5lower!=l4Buffer.lower32At(l4index)){ l5index = l5lower = l4Buffer.lower32At(l4index); l5upper = l5Buffer.size - 1; int size = l4Buffer.size; for (int i = l4index + 1; i < size; i++) { int temp = l4Buffer.lower32At(i); if (temp != 0xffffffff) { l5upper = temp - 1; break; } } } if (index>l5Buffer.intAt(l5index)){ while (l5index < l5upper && l5Buffer.intAt(l5index)<index ){ l5index++; } }else { while(l5index > l5lower && l5Buffer.intAt(l5index-1)> index){ l5index--; } } //assert(index<l3Buffer.intAt(l3index)); } break; default: if (l4Buffer.lower32At(l4index)!=-1){ if (l5lower!=l4Buffer.lower32At(l4index)){ l5index = l5lower = l4Buffer.lower32At(l4index); l5upper = l5Buffer.size - 1; int size = l4Buffer.size; for (int i = l4index + 1; i < size; i++) { int temp = l4Buffer.lower32At(i); if (temp != 0xffffffff) { l5upper = temp - 1; break; } } } //if (context[5]> l5Buffer.intAt(l5index)){ while (context[5] != l5Buffer.intAt(l5index)){ l5index++; } /*} else { while (context[5] != l5Buffer.intAt(l5index)){ l5index--; } }*/ //assert(index<l3Buffer.intAt(l3index)); } break; } } /** * This is for debugging purpose * * @param fib */ public void sampleState(FastIntBuffer fib){ // for(int i=0;i<context.) // context[i] = -1; // fib.append(context); if (context[0]>=1) fib.append(l1index); //else return; if (context[0]>=2){ fib.append(l2index); fib.append(l2lower); fib.append(l2upper); }//else return; if (context[0]>=3){ fib.append(l3index); fib.append(l3lower); fib.append(l3upper); }//else return; if (context[0]>=4){ fib.append(l4index); fib.append(l4lower); fib.append(l4upper); }//else return; if (context[0]>=5){ fib.append(l5index); fib.append(l5lower); fib.append(l5upper); } } public void dumpState(){ System.out.println("l1 index ==>"+l1index); System.out.println("l2 index ==>"+l2index); System.out.println("l2 lower ==>"+l2lower); System.out.println("l2 upper ==>"+l2upper); System.out.println("l3 index ==>"+l3index); System.out.println("l3 lower ==>"+l3lower); System.out.println("l3 upper ==>"+l3upper); System.out.println("l4 index ==>"+l4index); System.out.println("l4 lower ==>"+l4lower); System.out.println("l4 upper ==>"+l4upper); System.out.println("l5 index ==>"+l5index); System.out.println("l5 lower ==>"+l5lower); System.out.println("l5 upper ==>"+l5upper); } /** * A generic navigation method. Move the cursor to the element according to * the direction constants and the element name If no such element, no * position change and return false. "*" matches any element Creation date: * (12/2/03 1:43:50 PM) Legal direction constants are <br> * * <pre> * ROOT 0 * </pre> * <pre> * PARENT 1 * </pre> * <pre> * FIRST_CHILD 2 * </pre> * <pre> * LAST_CHILD 3 * </pre> * <pre> * NEXT_SIBLING 4 * </pre> * <pre> * PREV_SIBLING 5 * </pre> * * <br> * for ROOT and PARENT, element name will be ignored. * * @return boolean * @param direction * int * @param en * String * @exception com.ximpleware.NavException * When direction value is illegal. Or there are errors in * underlying byte representation of the document * @exception IllegalArguementException * if en is null */ public boolean toElement(int direction, String en) throws NavException { int temp=-1; int d=-1; int val=0; boolean b=false; if (en == null) throw new IllegalArgumentException(" Element name can't be null "); if (en.equals("*")) return toElement(direction); switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElement(en) == false) { if (toElement(NEXT_SIBLING, en) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElement(en) == false) { if (toElement(PREV_SIBLING, en) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal){ if (nodeToElement(NEXT_SIBLING)){ b=true; if (matchElement(en)){ return true; } }else return false; } if (!b){ d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } temp = context[d]; // store the current position } while (toElement(NEXT_SIBLING)) { if (matchElement(en)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; }else{ switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; case 4: l4index = val; break; case 5: l5index = val; break; default: } context[d] = temp; return false; } case PREV_SIBLING : if (atTerminal) { if (nodeToElement(PREV_SIBLING)){ b=true; if (matchElement(en)){ return true; } }else return false; } if (!b){ d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } temp = context[d]; // store the current position } while (toElement(PREV_SIBLING)) { if (matchElement(en)) { return true; } } if (b) { context[0]--;// LN value should not change atTerminal = true; return false; } else { switch (d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; case 4: l4index = val; break; case 5: l5index = val; break; default: } context[d] = temp; return false; } default : throw new NavException("illegal navigation options"); } } /** * A generic navigation method. Move the cursor to the element according to * the direction constants If no such element, no position change and return * false. Creation date: (12/2/03 1:43:50 PM) Legal direction constants are * * <pre> * ROOT 0 * </pre> *<pre> * PARENT 1 * </pre> *<pre> * FIRST_CHILD 2 * </pre> *<pre> * LAST_CHILD 3 * </pre> *<pre> * NEXT_SIBLING 4 * </pre> *<pre> * PREV_SIBLING 5 * </pre> * * @return boolean * @param direction * int * @exception com.ximpleware.NavException * When direction value is illegal. */ public boolean toElement(int direction) throws NavException { int size; //count++; //System.out.println("count ==>"+ count); switch (direction) { case ROOT : // to document element! if (context[0] != 0) { /* * for (int i = 1; i <= context[0]; i++) { context[i] = * 0xffffffff; } */ context[0] = 0; } atTerminal = false; l1index = l2index = l3index = -1; return true; case PARENT : if (atTerminal == true){ atTerminal = false; return true; } if (context[0] > 0) { //context[context[0]] = context[context[0] + 1] = // 0xffffffff; context[context[0]] = -1; context[0]--; return true; }else if (context[0]==0){ context[0]=-1; //to be compatible with XPath Data model return true; } else { return false; } case FIRST_CHILD : case LAST_CHILD : if (atTerminal) return false; switch (context[0]) { case -1: context[0] = 0; return true; case 0 : if (l1Buffer.size > 0) { context[0] = 1; l1index = (direction == FIRST_CHILD) ? 0 : (l1Buffer.size - 1); context[1] = l1Buffer.upper32At(l1index); //(int) (vtdToken >> 32); return true; } else return false; case 1 : l2lower = l1Buffer.lower32At(l1index); if (l2lower == -1) { return false; } context[0] = 2; l2upper = l2Buffer.size - 1; size = l1Buffer.size; for (int i = l1index + 1; i < size; i++) { int temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } //System.out.println(" l2 upper: " + l2upper + " l2 // lower : " + l2lower); l2index = (direction == FIRST_CHILD) ? l2lower : l2upper; context[2] = l2Buffer.upper32At(l2index); return true; case 2 : l3lower = l2Buffer.lower32At(l2index); if (l3lower == -1) { return false; } context[0] = 3; l3upper = l3Buffer.size - 1; size = l2Buffer.size; for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } //System.out.println(" l2 upper: " + l2upper + " l2 // lower : " + l2lower); l3index = (direction == FIRST_CHILD) ? l3lower : l3upper; context[3] = l3Buffer.upper32At(l3index); return true; case 3 : l4lower = l3Buffer.lower32At(l3index); if (l4lower == -1) { return false; } context[0] = 4; l4upper = l4Buffer.size - 1; size = l3Buffer.size; for (int i = l3index + 1; i < size; i++) { int temp = l3Buffer.lower32At(i); if (temp != 0xffffffff) { l4upper = temp - 1; break; } } //System.out.println(" l2 upper: " + l2upper + " l2 // lower : " + l2lower); l4index = (direction == FIRST_CHILD) ? l4lower : l4upper; context[4] = l4Buffer.upper32At(l4index); return true; case 4 : l5lower = l4Buffer.lower32At(l4index); if (l5lower == -1) { return false; } context[0] = 5; l5upper = l5Buffer.size - 1; size = l4Buffer.size; for (int i = l4index + 1; i < size; i++) { int temp = l4Buffer.lower32At(i); if (temp != 0xffffffff) { l5upper = temp - 1; break; } } //System.out.println(" l3 upper : " + l3upper + " l3 // lower : " + l3lower); l5index = (direction == FIRST_CHILD) ? l5lower : l5upper; context[5] = l5Buffer.intAt(l5index); return true; default : if (direction == FIRST_CHILD) { size = vtdBuffer.size; int index = context[context[0]] + 1; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth <= context[0]) { return false; } else if (depth == (context[0] + 1)) { context[0] += 1; context[context[0]] = index; return true; } } index++; } // what condition return false; } else { int index = context[context[0]] + 1; int last_index = -1; size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { if (depth <= context[0]) { break; } else if (depth == (context[0] + 1)) { last_index = index; } } index++; } if (last_index == -1) { return false; } else { context[0] += 1; context[context[0]] = last_index; return true; } } } case NEXT_SIBLING : case PREV_SIBLING : if(atTerminal)return nodeToElement(direction); switch (context[0]) { case -1: case 0 : return false; case 1 : if (direction == NEXT_SIBLING) { if (l1index + 1 >= l1Buffer.size) { return false; } l1index++; // global incremental } else { if (l1index - 1 < 0) { return false; } l1index--; // global incremental } context[1] = l1Buffer.upper32At(l1index); return true; case 2 : if (direction == NEXT_SIBLING) { if (l2index + 1 > l2upper) { return false; } l2index++; } else { if (l2index - 1 < l2lower) { return false; } l2index--; } context[2] = l2Buffer.upper32At(l2index); return true; case 3 : if (direction == NEXT_SIBLING) { if (l3index + 1 > l3upper) { return false; } l3index++; } else { if (l3index - 1 < l3lower) { return false; } l3index--; } context[3] = l3Buffer.upper32At(l3index); return true; case 4 : if (direction == NEXT_SIBLING) { if (l4index + 1 > l4upper) { return false; } l4index++; } else { if (l4index - 1 < l4lower) { return false; } l4index--; } context[4] = l4Buffer.upper32At(l4index); return true; case 5 : if (direction == NEXT_SIBLING) { if (l5index + 1 > l5upper) { return false; } l5index++; } else { if (l5index - 1 < l5lower) { return false; } l5index--; } context[5] = l5Buffer.intAt(l5index); return true; default : //int index = context[context[0]] + 1; if (direction == NEXT_SIBLING) { int index = context[context[0]] + 1; size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]) { return false; } else if (depth == (context[0])) { context[context[0]] = index; return true; } } index++; } return false; } else { int index = context[context[0]] - 1; while (index > context[context[0] - 1]) { // scan backforward long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /* * if (depth < context[0]) { return false; } * else */ if (depth == (context[0])) { context[context[0]] = index; return true; } } index--; } // what condition return false; } } default : throw new NavException("illegal navigation options"); } } protected boolean nodeToElement(int direction){ switch(direction){ case NEXT_SIBLING: switch (context[0]) { case 0: if (l1index!=-1){ context[0]=1; context[1]=l1Buffer.upper32At(l1index); atTerminal=false; return true; }else return false; case 1: if (l2index!=-1){ context[0]=2; context[2]=l2Buffer.upper32At(l2index); atTerminal=false; return true; }else return false; case 2: if (l3index!=-1){ context[0]=3; context[3]=l3Buffer.upper32At(l3index); atTerminal=false; return true; }else return false; case 3: if (l4index!=-1){ context[0]=4; context[4]=l4Buffer.upper32At(l4index); atTerminal=false; return true; }else return false; case 4: if (l5index!=-1){ context[0]=5; context[5]=l5Buffer.intAt(l5index); atTerminal=false; return true; }else return false; default: int index = LN + 1; int size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]) { return false; } else if (depth == (context[0])) { context[context[0]] = index; return true; } } index++; } return false; } case PREV_SIBLING: switch (context[0]) { case 0: if (l1index!=-1 && l1index>0){ l1index--; context[0]=1; context[1]=l1Buffer.upper32At(l1index); atTerminal=false; return true; }else return false; case 1: if (l2index!=-1 && l2index>l2lower){ l2index--; context[0]=2; context[2]=l2Buffer.upper32At(l2index); atTerminal=false; return true; }else return false; case 2: if (l3index!=-1 && l3index>l3lower){ l3index--; context[0]=3; context[3]=l3Buffer.upper32At(l3index); atTerminal=false; return true; }else return false; case 3: if (l4index!=-1 && l4index>l4lower){ l4index--; context[0]=4; context[4]=l4Buffer.upper32At(l4index); atTerminal=false; return true; }else return false; case 4: if (l5index!=-1 && l5index>l5lower){ l5index--; context[0]=5; context[5]=l5Buffer.intAt(l5index); atTerminal=false; return true; }else return false; default: int index = LN- 1; while (index > context[context[0] - 1]) { // scan backforward long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /* * if (depth < context[0]) { return false; } * else */ if (depth == (context[0])) { context[context[0]] = index; return true; } } index--; } // what condition return false; } } return false; } /** * A generic navigation method with namespace support. Move the cursor to * the element according to the direction constants and the prefix and local * names If no such element, no position change and return false. URL * * matches any namespace, including undefined namespaces a null URL means * hte namespace prefix is undefined for the element ln * matches any * localname Creation date: (12/2/03 1:43:50 PM) Legal direction constants * are <br> * * <pre> * ROOT 0 * </pre> * <pre> * PARENT 1 * </pre> * <pre> * FIRST_CHILD 2 * </pre> * <pre> * LAST_CHILD 3 * </pre> * <pre> * NEXT_SIBLING 4 * </pre> * <pre> * PREV_SIBLING 5 * </pre> * * <br> * for ROOT and PARENT, element name will be ignored. If not ns enabled, * return false immediately with no position change. * * @return boolean * @param direction * int * @param URL * String * @param ln * String * @exception com.ximpleware.NavException * When direction value is illegal. Or there are errors in * underlying byte representation of the document */ public boolean toElementNS(int direction, String URL, String ln) throws NavException { int temp=-1; int val=0; int d=-1; // temp location boolean b=false; if (ns == false) return false; switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElementNS(URL, ln) == false) { if (toElementNS(NEXT_SIBLING, URL, ln) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElementNS(URL, ln) == false) { if (toElementNS(PREV_SIBLING, URL, ln) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal){ if (nodeToElement(NEXT_SIBLING)){ b=true; if (matchElementNS(URL,ln)){ return true; } }else return false; } if (!b){ d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } } //if (d == 0) // return false; while (toElement(NEXT_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; }else{ switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } context[d] = temp; return false; } case PREV_SIBLING : if (atTerminal){ if (nodeToElement(PREV_SIBLING)){ b=true; if (matchElementNS(URL,ln)){ return true; } }else return false; } if (!b){ d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } } //if (d == 0) // return false; while (toElement(PREV_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; } else { switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; case 4: val = l4index; break; case 5: val = l5index; break; default: } context[d] = temp; return false; } default : throw new NavException("illegal navigation options"); } } /** * This method takes a vtd index, and recover its correspondin * node position, the index can only be of node type element, * document, attribute name, attribute value or character data, * or CDATA * @param index * @throws NavException */ public void recoverNode(int index) throws NavException{ if (index <0 || index>=vtdSize ) throw new NavException("Invalid VTD index"); int type = getTokenType(index); if (//type == VTDNav.TOKEN_COMMENT || // type == VTDNav.TOKEN_PI_NAME || type == VTDNav.TOKEN_PI_VAL || type == VTDNav.TOKEN_DEC_ATTR_NAME || type == VTDNav.TOKEN_DEC_ATTR_VAL || type == VTDNav.TOKEN_ATTR_VAL) throw new NavException("Token type not yet supported"); // get depth int d = getTokenDepth(index); // handle document node; switch (d){ case -1: context[0]=-1; if (index != 0){ LN = index; atTerminal = true; } return; case 0: context[0]=0; if (index != rootIndex){ LN = index; atTerminal = true; if (type>VTDNav.TOKEN_ATTR_NS) sync(0,index); } else atTerminal=false; return; } context[0]=d; if (type != VTDNav.TOKEN_STARTING_TAG){ LN = index; atTerminal = true; } // search LC level 1 recoverNode_l1(index); if (d==1){ if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(1,index); return; } // search LC level 2 recoverNode_l2(index); if (d==2){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(2,index); return; } // search LC level 3 recoverNode_l3(index); if (d==3){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(3,index); return; } recoverNode_l4(index); if (d==4){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(4,index); return; } recoverNode_l5(index); if (d==5){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(5,index); return; } // scan backward if ( type == VTDNav.TOKEN_STARTING_TAG ){ context[d] = index; } else{ int t = index-1; while( !(getTokenType(t)==VTDNav.TOKEN_STARTING_TAG && getTokenDepth(t)==d)){ t--; } context[d] = t; } int t = context[d]-1; d--; while(d>5){ while( !(getTokenType(t)==VTDNav.TOKEN_STARTING_TAG && getTokenDepth(t)==d)){ t--; } context[d] = t; d--; } //resolveLC(); } public void writeIndex(OutputStream os) throws IndexWriteException, IOException{ IndexHandler.writeIndex_L5((byte)1, this.encoding, this.ns, true, this.nestingLevel-1, 5, this.rootIndex, this.XMLDoc.getBytes(), this.docOffset, this.docLen, (FastLongBuffer)this.vtdBuffer, (FastLongBuffer)this.l1Buffer, (FastLongBuffer)this.l2Buffer, (FastLongBuffer)this.l3Buffer, (FastLongBuffer)this.l4Buffer, (FastIntBuffer)this.l5Buffer, os); } /** * Write VTDNav's VTD and LCs into an OutputStream (XML not written out) * @param os * @throws IndexWriteException * @throws IOException * */ public void writeSeparateIndex(OutputStream os) throws IndexWriteException, IOException{ IndexHandler.writeSeparateIndex_L5((byte)2, this.encoding, this.ns, true, this.nestingLevel-1, 5, this.rootIndex, // this.XMLDoc.getBytes(), this.docOffset, this.docLen, (FastLongBuffer)this.vtdBuffer, (FastLongBuffer)this.l1Buffer, (FastLongBuffer)this.l2Buffer, (FastLongBuffer)this.l3Buffer, (FastLongBuffer)this.l4Buffer, (FastIntBuffer)this.l5Buffer, os); } protected boolean toNode(int dir) throws NavException{ int index,tokenType,depth,lastEntry,tmp; //count++; //System.out.println("count ==>"+ count); switch(dir){ case ROOT: if (context[0] != 0) { /* * for (int i = 1; i <= context[0]; i++) { context[i] = * 0xffffffff; } */ context[0] = 0; } atTerminal = false; //l1index = l2index = l3index = l2lower=l2upper=l3lower=l3upper=l4lower=l4upper=l5lower=l5upper=-1; return true; case PARENT: if (atTerminal == true){ atTerminal = false; return true; } if (context[0] > 0) { //context[context[0]] = context[context[0] + 1] = // 0xffffffff; context[context[0]] = -1; context[0]--; return true; }else if (context[0]==0){ context[0]=-1; //to be compatible with XPath Data model return true; } else { return false; } case FIRST_CHILD: if(atTerminal)return false; switch (context[0]) { case -1: //starting with root element //scan backward, if there is a pi | comment node index = rootIndex-1; loop1: while(index >0){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_COMMENT: index--; break; case TOKEN_PI_VAL: index-=2;break; default: break loop1; } } index++; // points to if (index!=rootIndex){ atTerminal = true; LN = index; }else{ context[0]=0; } return true; case 0: if (l1Buffer.size!=0){ index = l1Buffer.upper32At(0)-1; //rewind loop1: while(index>rootIndex){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index-=2; break; default: break loop1; } } index++; l1index = 0; if(index == l1Buffer.upper32At(0)){ context[0]=1; context[1]= l1Buffer.upper32At(0); atTerminal = false; }else { atTerminal = true; LN = index; } return true; }else{ //get to the first non-attr node after the starting tag index = rootIndex+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==0){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 1: if (l1Buffer.lower32At(l1index)!=-1){ // l2upper and l2lower l2lower = l1Buffer.lower32At(l1index); tmp = l1index+1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ l2upper = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l1Buffer.size){ l2upper = l2Buffer.size-1; } index = context[1]+1; tmp = l2Buffer.upper32At(l2lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l2index = l2lower; atTerminal = true; LN = index; return true; } } l2index = l2lower; context[0] = 2; context[2] = index; return true; }else{ index = context[1]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==1 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 2: if (l2Buffer.lower32At(l2index)!=-1){ // l2upper and l2lower l3lower = l2Buffer.lower32At(l2index); tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ l3upper = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l2Buffer.size){ l3upper = l3Buffer.size-1; } index = context[2]+1; tmp = l3Buffer.upper32At(l3lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l3index = l3lower; atTerminal = true; LN = index; return true; } } l3index = l3lower; context[0] = 3; context[3] = index; return true; }else{ index = context[2]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==2 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 3: if (l3Buffer.lower32At(l3index)!=-1){ // l2upper and l2lower l4lower = l3Buffer.lower32At(l3index); tmp = l3index+1; while(tmp<l3Buffer.size){ if (l3Buffer.lower32At(tmp)!=-1){ l4upper = l3Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l3Buffer.size){ l4upper = l4Buffer.size-1; } index = context[3]+1; tmp = l4Buffer.upper32At(l4lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l4index = l4lower; atTerminal = true; LN = index; return true; } } l4index = l4lower; context[0] = 4; context[4] = index; return true; }else{ index = context[3]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==3 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 4: if (l4Buffer.lower32At(l4index)!=-1){ // l2upper and l2lower l5lower = l4Buffer.lower32At(l4index); tmp = l4index+1; while(tmp<l4Buffer.size){ if (l4Buffer.lower32At(tmp)!=-1){ l5upper = l4Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l4Buffer.size){ l5upper = l5Buffer.size-1; } index = context[4]+1; tmp = l5Buffer.intAt(l5lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l5index = l5lower; atTerminal = true; LN = index; return true; } } l5index = l5lower; context[0] = 5; context[5] = index; return true; }else{ index = context[4]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==4 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } default: index = context[context[0]] + 1; while (index < vtdBuffer.size) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); switch(tokenType){ case TOKEN_STARTING_TAG: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth <= context[0]){ return false; }else if (depth == (context[0] + 1)) { context[0] += 1; context[context[0]] = index; return true; }else throw new NavException("impossible condition"); case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2;break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]){ return false; }else if (depth == (context[0])) { LN = index; atTerminal = true; return true; } else index++; case TOKEN_PI_NAME: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]){ return false; }else if (depth == (context[0])) { LN = index; atTerminal = true; return true; } else index+=2; } //index++; } // what condition return false; } case LAST_CHILD: if(atTerminal)return false; return toNode_LastChild(); case NEXT_SIBLING: switch (context[0]) { case -1: if(atTerminal){ index = LN; tokenType = getTokenType(index); switch(tokenType){ case TOKEN_PI_NAME: index+=2; break; //break loop2; case TOKEN_COMMENT: index++; break; } if (index <vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == -1){ LN = index; return true; }else{ atTerminal = false; context[0]=0; return true; // depth has to be zero } }else return false; }else{ return false; } //break; case 0: if(atTerminal){ index = LN; tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; //index++; if (l1Buffer.size!=0){ if (index < l1Buffer.upper32At(l1index)){ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index <= l1Buffer.upper32At(l1index)){ if (index == l1Buffer.upper32At(l1index)){ atTerminal = false; context[0]=1; context[1]=index; return true; } depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } }else if ( l1index < l1Buffer.size -1){ // whether lindex is the last entry is l1 buffer l1index++; if (tokenType==TOKEN_PI_NAME) index++; if (index <= l1Buffer.upper32At(l1index)){ if (index == l1Buffer.upper32At(l1index)){ atTerminal = false; context[0]=1; context[1]=index; return true; } depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } }else{ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } } }else{ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } } }else{ index = vtdSize-1; depth = -2; // get to the end, then rewind while(index > rootIndex){ depth = getTokenDepth(index); if (depth ==-1){ index--; } else break; } index++; if (index>=vtdSize ) return false; else{ context[0]=-1; LN = index; atTerminal = true; return true; } } //break; case 1: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l1Buffer.lower32At(l1index) != -1) { if (LN < l2Buffer.upper32At(l2upper)) { tmp = l2Buffer.upper32At(l2index); index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 2; context[2] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==1 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; } else return false; } }else{ index= LN+1; if (getTokenType(LN)==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==1 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ if (l1index != l1Buffer.size-1){ // not the last one //rewind l1index++; index = lastEntry = l1Buffer.upper32At(l1index)-1; while(getTokenDepth(index)==0){ index--; } if (lastEntry==index){ atTerminal=false; context[0]=1; context[1]=index+1; return true; } else { atTerminal = true; context[0]=0; LN = index+1; return true; } }else{ index = vtdSize-1; while(index > l1Buffer.upper32At(l1index) && getTokenDepth(index)<=0){ index--; } if (index == vtdSize-1 ){ if (getTokenDepth(index)==0){ context[0]=0; LN = index; atTerminal = true; return true; }else return false; } index++; if (getTokenDepth(index)==0){ context[0]=0; LN = index; atTerminal = true; return true; }else{ return false; } } } case 2: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l2Buffer.lower32At(l2index) != -1) { if (LN < l3Buffer.upper32At(l3upper)) { tmp = l3Buffer.upper32At(l3index); index = LN + 1; if (tokenType== TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 3; context[3] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==2 && getTokenType(index)!=TOKEN_STARTING_TAG){ LN = index; return true; } return false; } return false; } }else{ index= LN+1; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==2 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ //l2index < l2upper if (l2index< l2upper){ tmp = l2Buffer.upper32At(l2index); l2index++; lastEntry = index = l2Buffer.upper32At(l2index)-1; //rewind loop2:while(index>tmp){ if (getTokenDepth(index)==1){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0]=2; context[2] = index+1; return true; } context[0]=1; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index!=l1Buffer.size-1){ lastEntry = index = l1Buffer.upper32At(l1index+1)-1; } tmp = l2Buffer.upper32At(l2index); //rewind while(index>tmp){ if (getTokenDepth(index)<2) index--; else break; } if ((/*lastEntry>=index &&*/ getTokenDepth(index)==1)){ LN = index; atTerminal = true; context[0]=1; return true; } if (lastEntry!=index && getTokenDepth(index+1)==1 ){ LN = index+1; atTerminal = true; context[0]=1; return true; } return false; } } //break; case 3: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l3Buffer.lower32At(l3index) != -1) { if (LN < l4Buffer.upper32At(l4upper)) { tmp = l4Buffer.upper32At(l4index); index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 4; context[4] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==3 && getTokenType(index)!=TOKEN_STARTING_TAG){ LN = index; return true; } return false; } return false; } }else{ index= LN+1; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==3 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ //l2index < l2upper if (l3index< l3upper){ tmp = l3Buffer.upper32At(l3index); l3index++; lastEntry = index = l3Buffer.upper32At(l3index)-1; //rewind loop2:while(index>tmp){ if (getTokenDepth(index)==2){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0]=3; context[3] = index+1; return true; } context[0]=2; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index != l1Buffer.size-1){ lastEntry = index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ lastEntry = index = l2Buffer.upper32At(l2index+1)-1; } // insert here tmp = l3Buffer.upper32At(l3index); //rewind while(index>tmp){ if (getTokenDepth(index)<3) index--; else break; } if ((/*lastEntry==index &&*/ getTokenDepth(index)==2)){ LN = index; atTerminal = true; context[0]=2; return true; } if (lastEntry!=index && getTokenDepth(index+1)==2 ){ LN = index+1; atTerminal = true; context[0]=2; return true; } return false; } } case 4: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l4Buffer.lower32At(l4index) != -1) { if (LN < l5Buffer.intAt(l5upper)) { tmp = l5Buffer.intAt(l5index); index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 5; context[5] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==4 && getTokenType(index)!=TOKEN_STARTING_TAG){ LN = index; return true; } return false; } return false; } }else{ index= LN+1; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==4 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ //l2index < l2upper if (l4index< l4upper){ tmp = l4Buffer.upper32At(l4index); l4index++; lastEntry = index = l4Buffer.upper32At(l4index)-1; //rewind loop2:while(index>tmp){ if (getTokenDepth(index)==3){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0] = 4; context[4] = index+1; return true; } context[0]=3; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index != l1Buffer.size-1){ lastEntry = index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ lastEntry = index = l2Buffer.upper32At(l2index+1)-1; } if (l3index != l3Buffer.size-1 && l3index != l3upper){ lastEntry = index = l3Buffer.upper32At(l3index+1)-1; } // insert here tmp = l4Buffer.upper32At(l4index); //rewind while(index>tmp){ if (getTokenDepth(index)<4) index--; else break; } if ((/*lastEntry==index &&*/ getTokenDepth(index)==3)){ LN = index; atTerminal = true; context[0]=3; return true; } if (lastEntry!=index && getTokenDepth(index+1)==3){ LN = index+1; atTerminal = true; context[0]=3; return true; } return false; } } case 5: if(!atTerminal){ //l2index < l2upper if (l5index< l5upper){ tmp = l5Buffer.intAt(l5index); l5index++; lastEntry = index = l5Buffer.intAt(l5index)-1; //rewind loop2:while(index>tmp){ if (getTokenDepth(index)==4){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0]= 5; context[5] = index+1; return true; } context[0]=4; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index != l1Buffer.size-1){ lastEntry = index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ lastEntry = index = l2Buffer.upper32At(l2index+1)-1; } if (l3index != l3Buffer.size-1 && l3index != l3upper){ lastEntry = index = l3Buffer.upper32At(l3index+1)-1; } if (l4index != l4Buffer.size-1 && l4index != l4upper){ lastEntry = index = l4Buffer.upper32At(l4index+1)-1; } // inser here tmp = l5Buffer.intAt(l5index); //rewind while(index>tmp){ if (getTokenDepth(index)<5) index--; else break; } if ((/*lastEntry==index &&*/ getTokenDepth(index)==4)){ LN = index; atTerminal = true; context[0]=4; return true; } if (lastEntry!=index && getTokenDepth(index+1)==4){ LN = index+1; atTerminal = true; context[0]=4; return true; } return false; } } //break; default: if (atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; index = LN+1; tmp = context[0]+1; } else{ index = context[context[0]] + 1; tmp = context[0]; } while (index < vtdSize) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); switch (tokenType) { case TOKEN_STARTING_TAG: if (depth < tmp) { return false; } else if (depth == tmp) { context[0]=tmp; context[context[0]] = index; atTerminal = false; return true; }else index++; break; case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index += 2; break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < tmp-1) { return false; } else if (depth == (tmp-1)) { context[0]=tmp-1; LN = index; atTerminal = true; return true; } else index++; break; case TOKEN_PI_NAME: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < tmp-1) { return false; } else if (depth == tmp-1) { context[0]=tmp-1; LN = index; atTerminal = true; return true; } else index += 2; break; default: index++; } } return false; } case PREV_SIBLING: return toNode_PrevSibling(); default : throw new NavException("illegal navigation options"); } } protected boolean toNode_PrevSibling(){ int index,tokenType,depth,tmp; switch (context[0]) { case -1: if(atTerminal){ index = LN-1; if (index>0){ depth = getTokenDepth(index); if (depth==-1){ tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_COMMENT: LN = index; return true; default: return false; } }else{ context[0] = 0; atTerminal = false; return true; } }else{ return false; } }else{ return false; } case 0: if(atTerminal){ if (l1Buffer.size!=0){ // three cases if (LN < l1Buffer.upper32At(l1index)){ index = LN-1; if (index>rootIndex){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 0){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; return true; case TOKEN_PI_VAL: LN = index -1; return true; } } if (l1index==0) return false; l1index--; atTerminal = false; context[0]=1; context[1]= l1Buffer.upper32At(l1index); return true; }else return false; } else { index = LN -1; if (index>l1Buffer.upper32At(l1index)){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 0){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; return true; case TOKEN_PI_VAL: LN = index -1; return true; } } } atTerminal = false; context[0]=1; context[1]= l1Buffer.upper32At(l1index); return true; } }else{ index = LN-1; if (index>rootIndex){ tokenType=getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=0; return true; default: return false; } } } return false; }else{ index = rootIndex-1; if (index>0){ tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_COMMENT: LN = index; atTerminal = true; context[0]=-1; return true; default: return false; } }else{ return false; } } //break; case 1: if(atTerminal){ if (l1Buffer.lower32At(l1index)!=-1){ tmp = l2Buffer.upper32At(l2index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==1){ LN = index; return true; }else{ atTerminal = false; context[0]=2; context[2]=tmp; return true; } } else if (l2index!=l2lower){ l2index--; atTerminal = false; context[0]=2; context[2]=l2Buffer.upper32At(l2index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=1; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[1]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[1]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==0 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=0; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l1index != 0){ l1index--; context[1] = l1Buffer.upper32At(l1index); return true; }else return false; } } //break; case 2: if(atTerminal){ if (l2Buffer.lower32At(l2index)!=-1){ tmp = l3Buffer.upper32At(l3index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==2){ LN = index; return true; }else{ atTerminal = false; context[0]=3; context[3]=tmp; return true; } } else if (l3index!=l3lower){ l3index--; atTerminal = false; context[0]=3; context[3]=l3Buffer.upper32At(l3index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=2; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[2]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[2]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==1 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=1; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l2index != l2lower){ l2index--; context[2] = l2Buffer.upper32At(l2index); return true; }else return false; } } //break; case 3: if(atTerminal){ if (l3Buffer.lower32At(l3index)!=-1){ tmp = l4Buffer.upper32At(l4index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==3){ LN = index; return true; }else{ atTerminal = false; context[0]=4; context[4]=tmp; return true; } } else if (l4index!=l4lower){ l4index--; atTerminal = false; context[0]=4; context[4]=l4Buffer.upper32At(l4index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=3; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[3]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[3]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==2 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=2; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l3index != l3lower){ l3index--; context[3] = l3Buffer.upper32At(l3index); return true; }else return false; } } case 4: if(atTerminal){ if (l4Buffer.lower32At(l4index)!=-1){ tmp = l5Buffer.intAt(l5index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==4){ LN = index; return true; }else{ atTerminal = false; context[0]=5; context[5]=tmp; return true; } } else if (l5index!=l5lower){ l5index--; atTerminal = false; context[0]=5; context[5]=l5Buffer.intAt(l5index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=4; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[4]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[4]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==3 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=3; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l4index != l4lower){ l4index--; context[4] = l4Buffer.upper32At(l4index); return true; }else return false; } } case 5: if(!atTerminal){ index = context[5]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==4 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=4; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l5index != l5lower){ l5index--; context[5] = l5Buffer.intAt(l5index); return true; }else return false; } } default: if (atTerminal){ index = LN-1; tmp = context[0]+1; } else{ index = context[context[0]] - 1; tmp = context[0]; } while (index > context[tmp-1]) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); switch (tokenType) { case TOKEN_STARTING_TAG: if (depth == tmp) { context[0] = tmp; context[context[0]] = index; atTerminal = false; return true; }else index--; break; case TOKEN_ATTR_VAL: //case TOKEN_ATTR_NS: index -= 2; break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: if (depth == tmp-1) { context[0]=tmp-1; LN = index; atTerminal = true; return true; } else index--; break; case TOKEN_PI_VAL: if (depth == (tmp-1)) { context[0] = tmp-1; LN = index-1; atTerminal = true; return true; } else index -= 2; break; default: index--; } } return false; } } protected boolean toNode_LastChild(){ int depth,index,tokenType,lastEntry,tmp; switch (context[0]) { case -1: index = vtdSize-1; tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == -1) { switch (tokenType) { case TOKEN_COMMENT: LN = index; atTerminal = true; return true; case TOKEN_PI_VAL: LN = index -1; atTerminal = true; return true; } } context[0]=0; return true; case 0: if (l1Buffer.size!=0){ lastEntry = l1Buffer.upper32At(l1Buffer.size-1); index = vtdSize-1; while(index > lastEntry){ depth = getTokenDepth(index); if (depth==-1){ index--; continue; } else if (depth ==0){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; l1index = l1Buffer.size -1; return true; case TOKEN_PI_VAL: LN = index -1; atTerminal = true; l1index = l1Buffer.size -1; return true; default: return false; } }else { l1index = l1Buffer.size -1; context[0]= 1; context[1]= lastEntry; return true; } } l1index = l1Buffer.size -1; context[0]= 1; context[1]= lastEntry; return true; }else{ index = vtdSize - 1; while(index>rootIndex){ depth = getTokenDepth(index); if (depth == -1){ index--; continue; } tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; return true; case TOKEN_PI_VAL: LN = index-1; atTerminal = true; return true; default: return false; } } return false; } case 1: if (l1Buffer.lower32At(l1index)!=-1){ l2lower = l1Buffer.lower32At(l1index); tmp = l1index+1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ l2upper = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l1Buffer.size){ l2upper = l2Buffer.size-1; } l2index = l2upper; index =vtdSize-1; if (l1index != l1Buffer.size-1){ index = l1Buffer.upper32At(l1index+1)-1; } tmp = l2Buffer.upper32At(l2index); // rewind and find the first node of depth 1 while(index > tmp){ depth = getTokenDepth(index); if (depth <1) index--; else if (depth == 1){ tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index-1; else LN = index; atTerminal = true; //context[0]=1; return true; }else break; } context[0]=2; context[2]=tmp; return true; }else{ index = context[1]+1; loop: while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: break loop; } } if (index< vtdSize && getTokenDepth(index)==1 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ lastEntry = index; index++; //scan forward loop2:while(index<vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 1){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index+=2; break; default: break loop2; } }else break loop2; } LN = lastEntry; atTerminal = true; return true; }else return false; } case 2: if (l2Buffer.lower32At(l2index)!=-1){ l3lower = l2Buffer.lower32At(l2index); tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ l3upper = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l2Buffer.size){ l3upper = l3Buffer.size-1; } l3index = l3upper; index =vtdSize-1; if (l1index != l1Buffer.size-1){ index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ index = l2Buffer.upper32At(l2index+1)-1; } tmp = l3Buffer.upper32At(l3index); // rewind and find the first node of depth 1 while(index > tmp){ depth = getTokenDepth(index); if (depth <2) index--; else if (depth == 2){ tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index-1; else LN = index; atTerminal = true; //context[0]=1; return true; }else break; } context[0]=3; context[3]=tmp; return true; }else{ index = context[2]+1; loop: while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: break loop; } } if (index< vtdSize && getTokenDepth(index)==2 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ lastEntry = index; index++; //scan forward loop2:while(index<vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 2){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index+=2; break; default: break loop2; } }else break loop2; } LN = lastEntry; atTerminal = true; return true; }else return false; } case 3: if (l3Buffer.lower32At(l3index) != -1) { l4lower = l3Buffer.lower32At(l3index); tmp = l3index + 1; while (tmp < l3Buffer.size) { if (l3Buffer.lower32At(tmp) != -1) { l4upper = l3Buffer.lower32At(tmp) - 1; break; } else tmp++; } if (tmp == l3Buffer.size) { l4upper = l4Buffer.size - 1; } l4index = l4upper; index = vtdSize - 1; if (l1index != l1Buffer.size - 1) { index = l1Buffer.upper32At(l1index + 1) - 1; } if (l2index != l2Buffer.size - 1 && l2index != l2upper) { index = l2Buffer.upper32At(l2index + 1) - 1; } if (l3index != l3Buffer.size - 1 && l3index != l3upper) { index = l3Buffer.upper32At(l3index + 1) - 1; } tmp = l4Buffer.upper32At(l4index); // rewind and find the first node of depth 1 while (index > tmp) { depth = getTokenDepth(index); if (depth < 3) index--; else if (depth == 3) { tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index - 1; else LN = index; atTerminal = true; // context[0]=1; return true; } else break; } context[0] = 4; context[4] = tmp; return true; } else { index = context[3] + 1; loop: while (index < vtdSize) { tokenType = getTokenType(index); switch (tokenType) { case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index += 2; break; default: break loop; } } if (index < vtdSize && getTokenDepth(index) == 3 && getTokenType(index) != VTDNav.TOKEN_STARTING_TAG) { lastEntry = index; index++; // scan forward loop2: while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 3) { switch (tokenType) { case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index += 2; break; default: break loop2; } } else break loop2; } LN = lastEntry; atTerminal = true; return true; } else return false; } case 4: if (l4Buffer.lower32At(l4index)!=-1){ l5lower = l4Buffer.lower32At(l4index); tmp = l4index+1; while(tmp<l4Buffer.size){ if (l4Buffer.lower32At(tmp)!=-1){ l5upper = l4Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l4Buffer.size){ l5upper = l5Buffer.size-1; } l5index = l5upper; index =vtdSize-1; if (l1index != l1Buffer.size-1){ index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ index = l2Buffer.upper32At(l2index+1)-1; } if (l3index != l3Buffer.size-1 && l3index != l3upper){ index = l3Buffer.upper32At(l3index+1)-1; } if (l4index != l4Buffer.size-1 && l4index != l4upper){ index = l4Buffer.upper32At(l4index+1)-1; } tmp = l5Buffer.intAt(l5index); // rewind and find the first node of depth 1 while(index > tmp){ depth = getTokenDepth(index); if (depth <4) index--; else if (depth == 4){ tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index-1; else LN = index; atTerminal = true; //context[0]=1; return true; }else break; } context[0]=5; context[5]=tmp; return true; }else{ index = context[4]+1; loop: while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: break loop; } } if (index< vtdSize && getTokenDepth(index)==4 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ lastEntry = index; index++; //scan forward loop2:while(index<vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 4){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index+=2; break; default: break loop2; } }else break loop2; } LN = lastEntry; atTerminal = true; return true; }else return false; } default: index = context[context[0]] + 1; lastEntry = -1; atTerminal = false; while (index < vtdBuffer.size) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth =getTokenDepth(index); switch(tokenType){ case TOKEN_STARTING_TAG: if (depth <= context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; }else{ context[0]+=1; context[context[0]] = lastEntry; } return true; } else return false; }else if (depth == (context[0] + 1)) { lastEntry = index; atTerminal= false; } index++; break; case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2;break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: if (depth < context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; }else if (depth == (context[0])) { lastEntry = index; atTerminal = true; } index++; break; case TOKEN_PI_NAME: if (depth < context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; }else if (depth == (context[0])) { lastEntry = index; atTerminal = true; } index+=2; break; } //index++; } // what condition if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; } } public boolean verifyNodeCorrectness(){ if (atTerminal){ // check l1 index, l2 index, l2lower, l2upper, l3 index, l3 lower, l3 upper if (getTokenDepth(LN)!=context[0]) return false; switch(context[0]){ case -1: return true; case 0: //if (getTokenDepth(LN)!=0) // return false; if (l1Buffer.size!=0){ if (l1index>=l1Buffer.size || l1index<0) return false; if (l1index != l1Buffer.size-1){ if (l1Buffer.upper32At(l1index)<LN) return false; } return true; }else return true; case 1: if (LN>context[1]){ //if (getTokenDepth(LN) != 1) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1, i2, i3; // l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if (i1 != -1) { int tmp = l1index + 1; i2 = l2Buffer.size - 1; while (tmp < l1Buffer.size) { if (l1Buffer.lower32At(tmp) != -1) { i2 = l1Buffer.lower32At(tmp) - 1; break; } else tmp++; } if (i1 != l2lower) return false; if (l2upper != i2) return false; if (l2index > l2upper || l2index < l2lower) return false; if (l2index != l2upper) { if (l2Buffer.upper32At(l2index) < LN) return false; } } return true; }else return false; case 2: if (LN>context[2] && context[2]> context[1]){ //if (getTokenDepth(LN) != 2) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2, i3; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if(i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1!=-1){ if (l3lower!=i1) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index > l3upper || l3index < l3lower) return false; if (l3index != l3upper) { if (l3Buffer.upper32At(l3index) < LN) return false; } } return true; }else return false; case 3: if (LN>context[3] && context[3]> context[2] && context[2]> context[1]){ //if (getTokenDepth(LN) != 2) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2, i3; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if(i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1==-1){return false;} if (l3lower!=i1) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index > l3upper || l3index < l3lower) return false; /*if (l3index != l3upper) { if (l3Buffer.upper32At(l3index) < LN) return false; } */ //l4 i1 = l3Buffer.lower32At(l3index); if (i1!=-1){ if (l4lower!=i1) return false; i2 = l4Buffer.size-1; tmp = l3index+1; while(tmp<l3Buffer.size){ if (l3Buffer.lower32At(tmp)!=-1){ i2 = l3Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l4lower!=i1) return false; if (l4upper!=i2) return false; if (l4index > l4upper || l4index < l4lower) return false; if (l4index != l4upper) { if (l4Buffer.upper32At(l4index) < LN) return false; } } return true; }else return false; case 4: if (LN>context[3] && context[3]> context[2] && context[2]> context[1]){ //if (getTokenDepth(LN) != 2) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2, i3; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if(i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1==-1){return false;} if (l3lower!=i1) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index > l3upper || l3index < l3lower) return false; /*if (l3index != l3upper) { if (l3Buffer.upper32At(l3index) < LN) return false; } */ i1 = l3Buffer.lower32At(l3index); if (i1==-1){ return false;} if (l4lower!=i1) return false; i2 = l4Buffer.size-1; tmp = l3index+1; while(tmp<l3Buffer.size){ if (l3Buffer.lower32At(tmp)!=-1){ i2 = l3Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l4lower!=i1) return false; if (l4upper!=i2) return false; if (l4index > l4upper || l4index < l4lower) return false; /*if (l4index != l4upper) { if (l4Buffer.upper32At(l4index) < LN) return false; }*/ i1=l4Buffer.lower32At(l4index); if (i1!=-1){ if (i1!=l5lower)return false; i2 = l5Buffer.size-1; tmp = l4index+1; while(tmp<l4Buffer.size){ if (l4Buffer.lower32At(tmp)!=-1){ i2 = l4Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l5lower!=i1) return false; if (l5upper!=i2) return false; if (l5index<i1 || l5index>i2) return false; if (l5index != l5upper) { if (l5Buffer.intAt(l5index) < LN) return false; } } return true; }else return false; default: if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2,i3; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if(i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1==-1){return false;} if (l3lower!=i1) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index > l3upper || l3index < l3lower) return false; i1 = l3Buffer.lower32At(l3index); if (i1==-1){ return false;} if (l4lower!=i1) return false; i2 = l4Buffer.size-1; tmp = l3index+1; while(tmp<l3Buffer.size){ if (l3Buffer.lower32At(tmp)!=-1){ i2 = l3Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l4lower!=i1) return false; if (l4upper!=i2) return false; if (l4index > l4upper || l4index < l4lower) return false; /*if (l4index != l4upper) { if (l4Buffer.upper32At(l4index) < LN) return false; }*/ i1=l4Buffer.lower32At(l4index); if (i1!=l5lower)return false; i2 = l5Buffer.size-1; tmp = l4index+1; while(tmp<l4Buffer.size){ if (l4Buffer.lower32At(tmp)!=-1){ i2 = l4Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l5lower!=i1) return false; if (l5upper!=i2) return false; if (l5index<i1 || l5index>i2) return false; if (context[context[0]]>LN) return false; if (context[0]==5){ if (l5index!=l5upper){ if(l5Buffer.intAt(l5index)>LN) return false; } if (l5index+1 <= l5Buffer.size-1){ if (l5Buffer.intAt(l5index+1)<LN){ return false; } } } return true; } }else { switch(context[0]){ case -1: case 0: case 1: case 2: case 3: case 4: case 5: default:return true; } } } }
117,421
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
BinaryExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/BinaryExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * The parser.java uses this class to contruct the corresponding * AST for XPath expression when there are two operands and one * operator * */ public class BinaryExpr extends Expr { public final static int ADD = 0; public final static int SUB = 1; public final static int MULT = 2; public final static int DIV = 3; public final static int MOD = 4; public final static int OR = 5; public final static int AND = 6; public final static int EQ = 7; public final static int NE = 8; public final static int LE = 9; public final static int GE = 10; public final static int LT = 11; public final static int GT = 12; //public final static int UNION = 13; public final static int BUF_SZ_EXP = 7; protected int op; boolean isNumerical; boolean isBoolean; protected Expr left; protected Expr right; protected FastIntBuffer fib1; /** * constructor * @param l * @param o * @param r */ public BinaryExpr ( Expr l, int o, Expr r) { op = o; left = l; right = r; fib1 = null; //cacheable =false; switch(op){ case ADD: case SUB: case MULT: case DIV: case MOD: isNumerical = true; isBoolean = false; break; case OR : case AND: case EQ: case NE: case LE: case GE: case LT: case GT: isNumerical = false; isBoolean = true; default: } } final public String toString(){ String os; switch(op){ case ADD: os = " + "; break; case SUB: os = " - "; break; case MULT: os = " * "; break; case DIV: os = " / "; break; case MOD: os = " mod "; break; case OR : os = " or ";break; case AND: os = " and "; break; case EQ: os = " = "; break; case NE: os = " != "; break; case LE: os = " <= "; break; case GE: os = " >= "; break; case LT: os = " < "; break; default: os = " > "; break; } return "("+ left + os + right+")"; } final public boolean evalBoolean(VTDNav vn){ //int i,i1=0; //int stackSize; //Expr e1, e2; //int t; //boolean b = false; switch(op){ case OR: return left.evalBoolean(vn) || right.evalBoolean(vn); case AND:return left.evalBoolean(vn) && right.evalBoolean(vn); case EQ: case NE: case LE: case GE: case LT: case GT: return computeComp(op,vn); default: double dval = evalNumber(vn); if (dval ==-0.0 || dval ==+0.0 || Double.isNaN(dval)) return false; return true; } } final public double evalNumber(VTDNav vn){ switch(op){ case ADD: return left.evalNumber(vn) + right.evalNumber(vn); case SUB: return left.evalNumber(vn) - right.evalNumber(vn); case MULT:return left.evalNumber(vn) * right.evalNumber(vn); case DIV: return left.evalNumber(vn) / right.evalNumber(vn); case MOD: return left.evalNumber(vn) % right.evalNumber(vn); default : if (evalBoolean(vn) == true) return 1; return 0; } } final public int evalNodeSet(VTDNav vn) throws XPathEvalException { throw new XPathEvalException("BinaryExpr can't eval to a node set!"); } final public String evalString(VTDNav vn){ if(isNumerical()){ double d = evalNumber(vn); if (d==(long)d){ return ""+(long)d; } else return ""+d; } else { boolean b = evalBoolean(vn); if (b) return "true"; else return "false"; } } final public void reset(VTDNav vn){ left.reset(vn); right.reset(vn); //cached = false; /*if (cachedNodeSet != null){ cachedNodeSet.clear(); }*/ }; final public boolean isNodeSet(){ return false; } final public boolean isNumerical(){ return isNumerical; } final public boolean isString(){ return false; } final public boolean isBoolean(){ return isBoolean; } // to support computation of context size // needs to add // public boolean needContextSize(); // public boolean SetContextSize(int contextSize); //If both objects to be compared are node-sets, then //the comparison will be true if and only if there is //a node in the first node-set and a node in the second //node-set such that the result of performing the comparison //on the string-values of the two nodes is true. If one //object to be compared is a node-set and the other is a //number, then the comparison will be true if and only if //there is a node in the node-set such that the result of //performing the comparison on the number to be compared and on //the result of converting the string-value of that node to a //number using the number function is true. If one object to be //compared is a node-set and the other is a string, then the //comparison will be true if and only if there is a node in //the node-set such that the result of performing the comparison //on the string-value of the node and the other string is true. //If one object to be compared is a node-set and the other is a boolean, //then the comparison will be true if and only if the result of //performing the comparison on the boolean and on the result of //converting the node-set to a boolean using the boolean function is true. //When neither object to be compared is a node-set and the operator //is = or !=, then the objects are compared by converting them to a //common type as follows and then comparing them. If at least one object //to be compared is a boolean, then each object to be compared is //converted to a boolean as if by applying the boolean function. //Otherwise, if at least one object to be compared is a number, then //each object to be compared is converted to a number as if by applying //the number function. Otherwise, both objects to be compared are //converted to strings as if by applying the string function. The = //comparison will be true if and only if the objects are equal; the //!= comparison will be true if and only if the objects are not equal. //Numbers are compared for equality according to IEEE 754 [IEEE 754]. Two //booleans are equal if either both are true or both are false. Two strings //are equal if and only if they consist of the same sequence of UCS characters. final private boolean computeComp(int op, VTDNav vn){ //int i, t, i1 = 0, stackSize, s1, s2; String st1, st2; if (left.isNodeSet() && right.isNodeSet()) { return compNodeSetNodeSet(left, right, vn, op); } else { if (left.isNumerical() && right.isNodeSet()){ return compNumericalNodeSet(left, right, vn, op); } if (left.isNodeSet() && right.isNumerical()) { //return compNumericalNodeSet(right, left, vn, op); return compNodeSetNumerical(left, right, vn, op); } if (left.isString() && right.isNodeSet()){ return compStringNodeSet(left, right, vn, op); } if (left.isNodeSet() && right.isString()) { //return compStringNodeSet(right, left, vn, op); return compNodeSetString(left, right, vn, op); } } if (op==EQ || op==NE){ if (left.isBoolean() || right.isBoolean()) { if (op == EQ) return left.evalBoolean(vn) == right.evalBoolean(vn); else return left.evalBoolean(vn) != right.evalBoolean(vn); } if (left.isNumerical() || right.isNumerical()) { if (op == EQ) return left.evalNumber(vn) == right.evalNumber(vn); else return left.evalNumber(vn) != right.evalNumber(vn); } st1 = left.evalString(vn); st2 = right.evalString(vn); /*if (st1 == null || st2 == null) if (op == EQ) return false; else return true;*/ return (op == EQ) ? (st1.equals(st2)) : (!st1.equals(st2)); } return compNumbers(left.evalNumber(vn),right.evalNumber(vn),op); } final public boolean requireContextSize(){ return left.requireContextSize() || right.requireContextSize(); } final public void setContextSize(int size){ left.setContextSize(size); right.setContextSize(size); } final public void setPosition(int pos){ left.setPosition(pos); right.setPosition(pos); } // this function computes the case where one expr is a node set, the other is a string final private boolean compNodeSetString(Expr left, Expr right, VTDNav vn,int op){ int i, i1 = 0, stackSize; String s; try { s = right.evalString(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); // if (i1==-1 && s.length()==0) //return true; if (i1 != -1) { boolean b = compareVString1(i1,vn,s,op); if (b){ left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return b; } } } vn.contextStack2.size = stackSize; vn.pop2(); left.reset(vn); return false; //compareEmptyNodeSet(op, s); } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } final private boolean compareEmptyNodeSet(int op, String s){ if (op == NE ){ if (s.length()==0) { return false; } else return true; }else{ if (s.length()==0) { return true; } else return false; } } final private boolean compStringNodeSet(Expr left, Expr right, VTDNav vn,int op){ int i, i1 = 0, stackSize; String s; try { s = left.evalString(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1){ boolean b = compareVString2(i1,vn,s,op); if (b){ right.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return b; } } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return false; //compareEmptyNodeSet(op, s); } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } final private boolean compNumbers(double d1, double d2, int op) { switch (op) { case LE: return d1 <= d2; case GE: return d1 >= d2; case LT: return d1 < d2; case GT: return d1 > d2; } return false; } // this function computes the boolean when one expression is node set // the other is numerical final private boolean compNumericalNodeSet(Expr left, Expr right, VTDNav vn, int op ){ int i, i1 = 0, stackSize; double d; try { d = left.evalNumber(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1!=-1 && compareVNumber1(i1,vn,d,op)){ right.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return true; } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return false; } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } final private boolean compNodeSetNumerical(Expr left, Expr right, VTDNav vn, int op ){ int i,i1 = 0, stackSize; double d; try { d = right.evalNumber(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1!=-1 && compareVNumber2(i1,vn,d,op)){ left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return true; } } vn.contextStack2.size = stackSize; vn.pop2(); left.reset(vn); return false; } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } final private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME) return i+1; else return i; } final private boolean compareVNumber1(int k, VTDNav vn, double d, int op) throws NavException { double d1 = vn.parseDouble(k); switch (op){ case EQ: return d == d1; case NE: return d != d1; case GE: return d >= d1; case LE: return d <= d1; case GT: return d > d1; default: return d < d1; } } final private boolean compareVString1(int k, VTDNav vn, String s, int op) throws NavException { int i = vn.compareTokenString(k, s); switch (i) { case -1: if (op == NE || op == LT || op == LE) { return true; } break; case 0: if (op == EQ || op == LE || op == GE) { return true; } break; case 1: if (op == NE || op == GE || op == GT) { return true; } } return false; } final private boolean compareVString2(int k, VTDNav vn, String s, int op) throws NavException { int i = vn.compareTokenString(k, s); switch(i){ case -1: if (op== NE || op == GT || op == GE){ return true; } break; case 0: if (op==EQ || op == LE || op == GE ){ return true; } break; case 1: if (op == NE || op==LE || op == LT ){ return true; } } return false; } final private boolean compareVNumber2(int k, VTDNav vn, double d, int op) throws NavException { double d1 = vn.parseDouble(k); switch (op){ case EQ: return d1 == d; case NE: return d1 != d; case GE: return d1 >= d; case LE: return d1 <= d; case GT: return d1 > d; default: return d1 < d; } } final private boolean compareVV(int k, VTDNav vn, int j,int op) throws NavException { int i = vn.compareTokens(k, vn, j); switch(i){ case 1: if (op == NE || op==GE || op == GT ){ return true; } break; case 0: if (op==EQ || op == LE || op == GE ){ return true; } break; case -1: if (op== NE || op == LT || op == LE){ return true; } } return false; } // this method compare node set with another node set final private boolean compNodeSetNodeSet(Expr left, Expr right, VTDNav vn, int op){ int i,i1,stackSize,s1; try { if (fib1 == null) fib1 = new FastIntBuffer(BUF_SZ_EXP); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1) fib1.append(i1); } left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1){ s1 = fib1.size; for (int k = 0; k < s1; k++) { boolean b = compareVV(fib1.intAt(k),vn,i1,op); if (b){ fib1.clear(); vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return true; } } } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); fib1.clear(); return false; } catch (Exception e) { fib1.clear(); throw new RuntimeException("Undefined behavior"); } } final public int adjust(int n){ int i = left.adjust(n); int j = right.adjust(n); if (i>j)return i; else return j; } final public boolean isFinal(){ return left.isFinal() && right.isFinal(); } final public void markCacheable(){ left.markCacheable(); right.markCacheable(); } final public void markCacheable2(){ if (left.isFinal() && left.isNodeSet()){ CachedExpr ce = new CachedExpr(left); left = ce; } left.markCacheable2(); if (right.isFinal() && right.isNodeSet()){ CachedExpr ce = new CachedExpr(right); right = ce; } right.markCacheable2(); } final public void clearCache(){ left.clearCache(); right.clearCache(); } }
19,479
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FuncExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FuncExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.*; /** * FuncExpr implements the function expression defined * in XPath spec * */ public class FuncExpr extends Expr{ public Alist argumentList; public int opCode; boolean isNumerical; boolean isBoolean; boolean isString; boolean isNodeSet; int contextSize; VTDNav newVN,xslVN; // double d; int position; int argCount; int a; int state; VTDGen vg; String s; //VTDNav vn; public static final int START = 0, // initial state END = 1, // return to begin TERMINAL = 2, // no more next step FORWARD = 3, // BACKWARD = 4; VTDNav getNewNav(){return newVN;} void setXslVn(VTDNav vn1){xslVN=vn1;} int argCount(){ Alist temp = argumentList; int count = 0; while(temp!=null){ count++; temp = temp.next; } return count; } public FuncExpr(int oc , Alist list){ a = 0; opCode = oc; argumentList = list; isBoolean = false; isString = false; position = 0; isNodeSet = false; isNumerical = false; argCount=argCount(); // cacheable =false; switch(opCode){ case FuncName.LAST: isNumerical = true;break; case FuncName.POSITION: isNumerical = true;break; case FuncName.COUNT: isNumerical = true;break; case FuncName.LOCAL_NAME: isString = true; break; case FuncName.NAMESPACE_URI: isString = true; break; case FuncName.NAME: isString = true; break; case FuncName.STRING: isString = true; break; case FuncName.CONCAT: isString = true; break; case FuncName.STARTS_WITH: isBoolean= true;break; case FuncName.CONTAINS: isBoolean= true;break; case FuncName.SUBSTRING_BEFORE: isString = true; break; case FuncName.SUBSTRING_AFTER: isString = true; break; case FuncName.SUBSTRING: isString = true; break; case FuncName.STRING_LENGTH: isNumerical = true;break; case FuncName.NORMALIZE_SPACE: isString = true; break; case FuncName.TRANSLATE: isString = true;break; case FuncName.BOOLEAN: isBoolean =true;break; case FuncName.NOT: isBoolean =true;break; case FuncName.TRUE: isBoolean = true;break; case FuncName.FALSE: isBoolean = true;break; case FuncName.LANG: isBoolean = true;break; case FuncName.NUMBER: isNumerical = true;break; case FuncName.SUM: isNumerical = true;break; case FuncName.FLOOR: isNumerical = true;break; case FuncName.CEILING: isNumerical = true;break; case FuncName.ROUND: isNumerical = true;break; case FuncName.ABS: isNumerical = true;break; case FuncName.ROUND_HALF_TO_EVEN : isNumerical = true;break; case FuncName.ROUND_HALF_TO_ODD: isNumerical = true;break; case FuncName.CODE_POINTS_TO_STRING: isString = true; break; case FuncName.COMPARE: isBoolean= true;break; case FuncName.UPPER_CASE: isString = true; break; case FuncName.LOWER_CASE: isString = true; break; case FuncName.ENDS_WITH: isBoolean= true;break; case FuncName.QNAME: isString = true; break; case FuncName.LOCAL_NAME_FROM_QNAME: isString = true; break; case FuncName.NAMESPACE_URI_FROM_QNAME: isString = true; break; case FuncName.NAMESPACE_URI_FOR_PREFIX: isString = true; break; case FuncName.RESOLVE_QNAME: isString = true; break; case FuncName.IRI_TO_URI: isString = true; break; case FuncName.ESCAPE_HTML_URI: isString = true; break; case FuncName.ENCODE_FOR_URI: isString = true; break; case FuncName.MATCH_NAME: isBoolean =true; break; case FuncName.MATCH_LOCAL_NAME: isBoolean=true;break; case FuncName.NOT_MATCH_NAME: isBoolean =true; break; case FuncName.NOT_MATCH_LOCAL_NAME: isBoolean=true;break; case FuncName.GENERATE_ID : isString = true; break; case FuncName.FORMAT_NUMBER: isString = true;break; case FuncName.KEY: isNodeSet = true; state = START; vg = new VTDGen(); break; case FuncName.DOCUMENT: isNodeSet = true; state = START; vg = new VTDGen();break; case FuncName.CURRENT: isNodeSet = true; state = START; vg = new VTDGen();break; case FuncName.SYSTEM_PROPERTY: isString = true; break; case FuncName.ELEMENT_AVAILABLE: isBoolean = true; break; case FuncName.FUNCTION_AVAILABLE: isBoolean = true; break; //case FuncName. //default: isNumerical = true; break; } } final public boolean checkArgumentCount(){ switch(opCode){ case FuncName.LAST: return argCount==0; case FuncName.POSITION: return argCount==0; case FuncName.COUNT: return (argCount==1 && argumentList.e.isNodeSet()); case FuncName.LOCAL_NAME: return (argCount==0 ||(argCount==1 && argumentList.e.isNodeSet())); case FuncName.NAMESPACE_URI: return (argCount==0 ||(argCount==1 && argumentList.e.isNodeSet())); case FuncName.NAME: return (argCount==0 ||(argCount==1 && argumentList.e.isNodeSet())); case FuncName.STRING: return argCount < 2; case FuncName.CONCAT: return argCount > 1; case FuncName.STARTS_WITH: return argCount ==2; case FuncName.CONTAINS: return argCount ==2; case FuncName.SUBSTRING_BEFORE: return argCount==2; case FuncName.SUBSTRING_AFTER: return argCount==2; case FuncName.SUBSTRING: return argCount==2 || argCount==3; case FuncName.STRING_LENGTH: return argCount<2; case FuncName.NORMALIZE_SPACE: return argCount <2; case FuncName.TRANSLATE: return argCount ==3; case FuncName.BOOLEAN: return argCount ==1; case FuncName.NOT: return argCount ==1; case FuncName.TRUE: return argCount ==0; case FuncName.FALSE: return argCount ==0; case FuncName.LANG: return (argCount==1); case FuncName.NUMBER: return argCount==1; case FuncName.SUM: return (argCount==1 && argumentList.e.isNodeSet()); case FuncName.FLOOR: return argCount==1; case FuncName.CEILING: return argCount==1; case FuncName.ROUND: return argCount==1; case FuncName.ABS: return argCount==1; case FuncName.ROUND_HALF_TO_EVEN : return argCount==1 || argCount == 2; case FuncName.ROUND_HALF_TO_ODD: return argCount==1 || argCount == 2; case FuncName.CODE_POINTS_TO_STRING: break; case FuncName.COMPARE: break; case FuncName.UPPER_CASE: return argCount==1; case FuncName.LOWER_CASE: return argCount==1; case FuncName.ENDS_WITH: return argCount==2; case FuncName.QNAME: break; case FuncName.LOCAL_NAME_FROM_QNAME: break; case FuncName.NAMESPACE_URI_FROM_QNAME: break; case FuncName.NAMESPACE_URI_FOR_PREFIX: break; case FuncName.RESOLVE_QNAME: break; case FuncName.IRI_TO_URI: break; case FuncName.ESCAPE_HTML_URI: break; case FuncName.ENCODE_FOR_URI: break; case FuncName.MATCH_NAME: return argCount==1 || argCount == 2; case FuncName.MATCH_LOCAL_NAME: return argCount==1 || argCount == 2; case FuncName.NOT_MATCH_NAME: return argCount==1 || argCount == 2; case FuncName.NOT_MATCH_LOCAL_NAME: return argCount==1 || argCount == 2; case FuncName.CURRENT: return argCount==0; case FuncName.GENERATE_ID : return argCount==0 || (argCount ==1 && argumentList.e.isNodeSet()); case FuncName.FORMAT_NUMBER: return argCount==2 || argCount == 3; case FuncName.KEY: return argCount==2; case FuncName.DOCUMENT: return argCount==1 || (argCount==2 && argumentList.next.e.isNodeSet()); case FuncName.SYSTEM_PROPERTY: return argCount==1 && argumentList.e.isString() ; case FuncName.ELEMENT_AVAILABLE: return argCount==1 && argumentList.e.isString(); case FuncName.FUNCTION_AVAILABLE: return argCount==1 && argumentList.e.isString(); } return false; } private String getSystemProperty(VTDNav vn){ String s = argumentList.e.evalString(vn); return ""; } private boolean isElementAvailable(VTDNav vn){ String s = argumentList.e.evalString(vn); return false; } private boolean isFunctionAvailable(VTDNav vn){ String s = argumentList.e.evalString(vn); return false; } final public String toString(){ if (argumentList == null) return fname()+" ("+")"; return fname()+" ("+argumentList +")"; } private String formatNumber(VTDNav vn){ return ""; } private String getLocalName(VTDNav vn){ if (argCount== 0){ try{ int index = vn.getCurrentIndex(); int type = vn.getTokenType(index); if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME)) { int offset = vn.getTokenOffset(index); int length = vn.getTokenLength(index); if (length < 0x10000){ if (vn.localNameIndex != index){ vn.localNameIndex = index; vn.localName = vn.toRawString(index); } return vn.localName; } else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0){ if (vn.localNameIndex != index){ vn.localNameIndex = index; vn.localName = vn.toRawString(offset + preLen+1, QLen - preLen - 1); } return vn.localName; } else { if (vn.localNameIndex != index){ vn.localNameIndex = index; vn.localName = vn.toRawString(offset, QLen); } return vn.localName; } } } else if (type == VTDNav.TOKEN_PI_NAME){ //int offset = vn.getTokenOffset(index); //int length = vn.getTokenLength(index); if (vn.localNameIndex != index){ vn.localNameIndex = index; vn.localName = vn.toRawString(index); } return vn.localName; }else return ""; }catch(NavException e){ return ""; // this will almost never occur } } else if (argCount == 1){ int a=evalFirstArgumentListNodeSet2(vn); if (a == -1 || vn.ns == false) return ""; int type = vn.getTokenType(a); /*if (type!=VTDNav.TOKEN_STARTING_TAG && type!= VTDNav.TOKEN_ATTR_NAME) return "";*/ if (type == VTDNav.TOKEN_STARTING_TAG || type== VTDNav.TOKEN_ATTR_NAME){ try { int offset = vn.getTokenOffset(a); int length = vn.getTokenLength(a); if (length < 0x10000) return vn.toRawString(a); else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0) return vn.toRawString(offset + preLen+1, QLen - preLen - 1); else { return vn.toRawString(offset, QLen); } } } catch (NavException e) { return ""; // this will almost never occur } }else if (type == VTDNav.TOKEN_PI_NAME){ try{ return vn.toRawString(a); }catch(NavException e){ return ""; } }else return ""; } else throw new IllegalArgumentException ("local-name()'s argument count is invalid"); } private String getNameSpaceURI(VTDNav vn){ if (argCount==0){ try{ int i = vn.getCurrentIndex(); int type = vn.getTokenType(i); if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME)) { int a = vn.lookupNS(); if (a == 0) return ""; else return vn.toString(a); } return ""; }catch (Exception e){ return ""; } }else if (argCount==1 && argumentList.e.isNodeSet()){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } String s=""; // return a; try { if (a == -1 || vn.ns == false) ; else { int type = vn.getTokenType(a); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME) s= vn.toString(vn.lookupNS()); } } catch (Exception e){} ; vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return s; }else throw new IllegalArgumentException ("namespace-uri()'s argument count is invalid"); } private String getName(VTDNav vn){ int a; if (argCount==0){ a = vn.getCurrentIndex(); int type = vn.getTokenType(a); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_PI_NAME){ try{ if (vn.nameIndex!=a){ vn.name = vn.toRawString(a); vn.nameIndex = a; } return vn.name; }catch(Exception e){ return ""; } } else return ""; } else if (argCount == 1){ a = evalFirstArgumentListNodeSet2(vn); try { if (a == -1 || vn.ns == false) return ""; else { int type = vn.getTokenType(a); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_PI_NAME) return vn.toRawString(a); return ""; } } catch (Exception e) { } return ""; }else throw new IllegalArgumentException ("name()'s argument count is invalid"); } // ISO 639 // http://www.loc.gov/standards/iso639-2/php/English_list.php // below are defined two-letter words // // ab , aa , af, ak, sq, am, ar, an, hy, as, av, ae, ay, az, bm // ba , eu , be, bn, bh, bi, nb, bs, br, bg, my, es, ca, km, ch // ce , ny , zh, za, cu, cv, kw, co, cr, hr, cs, da, dv, dv, nl // dz , en , eo, et, ee, fo, fj, fi, nl, fr, ff, gd, gl, lg, ka // de , ki , el, kl, gn, gu, ht, ha, he, hz, hi, ho, hu, is, io // ig , id , ia, ie, iu, ik, ga, it, ja, jv, kl, kn, kr, ks, kk // ki , rw , ky, kv, kg, ko, kj, ku, kj, ky, lo, la, lv, lb, li // ln , lt , lu, lb, mk, mg, ms, ml, dv, mt, gv, mi, mr, mh, mo // mn , na , nv, nv, nd, nr, ng, ne, nd, se, no, nb, nn, ii, nn, // ie , oc , oj, cu, or, om, os, pi, pa, ps, fa, pl, pt, oc, pa, // ps , qu , ro, rm, rn, ru, sm, sa, sc, gd, sr, sn, ii, si, sk, // sl , so , st, nr, es, su, sw, ss, sv, tl, ty, tg, ta, tt, te, // th , bo , ti, to, ts, tn, tr, tk, tw, ug, uk, ur, ug, uz, ca, // ve , vi , vo, wa, cy, fy, wo, xh, yi, yo, za, zu private boolean lang(VTDNav vn, String s){ // check the length of s boolean b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i!=-1){ b = vn.matchTokenString(i,s); break; } vn.toElement(VTDNav.P); } } catch (NavException e) { } vn.pop2(); return b; } private boolean startsWith(VTDNav vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ //boolean b = false; int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return "".startsWith(s2); else{ try{ int t = vn.getTokenType(a); if (t!=VTDNav.TOKEN_STARTING_TAG&&t!=VTDNav.TOKEN_DOCUMENT) return vn.startsWith(a, s2); else return vn.XPathStringVal_StartsWith(a,s2); }catch(Exception e){ } return false; } } String s1 = argumentList.e.evalString(vn); return s1.startsWith(s2); } private int evalFirstArgumentListNodeSet(VTDNav vn){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { a++; } /*else if (t == VTDNav.TOKEN_STARTING_TAG) { // a = vn.getText(); }*/else if (t == VTDNav.TOKEN_PI_NAME){ //if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL) a++; //else // a=-1; } //else if (t== VTDNav.T) } } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; } private int evalFirstArgumentListNodeSet2(VTDNav vn){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; } private boolean endsWith(VTDNav vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return "".startsWith(s2); else{ try{ int t=vn.getTokenType(a); if (t!=VTDNav.TOKEN_STARTING_TAG && t!=VTDNav.TOKEN_DOCUMENT) return vn.endsWith(a, s2); else return vn.XPathStringVal_EndsWith(a, s2); }catch(Exception e){ } return false; } } String s1 = argumentList.e.evalString(vn); return s1.endsWith(s2); } private boolean contains(VTDNav vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return false; try { int t=vn.getTokenType(a); if (t!=VTDNav.TOKEN_STARTING_TAG && t!=VTDNav.TOKEN_DOCUMENT) return vn.contains(a, s2); else return vn.XPathStringVal_Contains(a,s2); }catch (Exception e){ return false; } } String s1 = argumentList.e.evalString(vn); //return s1.contains(s2); return s1.indexOf(s2)!=-1; //return (s1.i)) } private String subString(VTDNav vn){ if (argCount== 2){ String s = argumentList.e.evalString(vn); double d1 = Math.floor(argumentList.next.e.evalNumber(vn)+0.5d); if (d1!=d1 || d1>s.length()) return ""; return s.substring(Math.max((int)(d1-1),0)); } else if (argCount == 3){ String s = argumentList.e.evalString(vn); double d1 = Math.floor(argumentList.next.e.evalNumber(vn) + 0.5d); double d2 = Math .floor(argumentList.next.next.e.evalNumber(vn) + 0.5d); //int i1 = Math.max(0, (int) d1 - 1); if ((d1 + d2) != (d1 + d2) || d1 > s.length()) return ""; return s.substring(Math.max(0, (int) d1 - 1), Math.min(s.length(), (int) (d1 - 1) + (int) d2)); //(int) argumentList.next.next.e.evalNumber(vn)-1); } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String subStringBefore(VTDNav vn){ if (argCount==2){ String s1 = argumentList.e.evalString(vn); String s2 = argumentList.next.e.evalString(vn); int len1 = s1.length(); int len2 = s2.length(); for (int i=0;i<len1;i++){ if (s1.regionMatches(i,s2,0,len2)) return s1.substring(0,i); } return ""; } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String subStringAfter(VTDNav vn){ if (argCount==2){ String s1 = argumentList.e.evalString(vn); String s2 = argumentList.next.e.evalString(vn); int len1 = s1.length(); int len2 = s2.length(); for (int i=0;i<len1;i++){ if (s1.regionMatches(i,s2,0,len2)) return s1.substring(i+len2); } return ""; } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String translate(VTDNav vn) { //if (argCount == 3) { String resultStr = argumentList.e.evalString(vn); String indexStr = argumentList.next.e.evalString(vn); if (resultStr == null || resultStr.length() == 0 || indexStr == null || indexStr.length() == 0) return resultStr; String replace = argumentList.next.next.e.evalString(vn); StringBuilder usedCharStr = new StringBuilder(); int lenRep = (replace != null) ? replace.length() : 0; for (int i = 0; i < indexStr.length(); i++) { char idxChar = indexStr.charAt(i); if (usedCharStr.indexOf(String.valueOf(idxChar)) < 0) { if (i < lenRep) { resultStr = resultStr.replace(idxChar, replace.charAt(i)); } else { resultStr = resultStr.replaceAll( String.valueOf(idxChar), ""); } usedCharStr.append(idxChar); } } return resultStr; /*} else { throw new IllegalArgumentException( "Argument count for translate() is invalid. Expected: 3; Actual: " + argCount); }*/ } private String normalizeSpace(VTDNav vn){ if (argCount== 0){ String s =null; try{ if (vn.atTerminal){ int ttype = vn.getTokenType(vn.LN); if (ttype == VTDNav.TOKEN_CDATA_VAL ) s= vn.toRawString(vn.LN); else if (ttype == VTDNav.TOKEN_ATTR_NAME || ttype == VTDNav.TOKEN_ATTR_NS){ s = vn.toNormalizedString(vn.LN+1); } else s= vn.toNormalizedString(vn.LN); }else { int i = vn.getCurrentIndex(); int t = vn.getTokenType(i); if (t==VTDNav.TOKEN_STARTING_TAG || t==VTDNav.TOKEN_DOCUMENT){ s = vn.toNormalizedXPathString(i); }else s= vn.toNormalizedString(i); } return s; } catch(NavException e){ return ""; // this will almost never occur } } else if (argCount == 1){ String s=""; if (argumentList.e.isNodeSet()){ //boolean b = false; int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else { try{ int t = vn.getTokenType(a); if (t==VTDNav.TOKEN_STARTING_TAG || t==VTDNav.TOKEN_DOCUMENT){ s = vn.toNormalizedXPathString(a); }else s = vn.toNormalizedString(a); } catch (Exception e){ } return s; } } else { s = argumentList.e.evalString(vn); return normalize(s); } } throw new IllegalArgumentException ("normalize-space()'s argument count is invalid"); //return null; } private String normalize(String s){ int len = s.length(); StringBuffer sb = new StringBuffer(len); int i=0; // strip off leading ws for(i=0;i<len;i++){ if (isWS(s.charAt(i))){ }else{ break; } } while(i<len){ char c = s.charAt(i); if (!isWS(c)){ sb.append(c); i++; } else { while(i<len){ c = s.charAt(i); if (isWS(c)) i++; else break; } if (i<len) sb.append(' '); } } return sb.toString(); } private boolean isWS(char c){ if (c==' ' || c=='\t' || c=='\r'||c=='\n') return true; return false; } private String concat(VTDNav vn){ StringBuffer sb = new StringBuffer(); //if (argCount>=2){ Alist temp = argumentList; while(temp!=null){ sb.append(temp.e.evalString(vn)); temp = temp.next; } return sb.toString(); //} else // throw new IllegalArgumentException //("concat()'s argument count is invalid"); } private String getString(VTDNav vn){ if (argCount== 0) try{ if (vn.atTerminal){ if (vn.getTokenType(vn.LN) == VTDNav.TOKEN_CDATA_VAL ) return vn.toRawString(vn.LN); return vn.toString(vn.LN); } return vn.getXPathStringVal(); } catch(NavException e){ return ""; // this will almost never occur } else if (argCount == 1){ return argumentList.e.evalString(vn); } else throw new IllegalArgumentException ("String()'s argument count is invalid"); } final public String evalString(VTDNav vn) throws UnsupportedException{ // int d=0; switch(opCode){ case FuncName.CONCAT: return concat(vn); //throw new UnsupportedException("Some functions are not supported"); case FuncName.LOCAL_NAME: return getLocalName(vn); case FuncName.NAMESPACE_URI: return getNameSpaceURI(vn); case FuncName.NAME: return getName(vn); case FuncName.STRING: return getString(vn); case FuncName.SUBSTRING_BEFORE: return subStringBefore(vn); case FuncName.SUBSTRING_AFTER: return subStringAfter(vn); case FuncName.SUBSTRING: return subString(vn); case FuncName.TRANSLATE: return translate(vn); case FuncName.NORMALIZE_SPACE: return normalizeSpace(vn); case FuncName.CODE_POINTS_TO_STRING: throw new com.ximpleware.xpath.UnsupportedException("not yet implemented"); case FuncName.UPPER_CASE: return upperCase(vn); case FuncName.LOWER_CASE: return lowerCase(vn); case FuncName.QNAME: case FuncName.LOCAL_NAME_FROM_QNAME: case FuncName.NAMESPACE_URI_FROM_QNAME: case FuncName.NAMESPACE_URI_FOR_PREFIX: case FuncName.RESOLVE_QNAME: case FuncName.IRI_TO_URI: case FuncName.ESCAPE_HTML_URI: case FuncName.ENCODE_FOR_URI: throw new com.ximpleware.xpath.UnsupportedException("not yet implemented"); case FuncName.GENERATE_ID: return generateID(vn); case FuncName.FORMAT_NUMBER: return formatNumber(vn); case FuncName.SYSTEM_PROPERTY: return getSystemProperty(vn); default: if (isBoolean()){ if (evalBoolean(vn)== true) return "true"; else return "false"; } else { double tmp = evalNumber(vn); if (tmp - ((int)tmp) ==0 ) return ""+ (int)tmp; else return ""+ tmp; } } } final public double evalNumber(VTDNav vn){ int ac = 0; switch(opCode){ case FuncName.LAST: /*if (argCount!=0 ) throw new IllegalArgumentException ("floor()'s argument count is invalid");*/ return contextSize; case FuncName.POSITION: /* if (argCount!=0 ) throw new IllegalArgumentException ("position()'s argument count is invalid");*/ return position; case FuncName.COUNT: return count(vn); case FuncName.NUMBER: /*if (argCount!=1) throw new IllegalArgumentException ("number()'s argument count is invalid");*/ return argumentList.e.evalNumber(vn); case FuncName.SUM: return sum(vn); case FuncName.FLOOR: /*if (argCount!=1 ) throw new IllegalArgumentException("floor ()'s argument count is invalid");*/ return Math.floor(argumentList.e.evalNumber(vn)); case FuncName.CEILING: /*if (argCount!=1 ) throw new IllegalArgumentException("ceiling()'s argument count is invalid");*/ return Math.ceil(argumentList.e.evalNumber(vn)); case FuncName.STRING_LENGTH: ac = argCount; if (ac == 0){ try{ if (vn.atTerminal == true){ int type = vn.getTokenType(vn.LN); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS){ return vn.getStringLength(vn.LN+1); } else { return vn.getStringLength(vn.LN); } }else { int i = vn.getText(); if (i==-1) return 0; else return vn.getStringLength(i); } }catch (NavException e){ return 0; } } else if (ac == 1){ return argumentList.e.evalString(vn).length(); } else { throw new IllegalArgumentException("string-length()'s argument count is invalid"); } case FuncName.ROUND: /*if (argCount!=1 ) throw new IllegalArgumentException("round()'s argument count is invalid");*/ return Math.floor(argumentList.e.evalNumber(vn))+0.5d; case FuncName.ABS: /*if (argCount!=1 ) throw new IllegalArgumentException("abs()'s argument count is invalid");*/ return Math.abs(argumentList.e.evalNumber(vn)); case FuncName.ROUND_HALF_TO_EVEN : return roundHalfToEven(vn); case FuncName.ROUND_HALF_TO_ODD: throw new com.ximpleware.xpath.UnsupportedException("not yet implemented"); default: if (isBoolean){ if (evalBoolean(vn)) return 1; else return 0; }else { try { double dval = Double.parseDouble(evalString(vn)); return dval; }catch (NumberFormatException e){ return Double.NaN; } } } } private double roundHalfToEven(VTDNav vn) { //int numArg = argCount; if (argCount < 1 || argCount > 2){ throw new IllegalArgumentException("Argument count for roundHalfToEven() is invalid. Expected: 1 or 2; Actual: " + argCount); } double value = argumentList.e.evalNumber(vn); long precision = (argCount == 2)? (long)Math.floor(argumentList.next.e.evalNumber(vn)+0.5d) : 0; if(value < 0) return -roundHalfToEvenPositive(-value, precision); else return roundHalfToEvenPositive(value, precision); } private double roundHalfToEvenPositive(double value, long precision){ final double ROUNDING_EPSILON = 0.00000001; long dec = 1; //shif the decimal point by precision long absPre = Math.abs(precision); for(int i = 0; i < absPre; i++){ dec *= 10; } if(precision > 0) value *= dec; else if (precision < 0)value /= dec; double result = 0; long intPart = (long)value; //'value' is exctly halfway between two integers if(Math.abs(value -(intPart +0.5d)) < ROUNDING_EPSILON){ // 'ipart' is even if(intPart%2 == 0){ result = intPart; }else{// nearest even integer result = (long)Math.ceil( intPart + 0.5d ); } }else{ //use the usual round to closest result = Math.round(value); } //shif the decimal point back to where it was if(precision > 0) result /= dec; else if(precision < 0) result *= dec; return result; } /** * */ final public int evalNodeSet(VTDNav vn) throws XPathEvalException { switch (opCode) { case FuncName.CURRENT: if (state == START) { vn.loadCurrentNode(); state = END; return vn.getCurrentIndex2(); } else { return -1; } // break; case FuncName.DOCUMENT: if (argCount == 1) { if (!argumentList.e.isNodeSet()) { if (state == START) { String s = argumentList.e.evalString(vn); if (s.length() == 0) { newVN = xslVN; newVN.context[0] = -1; } else if (vg.parseFile(s, true)) { newVN = vg.getNav(); newVN.context[0] = -1; newVN.URIName = s; } else { state = END; return -1; } state = END; return 0; } else { return -1; } } else { try { if (state != END) { a = argumentList.e.evalNodeSet(vn); if (a != -1) { String s = vn.toString(getStringVal(vn,a)); if (s.length() == 0) { newVN = xslVN; newVN.context[0] = -1; } else if (vg.parseFile(s, true)) { newVN = vg.getNav(); newVN.context[0] = -1; newVN.URIName = s; } else { state = END; return -1; } state = END; return 0; } else { state = END; return -1; } } else return -1; } catch (NavException e) { } } } break; case FuncName.KEY: throw new XPathEvalException(" key() not yet implemented "); // break; } throw new XPathEvalException(" Function Expr can't eval to node set "); } private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME ) return i+1; else return i; } final public boolean evalBoolean(VTDNav vn){ switch(opCode){ case FuncName.STARTS_WITH: //if (argCount!=2){ // throw new IllegalArgumentException("starts-with()'s argument count is invalid"); //} return startsWith(vn); case FuncName.CONTAINS: /*if (argCount!=2){ throw new IllegalArgumentException("contains()'s argument count is invalid"); }*/ return contains(vn); case FuncName.TRUE: /*if (argCount!=0){ throw new IllegalArgumentException("true() doesn't take any argument"); }*/ return true; case FuncName.FALSE:/*if (argCount!=0){ throw new IllegalArgumentException("false() doesn't take any argument"); }*/ return false; case FuncName.BOOLEAN: /*if (argCount!=1){ throw new IllegalArgumentException("boolean() doesn't take any argument"); }*/ return argumentList.e.evalBoolean(vn); case FuncName.NOT: /*if (argCount!=1){ throw new IllegalArgumentException("not() doesn't take any argument"); }*/ return !argumentList.e.evalBoolean(vn); case FuncName.LANG: /*if (argCount!=1){ throw new IllegalArgumentException("lang()'s argument count is invalid"); }*/ return lang(vn,argumentList.e.evalString(vn)); case FuncName.COMPARE:throw new com.ximpleware.xpath.UnsupportedException("not yet implemented"); case FuncName.ENDS_WITH: /*if (argCount!=2){ throw new IllegalArgumentException("ends-with()'s argument count is invalid"); }*/ return endsWith(vn); case FuncName.MATCH_NAME:return matchName(vn); case FuncName.MATCH_LOCAL_NAME: return matchLocalName(vn); case FuncName.NOT_MATCH_NAME:return !matchName(vn); case FuncName.NOT_MATCH_LOCAL_NAME: return !matchLocalName(vn); case FuncName.ELEMENT_AVAILABLE: return isElementAvailable(vn); case FuncName.FUNCTION_AVAILABLE: return isFunctionAvailable(vn); default: if (isNumerical()){ double d = evalNumber(vn); if (d==0 || d!=d) return false; return true; }else{ return evalString(vn).length()!=0; } } } final public void reset(VTDNav vn){ a = 0; state = START; //contextSize = 0; if (argumentList!=null) argumentList.reset(vn); } public String fname(){ switch(opCode){ case FuncName.LAST: return "last"; case FuncName.POSITION: return "position"; case FuncName.COUNT: return "count"; case FuncName.LOCAL_NAME: return "local-name"; case FuncName.NAMESPACE_URI: return "namespace-uri"; case FuncName.NAME: return "name"; case FuncName.STRING: return "string"; case FuncName.CONCAT: return "concat"; case FuncName.STARTS_WITH: return "starts-with"; case FuncName.CONTAINS: return "contains"; case FuncName.SUBSTRING_BEFORE: return "substring-before"; case FuncName.SUBSTRING_AFTER: return "substring-after"; case FuncName.SUBSTRING: return "substring"; case FuncName.STRING_LENGTH: return "string-length"; case FuncName.NORMALIZE_SPACE: return "normalize-space"; case FuncName.TRANSLATE: return "translate"; case FuncName.BOOLEAN: return "boolean"; case FuncName.NOT: return "not"; case FuncName.TRUE: return "true"; case FuncName.FALSE: return "false"; case FuncName.LANG: return "lang"; case FuncName.NUMBER: return "number"; case FuncName.SUM: return "sum"; case FuncName.FLOOR: return "floor"; case FuncName.CEILING: return "ceiling"; case FuncName.ROUND: return "round"; // added for 2.0 case FuncName.ABS: return "abs"; case FuncName.ROUND_HALF_TO_EVEN : return "round-half-to-even"; case FuncName.ROUND_HALF_TO_ODD: return "round-half-to-odd"; case FuncName.CODE_POINTS_TO_STRING: return "code-points-to-string"; case FuncName.COMPARE: return "compare"; case FuncName.UPPER_CASE: return "upper-case"; case FuncName.LOWER_CASE: return "lower-case"; case FuncName.ENDS_WITH: return "ends-with"; case FuncName.QNAME: return "QName"; case FuncName.LOCAL_NAME_FROM_QNAME: return "local-name-from-QName"; case FuncName.NAMESPACE_URI_FROM_QNAME: return "namespace-uri-from-QName"; case FuncName.NAMESPACE_URI_FOR_PREFIX: return "namespace-uri-for-prefix"; case FuncName.RESOLVE_QNAME: return "resolve-QName"; case FuncName.IRI_TO_URI: return "iri-to-uri"; case FuncName.ESCAPE_HTML_URI: return "escape-html-uri"; case FuncName.ENCODE_FOR_URI: return "encode-for-uri"; case FuncName.MATCH_NAME: return "match-name"; case FuncName.MATCH_LOCAL_NAME: return "match-local-name"; case FuncName.CURRENT: return "current"; case FuncName.GENERATE_ID: return "generate-id"; case FuncName.FORMAT_NUMBER: return "format-number"; case FuncName.KEY: return "key"; default: return "document"; } } final public boolean isNodeSet(){ return isNodeSet; } final public boolean isNumerical(){ return isNumerical; } final public boolean isString(){ return isString; } final public boolean isBoolean(){ return isBoolean; } private int count(VTDNav vn){ int a = -1; // if (argCount!=1 || argumentList.e.isNodeSet()==false) // throw new IllegalArgumentException // ("Count()'s argument count is invalid"); vn.push2(); int size= vn.contextStack2.size ; try{ a = 0; argumentList.e.adjust(vn.getTokenCount()); while(argumentList.e.evalNodeSet(vn)!=-1){ //System.out.println(" ===>"+vn.getCurrentIndex()); a ++; } }catch(Exception e){ System.out.println("exception in count"); } argumentList.e.reset(vn); vn.contextStack2.size = size; vn.pop2(); return a; } private double sum(VTDNav vn){ double d=0; /*if (argCount != 1 || argumentList.e.isNodeSet() == false) throw new IllegalArgumentException("sum()'s argument count or type is invalid");*/ vn.push2(); int size = vn.contextStack2.size; try { a = 0; int i1; while ((a =argumentList.e.evalNodeSet(vn)) != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); if (i1!=-1) d += vn.parseDouble(i1); if (Double.isNaN(d)) break; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS){ d += vn.parseDouble(a+1); if (Double.isNaN(d)) break; } else if (t == VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL || t== VTDNav.TOKEN_COMMENT){ d += vn.parseDouble(a); if (Double.isNaN(d)) break; } else if (t==VTDNav.TOKEN_PI_NAME){ if (a+1<vn.vtdSize && vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL){ d += vn.parseDouble(a+1); } else { d = Double.NaN; break; } } // fib1.append(i); } argumentList.e.reset(vn); vn.contextStack2.size = size; vn.pop2(); return d; } catch (Exception e) { argumentList.e.reset(vn); vn.contextStack2.size = size; vn.pop2(); return Double.NaN; } } // to support computer context size // needs to add final public boolean requireContextSize(){ if (opCode == FuncName.LAST) return true; else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ if (temp.e.requireContextSize()){ return true; } temp = temp.next; } } return false; } final public void setContextSize(int size){ if (opCode == FuncName.LAST){ contextSize = size; //System.out.println("contextSize: "+size); } else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ temp.e.setContextSize(size); temp = temp.next; } } } public void setPosition(int pos){ if (opCode == FuncName.POSITION){ position = pos; //System.out.println("PO: "+size); } else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ temp.e.setPosition(pos); temp = temp.next; } } } public int adjust(int n){ int i = 0; switch(opCode){ case FuncName.COUNT: case FuncName.SUM: i = argumentList.e.adjust(n); break; default: } return i; } private String upperCase(VTDNav vn){ if (argCount==1){ if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else{ try{ int t = vn.getTokenType(a); if (t!= VTDNav.TOKEN_STARTING_TAG && t!=VTDNav.TOKEN_DOCUMENT) return vn.toStringUpperCase(a); return vn.getXPathStringVal2(a, (short)1); }catch(Exception e){ } return ""; } }else { return (argumentList.e.evalString(vn)).toUpperCase(); } }else throw new IllegalArgumentException ("upperCase()'s argument count is invalid"); } private String lowerCase(VTDNav vn){ if (argCount==1){ if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else{ try{ int t = vn.getTokenType(a); if (t!= VTDNav.TOKEN_STARTING_TAG && t!=VTDNav.TOKEN_DOCUMENT) return vn.toStringLowerCase(a); return vn.getXPathStringVal2(a,(short)2); }catch(Exception e){ } return ""; } }else { return (argumentList.e.evalString(vn)).toLowerCase(); } }else throw new IllegalArgumentException ("lowerCase()'s argument count is invalid"); } private boolean matchName(VTDNav vn){ int a; if (argCount == 1) { a = vn.getCurrentIndex(); int type = vn.getTokenType(a); String s1 = argumentList.e.evalString(vn); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_PI_NAME) { try { return vn.matchRawTokenString(a, s1); } catch (Exception e) { return false; } } else return false; } else if (argCount == 2) { a = evalFirstArgumentListNodeSet2(vn); String s1 = argumentList.next.e.evalString(vn); try { if (a == -1 || vn.ns == false) return false; else { int type = vn.getTokenType(a); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_PI_NAME) return vn.matchRawTokenString(a, s1); return false; } } catch (Exception e) { } return false; } else throw new IllegalArgumentException( "name()'s argument count is invalid"); } private boolean matchLocalName(VTDNav vn){ if (argCount== 1){ try{ int index = vn.getCurrentIndex(); int type = vn.getTokenType(index); String s1 = argumentList.e.evalString(vn); if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME)) { int offset = vn.getTokenOffset(index); int length = vn.getTokenLength(index); if (length < 0x10000 || (length>>16)==0){ return (vn.compareRawTokenString(index, s1)==0);//vn.toRawString(index); } else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0){ return (vn.compareRawTokenString(offset + preLen+1, QLen - preLen - 1,s1)==0); } } } else if (type == VTDNav.TOKEN_PI_NAME){ return vn.compareRawTokenString(index, s1)==0; } else return "".equals(s1); }catch(NavException e){ return false; // this will never occur } } else if (argCount == 2){ int a=evalFirstArgumentListNodeSet2(vn); String s1 = argumentList.next.e.evalString(vn); if (a == -1 || vn.ns == false) return "".equals(s1); int type = vn.getTokenType(a); if (type==VTDNav.TOKEN_STARTING_TAG || type== VTDNav.TOKEN_ATTR_NAME){ //return "".equals(s1); try { int offset = vn.getTokenOffset(a); int length = vn.getTokenLength(a); if (length < 0x10000 || (length>> 16)==0) return vn.compareRawTokenString(a,s1)==0; else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0) return vn.compareRawTokenString(offset + preLen+1, QLen - preLen - 1,s1)==0; /*else { return vn.toRawString(offset, QLen); }*/ } } catch (NavException e) { return "".equals(s1); // this will almost never occur } }else if (type == VTDNav.TOKEN_PI_NAME){ try{ return vn.compareRawTokenString(a,s1)==0; }catch(NavException e){ return "".equals(s1); } } return "".equals(s1); } else throw new IllegalArgumentException ("local-name()'s argument count is invalid"); return false; } /** * generate-id(nodeset?); * @param vn * @return */ private String generateID(VTDNav vn){ if (argCount== 0){ return "v"+vn.getCurrentIndex2(); }else if (argCount== 1) { int i=evalFirstArgumentListNodeSet2(vn); return "v"+i; } else throw new IllegalArgumentException ("generate-id()'s argument count is invalid"); } public boolean isFinal(){ Alist temp = argumentList; if (temp ==null) return false; if (temp.e==null) return false; boolean s=true; while(temp!=null){ s= s && temp.e.isFinal(); if (!s) return false; temp = temp.next; } return s; } public void markCacheable2(){ Alist temp =argumentList; while(temp!=null ){ if (temp.e!=null){ if (temp.e.isFinal() && temp.e.isNodeSet()){ CachedExpr ce = new CachedExpr(temp.e); temp.e = ce; } temp.e.markCacheable2(); } temp = temp.next; } } public void markCacheable(){ Alist temp =argumentList; while(temp!=null){ if (temp.e!=null) temp.e.markCacheable(); temp = temp.next; } } public void clearCache(){ Alist temp =argumentList; while(temp!=null ){ if (temp.e!=null){ temp.e.clearCache(); } temp = temp.next; } } }
52,256
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDNav.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/VTDNav.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * * This class is created to update VTDNav's implementation with * a more thread safe version */ package com.ximpleware; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import com.ximpleware.parser.ISO8859_15; import com.ximpleware.parser.ISO8859_14; import com.ximpleware.parser.ISO8859_13; import com.ximpleware.parser.ISO8859_11; import com.ximpleware.parser.ISO8859_10; import com.ximpleware.parser.ISO8859_2; import com.ximpleware.parser.ISO8859_3; import com.ximpleware.parser.ISO8859_4; import com.ximpleware.parser.ISO8859_5; import com.ximpleware.parser.ISO8859_6; import com.ximpleware.parser.ISO8859_7; import com.ximpleware.parser.ISO8859_8; import com.ximpleware.parser.ISO8859_9; import com.ximpleware.parser.UTF8Char; import com.ximpleware.parser.WIN1250; import com.ximpleware.parser.WIN1251; import com.ximpleware.parser.WIN1252; import com.ximpleware.parser.WIN1253; import com.ximpleware.parser.WIN1254; import com.ximpleware.parser.WIN1255; import com.ximpleware.parser.WIN1256; import com.ximpleware.parser.WIN1257; import com.ximpleware.parser.WIN1258; /** * The VTD Navigator allows one to navigate XML document represented in VTD * records and Location caches. There is one and only one cursor that you can * navigate to any part of the tree. If a method operating on a node doesn't * accept the node as input, by default it refers to the cursor element. The * hierarchy consists entirely of elements. */ public class VTDNav { // Navigation directions public final static int ROOT = 0; public final static int PARENT = 1; public final static int FIRST_CHILD = 2; public final static int LAST_CHILD = 3; public final static int NEXT_SIBLING = 4; public final static int PREV_SIBLING = 5; // Navigation directions public final static int R = 0; public final static int P = 1; public final static int FC = 2; public final static int LC = 3; public final static int NS = 4; public final static int PS = 5; // token type definitions public final static int TOKEN_STARTING_TAG = 0; public final static int TOKEN_ENDING_TAG = 1; public final static int TOKEN_ATTR_NAME = 2; public final static int TOKEN_ATTR_NS = 3; public final static int TOKEN_ATTR_VAL = 4; public final static int TOKEN_CHARACTER_DATA = 5; public final static int TOKEN_COMMENT = 6; public final static int TOKEN_PI_NAME = 7; public final static int TOKEN_PI_VAL = 8; public final static int TOKEN_DEC_ATTR_NAME = 9; public final static int TOKEN_DEC_ATTR_VAL = 10; public final static int TOKEN_CDATA_VAL = 11; public final static int TOKEN_DTD_VAL = 12; public final static int TOKEN_DOCUMENT =13; // encoding format definition here public final static int FORMAT_UTF8 = 2; public final static int FORMAT_ASCII = 0; public final static int FORMAT_ISO_8859_1 = 1; public final static int FORMAT_ISO_8859_2 = 3; public final static int FORMAT_ISO_8859_3 = 4; public final static int FORMAT_ISO_8859_4 = 5; public final static int FORMAT_ISO_8859_5 = 6; public final static int FORMAT_ISO_8859_6 = 7; public final static int FORMAT_ISO_8859_7 = 8; public final static int FORMAT_ISO_8859_8 = 9; public final static int FORMAT_ISO_8859_9 = 10; public final static int FORMAT_ISO_8859_10 = 11; public final static int FORMAT_ISO_8859_11 = 12; public final static int FORMAT_ISO_8859_12 = 13; public final static int FORMAT_ISO_8859_13 = 14; public final static int FORMAT_ISO_8859_14 = 15; public final static int FORMAT_ISO_8859_15 = 16; public final static int FORMAT_ISO_8859_16 = 17; public final static int FORMAT_WIN_1250 = 18; public final static int FORMAT_WIN_1251 = 19; public final static int FORMAT_WIN_1252 = 20; public final static int FORMAT_WIN_1253 = 21; public final static int FORMAT_WIN_1254 = 22; public final static int FORMAT_WIN_1255 = 23; public final static int FORMAT_WIN_1256 = 24; public final static int FORMAT_WIN_1257 = 25; public final static int FORMAT_WIN_1258 = 26; public final static int FORMAT_UTF_16LE = 64; public final static int FORMAT_UTF_16BE = 63; // String style public final static int STRING_RAW =0; public final static int STRING_REGULAR = 1; public final static int STRING_NORMALIZED = 2; // masks for obtaining various fields from a VTD token protected final static long MASK_TOKEN_FULL_LEN = 0x000fffff00000000L; protected final static long MASK_TOKEN_PRE_LEN = 0x000ff80000000000L; protected final static long MASK_TOKEN_QN_LEN = 0x000007ff00000000L; protected long MASK_TOKEN_OFFSET = 0x000000003fffffffL; protected final static long MASK_TOKEN_TYPE = 0xf000000000000000L; protected final static long MASK_TOKEN_DEPTH = 0x0ff0000000000000L; // tri-state variable for namespace lookup protected final static long MASK_TOKEN_NS_MARK = 0x00000000c0000000L; protected short maxLCDepthPlusOne =4; protected int rootIndex; // where the root element is at protected int nestingLevel; protected int[] context; // main navigation tracker aka context object protected boolean atTerminal; // this variable is to make vn compatible with // xpath's data model // location cache part protected int l2upper; protected int l2lower; protected int l3upper; protected int l3lower; protected int l2index; protected int l3index; protected int l1index; // containers protected FastLongBuffer vtdBuffer; protected FastLongBuffer l1Buffer; protected FastLongBuffer l2Buffer; protected FastIntBuffer l3Buffer; protected IByteBuffer XMLDoc; //private int recentNS; // most recently visited NS node, experiment for // now // Hierarchical representation is an array of integers addressing elements // tokens protected ContextBuffer contextStack; protected ContextBuffer contextStack2;// this is reserved for XPath protected int LN; // record txt and attrbute for XPath eval purposes // the document encoding protected int encoding; //protected boolean writeOffsetAdjustment; // for string to token comparison //protected int currentOffset; //protected int currentOffset2; // whether the navigation is namespace enabled or not. protected boolean ns; // intermediate buffer for push and pop purposes protected int[] stackTemp; protected int docOffset; // length of the document protected int docLen; protected int vtdSize; //vtd record count protected String name; protected int nameIndex; protected String localName; protected int localNameIndex; protected FastIntBuffer fib;//for store string value protected boolean shallowDepth; protected BookMark currentNode; protected String URIName; protected int count; protected VTDNav(){} /** * Initialize the VTD navigation object. * * @param RootIndex * int * @param maxDepth * int * @param encoding * int * @param NS * boolean * @param x * byte[] * @param vtd * com.ximpleware.ILongBuffer * @param l1 * com.ximpleware.ILongBuffer * @param l2 * com.ximpleware.ILongBuffer * @param l3 * com.ximpleware.IIntBuffer * @param so * int starting offset of the document(in byte) * @param length * int length of the document (in byte) */ protected VTDNav( int RootIndex, int enc, boolean NS, int depth, IByteBuffer x, FastLongBuffer vtd, FastLongBuffer l1, FastLongBuffer l2, FastIntBuffer l3, int so, // start offset of the starting offset(in byte) int length) // lengnth of the XML document (in byte)) { // initialize all buffers if (l1 == null || l2 == null || l3 == null || vtd == null || x == null || depth < 0 || RootIndex < 0 //|| encoding <= FORMAT_UTF8 //|| encoding >= FORMAT_ISO_8859_1 || so < 0 || length < 0) { throw new IllegalArgumentException(); } count=0; l1Buffer = l1; l2Buffer = l2; l3Buffer = l3; vtdBuffer = vtd; XMLDoc = x; encoding = enc; //System.out.println("encoding " + encoding); rootIndex = RootIndex; nestingLevel = depth + 1; ns = NS; // namespace aware or not if (ns == false) MASK_TOKEN_OFFSET = 0x000000007fffffffL; // this allows xml size to // be 2GB else // if there is no namespace MASK_TOKEN_OFFSET = 0x000000003fffffffL; atTerminal = false; //this variable will only change value during XPath // eval // initialize the context object this.context = new int[nestingLevel]; //depth value is the first entry in the context because root is // singular. context[0] = 0; //set the value to zero for (int i = 1; i < nestingLevel; i++) { context[i] = -1; } //currentOffset = 0; //contextStack = new ContextBuffer(1024, nestingLevel + 7); contextStack = new ContextBuffer(10, nestingLevel + 9); contextStack2 = new ContextBuffer(10, nestingLevel+9); stackTemp = new int[nestingLevel + 9]; // initial state of LC variables l1index = l2index = l3index = -1; l2lower = l3lower = -1; l2upper = l3upper = -1; docOffset = so; docLen = length; //System.out.println("offset " + offset + " length " + length); //printL2Buffer(); vtdSize = vtd.size; //writeOffsetAdjustment = false; //recentNS = -1; name = null; nameIndex = -1; localName = null; localNameIndex = -1; fib = new FastIntBuffer(5); // page size is 32 ints shallowDepth = true; } /** * Return the attribute count of the element at the cursor position. when ns * is false, attr_ns tokens are considered attributes; otherwise, ns tokens * are not considered attributes * * @return int */ public int getAttrCount() { if (context[0]==-1)return 0; int count = 0; int index = getCurrentIndex() + 1; while (index < vtdSize) { int type = getTokenType(index); if (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_VAL || type == TOKEN_ATTR_NS) { if (type == TOKEN_ATTR_NAME || (!ns && (type == TOKEN_ATTR_NS))) { count++; } } else break; index++; } return count; } /** * Get the token index of the attribute value given an attribute name. * * @return int (-1 if no such attribute name exists) * @param an * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * @exception IllegalArguementException * if an is null */ public int getAttrVal(String an) throws NavException { //int size = vtdBuffer.size(); if (context[0]==-1 /*|| atTerminal*/) return -1; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; int type; if (index<vtdSize) type= getTokenType(index); else return -1; if (ns == false) { while ((type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (matchRawTokenString(index, an)) { // ns node visible only ns is disabled return index + 1; } index += 2; if (index >= vtdSize) break; type = getTokenType(index); } } else { while ((type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (type == TOKEN_ATTR_NAME && matchRawTokenString( index, an)) { // ns node visible only ns is disabled return index + 1; } index += 2; if (index>=vtdSize) break; type = getTokenType(index); } } return -1; } /** * Get the token index of the attribute value of given URL and local name. * If ns is not enabled, the lookup will return -1, indicating a no-found. * Also namespace nodes are invisible using this method. One can't use * to * indicate any name space because * is ambiguous!! * * @return int (-1 if no matching attribute found) * @param URL * java.lang.String (Name space URL) * @param ln * java.lang.String (local name) * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * @exception IllegalArguementException * if s is null */ public int getAttrValNS(String URL, String ln) throws NavException { if (!ns || context[0]==-1 /*|| atTerminal*/) return -1; if (URL!=null && URL.length()==0) URL = null; if (URL == null) return getAttrVal(ln); int size = vtdBuffer.size; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; // point to the token next to the element tag int type; if (index<vtdSize) type = getTokenType(index); else return -1; while (index < size && (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { int i = getTokenLength(index); int offset = getTokenOffset(index); int preLen = (i >> 16) & 0xffff; int fullLen = i & 0xffff; if (preLen != 0 // attribute name without a prefix is not bound to any // namespaces && matchRawTokenString( offset + preLen + 1, fullLen - preLen - 1, ln) && resolveNS(URL, offset, preLen)) { return index + 1; } else if ( preLen==3 && matchRawTokenString(offset, 3,"xml") && URL.equals("http://www.w3.org/XML/1998/namespace")){ // prefix matches "xml" return index+1; } index += 2; if (index>=vtdSize) break; type = getTokenType(index); } return -1; } private long handle_utf8(long temp, int offset) throws NavException { int c, d, a; long val; switch (UTF8Char.byteCount((int)temp & 0xff)) { case 2: c = 0x1f; d = 6; a = 1; break; case 3: c = 0x0f; d = 12; a = 2; break; case 4: c = 0x07; d = 18; a = 3; break; case 5: c = 0x03; d = 24; a = 4; break; case 6: c = 0x01; d = 30; a = 5; break; default: throw new NavException("UTF 8 encoding error: should never happen"); } val = (temp & c) << d; int i = a - 1; while (i >= 0) { temp = XMLDoc.byteAt(offset + a - i); if ((temp & 0xc0) != 0x80) throw new NavException( "UTF 8 encoding error: should never happen"); val = val | ((temp & 0x3f) << ((i << 2) + (i << 1))); i--; } //currentOffset += a + 1; return val | (((long)(a+1))<<32); } private long handle_utf16le(int offset) throws NavException { // implement UTF-16LE to UCS4 conversion int val, temp = (XMLDoc.byteAt((offset << 1) + 1 ) & 0xff) << 8 | (XMLDoc.byteAt(offset << 1) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // check for low surrogate if (temp == '\r') { if (XMLDoc.byteAt((offset << 1) + 2) == '\n' && XMLDoc.byteAt((offset << 1) + 3) == 0) { return '\n' | (2L<<32) ; } else { return '\n' | (1L<<32); } } return temp | (1L<<32); } else { if (temp<0xd800 || temp>0xdbff) throw new NavException("UTF 16 LE encoding error: should never happen"); val = temp; temp = (XMLDoc.byteAt((offset << 1) + 3)&0xff) << 8 | (XMLDoc.byteAt((offset << 1) + 2) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be high surrogate throw new NavException("UTF 16 LE encoding error: should never happen"); } val = ((temp - 0xd800)<<10) + (val - 0xdc00) + 0x10000; return val | (2L<<32); } //System.out.println("UTF 16 LE unimplemented for now"); } private long handle_utf16be(int offset) throws NavException{ long val; int temp = ((XMLDoc.byteAt(offset << 1) & 0xff) << 8) |(XMLDoc.byteAt((offset << 1) + 1)& 0xff); if ((temp < 0xd800) || (temp > 0xdfff)) { // not a high surrogate if (temp == '\r') { if (XMLDoc.byteAt((offset << 1) + 3) == '\n' && XMLDoc.byteAt((offset << 1) + 2) == 0) { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } //currentOffset++; return temp| (1L<<32); } else { if (temp<0xd800 || temp>0xdbff) throw new NavException("UTF 16 BE encoding error: should never happen"); val = temp; temp = ((XMLDoc.byteAt((offset << 1) + 2) & 0xff) << 8) | (XMLDoc.byteAt((offset << 1 )+ 3) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be a low surrogate here throw new NavException("UTF 16 BE encoding error: should never happen"); } val = ((temp - 0xd800) << 10) + (val - 0xdc00) + 0x10000; //currentOffset += 2; return val | (2L<<32); } } private long getChar4OtherEncoding(int offset) throws NavException{ if (encoding <= FORMAT_WIN_1258){ int temp = decode(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return temp|(1L<<32); } throw new NavException("Unknown Encoding"); } /** * This method decodes the underlying byte array into corresponding UCS2 * char representation . It doesn't resolves built-in entity and character * references. Length will never be zero Creation date: (11/21/03 6:26:17 * PM) * * @return int * @exception com.ximpleware.NavException * The exception is thrown if the underlying byte content * contains various errors. Notice that we are being * conservative in making little assumption on the * correctness of underlying byte content. This is because * the VTD can be generated by another machine, e.g. from a * load-balancer. */ private long getChar(int offset) throws NavException { long temp = 0; //int a, c, d; //int val; //int ch; //int inc; //a = c = d = val = 0; switch (encoding) { case FORMAT_ASCII : // ascii is compatible with UTF-8, the offset // value is bytes temp = XMLDoc.byteAt(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return temp|(1L<<32); case FORMAT_ISO_8859_1 : temp = XMLDoc.byteAt(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return (temp & 0xff)|(1L<<32); case FORMAT_UTF8 : temp = XMLDoc.byteAt(offset); if (temp>=0){ if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } //currentOffset++; return temp|(1L<<32); } return handle_utf8(temp,offset); case FORMAT_UTF_16BE : return handle_utf16be(offset); case FORMAT_UTF_16LE : return handle_utf16le(offset); default : return getChar4OtherEncoding(offset); //throw new NavException("Unknown Encoding"); } } /* * the exact same copy of getChar except it operates on currentOffset2 this * is needed to compare VTD tokens directly */ /** * This method decodes the underlying byte array into corresponding UCS2 * char representation . Also it resolves built-in entity and character * references. * * @return int * @exception com.ximpleware.NavException * The exception is thrown if the underlying byte content * contains various errors. Notice that we are being * conservative in making little assumption on the * correctness of underlying byte content. This is because * the VTD can be generated by another machine from a * load-balancer. */ private long getCharResolved(int offset) throws NavException { int ch = 0; int val = 0; long inc =2; long l = getChar(offset); ch = (int)l; if (ch != '&') return l; // let us handle references here //currentOffset++; offset++; ch = getCharUnit(offset); offset++; switch (ch) { case '#' : ch = getCharUnit(offset); if (ch == 'x') { while (true) { offset++; inc++; ch = getCharUnit(offset); if (ch >= '0' && ch <= '9') { val = (val << 4) + (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { val = (val << 4) + (ch - 'a' + 10); } else if (ch >= 'A' && ch <= 'F') { val = (val << 4) + (ch - 'A' + 10); } else if (ch == ';') { inc++; break; } else throw new NavException("Illegal char in a char reference"); } } else { while (true) { ch = getCharUnit(offset); offset++; inc++; if (ch >= '0' && ch <= '9') { val = val * 10 + (ch - '0'); } else if (ch == ';') { break; } else throw new NavException("Illegal char in char reference"); } } break; case 'a' : ch = getCharUnit(offset); if (ch == 'm') { if (getCharUnit(offset + 1) == 'p' && getCharUnit(offset + 2) == ';') { inc = 5; val = '&'; } else throw new NavException("illegal builtin reference"); } else if (ch == 'p') { if (getCharUnit(offset + 1) == 'o' && getCharUnit(offset + 2) == 's' && getCharUnit(offset + 3) == ';') { inc = 6; val = '\''; } else throw new NavException("illegal builtin reference"); } else throw new NavException("illegal builtin reference"); break; case 'q' : if (getCharUnit(offset) == 'u' && getCharUnit(offset + 1) == 'o' && getCharUnit(offset + 2) == 't' && getCharUnit(offset + 3) ==';') { inc = 6; val = '\"'; } else throw new NavException("illegal builtin reference"); break; case 'l' : if (getCharUnit(offset) == 't' && getCharUnit(offset + 1) == ';') { //offset += 2; inc = 4; val = '<'; } else throw new NavException("illegal builtin reference"); break; case 'g' : if (getCharUnit(offset) == 't' && getCharUnit(offset + 1) == ';') { inc = 4; val = '>'; } else throw new NavException("illegal builtin reference"); break; default : throw new NavException("Invalid entity char"); } //currentOffset++; return val | (inc << 32); } private int decode(int offset){ byte ch = XMLDoc.byteAt(offset); switch(encoding){ case FORMAT_ISO_8859_2: return ISO8859_2.decode(ch); case FORMAT_ISO_8859_3: return ISO8859_3.decode(ch); case FORMAT_ISO_8859_4: return ISO8859_4.decode(ch); case FORMAT_ISO_8859_5: return ISO8859_5.decode(ch); case FORMAT_ISO_8859_6: return ISO8859_6.decode(ch); case FORMAT_ISO_8859_7: return ISO8859_7.decode(ch); case FORMAT_ISO_8859_8: return ISO8859_8.decode(ch); case FORMAT_ISO_8859_9: return ISO8859_9.decode(ch); case FORMAT_ISO_8859_10: return ISO8859_10.decode(ch); case FORMAT_ISO_8859_11: return ISO8859_11.decode(ch); case FORMAT_ISO_8859_13: return ISO8859_13.decode(ch); case FORMAT_ISO_8859_14: return ISO8859_14.decode(ch); case FORMAT_ISO_8859_15: return ISO8859_15.decode(ch); case FORMAT_WIN_1250: return WIN1250.decode(ch); case FORMAT_WIN_1251: return WIN1251.decode(ch); case FORMAT_WIN_1252: return WIN1252.decode(ch); case FORMAT_WIN_1253: return WIN1253.decode(ch); case FORMAT_WIN_1254: return WIN1254.decode(ch); case FORMAT_WIN_1255: return WIN1255.decode(ch); case FORMAT_WIN_1256: return WIN1256.decode(ch); case FORMAT_WIN_1257: return WIN1257.decode(ch); default: return WIN1258.decode(ch); } } /** * Dump the in memory XML text into output stream * * @param os * @throws java.io.IOException * */ public void dumpXML(OutputStream os) throws java.io.IOException{ os.write(this.XMLDoc.getBytes(),this.docOffset,this.docLen); } /** * Dump the in-memory copy of XML text into a file * * @param fileName * @throws java.io.IOException * */ public void dumpXML(String fileName) throws java.io.IOException{ FileOutputStream fos = new FileOutputStream(fileName); try{ dumpXML(fos); } finally{ fos.close(); } } /** * Get the next char unit which gets decoded automatically * * @return int */ private int getCharUnit(int offset) { return (encoding <= 2) ? XMLDoc.byteAt(offset) & 0xff : (encoding <= FORMAT_WIN_1258) ? decode(offset):(encoding == FORMAT_UTF_16BE) ? (((int)XMLDoc.byteAt(offset << 1)) << 8 | XMLDoc.byteAt((offset << 1) + 1)) : (((int)XMLDoc.byteAt((offset << 1) + 1)) << 8 | XMLDoc.byteAt(offset << 1)); } /** * Get the depth (>=0) of the current element. Creation date: (11/16/03 * 6:58:22 PM) * * @return int */ final public int getCurrentDepth() { return context[0]; } /** * Get the index value of the current element. Creation date: (11/16/03 * 6:40:25 PM) * * @return int */ final public int getCurrentIndex() { if (atTerminal) return LN; return getCurrentIndex2(); //return (context[0] == 0) ? rootIndex : context[context[0]]; } // this one is used in iterAttr() in autoPilot final protected int getCurrentIndex2(){ switch(context[0]){ case -1: return 0; case 0: return rootIndex; default: return context[context[0]]; } } /** * getElementFragmentNS returns a ns aware version of the element fragment * encapsulated in an ElementFragment object * * @return an ElementFragment object * @throws NavException * */ public ElementFragmentNs getElementFragmentNs() throws NavException{ if (this.ns == false) throw new NavException("getElementFragmentNS can only be called when parsing is ns enabled"); FastIntBuffer fib = new FastIntBuffer(3); // init size 8 //fill the fib with integer // first get the list of name space nodes int[] ia = context; int d =ia[0]; // -1 for document node, 0 for root element; int c = getCurrentIndex2(); int len = (c == 0 || c == rootIndex )? 0: (getTokenLength(c) & 0xffff); // get the length of qualified node // put the neighboring ATTR_NS nodes into the array // and record the total # of them int i = 0; int count=0; if (d > 0){ // depth > 0 every node except document and root element int k=getCurrentIndex2()+1; if (k<this.vtdSize){ while(k<this.vtdSize){ int type = this.getTokenType(k); if (type==VTDNav.TOKEN_ATTR_NAME || type==VTDNav.TOKEN_ATTR_NS) if (type == VTDNav.TOKEN_ATTR_NS){ fib.append(k); //System.out.println(" ns name ==>" + toString(k)); } k+=2; //type = this.getTokenType(k); } } count = fib.size; d--; while (d >= 0) { // then search for ns node in the vinicity of the ancestor nodes if (d > 0) { // starting point k = ia[d]+1; } else { // starting point k = this.rootIndex+1; } if (k<this.vtdSize){ while (k < this.vtdSize) { int type = this.getTokenType(k); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { boolean unique = true; if (type == VTDNav.TOKEN_ATTR_NS) { for (int z = 0; z < fib.size; z++) { //System.out.println("fib size ==> // "+fib.size); //if (fib.size==4); if (matchTokens(fib.intAt(z), this, k)) { unique = false; break; } } if (unique) fib.append(k); } } k += 2; // type = this.getTokenType(k); } } d--; } // System.out.println("count ===> "+count); // then restore the name space node by shifting the array int newSz= fib.size-count; for (i= 0; i<newSz; i++ ){ fib.modifyEntry(i,fib.intAt(i+count)); } fib.resize(newSz); } long l = getElementFragment(); return new ElementFragmentNs(this,l,fib,len); } /** * Return the byte offset and length of up to i sibling fragments. If * there is a i+1 sibling element, the cursor element would * move to it; otherwise, there is no cursor movement. If the cursor isn't * positioned at an element (due to XPath evaluation), then -1 will be * returned * @param i number of silbing elements including the cursor element * @return a long encoding byte offset (bit 31 to bit 0), length (bit 62 * to bit 32) of those fragments * @throws NavException */ public long getSiblingElementFragments(int i) throws NavException{ if (i<=0) throw new IllegalArgumentException(" # of sibling can be less or equal to 0"); // get starting char offset if(atTerminal==true) return -1L; // so is the char offset int so = getTokenOffset(getCurrentIndex())-1; // char offset to byte offset conversion if (encoding>=FORMAT_UTF_16BE) so = so<<1; BookMark bm = new BookMark(this); bm.recordCursorPosition(); while(i>1 && toElement(VTDNav.NEXT_SIBLING)){ i--; } long l= getElementFragment(); int len = (int)l+(int)(l>>32)-so; if (i==1 && toElement(VTDNav.NEXT_SIBLING)){ }else bm.setCursorPosition(); return (((long)len)<<32)|so; } /** * Get the starting offset and length of an element encoded in a long, upper * 32 bits is length; lower 32 bits is offset Unit is in byte. Creation * date: (3/15/04 1:47:55 PM) */ public long getElementFragment() throws NavException { // a little scanning is needed // has next sibling case // if not int depth = getCurrentDepth(); // document length and offset returned if depth == -1 if (depth == -1){ int i=vtdBuffer.lower32At(0); if (i==0) return ((long)docLen)<<32| docOffset; else return ((long)(docLen-32))| 32; } int so = getTokenOffset(getCurrentIndex2()) - 1; int length = 0; // for an element with next sibling if (toElement(NEXT_SIBLING)) { int temp = getCurrentIndex(); int temp2 = temp; //boolean b = false; // rewind while (getTokenDepth(temp) == depth && (getTokenType(temp)==VTDNav.TOKEN_COMMENT || getTokenType(temp)==VTDNav.TOKEN_PI_VAL || getTokenType(temp)==VTDNav.TOKEN_PI_NAME)) { temp--; } /*if(temp!=temp2) temp++;*/ //temp++; int so2 = getTokenOffset(temp) - 1; // look for the first '>' while (getCharUnit(so2) != '>') { so2--; } length = so2 - so + 1; toElement(PREV_SIBLING); if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } // for root element if (depth == 0) { int temp = vtdBuffer.size - 1; boolean b = false; int so2 = 0; while (getTokenDepth(temp) == -1) { temp--; // backward scan b = true; } if (b == false) so2 = (encoding <= FORMAT_WIN_1258 ) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; else so2 = getTokenOffset(temp + 1); while (getCharUnit(so2) != '>') { so2--; } length = so2 - so + 1; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } // for a non-root element with no next sibling int temp = getCurrentIndex() + 1; int size = vtdBuffer.size; // temp is not the last entry in VTD buffer if (temp < size) { while (temp < size && getTokenDepth(temp) >= depth) { temp++; } if (temp != size) { int d = depth - getTokenDepth(temp) + ((getTokenType(temp) == TOKEN_STARTING_TAG) ? 1 : 0); int so2 = getTokenOffset(temp) - 1; int i = 0; // scan backward while (i < d) { if (getCharUnit(so2) == '>') i++; so2--; } length = so2 - so + 2; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } /* * int so2 = getTokenOffset(temp - 1) - 1; int d = depth - * getTokenDepth(temp - 1); int i = 0; while (i < d) { if * (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + * 2; if (encoding < 3) return ((long) length) < < 32 | so; else * return ((long) length) < < 33 | (so < < 1); */ } // temp is the last entry // scan forward search for /> or </cc> int so2 = (encoding <= FORMAT_WIN_1258) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; int d; d = depth + 1; int i = 0; while (i < d) { if (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + 2; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } /** * Get the encoding of the XML document. * * @return int */ final public int getEncoding() { return encoding; } /** * Get the maximum nesting depth of the XML document (>0). max depth is * nestingLevel -1 * * @return int */ final public int getNestingLevel() { return nestingLevel; } /** * Return the charater (not byte) offset after head (the ending bracket of the starting tag, * not including an empty element, in which case 0xffffffff 00000000 | len is returned) * @return * */ final public long getOffsetAfterHead(){ int i = getCurrentIndex(); if (getTokenType(i)!=VTDNav.TOKEN_STARTING_TAG){ return -1; } int j=i+1; while (j<vtdSize && (getTokenType(j)==VTDNav.TOKEN_ATTR_NAME || getTokenType(j)==VTDNav.TOKEN_ATTR_NS)){ j += 2; } int offset; // this is character offset if (i+1==j) { offset = getTokenOffset(i)+ ((ns==false)?getTokenLength(i):(getTokenLength(i)&0xff)); }else { offset = getTokenOffset(j-1)+((ns==false)?getTokenLength(j-1):(getTokenLength(j-1)&0xff))+1; } while(getCharUnit(offset)!='>'){ offset++; } if (getCharUnit(offset-1)=='/') return 0xffffffff00000000L|(offset); else return offset+1; } final protected long getOffsetBeforeTail() throws NavException{ long l = getElementFragment(); int offset = (int)l; int len = (int)(l>>32); // byte to char conversion if (this.encoding >= VTDNav.FORMAT_UTF_16BE){ offset <<= 1; len <<=1; } offset += len; if (getCharUnit(offset-2)=='/') return 0xffffffff00000000L | offset-1; else{ offset -= 2; while(getCharUnit(offset)!='/'){ offset--; } return offset -1; } //return 1; } /** * Get root index value , which is the index val of root element * * @return int */ final public int getRootIndex() { return rootIndex; } /** * This method returns of the token index of the type character data or * CDATA. Notice that it is intended to support data orient XML (not * mixed-content XML). return the index of the text token, or -1 if none * exists. * * @return int */ public int getText() { if (context[0]==-1) return -1; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; int depth = getCurrentDepth(); int type; if (index<vtdSize || !atTerminal) type = getTokenType(index); else return -1; while (true) { if (type == TOKEN_CHARACTER_DATA || type == TOKEN_CDATA_VAL) { if (depth == getTokenDepth(index)) return index; else return -1; } else if (type == TOKEN_ATTR_NS || type == TOKEN_ATTR_NAME) { index += 2; // assuming a single token for attr val } else if ( type == TOKEN_PI_NAME || type == TOKEN_PI_VAL || type == TOKEN_COMMENT) { if (depth == getTokenDepth(index)) { index += 1; } else return -1; } else return -1; if (index >= vtdSize) break; type = getTokenType(index); } return -1; } /** * Get total number of VTD tokens for the current XML document. * * @return int */ final public int getTokenCount() { return vtdSize; } /** * Get the depth value of a token (>=0). * * @return int * @param index * int */ final public int getTokenDepth(int index) { int i = (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_DEPTH) >> 52); if (i != 255) return i; return -1; } final protected int getTokenLength2(int index){ return (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_FULL_LEN) >> 32); } /** * Get the token length at the given index value please refer to VTD spec * for more details Length is in terms of the UTF char unit For prefixed * tokens, it is the qualified name length. When ns is not enabled, return * the full name length for attribute name and element name When ns is * enabled, return an int with upper 16 bit for prefix length, lower 16 bit * for qname length * * @return int * @param index * int */ public int getTokenLength(int index) { int type = getTokenType(index); int depth; int len = 0; long l; int temp=0; switch (type) { case TOKEN_ATTR_NAME : case TOKEN_ATTR_NS : case TOKEN_STARTING_TAG : l = vtdBuffer.longAt(index); return (ns == false) ? (int) ((l & MASK_TOKEN_QN_LEN) >> 32) : ((int) ((l & MASK_TOKEN_QN_LEN) >> 32) | ((int) ((l & MASK_TOKEN_PRE_LEN) >> 32) << 5)); case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: // make sure this is total length depth = getTokenDepth(index); do{ len = len + (int) ((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN) >> 32); temp = getTokenOffset(index)+(int) ((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN) >> 32); index++; } while(index < vtdSize && depth == getTokenDepth(index) && type == getTokenType(index) && temp == getTokenOffset(index)); //if (int k=0) return len; default : return (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_FULL_LEN) >> 32); } } /** * Get the starting offset (unit in native char) of the token at the given * index. * * @return int * @param index * int */ final public int getTokenOffset(int index) { //return (context[0] != 0) // ? (int) (vtdBuffer.longAt(context[context[0]]) & MASK_TOKEN_OFFSET) // : (int) (vtdBuffer.longAt(rootIndex) & MASK_TOKEN_OFFSET); return (int) (vtdBuffer.longAt(index) & MASK_TOKEN_OFFSET); } /** * Get the XML document * * @return IByteBuffer */ final public IByteBuffer getXML() { return XMLDoc; } /** * Get the token type of the token at the given index value. Creation date: * (11/16/03 6:41:51 PM) * * @return int * @param index * int */ final public int getTokenType(int index) { return (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf; } /** * Test whether current element has an attribute with the matching name. "*" * will match any attribute name, therefore is a test whether there is any * attribute at all if namespace is disabled, this function will not * distinguish between ns declaration and attribute otherwise, ns tokens are * invisible Creation date: (11/16/03 5:50:26 PM) * * @return boolean (true if such an attribute exists) * @param an * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * @exception IllegalArguementException * if an is null */ final public boolean hasAttr(String an) throws NavException { return getAttrVal(an)!=-1; } /** * Test whether the current element has an attribute with matching namespace * URL and localname. If ns is false, return false immediately * * @return boolean * @param URL * java.lang.String (namespace URL) * @param ln * java.lang.String (localname ) * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. * @exception IllegalArguementException * if ln is null */ final public boolean hasAttrNS(String URL, String ln) throws NavException { return (getAttrValNS(URL, ln) != -1); } /** * Test the token type, to see if it is a starting tag. * * @return boolean * @param index * int */ protected final boolean isElement(int index) { return (((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf) == TOKEN_STARTING_TAG; } /** * Test the token type, to see if it is a starting tag or document token * (introduced in 1.0). * * @return boolean * @param index * int */ protected final boolean isElementOrDocument(int index){ long i =(((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf); return (i==TOKEN_STARTING_TAG||i==TOKEN_DOCUMENT); } /** * Test whether ch is a white space character or not. * * @return boolean * @param ch * int */ final private boolean isWS(int ch) { return (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r'); } /** * This function is called by selectElement_P in autoPilot * * @param en * element Name * @param a * context of current position * @param special * whether the test type is node() * @return boolean * @throws NavException */ protected boolean iterate_preceding(String en, int[] a, int endIndex) throws NavException { int index = getCurrentIndex() +1; int tokenType; //int depth = getTokenDepth(index); //int size = vtdBuffer.size; while (index< endIndex) { tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index = index + 2; continue; case TOKEN_STARTING_TAG: //case TOKEN_DOCUMENT: int depth = getTokenDepth(index); if (index!=a[depth]){ if (en.equals("*")||matchRawTokenString(index,en)){ context[0] = depth; if (depth > 0) context[depth] = index; if (depth < maxLCDepthPlusOne) resolveLC(); atTerminal = false; return true; }else{ context[depth] = index; index++; continue; } }else{ context[depth] = index; index++; continue; } case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: index++; continue; case TOKEN_PI_NAME: index+=2; continue; } index++; } return false; } /** * This function is called by selectElementNS_P in autoPilot * * @param URL * @param ln * @return boolean * @throws NavException */ protected boolean iterate_precedingNS(String URL, String ln, int[] a,int endIndex ) throws NavException { int index = getCurrentIndex() - 1; int tokenType; //int depth = getTokenDepth(index); //int size = vtdBuffer.size; while (index< endIndex) { tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index = index + 2; continue; case TOKEN_STARTING_TAG: //case TOKEN_DOCUMENT: int depth = getTokenDepth(index); if (index!=a[depth]){ context[0] = depth; if (depth > 0) context[depth] = index; if (matchElementNS(ln,URL)){ if (depth < maxLCDepthPlusOne) resolveLC(); atTerminal = false; return true; }else{ context[depth] = index; index++; continue; } }else{ context[depth] = index; index++; continue; } case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: index++; continue; case TOKEN_PI_NAME: index+=2; continue; } index++; } return false; } /** * This function is called by selectElement_F in autoPilot * * @param en * ElementName * @param special * whether it is a node() * @return boolean * @throws NavException */ protected boolean iterate_following(String en, boolean special) throws NavException{ int index = getCurrentIndex() + 1; int tokenType; //int size = vtdBuffer.size; while (index < vtdSize) { tokenType = getTokenType(index); if (tokenType == VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME) { index = index + 2; continue; } // if (isElementOrDocument(index)) { if (tokenType == VTDNav.TOKEN_STARTING_TAG || tokenType == VTDNav.TOKEN_DOCUMENT) { int depth = getTokenDepth(index); context[0] = depth; if (depth > 0) context[depth] = index; if (special || matchElement(en)) { if (depth < maxLCDepthPlusOne) resolveLC(); return true; } } index++; } return false; } /** * This function is called by selectElementNS_F in autoPilot * * @param URL * @param ln * @return boolean * @throws NavException */ protected boolean iterate_followingNS(String URL, String ln) throws NavException{ int index = getCurrentIndex() + 1; int tokenType; //int size = vtdBuffer.size; while (index < vtdSize) { tokenType = getTokenType(index); if (tokenType == VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME) { index = index + 2; continue; } // if (isElementOrDocument(index)) { if (tokenType == VTDNav.TOKEN_STARTING_TAG || tokenType == VTDNav.TOKEN_DOCUMENT) { int depth = getTokenDepth(index); context[0] = depth; if (depth > 0) context[depth] = index; if (matchElementNS(URL, ln)) { if (depth < maxLCDepthPlusOne) resolveLC(); return true; } } index++; } return false; } /** * This method is similar to getElementByName in DOM except it doesn't * return the nodeset, instead it iterates over those nodes. Notice that * this method is called by the "iterate" method in the Autopilot class. "*" * will match any element Creation date: (12/2/03 2:31:20 PM) * * @return boolean * @param dp * int (The depth of the starting position before iterating) * @param en * java.lang.String * @exception com.ximpleware.NavException * The exception is signaled if the underlying byte content * contains various errors. Notice that we are being * conservative in making little assumption on the * correctness of underlying byte content. This is because * VTD records can be generated by another machine from a * load-balancer. null element name allowed represent * node()in XPath; */ protected boolean iterate(int dp, String en, boolean special) throws NavException { // the navigation doesn't rely on LC // get the current depth int index = getCurrentIndex() + 1; int tokenType; //int size = vtdBuffer.size; while (index < vtdSize) { tokenType = getTokenType(index); if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType ==VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } //if (isElementOrDocument(index)) { if (tokenType == VTDNav.TOKEN_STARTING_TAG || tokenType == VTDNav.TOKEN_DOCUMENT){ int depth = getTokenDepth(index); if (depth > dp) { context[0] = depth; if (depth>0) context[depth] = index; if (special || matchElement(en)) { if (dp< maxLCDepthPlusOne) resolveLC(); return true; } } else { return false; } } index++; } return false; } //preceding::node() protected boolean iterate_preceding_node(int[] a, int endIndex) throws NavException { int index = getCurrentIndex()+1; int tokenType; //int t,d; //int depth = getTokenDepth(index); //int size = vtdBuffer.size; while (index < endIndex) { tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index = index + 2; continue; case TOKEN_STARTING_TAG: //case TOKEN_DOCUMENT: int depth = getTokenDepth(index); if (depth>0 && (index!=a[depth])){ context[0] = depth; if (depth > 0) context[depth] = index; if (depth < maxLCDepthPlusOne) resolveLC(); atTerminal = false; return true; }else{ if (depth > 0) context[depth] = index; if (depth < maxLCDepthPlusOne) resolveLC(); index++; atTerminal = false; continue; } case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: case TOKEN_PI_NAME: depth = getTokenDepth(index); context[0]=depth; LN = index; atTerminal = true; sync(depth,index); return true; } index++; } return false; } protected boolean iterate_following_node() throws NavException { int index = getCurrentIndex() + 1; int tokenType; //int size = vtdBuffer.size; while (index < vtdSize) { tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index = index + 2; continue; case TOKEN_STARTING_TAG: case TOKEN_DOCUMENT: int depth = getTokenDepth(index); context[0] = depth; if (depth > 0) context[depth] = index; if (depth < maxLCDepthPlusOne) resolveLC(); atTerminal = false; return true; case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: case TOKEN_PI_NAME: depth = getTokenDepth(index); context[0]=depth; LN = index; atTerminal = true; sync(depth,index); return true; } index++; } return false; } /** * */ protected boolean iterateNode(int dp) throws NavException { // the navigation doesn't rely on LC // get the current depth int index = getCurrentIndex() + 1; int tokenType,depth; // int size = vtdBuffer.size; while (index < vtdSize) { tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index = index + 2; continue; case TOKEN_STARTING_TAG: case TOKEN_DOCUMENT: depth = getTokenDepth(index); atTerminal = false; if (depth > dp) { context[0] = depth; if (depth > 0) context[depth] = index; if (dp < maxLCDepthPlusOne) resolveLC(); return true; } else { return false; } case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_PI_NAME: case TOKEN_CDATA_VAL: depth = getTokenDepth(index); if (depth >= dp){ sync(depth,index); LN= index; context[0]= depth; atTerminal = true; return true; } return false; default: index ++; } } return false; } /** * This method is similar to getElementByName in DOM except it doesn't * return the nodeset, instead it iterates over those nodes . When URL is * "*" it will match any namespace if ns is false, return false immediately * * @return boolean * @param dp * int (The depth of the starting position before iterating) * @param URL * java.lang.String * @param ln * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because VTD records can be generated * by another machine from a load-balancer.. * @exception IllegalArguementException * if ln is null example * * int depth = nv.getCurrentDepth() while(iterateNS(depth, * "www.url.com","node_name")){ push(); // store the current position //move * position safely pop(); // load the position } */ protected boolean iterateNS(int dp, String URL, String ln) throws NavException { if (ns == false) return false; int tokenType; int index = getCurrentIndex() + 1; while (index < vtdSize) { tokenType = getTokenType(index); if(tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType ==VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } //if (isElementOrDocument(index)) { if (tokenType == VTDNav.TOKEN_STARTING_TAG || tokenType == VTDNav.TOKEN_DOCUMENT){ int depth = getTokenDepth(index); if (depth > dp) { context[0] = depth; if (depth>0) context[depth] = index; if (matchElementNS(URL, ln)) { if (dp < maxLCDepthPlusOne) resolveLC(); return true; } } else { return false; } } index++; } return false; } /** * Test if the current element matches the given name. Creation date: * (11/26/03 2:09:43 PM) * * @return boolean * @param en * java.lang.String * @exception com.ximpleware.NavException * If the underlying raw char representation has errors. */ final public boolean matchElement(String en) throws NavException { if (en.equals("*") && context[0]!=-1) return true; if (context[0]==-1) return false; return matchRawTokenString( (context[0] == 0) ? rootIndex : context[context[0]], en); } /** * Test whether the current element matches the given namespace URL and * localname. URL, when set to "*", matches any namespace (including null), * when set to null, defines a "always-no-match" ln is the localname that, * when set to *, matches any localname * * @return boolean * @param URL * java.lang.String * @param ln * java.lang.String * @exception com.ximpleware.NavException * When there is any encoding conversion error or unknown * entity. * */ final public boolean matchElementNS(String URL, String ln) throws NavException { if (context[0]==-1) return false; int i = getTokenLength((context[0] != 0) ? context[context[0]] : rootIndex); int offset = getTokenOffset((context[0] != 0) ? context[context[0]] : rootIndex); int preLen = (i >> 16) & 0xffff; int fullLen = i & 0xffff; if (URL!=null && URL.length()==0) URL = null; if (ln.equals("*") || ((preLen != 0) ? matchRawTokenString( offset + preLen + 1, fullLen - preLen - 1, ln) : matchRawTokenString( offset, fullLen, ln))) { // no prefix, search for xmlns if (((URL != null) ? URL.equals("*") : false) || (resolveNS(URL, offset, preLen) == true)) return true; if ( preLen==3 && matchRawTokenString(offset, preLen,"xml") && URL.equals("http://www.w3.org/XML/1998/namespace")) return true; } return false; } final private boolean matchRawTokenString(int offset, int len, String s) throws NavException{ return compareRawTokenString(offset, len, s)==0; } final protected int compareTokenString(int offset, int len, String s) throws NavException { int i, l; long l1; //this.currentOffset = offset; int endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { l1 = getCharResolved(offset); int i1 = s.charAt(i); if (i1 < (int) l1) return 1; if (i1 > (int) l1) return -1; offset += (int) (l1 >> 32); } if (i == l && offset < endOffset) return 1; if (i < l && offset == endOffset) return -1; return 0; } /** * <em>New in 2.0</em> This method compares two VTD tokens of VTDNav * objects The behavior of this method is like compare the strings * corresponds to i1 and i2, meaning for text or attribute val, entities * will be converted into the corresponding char, return 0 if two tokens * are the identical when converted to Unicode String using toString() * respectively * * @param i1 * @param vn2 * @param i2 * @return -1,0 (when equal), or 1 * @throws NavException * */ final public int compareTokens(int i1, VTDNav vn2, int i2) throws NavException{ int t1, t2; int ch1, ch2; int endOffset1, endOffset2; long l; if ( i1 ==i2 && this == vn2) return 0; t1 = this.getTokenType(i1); t2 = vn2.getTokenType(i2); int offset1 = this.getTokenOffset(i1); int offset2 = vn2.getTokenOffset(i2); int len1 = (t1 == TOKEN_STARTING_TAG || t1 == TOKEN_ATTR_NAME || t1 == TOKEN_ATTR_NS) ? getTokenLength(i1) & 0xffff : getTokenLength(i1); int len2 = (t2 == TOKEN_STARTING_TAG || t2 == TOKEN_ATTR_NAME || t2 == TOKEN_ATTR_NS) ? vn2.getTokenLength(i2) & 0xffff : vn2.getTokenLength(i2); endOffset1 = len1+offset1; endOffset2 = len2+ offset2; for(;offset1<endOffset1&& offset2< endOffset2;){ if(t1 == VTDNav.TOKEN_CHARACTER_DATA || t1== VTDNav.TOKEN_ATTR_VAL){ l = this.getCharResolved(offset1); } else { l = this.getChar(offset1); } ch1 = (int)l; offset1 += (int)(l>>32); if(t2 == VTDNav.TOKEN_CHARACTER_DATA || t2== VTDNav.TOKEN_ATTR_VAL){ l = vn2.getCharResolved(offset2); } else { l = vn2.getChar(offset2); } ch2 = (int)l; offset2 += (int)(l>>32); if (ch1 > ch2) return 1; if (ch1 < ch2) return -1; } if (offset1 == endOffset1 && offset2 < endOffset2) return -1; else if (offset1 < endOffset1 && offset2 == endOffset2) return 1; else return 0; } /** * Lexicographically compare a string against a token with given offset and * len, entities doesn't get resolved. * * @return int (0 if they are equal, 1 if greater, else -1) * * @param offset * int * @param len * int * @param s * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ final protected int compareRawTokenString(int offset, int len, String s) throws NavException { int i, l; long l1; //this.currentOffset = offset; int endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { l1 = getChar(offset); int i1 = s.charAt(i); if (i1 < (int) l1) return 1; if (i1 > (int) l1) return -1; offset += (int) (l1 >> 32); } if (i == l && offset < endOffset) return 1; if (i<l && offset == endOffset) return -1; return 0; } /** * <em>New in 2.0</em> Compare the string against the token at the given * index value. When a token is an attribute name or starting tag, qualified * name is what gets compared against This method has to take care of the * underlying encoding conversion but it <em> doesn't </em> resolve entity * reference in the underlying document The behavior is the same as calling * toRawString on index, then compare to s * * @param index * @param s * @return the result of lexical comparison * @exception NavException * */ final public int compareRawTokenString(int index, String s) throws NavException { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime return compareRawTokenString(getTokenOffset(index), len, s); } /** * Match the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched * against This method has to take care of the underlying encoding * conversion but it <em> doesn't </em> resolve entity reference in the * underlying document * * @return boolean * @param index * int (index into the VTD token buffer) * @param s * java.lang.String * @exception com.ximpleware.NavException * When if the underlying byte content contains various * errors. Notice that we are being conservative in making * little assumption on the correctness of underlying byte * content. This is because the VTD can be generated by * another machine such as a load-balancer. */ final public boolean matchRawTokenString(int index, String s) throws NavException { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime return compareRawTokenString(getTokenOffset(index), len, s)==0; } /** * Match a string with a token represented by a long (upper 32 len, lower 32 * offset). * * @return boolean * @param l * long * @param s * java.lang.String * @exception com.ximpleware.NavException * When if the underlying byte content contains various * errors. Notice that we are being conservative in making * little assumption on the correctness of underlying byte * content. This is because the VTD can be generated by * another machine such as a load-balancer. * */ /*final private boolean matchRawTokenString(long l, String s) throws NavException { int len = (int) ((l & MASK_TOKEN_FULL_LEN) >> 32); // a little hardcode is always bad //currentOffset = (int) l; return compareRawTokenString((int)l, len, s)==0; }*/ /** * Match a string against a token with given offset and len, entities get * resolved properly. Creation date: (11/24/03 1:37:42 PM) * * @return boolean * @param offset * int * @param len * int * @param s * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. * @exception IllegalArguementException * if s is null */ /*final private boolean matchTokenString(int offset, int len, String s) throws NavException { return compareTokenString(offset,len,s)==0; }*/ /** * <em>New in 2.0</em> Compare the string against the token at the given * index value. When a token is an attribute name or starting tag, qualified * name is what gets matched against This method has to take care of the * underlying encoding conversion as well as entity reference comparison * * @param index * @param s * @return int * @throws NavException * */ final public int compareTokenString(int index, String s) throws NavException{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime if (type == TOKEN_CHARACTER_DATA || type == TOKEN_ATTR_VAL) return compareTokenString(getTokenOffset(index), len, s); else return compareRawTokenString(getTokenOffset(index), len, s); } /** * Match the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched * against This method has to take care of the underlying encoding * conversion as well as entity reference comparison * * @return boolean * @param index * int * @param s * java.lang.String * @exception com.ximpleware.NavException * When if the underlying byte content contains various * errors. Notice that we are being conservative in making * little assumption on the correctness of underlying byte * content. This is because the VTD can be generated by * another machine such as a load-balancer. */ final public boolean matchTokenString(int index, String s) throws NavException { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime return compareTokenString(getTokenOffset(index), len, s)==0; } /** * Match the string against the token at the given index value. The token will be * interpreted as if it is normalized (i.e. all white space char (\r\n\a ) is replaced * by a white space, char entities and entity references will be replaced by their correspondin * char see xml 1.0 spec interpretation of attribute value normalization) * @param index * @param s * @return * @throws NavException */ final protected boolean matchNormalizedTokenString2(int index, String s) throws NavException{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); return compareNormalizedTokenString2(getTokenOffset(index), len, s)==0; } final protected int compareNormalizedTokenString2(int offset, int len, String s) throws NavException { int i, l, temp; long l1,l2; //boolean b = false; // this.currentOffset = offset; int endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); // System.out.println(s); for (i = 0; i < l && offset < endOffset;) { l1 = getCharResolved(offset); temp = (int) l1; l2 = (l1>>32); if (l2<=2 && isWS(temp)) temp = ' '; int i1 = s.charAt(i); if (i1 < temp) return 1; if (i1 > temp) return -1; i++; offset += (int) (l1 >> 32); } if (i == l && offset < endOffset) return 1; if (i < l && offset == endOffset) return -1; return 0; // return -1; } /** * Match a string against a "non-extractive" token represented by a long * (upper 32 len, lower 32 offset). * * @return boolean * @param l * long * @param s * java.lang.String * @exception com.ximpleware.NavException * When the underlying byte content contains various errors. * Notice that we are being conservative in making little * assumption on the correctness of underlying byte content. * This is because the VTD can be generated by another * machine such as a load-balancer. * */ /*final private boolean matchTokenString(long l, String s) throws NavException { int len = (int) (l >> 32) & 0xffff; //currentOffset = (int) l; return compareTokenString((int) l, len, s)==0; }*/ /** * Evaluate the namespace indicator in bit 31 and bit 30. Creation date: * (11/27/03 5:38:51 PM) * * @return int * @param i * int */ final private int NSval(int i) { return (int) (vtdBuffer.longAt(i) & MASK_TOKEN_NS_MARK); } /** * overWrite is introduced in version 2.0 that allows you to directly * overwrite the XML content if the token is long enough If the operation is * successful, the new content along with whitespaces will fill the * available token space, and there will be no need to regenerate the VTD * and LCs !!! * <em> The current version (2.0) only allows overwrites on attribute value, * character data, and CDATA</em> * * Consider the XML below: <a>good </a> After overwriting the token "good" * with "bad," the new XML looks like: <a>bad </a> as you can see, "goo" is * replaced with "bad" character-by-character, and the remaining "d" is * replace with a white space * * @param index * @param ba * the byte array contains the new content to be overwritten * @return boolean as the status of the overwrite operation * */ final public boolean overWrite(int index, byte[] ba){ return overWrite(index,ba,0,ba.length); } /** * overWrite is introduced in version 2.0 that allows you to directly * overwrite the XML content if the token is long enough If the operation is * successful, white spaces will be used to fill the available token space, * and there will be no need to regenerate the VTD and LCs * <em> The current version (2.0) only allows overwrites on attribute value, * character data, and CDATA</em> * * Consider the XML below: <a>good </a> After overwriting the token "good" * with "bad," the new XML looks like: <a>bad </a> as you can see, "goo" is * replaced with "bad", and the remaining "d" is replace with a white space * * @param index * the VTD record to which the change will be applied * @param ba * the byte array contains the new content to be overwritten * @param offset * @param len * @return boolean as the status of the overwrite operation * */ public boolean overWrite(int index, byte[] ba, int offset, int len){ if ( ba == null || index >= this.vtdSize || offset<0 || offset + len > ba.length) throw new IllegalArgumentException("Illegal argument for overwrite"); if (encoding >=VTDNav.FORMAT_UTF_16BE && (((len & 1)==1 ) || ((offset&1)==1))){ // for UTF 16, len and offset must be integer multiple // of 2 return false; } int t = getTokenType(index); if ( t== VTDNav.TOKEN_CHARACTER_DATA || t==VTDNav.TOKEN_ATTR_VAL || t==VTDNav.TOKEN_CDATA_VAL){ int length = getTokenLength(index); if ( length < len) return false; int os = getTokenOffset(index); int temp = length - len; //System.out.println("temp ==>"+temp); // get XML doc System.arraycopy(ba, offset, XMLDoc.getBytes(),os, len); for (int k=0;k<temp;){ //System.out.println("encoding ==>"+encoding); if (encoding < VTDNav.FORMAT_UTF_16BE){ // write white spaces // System.out.println("replacing..."); (XMLDoc.getBytes())[os+len+k] = ' '; k++; }else{ if (encoding == VTDNav.FORMAT_UTF_16BE){ XMLDoc.getBytes()[os+len+k] = 0; XMLDoc.getBytes()[os+len+k+1] = ' '; }else{ XMLDoc.getBytes()[os+len+k] = ' '; XMLDoc.getBytes()[os+len+k+1] = 0; } k += 2; } } return true; } return false; } /** * Convert a vtd token into a double. Creation date: (12/8/03 2:28:31 PM) * * @return double * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ public double parseDouble(int index) throws NavException { //if (matchTokenString() int offset = getTokenOffset(index); long l=0; int end = offset + getTokenLength(index); int t = getTokenType(index); boolean b = (t==VTDNav.TOKEN_CHARACTER_DATA )|| (t==VTDNav.TOKEN_ATTR_VAL); boolean expneg = false; int ch; //past the last one by one { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } while (offset < end) { // trim leading whitespaces if (!isWS(ch)) break; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (offset > end) // all whitespace return Double.NaN; boolean neg = (ch == '-'); if (ch == '-' || ch == '+'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //get another one if it is sign. } //left part of decimal double left = 0; while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; left = left * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32);; } //right part of decimal double right = 0; double scale = 1; if (ch == '.') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; right = right * 10 + dig; scale *= 10; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } } //exponent long exp = 0; if (ch == 'E' || ch == 'e') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); expneg = (ch == '-'); //sign for exp if (ch == '+' || ch == '-'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //skip the +/- sign } int cur = offset; //remember the indx, used to find a invalid number like 1.23E while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; exp = exp * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (cur == offset) return Double.NaN; //found a invalid number like 1.23E //if (expneg) // exp = (-exp); } //anything left must be space while (offset <= end) { if (!isWS(ch)) return Double.NaN; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } double v = (double) left; if (right != 0) v += ((double) right) / (double) scale; if (exp != 0) v = (expneg)? v /(Math.pow(10,exp)): v*Math.pow(10,exp); return ((neg) ? (-v) : v); } /** * Convert a vtd token into a float. we assume token type to be attr val or * character data Creation date: (12/8/03 2:28:18 PM) * * @return float * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ public float parseFloat(int index) throws NavException { int offset = getTokenOffset(index); int end = offset + getTokenLength(index); long l; //past the last one by one int t = getTokenType(index); boolean b = (t==VTDNav.TOKEN_CHARACTER_DATA )|| (t==VTDNav.TOKEN_ATTR_VAL); int ch ; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { // trim leading whitespaces if (!isWS(ch)) break; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (offset > end) // all whitespace throw new NavException("Empty string"); boolean neg = (ch == '-'); if (ch == '-' || ch == '+'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //get another one if it is sign. } //left part of decimal long left = 0; while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; left = left * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } //right part of decimal long right = 0; long scale = 1; if (ch == '.') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; right = right * 10 + dig; scale *= 10; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } } //exponent long exp = 0; if (ch == 'E' || ch == 'e') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); boolean expneg = (ch == '-'); //sign for exp if (ch == '+' || ch == '-'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //skip the +/- sign } int cur = offset; //remember the indx, used to find a invalid number like 1.23E while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; exp = exp * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (cur == offset) return Float.NaN; //found a invalid number like 1.23E if (expneg) exp = (-exp); } //anything left must be space while (offset <= end) { if (!isWS(ch)) throw new NavException(toString(index)); l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } double v = (double) left; if (right != 0) v += ((double) right) / (double) scale; if (exp != 0) v = v * Math.pow(10, exp); float f = (float) v; //try to handle overflow/underflow if (v >= (double)Float.MAX_VALUE) f = Float.MAX_VALUE; else if (v <= (double)Float.MIN_VALUE) f = Float.MIN_VALUE; if (neg) f = -f; return f; } /** * Convert a vtd token into an int. This method will automatically strip off * the leading and trailing we assume token type to be attr val or character * data zero, unlike Integer.parseInt(int index) * * Creation date: (12/8/03 2:32:22 PM) * * @return int * @param index * int * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ public int parseInt(int index) throws NavException { return parseInt(index, 10); } /** * Convert a vtd token into an int, with the given radix. we assume token * type to be attr val or character data the first char can be either '+' or * '-' Creation date: (12/16/03 1:21:20 PM) * * @return int * @param index * int * @param radix * int * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ protected int parseInt(int index, int radix) throws NavException { if (radix < 2 || radix > 36) throw new NumberFormatException( "radix " + radix + " out of valid range"); int t = getTokenType(index); boolean b = (t==VTDNav.TOKEN_CHARACTER_DATA )|| (t==VTDNav.TOKEN_ATTR_VAL); int offset = getTokenOffset(index); int endOffset = offset + getTokenLength(index); int c; long l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); // trim leading whitespaces while ((c == ' ' || c == '\n' || c == '\t' || c == '\r') && (offset <= endOffset)){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset > endOffset) // all whitespace throw new NumberFormatException(" empty string"); boolean neg = (c == '-'); if (neg || c == '+') { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); //skip sign } long result = 0; while (offset <= endOffset) { int digit = Character.digit((char) c, radix); if (digit < 0) break; //Note: for binary we can simply shift to left to improve // performance result = result * radix + digit; //pos *= radix; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (result > Integer.MAX_VALUE) throw new NumberFormatException("Overflow: " + toString(index)); // take care of the trailing while (offset <= endOffset && isWS(c)) { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset == (endOffset + 1)) return (int) ((neg) ? (-result) : result); else throw new NumberFormatException(toString(index)); } /** * Convert a vtd token into a long. we assume token type to be attr val or * character data Creation date: (12/8/03 2:32:59 PM) * * @return long * @param index * int * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ public long parseLong(int index) throws NavException { return parseLong(index, 10); } /** * Convert a vtd token into a long, with the given radix. the first char can * be either '+' or '-', leading and trailing will be stripped we assume * token type to be attr val or character data Creation date: (12/17/03 * 1:51:06 PM) * * @return long * @param index * int * @param radix * int * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD can be generated by * another machine such as a load-balancer. */ protected long parseLong(int index, int radix) throws NavException { if (radix < 2 || radix > 36) throw new NumberFormatException( "radix " + radix + " out of valid range"); int t = getTokenType(index); boolean b = (t==VTDNav.TOKEN_CHARACTER_DATA )|| (t==VTDNav.TOKEN_ATTR_VAL); int offset = getTokenOffset(index); int endOffset = offset + getTokenLength(index); int c; long l; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); // trim leading whitespaces while ((c == ' ' || c == '\n' || c == '\t' || c == '\r') && (offset <= endOffset)){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset > endOffset) // all whitespace throw new NumberFormatException(" empty string"); boolean neg = (c == '-'); if (neg || c == '+'){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);//skip sign } long result = 0; while (offset <= endOffset) { int digit = Character.digit((char) c, radix); if (digit < 0) break; //Note: for binary we can simply shift to left to improve // performance result = result * radix + digit; //pos *= radix; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);; } if (result > Long.MAX_VALUE) throw new NumberFormatException("Overflow: " + toString(index)); // take care of the trailing while (offset <= endOffset && isWS(c)) { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset == (endOffset + 1)) return (long) ((neg) ? (-result) : result); else throw new NumberFormatException(toString(index)); } /** * Load the context info from ContextBuffer. Info saved including LC and * current state of the context * * @return boolean * */ public boolean pop() { boolean b = contextStack.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l2lower = stackTemp[nestingLevel + 3]; l2upper = stackTemp[nestingLevel + 4]; l3lower = stackTemp[nestingLevel + 5]; l3upper = stackTemp[nestingLevel + 6]; atTerminal = (stackTemp[nestingLevel + 7] == 1); LN = stackTemp[nestingLevel+8]; return true; } /** * Load the context info from contextStack2. This method is dedicated for * XPath evaluation. * * @return status of pop2 */ protected boolean pop2(){ boolean b = contextStack2.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l2lower = stackTemp[nestingLevel + 3]; l2upper = stackTemp[nestingLevel + 4]; l3lower = stackTemp[nestingLevel + 5]; l3upper = stackTemp[nestingLevel + 6]; atTerminal = (stackTemp[nestingLevel + 7] == 1); LN = stackTemp[nestingLevel+8]; return true; } /** * Store the context info into the ContextBuffer. Info saved including LC * and current state of the context Creation date: (11/16/03 7:00:27 PM) */ public void push() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l2lower; stackTemp[nestingLevel + 4] = l2upper; stackTemp[nestingLevel + 5] = l3lower; stackTemp[nestingLevel + 6] = l3upper; if (atTerminal) stackTemp[nestingLevel + 7] =1; else stackTemp[nestingLevel + 7] =0; stackTemp[nestingLevel+8] = LN; contextStack.store(stackTemp); } /** * Store the context info into the contextStack2. This method is reserved * for XPath Evaluation * */ protected void push2() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l2lower; stackTemp[nestingLevel + 4] = l2upper; stackTemp[nestingLevel + 5] = l3lower; stackTemp[nestingLevel + 6] = l3upper; if (atTerminal) stackTemp[nestingLevel + 7] =1; else stackTemp[nestingLevel + 7] =0; stackTemp[nestingLevel+8] = LN; contextStack2.store(stackTemp); } /** * clear the contextStack2 after XPath evaluation * * */ final protected void clearStack2(){ contextStack2.size = 0; } /** * Used by following:: axis * @param depth * @param index */ protected void sync(int depth, int index){ // assumption is that this is always at terminal int t=-1; switch(depth){ case -1: return; case 0: if(l1Buffer.size!=0){ if (l1index==-1) l1index=0; if (index> l1Buffer.upper32At(l1Buffer.size-1)){ l1index = l1Buffer.size-1; return; } if (index > l1Buffer.upper32At(l1index)){ while (l1index < l1Buffer.size - 1 && l1Buffer.upper32At(l1index) < index) { l1index++; } } else{ while (l1index >0 && l1Buffer.upper32At(l1index-1) > index) { l1index--; } } //assert(index<l1Buffer.upper32At(l1index)); } break; case 1: if (l1Buffer.lower32At(l1index)!=-1){ if (l2lower!=l1Buffer.lower32At(l1index)){ l2lower = l2index=l1Buffer.lower32At(l1index); l2upper = l2Buffer.size - 1; int size = l1Buffer.size; for (int i = l1index + 1; i < size; i++) { int temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } //l2upper = l1Buffer.lower32At(l1index); } if (index>l2Buffer.upper32At(l2index)){ while (l2index < l2upper && l2Buffer.upper32At(l2index)< index){ l2index++; } } else { while(l2index > l2lower && l2Buffer.upper32At(l2index-1)> index){ l2index--; } } //assert(index<l2Buffer.upper32At(l2index)); } break; case 2: if (l2Buffer.lower32At(l2index)!=-1){ if (l3lower!=l2Buffer.lower32At(l2index)){ l3index = l3lower = l2Buffer.lower32At(l2index); l3upper = l3Buffer.size - 1; int size = l2Buffer.size; for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } if (index>l3Buffer.intAt(l3index)){ while (l3index < l3upper && l3Buffer.intAt(l3index)<index ){ l3index++; } }else { while(l3index > l3lower && l3Buffer.intAt(l3index-1)> index){ l3index--; } } //assert(index<l3Buffer.intAt(l3index)); } break; default: if (l2Buffer.lower32At(l2index)!=-1){ if (l3lower!=l2Buffer.lower32At(l2index)){ l3index = l3lower = l2Buffer.lower32At(l2index); l3upper = l3Buffer.size - 1; int size = l2Buffer.size; for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } //if (context[3]> l3Buffer.intAt(l3index)){ while (context[3] != l3Buffer.intAt(l3index)){ l3index++; } //} else { // while (context[3] != l3Buffer.intAt(l3index)){ // l3index--; // } //} //assert(index<l3Buffer.intAt(l3index)); } break; } } /** * Sync up the current context with location cache. This operation includes * finding out l1index, l2index, l3index and restores upper and lower bound * info To improve efficieny this method employs some heuristic search * algorithm. The result is that it is quite close to direct access. * Creation date: (11/16/03 7:44:53 PM) * * @return int The index of the NS URL */ protected void resolveLC() { if (context[0]<=0) return; resolveLC_l1(); if (context[0] == 1) return; resolveLC_l2(); if (context[0] == 2) return; resolveLC_l3(); } /** * Sync level 1 location cache */ protected void resolveLC_l1(){ if (l1index < 0 || l1index >= l1Buffer.size || context[1] != l1Buffer.upper32At(l1index)) { if (l1index >= l1Buffer.size || l1index < 0) { l1index = 0; } if (l1index+1<l1Buffer.size && context[1] != l1Buffer.upper32At(l1index+1)) { int init_guess = (int) (l1Buffer.size * ((float) context[1] / vtdBuffer .size)); if (l1Buffer.upper32At(init_guess) > context[1]) { while (l1Buffer.upper32At(init_guess) != context[1]) { init_guess--; } } else if (l1Buffer.upper32At(init_guess) < context[1]) { while (l1Buffer.upper32At(init_guess) != context[1]) { init_guess++; } } l1index = init_guess; } else{ if (context[1]>=l1Buffer.upper32At(l1index)){ while(context[1]!=l1Buffer.upper32At(l1index) && l1index < l1Buffer.size){ l1index++; } } else{ while(context[1]!=l1Buffer.upper32At(l1index) && l1index >=0){ l1index--; } } } } } /** * Sync Level 2 location cache */ protected void resolveLC_l2(){ int temp = l1Buffer.lower32At(l1index); if (l2lower != temp) { l2lower = temp; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously l2index = l2lower; l2upper = l2Buffer.size - 1; for (int i = l1index + 1; i < l1Buffer.size; i++) { temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } } // intelligent guess again ?? if (l2index < 0 || l2index >= l2Buffer.size || context[2] != l2Buffer.upper32At(l2index)) { if (l2index >= l2Buffer.size || l2index<0) l2index = l2lower; if (l2index+1< l2Buffer.size&& context[2] == l2Buffer.upper32At(l2index + 1)) l2index = l2index + 1; else if (l2upper - l2lower >= 16) { int init_guess = l2lower + (int) ((l2upper - l2lower) * ((float) context[2] - l2Buffer .upper32At(l2lower)) / (l2Buffer .upper32At(l2upper) - l2Buffer .upper32At(l2lower))); if (l2Buffer.upper32At(init_guess) > context[2]) { while (context[2] != l2Buffer.upper32At(init_guess)) init_guess--; } else if (l2Buffer.upper32At(init_guess) < context[2]) { while (context[2] != l2Buffer.upper32At(init_guess)) init_guess++; } l2index = init_guess; } else if (context[2]<l2Buffer.upper32At(l2index)){ while ( context[2] != l2Buffer.upper32At(l2index)) { l2index--; } } else { while(context[2]!=l2Buffer.upper32At(l2index)) l2index++; } } } /** * Sync L3 location Cache */ protected void resolveLC_l3(){ int temp = l2Buffer.lower32At(l2index); if (l3lower != temp) { //l3lower and l3upper are always together l3lower = temp; // l3lower shouldn't be -1 l3index = l3lower; l3upper = l3Buffer.size - 1; for (int i = l2index + 1; i < l2Buffer.size; i++) { temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } if (l3index < 0 || l3index >= l3Buffer.size || context[3] != l3Buffer.intAt(l3index)) { if (l3index >= l3Buffer.size || l3index <0) l3index = l3lower; if (l3index+1 < l3Buffer.size && context[3] == l3Buffer.intAt(l3index + 1)) l3index = l3index + 1; else if (l3upper - l3lower >= 16) { int init_guess = l3lower + (int) ((l3upper - l3lower) * ((float) (context[3] - l3Buffer .intAt(l3lower)) / (l3Buffer.intAt(l3upper) - l3Buffer .intAt(l3lower)))); if (l3Buffer.intAt(init_guess) > context[3]) { while (context[3] != l3Buffer.intAt(init_guess)) init_guess--; } else if (l3Buffer.intAt(init_guess) < context[3]) { while (context[3] != l3Buffer.intAt(init_guess)) init_guess++; } l3index = init_guess; } else if (context[3]<l3Buffer.intAt(l3index)){ while (context[3] != l3Buffer.intAt(l3index)) { l3index--; } } else { while (context[3] != l3Buffer.intAt(l3index)) { l3index++; } } } } /** * Test whether the URL is defined in the scope. Null is allowed to indicate * the name space is undefined. Creation date: (11/16/03 7:54:01 PM) * * @param URL * java.lang.String * @exception com.ximpleware.NavException * When there is any encoding conversion error or unknown * entity. */ final protected int lookupNS() throws NavException { if (context[0]==-1) throw new NavException("Can't lookup NS for document node"); int i = getTokenLength((context[0] != 0) ? context[context[0]] : rootIndex); int offset = getTokenOffset((context[0] != 0) ? context[context[0]] : rootIndex); int preLen = (i >> 16) & 0xffff; return lookupNS(offset, preLen); //return resolveNS(URL, offset, preLen); } /** * This function returns the VTD record index of the namespace that matches * the prefix of cursor element * * @param URL * @return int * */ protected int lookupNS(int offset, int len){ long l; boolean hasNS = false; int size = vtdBuffer.size; // look for a match in the current hiearchy and return true for (int i = context[0]; i >= 0; i--) { int s = (i != 0) ? context[i] : rootIndex; switch (NSval(s)) { // checked the ns marking case 0xc0000000 : s = s + 1; if (s>=size) break; int type = getTokenType(s); while ((type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (type == TOKEN_ATTR_NS) { // Get the token length int temp = getTokenLength(s); int preLen = ((temp >> 16) & 0xffff); int fullLen = temp & 0xffff; int os = getTokenOffset(s); // xmlns found if (temp == 5 && len == 0) { return s+1; } else if ((fullLen - preLen - 1) == len) { // prefix length identical to local part of ns // declaration boolean a = true; for (int j = 0; j < len; j++) { if (getCharUnit(os + preLen + 1 + j) != getCharUnit(offset + j)) { a = false; break; } } if (a == true) { return s+1; } } } //return (URL != null) ? true : false; s += 2; if (s>=size) break; type = getTokenType(s); } break; case 0x80000000 : break; default : // check the ns existence, mark bit 31:30 to 11 or 10 int k = s + 1; if (k>=size) break; type = getTokenType(k); while ( (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (type == TOKEN_ATTR_NS) { // Get the token length hasNS = true; int temp = getTokenLength(k); int preLen = ((temp >> 16) & 0xffff); int fullLen = temp & 0xffff; int os = getTokenOffset(k); // xmlns found if (temp == 5 && len == 0) { l = vtdBuffer.longAt(s); hasNS = false; vtdBuffer.modifyEntry( s, l | 0x00000000c0000000L); return k+1; } else if ((fullLen - preLen - 1) == len) { // prefix length identical to local part of ns // declaration boolean a = true; for (int j = 0; j < len; j++) { if (getCharUnit(os + preLen + 1 + j) != getCharUnit(offset + j)) { a = false; break; } } if (a == true) { l = vtdBuffer.longAt(s); //hasNS = false; vtdBuffer.modifyEntry( s, l | 0x00000000c0000000L); return k+1; } } } //return (URL != null) ? true : false; k += 2; if (k>=size) break; type = getTokenType(k); } l = vtdBuffer.longAt(s); if (hasNS) { hasNS = false; vtdBuffer.modifyEntry(s, l | 0x00000000c0000000L); } else { vtdBuffer.modifyEntry(s, l | 0x0000000080000000L); } break; } } return 0; //return -1; } private boolean resolveNS(String URL, int offset, int len) throws NavException { int result = lookupNS(offset, len); switch(result){ case 0: if (URL == null){ return true; } else { return false; } default: if (URL == null) { if (getTokenLength(result)==0) return true; return false; } else { return matchNormalizedTokenString2(result, URL); } } } /** * A generic navigation method. Move the cursor to the element according to * the direction constants If no such element, no position change and return * false. Creation date: (12/2/03 1:43:50 PM) Legal direction constants are * * <pre> * ROOT 0 * </pre> *<pre> * PARENT 1 * </pre> *<pre> * FIRST_CHILD 2 * </pre> *<pre> * LAST_CHILD 3 * </pre> *<pre> * NEXT_SIBLING 4 * </pre> *<pre> * PREV_SIBLING 5 * </pre> * * @return boolean * @param direction * int * @exception com.ximpleware.NavException * When direction value is illegal. */ public boolean toElement(int direction) throws NavException { int size; //count++; //System.out.println("count ==>"+ count); switch (direction) { case ROOT : // to document element! if (context[0] != 0) { /* * for (int i = 1; i <= context[0]; i++) { context[i] = * 0xffffffff; } */ context[0] = 0; } atTerminal = false; //l1index = l2index = l3index = -1; return true; case PARENT : if (atTerminal == true){ atTerminal = false; return true; } if (context[0] > 0) { //context[context[0]] = context[context[0] + 1] = // 0xffffffff; context[context[0]] = -1; context[0]--; return true; }else if (context[0]==0){ context[0]=-1; //to be compatible with XPath Data model return true; } else { return false; } case FIRST_CHILD : case LAST_CHILD : if (atTerminal) return false; switch (context[0]) { case -1: context[0] = 0; return true; case 0 : if (l1Buffer.size > 0) { context[0] = 1; l1index = (direction == FIRST_CHILD) ? 0 : (l1Buffer.size - 1); context[1] = l1Buffer.upper32At(l1index); //(int) (vtdToken >> 32); return true; } else return false; case 1 : l2lower = l1Buffer.lower32At(l1index); if (l2lower == -1) { return false; } context[0] = 2; l2upper = l2Buffer.size - 1; size = l1Buffer.size; for (int i = l1index + 1; i < size; i++) { int temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } //System.out.println(" l2 upper: " + l2upper + " l2 // lower : " + l2lower); l2index = (direction == FIRST_CHILD) ? l2lower : l2upper; context[2] = l2Buffer.upper32At(l2index); return true; case 2 : l3lower = l2Buffer.lower32At(l2index); if (l3lower == -1) { return false; } context[0] = 3; l3upper = l3Buffer.size - 1; size = l2Buffer.size; for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } //System.out.println(" l3 upper : " + l3upper + " l3 // lower : " + l3lower); l3index = (direction == FIRST_CHILD) ? l3lower : l3upper; context[3] = l3Buffer.intAt(l3index); return true; default : if (direction == FIRST_CHILD) { size = vtdBuffer.size; int index = context[context[0]] + 1; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth <= context[0]) { return false; } else if (depth == (context[0] + 1)) { context[0] += 1; context[context[0]] = index; return true; } } index++; } // what condition return false; } else { int index = context[context[0]] + 1; int last_index = -1; size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { if (depth <= context[0]) { break; } else if (depth == (context[0] + 1)) { last_index = index; } } index++; } if (last_index == -1) { return false; } else { context[0] += 1; context[context[0]] = last_index; return true; } } } case NEXT_SIBLING : case PREV_SIBLING : if(atTerminal)return nodeToElement(direction); switch (context[0]) { case -1: case 0 : return false; case 1 : if (direction == NEXT_SIBLING) { if (l1index + 1 >= l1Buffer.size) { return false; } l1index++; // global incremental } else { if (l1index - 1 < 0) { return false; } l1index--; // global incremental } context[1] = l1Buffer.upper32At(l1index); return true; case 2 : if (direction == NEXT_SIBLING) { if (l2index + 1 > l2upper) { return false; } l2index++; } else { if (l2index - 1 < l2lower) { return false; } l2index--; } context[2] = l2Buffer.upper32At(l2index); return true; case 3 : if (direction == NEXT_SIBLING) { if (l3index + 1 > l3upper) { return false; } l3index++; } else { if (l3index - 1 < l3lower) { return false; } l3index--; } context[3] = l3Buffer.intAt(l3index); return true; default : //int index = context[context[0]] + 1; if (direction == NEXT_SIBLING) { int index = context[context[0]] + 1; size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]) { return false; } else if (depth == (context[0])) { context[context[0]] = index; return true; } } index++; } return false; } else { int index = context[context[0]] - 1; while (index > context[context[0] - 1]) { // scan backforward long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /* * if (depth < context[0]) { return false; } * else */ if (depth == (context[0])) { context[context[0]] = index; return true; } } index--; } // what condition return false; } } default : throw new NavException("illegal navigation options"); } } /** the corner case of element to node jump * * @param direction * @return */ protected boolean nodeToElement(int direction){ switch(direction){ case NEXT_SIBLING: switch (context[0]) { case 0: if (l1index!=-1){ context[0]=1; context[1]=l1Buffer.upper32At(l1index); atTerminal=false; return true; }else return false; case 1: if (l2index!=-1){ context[0]=2; context[2]=l2Buffer.upper32At(l2index); atTerminal=false; return true; }else return false; case 2: if (l3index!=-1){ context[0]=3; context[3]=l3Buffer.intAt(l3index); atTerminal=false; return true; }else return false; default: int index = LN + 1; int size = vtdBuffer.size; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]) { return false; } else if (depth == (context[0])) { context[context[0]] = index; return true; } } index++; } return false; } case PREV_SIBLING: switch (context[0]) { case 0: if (l1index!=-1 && l1index>0){ l1index--; context[0]=1; context[1]=l1Buffer.upper32At(l1index); atTerminal=false; return true; }else return false; case 1: if (l2index!=-1 && l2index>l2lower){ l2index--; context[0]=2; context[2]=l2Buffer.upper32At(l2index); atTerminal=false; return true; }else return false; case 2: if (l2index!=-1 && l3index>l3lower){ l3index--; context[0]=3; context[3]=l3Buffer.intAt(l3index); atTerminal=false; return true; }else return false; default: int index = LN- 1; while (index > context[context[0] - 1]) { // scan backforward long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /* * if (depth < context[0]) { return false; } * else */ if (depth == (context[0])) { context[context[0]] = index; return true; } } index--; } // what condition return false; } } return false; } /** * A generic navigation method. Move the cursor to the element according to * the direction constants and the element name If no such element, no * position change and return false. "*" matches any element Creation date: * (12/2/03 1:43:50 PM) Legal direction constants are <br> * * <pre> * ROOT 0 * </pre> * <pre> * PARENT 1 * </pre> * <pre> * FIRST_CHILD 2 * </pre> * <pre> * LAST_CHILD 3 * </pre> * <pre> * NEXT_SIBLING 4 * </pre> * <pre> * PREV_SIBLING 5 * </pre> * * <br> * for ROOT and PARENT, element name will be ignored. * * @return boolean * @param direction * int * @param en * String * @exception com.ximpleware.NavException * When direction value is illegal. Or there are errors in * underlying byte representation of the document * @exception IllegalArguementException * if en is null */ public boolean toElement(int direction, String en) throws NavException { int temp=-1; int d=-1; int val=0; boolean b=false; if (en == null) throw new IllegalArgumentException(" Element name can't be null "); if (en.equals("*")) return toElement(direction); switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElement(en) == false) { if (toElement(NEXT_SIBLING, en) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElement(en) == false) { if (toElement(PREV_SIBLING, en) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal){ if (nodeToElement(NEXT_SIBLING)){ b=true; if (matchElement(en)){ return true; } }else return false; } if (!b){ d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } temp = context[d]; // store the current position } while (toElement(NEXT_SIBLING)) { if (matchElement(en)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; } else { switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; } case PREV_SIBLING : if (atTerminal){ if (nodeToElement(PREV_SIBLING)){ b=true; if (matchElement(en)){ return true; } }else return false; } if (!b){ d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } temp = context[d]; // store the current position } while (toElement(PREV_SIBLING)) { if (matchElement(en)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; } else{ switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; } default : throw new NavException("illegal navigation options"); } } /** * A generic navigation method with namespace support. Move the cursor to * the element according to the direction constants and the prefix and local * names If no such element, no position change and return false. URL * * matches any namespace, including undefined namespaces a null URL means * hte namespace prefix is undefined for the element ln * matches any * localname Creation date: (12/2/03 1:43:50 PM) Legal direction constants * are <br> * * <pre> * ROOT 0 * </pre> * <pre> * PARENT 1 * </pre> * <pre> * FIRST_CHILD 2 * </pre> * <pre> * LAST_CHILD 3 * </pre> * <pre> * NEXT_SIBLING 4 * </pre> * <pre> * PREV_SIBLING 5 * </pre> * * <br> * for ROOT and PARENT, element name will be ignored. If not ns enabled, * return false immediately with no position change. * * @return boolean * @param direction * int * @param URL * String * @param ln * String * @exception com.ximpleware.NavException * When direction value is illegal. Or there are errors in * underlying byte representation of the document */ public boolean toElementNS(int direction, String URL, String ln) throws NavException { boolean b=false; int temp=-1; int val=0; int d=-1; // temp location if (ns == false) return false; switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElementNS(URL, ln) == false) { if (toElementNS(NEXT_SIBLING, URL, ln) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElementNS(URL, ln) == false) { if (toElementNS(PREV_SIBLING, URL, ln) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal){ if (nodeToElement(NEXT_SIBLING)){ b=true; if (matchElementNS(URL,ln)){ return true; } }else return false; } if (!b){ d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } } //if (d == 0) // return false; while (toElement(NEXT_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; } else{ switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; } case PREV_SIBLING : if (atTerminal){ if (nodeToElement(PREV_SIBLING)){ b=true; if (matchElementNS(URL,ln)){ return true; } }else return false; } if (!b){ d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } } //if (d == 0) // return false; while (toElement(PREV_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } if (b){ context[0]--;//LN value should not change atTerminal=true; return false; }else { switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; } default : throw new NavException("illegal navigation options"); } } /** * (New since version 2.9) * Shallow Normalization follows the rules below to normalize a token into * a string * *#xD#xA gets converted to #xA * *For a character reference, append the referenced character to the normalized value. * *For an entity reference, recursively apply step 3 of this algorithm to the replacement text of the entity. * *For a white space character (#x20, #xD, #xA, #x9), append a space character (#x20) to the normalized value. * *For another character, append the character to the normalized value. * @param index * @return * @throws NavException */ public String toNormalizedString2(int index) throws NavException{ int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); long l; int len; len = getTokenLength(index); if (len == 0) return ""; int offset = getTokenOffset(index); int endOffset = len + offset - 1; // point to the last character StringBuffer sb = new StringBuffer(len); int ch; //boolean d = false; while (offset <= endOffset) { l = getCharResolved(offset); ch = (int)l; offset += (int)(l>>32); if (isWS(ch) && (l>>32)<=2) { //d = true; sb.append(' '); } else sb.append((char) ch); } return sb.toString(); } /** * This method normalizes a token into a string value of character data * and attr val in a way that resembles DOM. The leading and trailing * white space characters will be stripped. The entity and character * references will be resolved Multiple whitespaces char will be collapsed * into one. Whitespaces via entities will nonetheless be preserved. * Creation date: (12/8/03 1:57:10 PM) * * @return java.lang.String * @param index * int * @exception NavException * When the encoding has errors */ public String toNormalizedString(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); long l; int len; len = getTokenLength(index); if (len == 0) return ""; int offset = getTokenOffset(index); int endOffset = len + offset - 1; // point to the last character StringBuffer sb = new StringBuffer(len); int ch; // trim off the leading whitespaces while (true) { int temp = offset; l = getChar(offset); ch = (int)l; offset += (int)(l>>32); if (!isWS(ch)) { offset = temp; break; } } boolean d = false; while (offset <= endOffset) { l = getCharResolved(offset); ch = (int)l; offset += (int)(l>>32); if (isWS(ch) && getCharUnit(offset - 1) != ';') { d = true; } else { if (d == false) sb.append((char) ch); // java only supports 16 bit unicode else { sb.append(' '); sb.append((char) ch); d = false; } } } return sb.toString(); } /** * Get the string length of a token as if it is converted into a normalized UCS string * @param index * @return the string length * @throws NavException * */ final public int getNormalizedStringLength(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return getRawStringLength(index); long l; int len,len1=0; len = getTokenLength(index); if (len == 0) return 0; int offset = getTokenOffset(index); int endOffset = len + offset - 1; // point to the last character //StringBuffer sb = new StringBuffer(len); int ch; // trim off the leading whitespaces while (true) { int temp = offset; l = getChar(offset); ch = (int)l; offset += (int)(l>>32); if (!isWS(ch)) { offset = temp; break; } } boolean d = false; while (offset <= endOffset) { l = getCharResolved(offset); ch = (int)l; offset += (int)(l>>32); if (isWS(ch) && getCharUnit(offset - 1) != ';') { d = true; } else { if (d == false) len1++; // java only supports 16 bit unicode else { len1= len1+2; d = false; } } } return len1; } /** * Convert a token at the given index to a String, * (entities and char references not expanded). * Creation date: (11/16/03 7:28:49 PM) * * @return java.lang.String * @param index int * @exception NavException When the encoding has errors */ final public String toRawString(int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); int offset = getTokenOffset(index); return toRawString(offset, len); } final protected void toRawString(StringBuilder sb, int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength2(index) & 0xffff; else len = getTokenLength2(index); int offset = getTokenOffset(index); toRawString(offset, len,sb); } /** * Convert a token at the given index to a String, upper case chars * get converted into lower case * (entities and char references not expanded). * @param index * @return * @throws NavException */ final public String toRawStringLowerCase(int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); int offset = getTokenOffset(index); return toRawStringLowerCase(offset, len); } /** * Convert a token at the given index to a String, lower case chars * get converted into upper case * (entities and char references not expanded). * @param index * @return * @throws NavException */ final public String toRawStringUpperCase(int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); int offset = getTokenOffset(index); return toRawStringUpperCase(offset, len); } /** * Convert a segment of XML bytes a into string, without entity resolution * @param os (in terms of chars <em>not bytes</em>) * @param len (in terms of chars <em>not bytes</em>) * @return * @throws NavException * */ final public String toRawString(int os, int len) throws NavException{ StringBuffer sb = new StringBuffer(len); int offset = os; int endOffset = os + len; //if (encoding> FORMAT_WIN_1258){ // offset = offset>>1; // endOffset = endOffset>>1; //} long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); sb.append((char)l); } return sb.toString(); } final protected void toRawString(int os, int len, StringBuffer sb) throws NavException { int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); sb.append((char)l); } } final protected void toRawString(int os, int len, StringBuilder sb) throws NavException { int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); sb.append((char)l); } } final protected void toString(int os, int len, StringBuilder sb) throws NavException { int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); sb.append((char)l); } } final protected void toStringUpperCase(int os, int len, StringBuilder sb) throws NavException { //StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } //return sb.toString(); } final protected void toStringLowerCase(int os, int len, StringBuilder sb) throws NavException { //StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } //return sb.toString(); } /** * getStringLength return the string length of a token as if the token is converted into * a string (entity resolved for character data and attr val) * @param index * @return the string length as if the token is converted to a UCS string (entity resolved) * @throws NavException * */ final public int getStringLength(int index) throws NavException { int type = getTokenType(index); if (type != TOKEN_CHARACTER_DATA && type != TOKEN_ATTR_VAL) return getRawStringLength(index); int len = 0, len1 = 0; len = getTokenLength(index); int offset = getTokenOffset(index); int endOffset = offset + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int) (l >> 32); len1++; } return len1; } /** * Get the string length as if the token is converted into a UCS string (entity not resolved) * @param index * @return * @throws NavException * */ final public int getRawStringLength(int index) throws NavException { int type = getTokenType(index); int len = 0, len1 = 0; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); if (encoding!=VTDNav.FORMAT_UTF8 && encoding!=VTDNav.FORMAT_UTF_16BE && encoding!=VTDNav.FORMAT_UTF_16LE) { return len; } int offset = getTokenOffset(index); int endOffset = offset + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int) (l >> 32); len1++; } return len1; } /** * Convert a token at the given index to a String, (entities and char * references resolved character data and attr val). An attribute name or * an element name will get the UCS2 string of qualified name * Creation date: (11/16/03 7:27:19 PM) * * @return java.lang.String * @param index * @exception NavException */ public String toString(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toString(offset, len); } /** * Convert a token at the given index to a String and any lower case * character will be converted to upper case, (entities and char * references resolved character data and attr val). * @param index * @return * @throws NavException */ public String toStringUpperCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringUpperCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringUpperCase(offset, len); } /** * Convert a token at the given index to a String and any upper case * character will be converted to lower case, (entities and char * references resolved for character data and attr val). * @param index * @return * @throws NavException */ public String toStringLowerCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringLowerCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringLowerCase(offset, len); } /** * Convert the byte content segment (in terms of offset and length) to * String (entities are resolved) * * @param os * the char offset of the segment (not byte) * @param len * the length of the segment in char (not byte) * @return the corresponding string value * @throws NavException * */ final public String toString(int os, int len) throws NavException{ StringBuffer sb = new StringBuffer(len); int offset = os; int endOffset = os + len; //if (encoding> FORMAT_WIN_1258){ // offset = offset>>1; // endOffset = endOffset>>1; //} long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); sb.append((char)l); } return sb.toString(); } final protected void toString(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index);*/ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toString(offset, len, sb); else toRawString(offset, len, sb); } final protected void toStringUpperCase(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index);*/ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toStringUpperCase(offset, len, sb); else toRawStringUpperCase(offset, len, sb); } final protected void toStringLowerCase(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index); */ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toStringLowerCase(offset, len, sb); else toRawStringLowerCase(offset, len, sb); } /** * Convert the byte content segment (in terms of offset and length) to * String, lower case characters are converted to upper case * * @param os * the offset of the segment * @param len * the length of the segment * @return the corresponding string value * @throws NavException * */ final protected String toStringUpperCase(int os, int len) throws NavException{ StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } return sb.toString(); } /** * Convert the byte content segment (in terms of offset and length) to * String, upper case characters are converted to lower case * * @param os * the offset of the segment * @param len * the length of the segment * @return the corresponding string value * @throws NavException * */ final protected String toStringLowerCase(int os, int len) throws NavException{ StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } return sb.toString(); } final protected String toRawStringLowerCase(int os, int len) throws NavException{ StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } return sb.toString(); } final protected void toRawStringLowerCase(int os, int len, StringBuilder sb) throws NavException{ //StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } //return sb.toString(); } final protected String toRawStringUpperCase(int os, int len) throws NavException{ StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } return sb.toString(); } final protected void toRawStringUpperCase(int os, int len, StringBuilder sb) throws NavException{ //StringBuilder sb = new StringBuilder(len); int offset = os; int endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } //return sb.toString(); } /** * This method matches two VTD tokens of VTDNav objects * * @param i1 * index of the first token * @param vn2 * the second VTDNav instance * @param i2 * index of the second token * @return boolean true if two tokens are lexically identical * */ final public boolean matchTokens(int i1, VTDNav vn2, int i2) throws NavException{ return compareTokens(i1,vn2,i2)==0; } /** * Set the value of atTerminal This function only gets called in XPath eval * when a step calls for @* or child::text() * @param b */ final protected void setAtTerminal(boolean b){ atTerminal = b; } /** * Test the start of token content at index i matches the content * of s, notice that this is to save the string allocation cost of * using String's built-in startsWidth * @param i * @param s * @return */ final public boolean startsWith(int index, String s) throws NavException{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int offset = getTokenOffset(index); long l1; int i,l; int endOffset = offset + len; boolean b = (type == TOKEN_ATTR_VAL || type == TOKEN_CHARACTER_DATA); // System.out.print("currentOffset :" + currentOffset); l = s.length(); if (l> len) return false; //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { if (b) l1 = getCharResolved(offset); else l1 = getChar(offset); int i1 = s.charAt(i); if (i1 != (int) l1) return false; offset += (int) (l1 >> 32); } return true; } /** * Test the end of token content at index i matches the content * of s, notice that this is to save the string allocation cost of * using String's built-in endsWidth * @param i * @return */ final public boolean endsWith(int index, String s) throws NavException{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int offset = getTokenOffset(index); long l1; int i,l, i2; boolean b = (type == TOKEN_ATTR_VAL || type == TOKEN_CHARACTER_DATA); //int endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); if (l>len) return false; if (b == true) i2 = getStringLength(index); else i2 = getRawStringLength(index); if (l> i2) return false; i2 = i2 - l; // calculate the # of chars to be skipped // eat away first several chars for (i = 0; i < i2; i++) { if (b== true) l1 = getCharResolved(offset); else l1 = getChar(offset); offset += (int) (l1 >> 32); } //System.out.println(s); for (i = 0; i < l; i++) { if (b==true) l1 = getCharResolved(offset); else l1 = getChar(offset); int i1 = s.charAt(i); if (i1 != (int) l1) return false; offset += (int) (l1 >> 32); } return true; } /** * Test whether a given token contains s. notie that this function * directly operates on the byte content of the token to avoid string creation * @param index * @param s * @return * @throws NavException */ final public boolean contains(int index, String s) throws NavException{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int offset = getTokenOffset(index); long l1; int i,l; int endOffset = offset + len; boolean b = (type == TOKEN_ATTR_VAL || type == TOKEN_CHARACTER_DATA); // System.out.print("currentOffset :" + currentOffset); int gOffset = offset; l = s.length(); if (l> len) return false; //System.out.println(s); while( offset<endOffset){ gOffset = offset; if (endOffset-gOffset< l) return false; for (i = 0; i < l && gOffset < endOffset; i++) { if (b==true) l1 = getCharResolved(gOffset); else l1 = getChar(gOffset); int i1 = s.charAt(i); gOffset += (int) (l1 >> 32); if (i ==0) offset = gOffset; if (i1 != (int) l1) break; } if (i==l) return true; } return false; } /** * Get the value of atTerminal This function only gets called in XPath eval * * @return boolean */ final protected boolean getAtTerminal(){ return atTerminal; } /** * This is for debugging purpose * * @param fib */ public boolean verifyNodeCorrectness(){ if (atTerminal){ // check l1 index, l2 index, l2lower, l2upper, l3 index, l3 lower, l3 upper if (getTokenDepth(LN)!=context[0]) return false; switch(context[0]){ case -1: return true; case 0: //if (getTokenDepth(LN)!=0) // return false; if (l1Buffer.size!=0){ if (l1index>=l1Buffer.size || l1index<0) return false; if (l1index != l1Buffer.size-1){ if (l1Buffer.upper32At(l1index)<LN) return false; } return true; }else return true; case 1: if (LN>context[1]){ //if (getTokenDepth(LN) != 1) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1, i2; // l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if (i1 != -1) { if (i1 != l2lower) return false; int tmp = l1index + 1; i2 = l2Buffer.size - 1; while (tmp < l1Buffer.size) { if (l1Buffer.lower32At(tmp) != -1) { i2 = l1Buffer.lower32At(tmp) - 1; break; } else tmp++; } if (l2upper != i2) return false; if (l2index > l2upper || l2index < l2lower) return false; if (l2index != l2upper) { if (l2Buffer.upper32At(l2index) < LN) return false; } if (l2index!=l2lower){ if (l2Buffer.upper32At(l2index-1)>LN) return false; } } return true; }else return false; case 2: if (LN>context[2] && context[2]> context[1]){ //if (getTokenDepth(LN) != 2) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if(i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1!=-1){ if (l3lower!=i1) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index<i1 || l3index>i2) return false; if (l3index != l3upper) { if (l3Buffer.intAt(l3index) < LN) return false; } if (l3index!=l3lower){ if (l3Buffer.intAt(l3index-1)>LN) return false; } } return true; }else return false; default: //if (getTokenDepth(LN) != 2) // return false; if (l1index<0 || l1index>l1Buffer.size) return false; int i1,i2; //l2lower, l2upper and l2index i1 = l1Buffer.lower32At(l1index); if (i1==-1)return false; if (i1!=l2lower) return false; int tmp = l1index+1; i2 = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ i2 = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if(context[2]!=l2Buffer.upper32At(l2index)){ return false; } if (l2index>l2upper || l2index < l2lower){ return false; } //l3 i1 = l2Buffer.lower32At(l2index); if (i1==-1) return false; if (i1!=l3lower) return false; i2 = l3Buffer.size-1; tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ i2 = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (l3lower!=i1) return false; if (l3upper!=i2) return false; if (l3index<i1 || l3index>i2) return false; if (context[context[0]]>LN) return false; if (context[0]==3){ if (l3index!=l3upper){ if(l3Buffer.intAt(l3index)>LN) return false; } if (l3index+1 <= l3Buffer.size-1){ if (l3Buffer.intAt(l3index+1)<LN){ return false; } } } } return true; }else { switch(context[0]){ case -1: case 0: case 1: case 2: case 3: case 4: case 5: default:return true; } } } public void sampleState(FastIntBuffer fib){ // for(int i=0;i<context.) // context[i] = -1; for (int i=0;i<=context[0];i++) fib.append(context[i]); if (atTerminal) fib.append(LN); if (context[0]>=1) fib.append(l1index); if (context[0]>=2){ fib.append(l2index); fib.append(l2lower); fib.append(l2upper); } // else return; if (context[0]>=3){ fib.append(l3index); fib.append(l3lower); fib.append(l3upper); } //else return; } public void dumpState(){ System.out.println("l1 index ==>"+l1index); System.out.println("l2 index ==>"+l2index); System.out.println("l2 lower ==>"+l2lower); System.out.println("l2 upper ==>"+l2upper); System.out.println("l3 index ==>"+l3index); System.out.println("l3 lower ==>"+l3lower); System.out.println("l3 upper ==>"+l3upper); } /** * Write VTDNav's internal structure into an OutputStream * * @param os * @throws IndexWriteException * @throws IOException * */ public void writeIndex(OutputStream os) throws IndexWriteException, IOException{ IndexHandler.writeIndex_L3((byte)1, this.encoding, this.ns, true, this.nestingLevel-1, 3, this.rootIndex, this.XMLDoc.getBytes(), this.docOffset, this.docLen, (FastLongBuffer)this.vtdBuffer, (FastLongBuffer)this.l1Buffer, (FastLongBuffer)this.l2Buffer, (FastIntBuffer)this.l3Buffer, os); } /** * Write VTDNav's VTD and LCs into an OutputStream (XML not written out) * @param os * @throws IndexWriteException * @throws IOException * */ public void writeSeparateIndex(OutputStream os) throws IndexWriteException, IOException{ IndexHandler.writeSeparateIndex_L3((byte)2, this.encoding, this.ns, true, this.nestingLevel-1, 3, this.rootIndex, // this.XMLDoc.getBytes(), this.docOffset, this.docLen, (FastLongBuffer)this.vtdBuffer, (FastLongBuffer)this.l1Buffer, (FastLongBuffer)this.l2Buffer, (FastIntBuffer)this.l3Buffer, os); } /** * Write VTDNav's internal structure into a VTD+XML file * * @param fileName * @throws IOException * @throws IndexWriteException * */ public void writeIndex(String fileName) throws IOException,IndexWriteException{ FileOutputStream fos = new FileOutputStream(fileName); writeIndex(fos); fos.close(); } /** * Write VTDNav's internal structure (VTD and LCs, but not XML) into a file * @param fileName * @throws IOException * @throws IndexWriteException * */ public void writeSeparateIndex(String fileName) throws IOException,IndexWriteException{ FileOutputStream fos = new FileOutputStream(fileName); writeSeparateIndex(fos); fos.close(); } /** * Precompute the size of VTD+XML index * * @return size of the index * */ public long getIndexsize(){ int size; if ( (docLen & 7)==0) size = docLen; else size = ((docLen >>3)+1)<<3; size += (vtdBuffer.size<<3)+ (l1Buffer.size<<3)+ (l2Buffer.size<<3); if ((l3Buffer.size & 1) == 0){ //even size += l3Buffer.size<<2; } else { size += (l3Buffer.size+1)<<2; //odd } return size+64; } /** * Duplicate the VTDNav instance with shared XML, VTD and LC buffers * This method may be useful for parallel XPath evaluation * The node Position is at root element * @return a VTDNav instance * */ public VTDNav duplicateNav(){ return new VTDNav(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen ); } /** * Clone the VTDNav instance to get with shared XML, VTD and LC buffers * The node position is also copied from the original instance * @return a new instance of VTDNav */ public VTDNav cloneNav(){ VTDNav vn = new VTDNav(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen ); vn.atTerminal = this.atTerminal; vn.LN = this.LN; if (this.context[0]!=-1) System.arraycopy(this.context, 0, vn.context, 0, this.context[0]+1 ); else vn.context[0]=-1; vn.l1index = l1index; if (getCurrentDepth()>1){ vn.l2index = this.l2index; vn.l2upper = l2upper; vn.l2lower = l2lower; } if (getCurrentDepth() > 2) { vn.l3lower = l3lower; vn.l3index = l3index; vn.l3upper = l3upper; } return vn; } /** * This function return the substring * @param offset * @return sub string of */ /*final public String toSubString(int index, int so){ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int offset = getTokenOffset(index); long l1; int i,l; int endOffset = offset + len; if (so >= len) return ""; return ""; }*/ /** * */ public static final short XPATH_STRING_MODE_NORMAL = 0; public static final short XPATH_STRING_MODE_UPPERCASE = 1; public static final short XPATH_STRING_MODE_LOWERCASE = 2; final public void fillXPathString(FastIntBuffer indexBuffer, FastIntBuffer countBuffer) throws NavException{ int count = 0; int index = getCurrentIndex() + 1; int tokenType, depth, t=0, length,i=0; int dp = context[0]; //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ length = getTokenLength(index); t += length; fib.append(index); if (length > VTDGen.MAX_TOKEN_LENGTH){ while(length > VTDGen.MAX_TOKEN_LENGTH){ length -=VTDGen.MAX_TOKEN_LENGTH; i++; } index += i+1; }else index++; continue; // } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS){ index = index+2; continue; } index++; } } final public String getXPathStringVal() throws NavException{ return getXPathStringVal((short)0); } /** * Return the String value of an Element Node * @param mode * @return * @throws NavException */ final public String getXPathStringVal(short mode) throws NavException{ return getXPathStringVal2(getCurrentIndex(),mode); /*int index = getCurrentIndex() + 1; int tokenType, depth, t=0; int dp = context[0]; //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); t = t + getTokenLength2(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } switch(tokenType){ case VTDNav.TOKEN_ATTR_NAME: case VTDNav.TOKEN_ATTR_NS: case VTDNav.TOKEN_PI_NAME: index = index+2; continue; case VTDNav.TOKEN_CHARACTER_DATA: case VTDNav.TOKEN_CDATA_VAL: fib.append(index); index++; continue; } /*if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ length = getTokenLength(index); t += length; fib.append(index); if (length > VTDGen.MAX_TOKEN_LENGTH){ while(length > VTDGen.MAX_TOKEN_LENGTH){ length -=VTDGen.MAX_TOKEN_LENGTH; i++; } index += i+1; }else index++; continue; // } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS){ index = index+2; continue; }*/ // index++; //} // calculate the total length /*StringBuilder sb = new StringBuilder(t); for(t=0;t<fib.size;t++ ){ switch(mode){ case 0:toString(sb,fib.intAt(t)); break; case 1:toStringUpperCase(sb, fib.intAt(t)); break; case 2:toStringLowerCase(sb, fib.intAt(t)); break; default:throw new NavException("Invaild xpath string val mode"); } } // clear the fib and return a string fib.clear(); return sb.toString();*/ } final protected String getXPathStringVal2(int j, short mode) throws NavException{ /*if (j>= vtdSize) throw new NavException("Invalid vtd-xml index, out of range"); int tokenType = getTokenType(j); if (tokenType!= VTDNav.TOKEN_STARTING_TAG && tokenType != VTDNav.TOKEN_DOCUMENT) throw new NavException("Node type incorrect for XPath STring val");*/ int tokenType; int index = j + 1; int depth, t=0, length,i=0; int dp = getTokenDepth(j); //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); t=t+getTokenLength2(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ length = getTokenLength(index); t += length; fib.append(index); if (length > VTDGen.MAX_TOKEN_LENGTH){ while(length > VTDGen.MAX_TOKEN_LENGTH){ length -=VTDGen.MAX_TOKEN_LENGTH; i++; } index += i+1; }else index++; continue; // } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } index++; } // calculate the total length StringBuilder sb = new StringBuilder(t); for(t=0;t<fib.size;t++ ){ switch(mode){ case 0:toString(sb,fib.intAt(t)); break; case 1:toStringUpperCase(sb, fib.intAt(t)); break; case 2:toStringLowerCase(sb, fib.intAt(t)); break; //case 3:toNormalizedString(sb,fib.intAt(t)); break; default:throw new NavException("Invaild xpath string val mode"); } } // clear the fib and return a string fib.clear(); return sb.toString(); } final public boolean XPathStringVal_Contains(int j, String s) throws NavException{ int tokenType; int index = j + 1; int depth, t=0, i=0,offset, endOffset,len,type,c; long l; boolean result=false; int dp = getTokenDepth(j); //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); //t=t+getTokenLength2(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ //length = getTokenLength2(index); //t += length; fib.append(index); index++; continue; // } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } index++; } index=0; loop:while(index<fib.size){ type = getTokenType(fib.intAt(index)); offset = getTokenOffset(fib.intAt(index)); len = getTokenLength(fib.intAt(index)); endOffset = offset+len; while(offset<endOffset){ if (type==VTDNav.TOKEN_CHARACTER_DATA) l = getCharResolved(offset); else l = getChar(offset); c = (int)l; if (c==s.charAt(0)&& matchSubString(offset, endOffset, index, type,s)){ result=true; break loop; }else offset += (int)(l>>32); } index++; } fib.clear(); return result; } private boolean matchSubString(int os, int eos, int index, int t, String s) throws NavException{ int offset = os, endOffset=eos, type =t, c;long l; int i=0; boolean b=false; while(offset<endOffset){ if (type==VTDNav.TOKEN_CHARACTER_DATA) l = getCharResolved(offset); else l = getChar(offset); c = (int)l; if (i<s.length()-1 && c==s.charAt(i)){ offset += (int)(l>>32); i++; }else if(i==s.length()-1) return true; else return false; } index++; while(index<fib.size){ offset = getTokenOffset(fib.intAt(index)); endOffset = offset + getTokenLength2(fib.intAt(index)); type = getTokenType(fib.intAt(index)); while(offset<endOffset){ if (type==VTDNav.TOKEN_CHARACTER_DATA) l = getCharResolved(offset); else l = getChar(offset); c = (int)l; if (i<s.length() && c==s.charAt(i)){ offset += (int)(l>>32); i++; }else if(i==s.length()) return true; else return false; } index++; }while(index<fib.size); if (i==s.length()) return true; return false; } final public boolean XPathStringVal_StartsWith(int j, String s) throws NavException{ int tokenType; int index = j + 1; int depth,length,i=0, offset, endOffset, len,c; long l; int dp = getTokenDepth(j); boolean r = false;//default //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); //t=t+getTokenLength2(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA ){ //if (!match) offset = getTokenOffset(index); len = getTokenLength2(index); endOffset = offset + len; while(offset<endOffset){ l = getCharResolved(offset); c = (int)l; if (i< s.length()&& c == s.charAt(i)){ offset += (int)(l>>32); i++; }else if (i==s.length()) return true; else return false; } index++; continue; }else if( tokenType==VTDNav.TOKEN_CDATA_VAL){ offset = getTokenOffset(index); len = getTokenLength2(index); endOffset = offset + len; while(offset<endOffset){ l = getChar(offset); c = (int)l; if (i< s.length()&& c == s.charAt(i)){ offset += (int)(l>>32); i++; }else if (i==s.length()) return true; else return false; } index++; continue; }else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } index++; } return false; } final public boolean XPathStringVal_EndsWith(int j,String s) throws NavException{ int tokenType; int index = j + 1; int depth, t=0, length,i=0,d=0, offset,endOffset,type; boolean b=false; long l; int dp = getTokenDepth(j); //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); //t=t+getStringLength(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ length = getTokenLength2(index); //t += length; fib.append(index); index++; continue; // } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } index++; } //if (t<s.length()) // return false; for (i=fib.size-1;i!=0;i--){ t+=getStringLength(fib.intAt(i)); if (t>=s.length()){ d = t-s.length();//# of chars to be skipped break; } } if (i<-1)return false; type = getTokenType(fib.intAt(i)); offset = getTokenOffset(fib.intAt(i)); endOffset = offset+getTokenLength2(fib.intAt(i)); for(j=0;j<d;j++){ if (type==VTDNav.TOKEN_CHARACTER_DATA){ l=getCharResolved(offset); }else l=getChar(offset); offset += (int)(l>>32); } b =matchSubString(offset, endOffset,i,type,s); fib.clear(); return b; } /** * Get content fragment returns a long encoding the offset and length of the byte segment of * the content of current element, which is the byte segment between the starting tag and * ending tag, -1 is returned if the current element is an empty element * * @return long whose upper 32 bite is length, lower 32 bit is offset */ public long getContentFragment() throws NavException{ // a little scanning is needed // has next sibling case // if not int depth = getCurrentDepth(); // document length and offset returned if depth == -1 if (depth == -1){ int i=vtdBuffer.lower32At(0); if (i==0) return ((long)docLen)<<32| docOffset; else return ((long)(docLen-32))| 32; } long l = getOffsetAfterHead(); if (l<0) return -1L; int so = (int)l; int length = 0; // for an element with next sibling if (toElement(NEXT_SIBLING)) { int temp = getCurrentIndex(); //temp2=temp; // rewind while (getTokenDepth(temp) == depth && (getTokenType(temp)==VTDNav.TOKEN_COMMENT || getTokenType(temp)==VTDNav.TOKEN_PI_VAL || getTokenType(temp)==VTDNav.TOKEN_PI_NAME)) { temp--; } /*if(temp!=temp2) temp++;*/ //temp++; int so2 = getTokenOffset(temp) - 1; // look for the first '>' while (getCharUnit(so2) != '>') { so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; toElement(PREV_SIBLING); if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } // for root element if (depth == 0) { int temp = vtdBuffer.size - 1; boolean b = false; int so2 = 0; while (getTokenDepth(temp) == -1) { temp--; // backward scan b = true; } if (b == false) so2 = (encoding <= FORMAT_WIN_1258 ) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; else so2 = getTokenOffset(temp + 1); while (getCharUnit(so2) != '>') { so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } // for a non-root element with no next sibling int temp = getCurrentIndex() + 1; int size = vtdBuffer.size; // temp is not the last entry in VTD buffer if (temp < size) { while (temp < size && getTokenDepth(temp) >= depth) { temp++; } if (temp != size) { int d = depth - getTokenDepth(temp) + ((getTokenType(temp) == TOKEN_STARTING_TAG) ? 1 : 0); int so2 = getTokenOffset(temp) - 1; int i = 0; // scan backward while (i < d) { if (getCharUnit(so2) == '>') i++; so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } /* * int so2 = getTokenOffset(temp - 1) - 1; int d = depth - * getTokenDepth(temp - 1); int i = 0; while (i < d) { if * (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + * 2; if (encoding < 3) return ((long) length) < < 32 | so; else * return ((long) length) < < 33 | (so < < 1); */ } // temp is the last entry // scan forward search for /> or </cc> int so2 = (encoding <= FORMAT_WIN_1258) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; int d; d = depth + 1; int i = 0; while (i < d) { if (getCharUnit(so2) == '>') { i++; } so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258) return ((long) length) << 32 | so; else return ((long) length) << 33 | (so << 1); } /** * This method takes a vtd index, and recover its correspondin * node position, the index can only be of node type element, * document, attribute name, attribute value or character data, * or CDATA * @param index * @throws NavException */ public void recoverNode(int index) throws NavException{ if (index <0 || index>=vtdSize ) throw new NavException("Invalid VTD index"); int type = getTokenType(index); if (//type == VTDNav.TOKEN_COMMENT || // type == VTDNav.TOKEN_PI_NAME || type == VTDNav.TOKEN_PI_VAL || type == VTDNav.TOKEN_DEC_ATTR_NAME || type == VTDNav.TOKEN_DEC_ATTR_VAL || type == VTDNav.TOKEN_ATTR_VAL) throw new NavException("Token type not yet supported"); // get depth int d = getTokenDepth(index); // handle document node; switch (d){ case -1: context[0]=-1; if (index != 0){ LN = index; atTerminal = true; }else atTerminal=false; return; case 0: context[0]=0; if (index != rootIndex){ LN = index; atTerminal = true; if (type>VTDNav.TOKEN_ATTR_NS) sync(0,index); } else atTerminal=false; return; } context[0]=d; if (type != VTDNav.TOKEN_STARTING_TAG){ LN = index; atTerminal = true; }else atTerminal = false; // search LC level 1 recoverNode_l1(index); if (d==1){ if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(1,index); return; } // search LC level 2 recoverNode_l2(index); if (d==2){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(2,index); return; } // search LC level 3 recoverNode_l3(index); if (d==3){ //resolveLC(); if (atTerminal && type>VTDNav.TOKEN_ATTR_NS) sync(3,index); return; } // scan backward if ( type == VTDNav.TOKEN_STARTING_TAG ){ context[d] = index; } else{ int t = index-1; while( !(getTokenType(t)==VTDNav.TOKEN_STARTING_TAG && getTokenDepth(t)==d)){ t--; } context[d] = t; } int t = context[d]-1; d--; while(d>3){ while( !(getTokenType(t)==VTDNav.TOKEN_STARTING_TAG && getTokenDepth(t)==d)){ t--; } context[d] = t; d--; } //resolveLC(); } protected final void recoverNode_l1(int index){ int i; if(context[1]==index){ } else if (l1index !=-1 && context[1]>index && l1index+1<l1Buffer.size && l1Buffer.upper32At(l1index+1)<index){ } else { i= (index/vtdSize)*l1Buffer.size; if (i>=l1Buffer.size) i=l1Buffer.size-1; if (l1Buffer.upper32At(i)< index) { while(i<l1Buffer.size-1 && l1Buffer.upper32At(i)<index){ i++; } if (l1Buffer.upper32At(i)>index) i--; } else { while(l1Buffer.upper32At(i)>index){ i--; } } context[1] = l1Buffer.upper32At(i); l1index = i; } } protected final void recoverNode_l2(int index){ int i = l1Buffer.lower32At(l1index); if (l2lower != i) { l2lower = i; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously //l2index = l2lower; l2upper = l2Buffer.size - 1; for (int k = l1index + 1; k < l1Buffer.size; k++) { i = l1Buffer.lower32At(k); if (i != 0xffffffff) { l2upper = i - 1; break; } } } // guess what i would be in l2 cache int t1=l2Buffer.upper32At(l2lower); int t2=l2Buffer.upper32At(l2upper); //System.out.print(" t2 ==>"+t2+" t1 ==>"+t1); i= Math.min(l2lower+ (int)(((float)(index-t1)/(t2-t1+1))*(l2upper-l2lower)),l2upper) ; //System.out.print(" i1 "+i); while(i<l2Buffer.size-1 && l2Buffer.upper32At(i)<index){ i++; } //System.out.println(" ==== i2 "+i+" index ==> "+index); while (l2Buffer.upper32At(i)>index && i>0) i--; context[2] = l2Buffer.upper32At(i); l2index = i; //System.out.println("l2lower ==>"+l2lower+" l2upper==>"+l2upper+" l2index==> "+l2index); } private final void recoverNode_l3(int index){ int i = l2Buffer.lower32At(l2index); if (l3lower != i) { //l3lower and l3upper are always together l3lower = i; // l3lower shouldn't be -1 //l3index = l3lower; l3upper = l3Buffer.size - 1; for (int k = l2index + 1; k < l2Buffer.size; k++) { i = l2Buffer.lower32At(k); if (i != 0xffffffff) { l3upper = i - 1; break; } } } int t1=l3Buffer.intAt(l3lower); int t2=l3Buffer.intAt(l3upper); i= Math.min(l3lower+ (int)(((float)(index-t1)/(t2-t1+1))*(l3upper-l3lower)),l3upper) ; while(i<l3Buffer.size-1 && l3Buffer.intAt(i)<index){ i++; } while (l3Buffer.intAt(i)>index && i>0) i--; //System.out.println(" i ===> "+i); context[3] = l3Buffer.intAt(i); l3index = i; } /** * Return the prefix of a token as a string if the token * is of the type of starting tag, attribute name, if the * the prefix doesn't exist, a null string is returned; * otherwise a null string is returned * * @param i VTD index of a token * @return */ public String getPrefixString(int i) throws NavException{ if (ns == false) return null; int type = getTokenType(i); if (type != TOKEN_ATTR_NAME && type != TOKEN_STARTING_TAG) return null; int offset = getTokenOffset(i); int preLen = getTokenLength(i) >> 16; if (preLen !=0) return toRawString(offset,preLen); return null; } protected void setCurrentNode(){ if (currentNode == null){ currentNode = new BookMark(this); }else { currentNode.recordCursorPosition(); } } protected void loadCurrentNode(){ currentNode.setCursorPosition(); } // like toElement, toNode takes an integer that determines the protected boolean toNode(int dir) throws NavException{ int index,tokenType,depth,lastEntry,tmp; //count++; //System.out.println("count ==>"+ count); switch(dir){ case ROOT: if (context[0] != 0) { /* * for (int i = 1; i <= context[0]; i++) { context[i] = * 0xffffffff; } */ context[0] = 0; } atTerminal = false; //l1index = l2index = l3index = -1; return true; case PARENT: if (atTerminal == true){ atTerminal = false; return true; } if (context[0] > 0) { //context[context[0]] = context[context[0] + 1] = // 0xffffffff; context[context[0]] = -1; context[0]--; return true; }else if (context[0]==0){ context[0]=-1; //to be compatible with XPath Data model return true; } else { return false; } case FIRST_CHILD: if(atTerminal)return false; switch (context[0]) { case -1: //starting with root element //scan backward, if there is a pi | comment node index = rootIndex-1; loop1: while(index >0){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_COMMENT: index--; break; case TOKEN_PI_VAL: index-=2;break; default: break loop1; } } index++; // points to if (index!=rootIndex){ atTerminal = true; LN = index; }else{ context[0]=0; } return true; case 0: if (l1Buffer.size!=0){ index = l1Buffer.upper32At(0)-1; //rewind loop1: while(index>rootIndex){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index-=2; break; default: break loop1; } } index++; l1index = 0; if(index == l1Buffer.upper32At(0)){ context[0]=1; context[1]= l1Buffer.upper32At(0); atTerminal = false; }else { atTerminal = true; LN = index; } return true; }else{ //get to the first non-attr node after the starting tag index = rootIndex+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==0){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 1: if (l1Buffer.lower32At(l1index)!=-1){ // l2upper and l2lower l2lower = l1Buffer.lower32At(l1index); tmp = l1index+1; l2upper = l2Buffer.size-1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ l2upper = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } //if (tmp==l1Buffer.size){ // l2upper = l2Buffer.size-1; //} index = context[1]+1; tmp = l2Buffer.upper32At(l2lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l2index = l2lower; atTerminal = true; LN = index; return true; } } l2index = l2lower; context[0] = 2; context[2] = index; return true; }else{ index = context[1]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==1 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } case 2: if (l2Buffer.lower32At(l2index)!=-1){ // l2upper and l2lower l3lower = l2Buffer.lower32At(l2index); tmp = l2index+1; l3upper = l3Buffer.size-1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ l3upper = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } //if (tmp==l2Buffer.size){ // l3upper = l3Buffer.size-1; //} index = context[2]+1; tmp = l3Buffer.intAt(l3lower); while(index<tmp){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: l3index = l3lower; atTerminal = true; LN = index; return true; } } l3index = l3lower; context[0] = 3; context[3] = index; return true; }else{ index = context[2]+1; while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: if (getTokenDepth(index)==2 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ atTerminal = true; LN = index; return true; }else return false; } } return false; } default: index = context[context[0]] + 1; while (index < vtdBuffer.size) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); switch(tokenType){ case TOKEN_STARTING_TAG: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth <= context[0]){ return false; }else if (depth == (context[0] + 1)) { context[0] += 1; context[context[0]] = index; return true; }else throw new NavException("impossible condition"); case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2;break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]){ return false; }else if (depth == (context[0])) { //System.out.println("inside to Node next sibling"); LN = index; atTerminal = true; return true; } else throw new NavException("impossible condition"); case TOKEN_PI_NAME: depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < context[0]){ return false; }else if (depth == (context[0])) { LN = index; atTerminal = true; return true; } else throw new NavException("impossible condition"); } //index++; } // what condition return false; } case LAST_CHILD: if(atTerminal)return false; return toNode_LastChild(); case NEXT_SIBLING: switch (context[0]) { case -1: if(atTerminal){ index = LN; tokenType = getTokenType(index); switch(tokenType){ case TOKEN_PI_NAME: index+=2; break; //break loop2; case TOKEN_COMMENT: index++; break; } if (index <vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == -1){ LN = index; return true; }else{ atTerminal = false; context[0]=0; return true; // depth has to be zero } }else return false; }else{ return false; } //break; case 0: if(atTerminal){ index = LN; tokenType = getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; //index++; if (l1Buffer.size!=0){ if (index < l1Buffer.upper32At(l1index)){ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index <= l1Buffer.upper32At(l1index)){ if (index == l1Buffer.upper32At(l1index)){ atTerminal = false; context[0]=1; context[1]=index; return true; } depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } }else if ( l1index < l1Buffer.size -1){ // whether l1index is the last entry in l1 buffer l1index++; if (tokenType==TOKEN_PI_NAME) index++; if (index <= l1Buffer.upper32At(l1index)){ if (index == l1Buffer.upper32At(l1index)){ atTerminal = false; context[0]=1; context[1]=index; return true; } depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } }else{ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } } }else{ index++; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth!=0) return false; LN = index; atTerminal = true; return true; }else{ return false; } } }else{ index = vtdSize-1; depth = -2; // get to the end, then rewind while(index > rootIndex){ depth = getTokenDepth(index); if (depth ==-1){ index--; } else break; } index++; if (index>=vtdSize ) return false; else{ context[0]=-1; LN = index; atTerminal = true; return true; } } //break; case 1: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l1Buffer.lower32At(l1index) != -1) { if (LN < l2Buffer.upper32At(l2upper)) { tmp = l2Buffer.upper32At(l2index); index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 2; context[2] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==1 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; } else return false; } }else{ index= LN+1; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==1 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ if (l1index != l1Buffer.size-1){ // not the last one //rewind l1index++; index = lastEntry = l1Buffer.upper32At(l1index)-1; while(getTokenDepth(index)==0){ index--; } if (lastEntry==index){ atTerminal=false; context[0]=1; context[1]=index+1; return true; } else { atTerminal = true; context[0]=0; LN = index+1; return true; } }else{ index = vtdSize-1; while(index > l1Buffer.upper32At(l1index) && getTokenDepth(index)<=0){ index--; } if (index == vtdSize-1 ){ if (getTokenDepth(index)==0){ context[0]=0; LN = index; atTerminal = true; return true; }else return false; } index++; if (getTokenDepth(index)==0){ context[0]=0; LN = index; atTerminal = true; return true; }else{ return false; } } } case 2: if(atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; if (l2Buffer.lower32At(l2index) != -1) { if (LN < l3Buffer.intAt(l3upper)) { tmp = l3Buffer.intAt(l3index); index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < tmp) { LN = index; return true; } else { context[0] = 3; context[3] = tmp; atTerminal = false; return true; } } else { index = LN + 1; if (tokenType == TOKEN_PI_NAME) index++; if (index < vtdSize) { depth = getTokenDepth(index); if (depth==2 && getTokenType(index)!=TOKEN_STARTING_TAG){ LN = index; return true; } return false; } return false; } }else{ index= LN+1; if (tokenType==TOKEN_PI_NAME) index++; if (index < vtdSize){ depth = getTokenDepth(index); if (depth==2 && getTokenType(index)!= TOKEN_STARTING_TAG){ LN = index; atTerminal = true; return true; } return false; }else{ return false; } } }else{ //l2index < l2upper if (l2index< l2upper){ tmp = l2Buffer.upper32At(l2index); l2index++; lastEntry = index = l2Buffer.upper32At(l2index)-1; //rewind loop2: while(index>tmp){ if (getTokenDepth(index)==1){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0]=2; context[2] = index+1; return true; } context[0]=1; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index!=l1Buffer.size-1){ lastEntry = index = l1Buffer.upper32At(l1index+1)-1; } tmp = l2Buffer.upper32At(l2upper);// pointing to last level 2 element //rewind while(index>tmp){ if (getTokenDepth(index)<2) index--; else break; } if (( /*lastEntry!=index &&*/ getTokenDepth(index)==1)){ LN = index; atTerminal = true; context[0]=1; return true; } if (/*getTokenDepth(index+1)==1 && getTokenType(index+1)!= TOKEN_STARTING_TAG &&index !=tmp+1*/ lastEntry!=index && getTokenDepth(index+1)==1){ //index has moved LN = index+1; atTerminal = true; context[0]=1; return true; } return false; } } //break; case 3: if(!atTerminal){ //l2index < l2upper if (l3index< l3upper){ //System.out.println(l3index+" "+l3upper+" "+l3lower+" "+l3Buffer.size+" "); tmp = l3Buffer.intAt(l3index); l3index++; //lastEntry = index = vtdSize-1; //if (l3index <l3Buffer.size-1){ lastEntry = index = l3Buffer.intAt(l3index)-1; //} //rewind loop2:while(index>tmp){ if (getTokenDepth(index)==2){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: index--; break; case TOKEN_PI_VAL: index = index -2; break; default: break loop2; } }else break loop2; } if (index == lastEntry){ context[0]=3; context[3] = index+1; return true; } context[0]=2; LN = index+1; atTerminal = true; return true; }else{ lastEntry = index = vtdSize-1; if (l1index != l1Buffer.size-1){ lastEntry=index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ lastEntry=index = l2Buffer.upper32At(l2index+1)-1; } // inser here tmp = l3Buffer.intAt(l3index); //rewind while(index>tmp){ if (getTokenDepth(index)<3) index--; else break; } if ((/*lastEntry==index &&*/ getTokenDepth(index)==2)){ LN = index; atTerminal = true; context[0]=2; return true; } if (lastEntry!=index && getTokenDepth(index+1)==2){ LN = index+1; atTerminal = true; context[0]=2; return true; } return false; } } //break; default: if (atTerminal){ tokenType=getTokenType(LN); if (tokenType==VTDNav.TOKEN_ATTR_NAME) return false; index = LN+1; tmp = context[0]+1; } else{ index = context[context[0]] + 1; tmp = context[0]; } while (index < vtdSize) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); switch (tokenType) { case TOKEN_STARTING_TAG: if (depth < tmp) { return false; } else if (depth == tmp) { context[0]=tmp; context[context[0]] = index; atTerminal = false; return true; }else index++; break; case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index += 2; break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < tmp-1) { return false; } else if (depth == tmp-1) { LN = index; context[0]= tmp-1; atTerminal = true; return true; } else index++; break; case TOKEN_PI_NAME: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); if (depth < tmp-1) { return false; } else if (depth == tmp-1) { LN = index; context[0]= tmp-1; atTerminal = true; return true; } else index += 2; break; default: index++; } } return false; } case PREV_SIBLING: return toNode_PrevSibling(); default : throw new NavException("illegal navigation options"); } } protected boolean toNode_PrevSibling(){ int index,tokenType,depth,tmp; switch (context[0]) { case -1: if(atTerminal){ index = LN-1; if (index>0){ depth = getTokenDepth(index); if (depth==-1){ tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_COMMENT: LN = index; return true; default: return false; } }else{ context[0] = 0; atTerminal = false; return true; } }else{ return false; } }else{ return false; } case 0: if(atTerminal){ if (l1Buffer.size!=0){ // three cases if (LN < l1Buffer.upper32At(l1index)){ index = LN-1; if (index>rootIndex){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 0){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; return true; case TOKEN_PI_VAL: LN = index -1; return true; } } if (l1index==0) return false; l1index--; atTerminal = false; context[0]=1; context[1]= l1Buffer.upper32At(l1index); return true; }else return false; } else { index = LN -1; if (index>l1Buffer.upper32At(l1index)){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 0){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; return true; case TOKEN_PI_VAL: LN = index -1; return true; } } } atTerminal = false; context[0]=1; context[1]= l1Buffer.upper32At(l1index); return true; } }else{ index = LN-1; if (index>rootIndex){ tokenType=getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=0; return true; default: return false; } } return false; } }else{ index = rootIndex-1; if (index>0){ tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_COMMENT: LN = index; atTerminal = true; context[0]=-1; return true; default: return false; } }else{ return false; } } //break; case 1: if(atTerminal){ if (l1Buffer.lower32At(l1index)!=-1){ tmp = l2Buffer.upper32At(l2index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==1){ LN = index; return true; }else{ atTerminal = false; context[0]=2; context[2]=tmp; return true; } } else if (l2index!=l2lower){ l2index--; atTerminal = false; context[0]=2; context[2]=l2Buffer.upper32At(l2index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=1; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[1]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[1]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==0 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=0; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l1index != 0){ l1index--; context[1] = l1Buffer.upper32At(l1index); return true; }else return false; } } //break; case 2: if(atTerminal){ if (l2Buffer.lower32At(l2index)!=-1){ tmp = l3Buffer.intAt(l3index); if (LN > tmp){ index = LN-1; if (getTokenType(index)==TOKEN_PI_VAL){ index--; } if (getTokenDepth(index)==2){ LN = index; return true; }else{ atTerminal = false; context[0]=3; context[3]=tmp; return true; } } else if (l3index!=l3lower){ l3index--; atTerminal = false; context[0]=3; context[3]=l3Buffer.intAt(l3index); return true; } else { index = LN-1; tokenType = getTokenType(index); switch (tokenType) { case TOKEN_PI_VAL: index--; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; context[0]=2; return true; default: return false; } } }else{ index= LN-1; if (getTokenType(index)==TOKEN_PI_VAL) index--; if (index > context[2]){ tokenType = getTokenType(index); if (tokenType!= VTDNav.TOKEN_ATTR_VAL){ LN = index; atTerminal = true; return true; }else return false; }else{ return false; } } }else{ index = context[2]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==1 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=1; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l2index != l2lower){ l2index--; context[2] = l2Buffer.upper32At(l2index); return true; }else return false; } } //break; case 3: if(!atTerminal){ index = context[3]-1; tokenType = getTokenType(index); if (getTokenDepth(index)==2 && tokenType!= TOKEN_ATTR_VAL && tokenType!= TOKEN_STARTING_TAG){ if (tokenType==TOKEN_PI_VAL) index--; context[0]=2; atTerminal = true; LN = index; return true; }else{ // no more prev sibling element if (l3index != l3lower){ l3index--; context[3] = l3Buffer.intAt(l3index); return true; }else return false; } } //break; default: if (atTerminal){ index = LN-1; tmp = context[0]+1; } else{ index = context[context[0]] - 1; tmp = context[0]; } while (index > context[tmp-1]) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); switch (tokenType) { case TOKEN_STARTING_TAG: /*if (depth < tmp) { return false; } else*/ if (depth == tmp) { context[0] = depth; context[context[0]] = index; atTerminal = false; return true; }else index--; break; case TOKEN_ATTR_VAL: //case TOKEN_ATTR_NS: index -= 2; break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /*if (depth < tmp-1) { return false; } else*/ if (depth == tmp-1) { context[0] = tmp-1; LN = index; atTerminal = true; return true; } else index--; break; case TOKEN_PI_VAL: //depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 52); /*if (depth < context[0]) { return false; } else*/ if (depth == (tmp-1)) { context[0] = tmp-1; LN = index-1; atTerminal = true; return true; } else index -= 2; break; default: index--; } } return false; } } protected boolean toNode_LastChild(){ int depth,index,tokenType,lastEntry,tmp; switch (context[0]) { case -1: index = vtdSize-1; tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == -1) { switch (tokenType) { case TOKEN_COMMENT: LN = index; atTerminal = true; return true; case TOKEN_PI_VAL: LN = index -1; atTerminal = true; return true; } } context[0]=0; return true; case 0: if (l1Buffer.size!=0){ lastEntry = l1Buffer.upper32At(l1Buffer.size-1); index = vtdSize-1; while(index > lastEntry){ depth = getTokenDepth(index); if (depth==-1){ index--; continue; } else if (depth ==0){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; l1index = l1Buffer.size -1; return true; case TOKEN_PI_VAL: LN = index -1; atTerminal = true; l1index = l1Buffer.size -1; return true; default: return false; } }else { l1index = l1Buffer.size -1; context[0]= 1; context[1]= lastEntry; return true; } } l1index = l1Buffer.size -1; context[0]= 1; context[1]= lastEntry; return true; }else{ index = vtdSize - 1; while(index>rootIndex){ depth = getTokenDepth(index); if (depth == -1){ index--; continue; } tokenType = getTokenType(index); switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: LN = index; atTerminal = true; return true; case TOKEN_PI_VAL: LN = index-1; atTerminal = true; return true; default: return false; } } return false; } case 1: if (l1Buffer.lower32At(l1index)!=-1){ l2lower = l1Buffer.lower32At(l1index); tmp = l1index+1; while(tmp<l1Buffer.size){ if (l1Buffer.lower32At(tmp)!=-1){ l2upper = l1Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l1Buffer.size){ l2upper = l2Buffer.size-1; } l2index = l2upper; index =vtdSize-1; if (l1index != l1Buffer.size-1){ index = l1Buffer.upper32At(l1index+1)-1; } tmp = l2Buffer.upper32At(l2index); // rewind and find the first node of depth 1 while(index > tmp){ depth = getTokenDepth(index); if (depth <1) index--; else if (depth == 1){ tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index-1; else LN = index; atTerminal = true; //context[0]=1; return true; }else break; } context[0]=2; context[2]=tmp; return true; }else{ index = context[1]+1; loop: while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: break loop; } } if (index< vtdSize && getTokenDepth(index)==1 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ lastEntry = index; index++; //scan forward loop2:while(index<vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 1){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index+=2; break; default: break loop2; } }else break loop2; } LN = lastEntry; atTerminal = true; return true; }else return false; } case 2: if (l2Buffer.lower32At(l2index)!=-1){ l3lower = l2Buffer.lower32At(l2index); tmp = l2index+1; while(tmp<l2Buffer.size){ if (l2Buffer.lower32At(tmp)!=-1){ l3upper = l2Buffer.lower32At(tmp)-1; break; }else tmp++; } if (tmp==l2Buffer.size){ l3upper = l3Buffer.size-1; } l3index = l3upper; index =vtdSize-1; if (l1index != l1Buffer.size-1){ index = l1Buffer.upper32At(l1index+1)-1; } if (l2index != l2Buffer.size-1 && l2index != l2upper){ index = l2Buffer.upper32At(l2index+1)-1; } tmp = l3Buffer.intAt(l3index); // rewind and find the first node of depth 1 while(index > tmp){ depth = getTokenDepth(index); if (depth <2) index--; else if (depth == 2){ tokenType = getTokenType(index); if (tokenType == TOKEN_PI_VAL) LN = index-1; else LN = index; atTerminal = true; //context[0]=1; return true; }else break; } context[0]=3; context[3]=tmp; return true; }else{ index = context[2]+1; loop: while(index<vtdSize){ tokenType = getTokenType(index); switch(tokenType){ case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2; break; default: break loop; } } if (index< vtdSize && getTokenDepth(index)==2 && getTokenType(index)!=VTDNav.TOKEN_STARTING_TAG){ lastEntry = index; index++; //scan forward loop2:while(index<vtdSize){ tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth == 2){ switch(tokenType){ case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: lastEntry = index; index++; break; case TOKEN_PI_NAME: lastEntry = index; index+=2; break; default: break loop2; } }else break loop2; } LN = lastEntry; atTerminal = true; return true; }else return false; } default: index = context[context[0]] + 1; lastEntry = -1; atTerminal = false; while (index < vtdBuffer.size) { long temp = vtdBuffer.longAt(index); tokenType = (int) ((MASK_TOKEN_TYPE & temp) >>> 60); depth =getTokenDepth(index); switch(tokenType){ case TOKEN_STARTING_TAG: if (depth <= context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; }else{ context[0]+=1; context[context[0]] = lastEntry; atTerminal = false; } return true; } else return false; }else if (depth == (context[0] + 1)) { lastEntry = index; atTerminal = false; } index++; break; case TOKEN_ATTR_NAME: case TOKEN_ATTR_NS: index+=2;break; case TOKEN_CHARACTER_DATA: case TOKEN_COMMENT: case TOKEN_CDATA_VAL: if (depth < context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; }else if (depth == (context[0])) { lastEntry = index; atTerminal = true; } index++; break; case TOKEN_PI_NAME: if (depth < context[0]){ if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; }else if (depth == (context[0])) { lastEntry = index; atTerminal = true; } index+=2; break; } //index++; } // what condition if (lastEntry !=-1){ if (atTerminal){ LN = lastEntry; } else{ context[0]++; context[context[0]]=lastEntry; } return true; }else return false; } } final public String toNormalizedXPathString(int j) throws NavException{ // TODO Auto-generated method stub int tokenType; int index = j + 1; int depth, t=0; int dp = getTokenDepth(j); boolean r = false;//default //int size = vtdBuffer.size; // store all text tokens underneath the current element node while (index < vtdSize) { tokenType = getTokenType(index); depth = getTokenDepth(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){ break; } if (tokenType==VTDNav.TOKEN_CHARACTER_DATA || tokenType==VTDNav.TOKEN_CDATA_VAL){ //if (!match) t=t+getTokenLength2(index); fib.append(index); index++; continue; } else if (tokenType==VTDNav.TOKEN_ATTR_NAME || tokenType == VTDNav.TOKEN_ATTR_NS || tokenType == VTDNav.TOKEN_PI_NAME){ index = index+2; continue; } index++; } //allocate string buffer StringBuilder sb = new StringBuilder(t); //now create teh string, leading zeros/trailling zero stripped, multiple ws collapse into one index =0; int state=0;// start while(index<fib.size){ int offset= getTokenOffset(fib.intAt(index)); int len = getTokenLength2(fib.intAt(index)); int endOS= offset + len; int c; long l; int type = getTokenType(fib.intAt(index)); if (type==VTDNav.TOKEN_CHARACTER_DATA){ while(offset < endOS){ l = getCharResolved(offset); c = (int)l; offset += (int)(l>>32); switch(state){ case 0: if(isWS(c)){ }else{ sb.append((char)c); state =1; } break; case 1: if(isWS(c)){ sb.append((char)' '); state =2; }else{ sb.append((char)c); } break; case 2: if (isWS(c)){ }else{ sb.append((char)c); state = 1; } break; } } }else{ while(offset < endOS){ l = getChar(offset); c = (int)l; offset += (int)(l>>32); switch(state){ case 0: if(isWS(c)){ }else{ sb.append((char)c); state =1; } break; case 1: if(isWS(c)){ sb.append((char)' '); state =2; }else{ sb.append((char)c); } break; case 2: if (isWS(c)){ }else{ sb.append((char)c); state = 1; } break; } } } index++; //System.out.println(sb.toString()); } fib.clear(); //String s =sb.toString(); //System.out.println(); return sb.toString(); } }
227,483
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UnionExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/UnionExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.*; public class UnionExpr extends Expr { public intHash ih; public Expr e; public UnionExpr next; UnionExpr current; int state; public UnionExpr(Expr e1) { e = e1; next = null; current = this; ih = null; state = 0; //cacheable =false; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalBoolean(com.ximpleware.VTDNav) */ final public boolean evalBoolean(VTDNav vn) { /*if (e.isNodeSet()==false) return e.evalBoolean(vn); else{*/ boolean a = false; vn.push2(); // record teh stack size int size = vn.contextStack2.size; try { a = (evalNodeSet(vn) != -1); } catch (Exception e) { } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; //} /*else if (e.isNumerical()){ double dval = e.evalNumber(vn); if (dval == 0.0 || Double.isNaN(dval) ) return false; return true; }else { String s = e.evalString(vn); if (s==null || s.length()==0) return false; return true; }*/ } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalNumber(com.ximpleware.VTDNav) */ final public double evalNumber(VTDNav vn) { if (e.isNodeSet()== false) return e.evalNumber(vn); //double d; double d = Double.NaN; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a+1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t ==VTDNav.TOKEN_DOCUMENT) { String s = vn.getXPathStringVal(); d = Double.parseDouble(s); }else if (t == VTDNav.TOKEN_PI_NAME) { if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL) //s = vn.toString(a+1); d = vn.parseDouble(a+1); }else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalNodeSet(com.ximpleware.VTDNav) */ final public int evalNodeSet(VTDNav vn) throws XPathEvalException, NavException { int a; /*if (this.next == null) { return e.evalNodeSet(vn); } else {*/ while (true) { switch (state) { case 0: if (ih==null) ih = new intHash(); if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; } else state = 3; break; case 1: while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; case 2: current = current.next; if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } vn.pop2(); break; } else state = 3; break; case 3: return -1; default: throw new XPathEvalException( "Invalid state evaluating UnionExpr"); } } //} /* * default: throw new XPathEvalException( "Invalid state evaluating * PathExpr"); */ } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalString(com.ximpleware.VTDNav) */ final public String evalString(VTDNav vn) { if (e.isNodeSet() == false) return e.evalString(vn); else { String s = ""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch(t){ case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } /*if (t == VTDNav.TOKEN_ATTR_NAME) { s = vn.toString(a + 1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t == VTDNav.TOKEN_DOCUMENT) { s = vn.getXPathStringVal(); } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); // s = vn.toString(a+1); } else s = vn.toString(a);*/ } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; } } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#reset(com.ximpleware.VTDNav) */ final public void reset(VTDNav vn) { // travese el list and reset every expression e.reset(vn); current = this; UnionExpr tmp = this.next; while (tmp != null) { tmp.e.reset(vn); tmp = tmp.next; } if (ih != null) ih.reset(); state = 0; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ final public String toString() { if (this.next == null) return this.e.toString(); else return this.e.toString() + " | " + this.next.toString(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isNumerical() */ final public boolean isNumerical() { return e.isNumerical(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isNodeSet() */ final public boolean isNodeSet() { return e.isNodeSet(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isString() */ final public boolean isString() { return e.isString(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isBoolean() */ final public boolean isBoolean() { return e.isBoolean(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#requireContextSize() */ final public boolean requireContextSize() { // boolean b = false; UnionExpr tmp = this; while (tmp != null) { if (tmp.e.requireContextSize()== true){ return true; } tmp = tmp.next; } return false; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#setContextSize(int) */ final public void setContextSize(int size) { current = this; current.e.setContextSize(size); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.setContextSize(size); tmp = tmp.next; } } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#setPosition(int) */ final public void setPosition(int pos) { current = this; current.e.setPosition(pos); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.setPosition(pos); tmp = tmp.next; } } final public boolean isUnique(int i) { return ih.isUnique(i); } final public int adjust(int n){ int i = e.adjust(n); if (this.next == null) return i; // no need to create hash table here if (ih!=null && i==ih.e) {} else ih = new intHash(i); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.adjust(n); tmp = tmp.next; } return i; } final public boolean isFinal(){ UnionExpr tmp = this; while (tmp != null) { if (tmp.e.isFinal()== false){ return false; } tmp = tmp.next; } return true; } final public void markCacheable(){ UnionExpr tmp = this; while (tmp != null) { tmp.e.markCacheable(); tmp = tmp.next; } } final public void markCacheable2(){ UnionExpr tmp = this; while (tmp != null) { if (tmp.e.isFinal() && tmp.e.isNodeSet()){ CachedExpr ce = new CachedExpr(tmp.e); tmp.e = ce; } tmp.e.markCacheable2(); tmp = tmp.next; } } final public void clearCache(){ UnionExpr tmp = this; while (tmp != null) { tmp.e.clearCache(); tmp = tmp.next; } } }
11,526
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
intHash.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/intHash.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * * This is the implementation of a hash table for integers * It is used by various XPath expressions to check for uniqueness * of a node */ class intHash { private int mask1 = 0x7ff; //2048 private int mask2 = 0xfffff800; private int pageSizeE = 4; // 32 * 4 bytes protected FastIntBuffer[] storage; private int hashWidth = 1<<11; private int maxDepth; protected int e; /** * Test whether the input i is unique; * if not, insert into the hash table and return false * otherwise, return true */ public boolean isUnique(int i){ int temp = i & mask1; if (temp>maxDepth){ maxDepth = temp; } if (storage[temp]==null) { storage[temp]= new FastIntBuffer(pageSizeE); storage[temp].append(i); return true; } else{ int size = storage[temp].size; for (int j=0;j<size;j++){ if (i == storage[temp].intAt(j)){ return false; } } storage[temp].append(i); return true; } } /** * This function differs from isUnique(int i) in that it doesn't insert i into * intHash if it is unique, use to implement intersection or difference of nodesets * @param i * @return */ public boolean _isUnique(int i){ int temp = i & mask1; if (temp>maxDepth){ maxDepth = temp; } if (storage[temp]==null) { //storage[temp]= new FastIntBuffer(pageSizeE); //storage[temp].append(i); return true; } else{ int size = storage[temp].size; for (int j=0;j<size;j++){ if (i == storage[temp].intAt(j)){ return false; } } //storage[temp].append(i); return true; } } /** * Clear all entries in the hash table * This method sets the size of member FastIntBuffer * to zero */ final public void reset(){ for (int i=0;i<=maxDepth;i++){ if (storage[i]!=null){ storage[i].size=0; } } } /** * Constructor * */ public intHash(){ hashWidth = 1<<0; mask1 = (hashWidth) -1; mask2 = (~mask1) & 0xffffffff; storage = new FastIntBuffer[hashWidth]; e=0; } public intHash(int hashWidthExpo){ e=hashWidthExpo; hashWidth = 1<<hashWidthExpo; mask1 = (hashWidth) -1; mask2 = (~mask1) & 0xffffffff; storage = new FastIntBuffer[hashWidth]; } public static void main(String[] args) { intHash a = new intHash(6); for(int i=0;i<667;i++) System.out.println("" + i + " " + a.isUnique(i)); for(int i=0;i<667;i++) System.out.println("" + i + " " + a.isUnique(i)); } public static int determineHashWidth(int i){ if (i<(1<<8)) return 3; if (i<(1<<9)) return 4; if (i<(1<<10)) return 5; if (i<(1<<11)) return 6; if (i<(1<<12)) return 7; if (i<(1<<13)) return 8; if (i<(1<<14)) return 9; if (i<(1<<15)) return 10; if (i<(1<<16)) return 11; if (i<(1<<17)) return 12; if (i<(1<<18)) return 13; if (i<(1<<19)) return 14; if (i<(1<<20)) return 15; if (i<(1<<21)) return 16; if (i<(1<<22)) return 17; if (i<(1<<23)) return 18; if (i<(1<<25)) return 19; if (i<(1<<27)) return 20; if (i<(1<<29)) return 21; return 22; } }
4,876
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
TextIter.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/TextIter.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This class iterates through all text nodes of an element. * VTDNav has getText() which is inadequate for mixed content style of XML. * text nodes include character_data and CDATA. * Since version 2.8, selectText(), selectComment(), and selectPI() were * added * Creation date: (12/5/03 5:53:41 PM) */ public class TextIter { private int prevLocation; //previous location of text node protected int depth; protected int index; // this is index for the element protected VTDNav vn; private int lcIndex; private int lcLower; private int lcUpper; private int sel_type; private String piName; /** * TextIter constructor comment. * Text type is selected by default */ public TextIter() { super(); vn = null; sel_type = 0; piName = null; /*sel_char_data = true; sel_comment = true; sel_cdata = true;*/ } /** * Ask textIter to return character data or CDATA nodes */ public void selectText( ){ sel_type = 0; } /** * Ask textIter to return comment nodes */ public void selectComment(){ sel_type = 1; } /** * Ask TextIter to return processing instruction name * no value */ public void selectPI0(){ sel_type = 2; } public void selectPI1(String s){ sel_type =3; piName = s; } public void selectNode(){ sel_type =4; } /** * Get the index vals for the text, PI name, or comment node in document order. * Creation date: (12/5/03 6:11:50 PM) * @return int (-1 if no more left) */ public int getNext() { if (vn == null) throw new IllegalArgumentException(" VTDNav instance can't be null"); if (vn.shallowDepth) switch (depth) { case -1: return handleDocumentNode(); case 0: return handleLevel0(); case 1: return handleLevel1(); case 2: return handleLevel2(); default: return handleDefault(); } else { switch (depth) { case -1: return handleDocumentNode(); case 0: return handleLevel0(); case 1: return handleLevel1(); case 2: return _handleLevel2(); case 3: return handleLevel3(); case 4: return handleLevel4(); default: return handleDefault(); } } //prevLocation = vtdSize-1; } /** * Test whether a give token type is a TEXT, comment or PI name * Creation date: (12/11/03 3:46:10 PM) * @return boolean * @param type int */ final private boolean isText(int index) { int type = vn.getTokenType(index); /*if (sel_type == 0) { return (type == VTDNav.TOKEN_CHARACTER_DATA // || type == vn.TOKEN_COMMENT || type == VTDNav.TOKEN_CDATA_VAL); } if (sel_type == 1) { return (type == VTDNav.TOKEN_COMMENT); } if (sel_type == 2) return (type == VTDNav.TOKEN_PI_NAME); if (sel_type == 3) try { return (vn.matchRawTokenString(index, piName)); } catch(NavException e){ return false; } return true;*/ switch(sel_type){ case 0:return (type == VTDNav.TOKEN_CHARACTER_DATA // || type == vn.TOKEN_COMMENT || type == VTDNav.TOKEN_CDATA_VAL); case 1: return (type == VTDNav.TOKEN_COMMENT); case 2: return (type == VTDNav.TOKEN_PI_NAME); case 3: try { return (vn.matchRawTokenString(index, piName)); } catch(NavException e){ return false; } case 4: return type!=VTDNav.TOKEN_PI_VAL; default: return false; } } /** * Obtain the current navigation position and element info from VTDNav. So * one can instantiate it once and use it for many different elements * Creation date: (12/5/03 6:20:44 PM) * * @param v * com.ximpleware.VTDNav */ public void touch(VTDNav v) { if (v == null) throw new IllegalArgumentException(" VTDNav instance can't be null"); depth = v.context[0]; if (depth == -1) index = 0; else index = (depth != 0) ? v.context[depth] : v.rootIndex; vn = v; prevLocation = -1; lcIndex = -1; lcUpper = -1; lcLower = -1; } private int increment(int sp){ int type = vn.getTokenType(sp); int vtdSize = vn.vtdBuffer.size; int i=sp+1; while(i<vtdSize && depth == vn.getTokenDepth(i) && type == vn.getTokenType(i)&& (vn.getTokenOffset(i-1)+ (int)((vn.vtdBuffer.longAt(i-1) & VTDNav.MASK_TOKEN_FULL_LEN)>>32) == vn.getTokenOffset(i)) ){ i++; } return i; } private int handleLevel0(){ // scan forward, if none found, jump to level 1 element and scan backward until one is found // if there isn't a level-one element, jump to the end of vtd buffer and scan backward int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (vn.l1Buffer.size != 0) { int temp1 = vn.l1Buffer.upper32At(0); int temp2 = vn.l1Buffer.upper32At(vn.l1Buffer.size - 1); lcIndex = (lcIndex != -1) ? lcIndex : 0; while (sp < vn.vtdSize) { if (sp >= temp1 && sp < temp2) { int s = vn.l1Buffer.upper32At(lcIndex); if (sp == s) { // get to the next l1 element then do a rewind lcIndex++; sp = vn.l1Buffer.upper32At(lcIndex)-1; boolean b = false; while (vn.getTokenDepth(sp) == 0 /*&& vn.getTokenType(sp) != VTDNav.TOKEN_STARTING_TAG*/) { //probe depth in here b = true; sp--; } if (b) sp++; // point to the first possible node } if (isText(sp) == true && vn.getTokenDepth(sp)==0) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true && vn.getTokenDepth(sp)==0) { prevLocation = sp; return sp; } sp++; } else { if (sp == temp2) { // get to the end of the document and do a rewind sp = vn.vtdBuffer.size- 1; while (vn.getTokenDepth(sp) <= 0) { sp--; } sp++; //continue; } if (sp>=vn.vtdSize) return -1; else if (isText(sp) == true && vn.getTokenDepth(sp)==0) { prevLocation = sp; return sp; } else if (vn.getTokenDepth(sp)>1) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; // found nothing } else { // no child element for root, just scan right forward while (sp < vn.vtdSize) { if (isText(sp) == true && vn.getTokenDepth(sp)==0) { prevLocation = sp; return sp; } sp++; } return -1; } } private int handleLevel1(){ int sp; if (prevLocation != -1) { sp = increment(prevLocation) ; } else { // fetch lclower and lcupper lcLower = vn.l1Buffer.lower32At(vn.l1index); if (lcLower != -1) { lcUpper = vn.l2Buffer.size - 1; int size = vn.l1Buffer.size; for (int i = vn.l1index + 1; i < size ; i++) { int temp = vn.l1Buffer.lower32At(i); if (temp != 0xffffffff) { lcUpper = temp - 1; break; } } } sp = index + 1; } // check for l2lower and l2upper if (lcLower != -1) { // have at least one child element int temp1 = vn.l2Buffer.upper32At(lcLower); int temp2 = vn.l2Buffer.upper32At(lcUpper); lcIndex = (lcIndex != -1) ? lcIndex : lcLower; while (sp < vn.vtdSize) { int s = vn.l2Buffer.upper32At(lcIndex); if (sp >= temp1 && sp < temp2) { if (sp == s) { lcIndex++; sp = vn.l2Buffer.upper32At(lcIndex) - 1; //boolean b = false; while (vn.getTokenDepth(sp) == 1) { //b = true; sp--; } //if (b) sp++; //continue; } if (isText(sp) == true && vn.getTokenDepth(sp)==1 ) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true) { prevLocation = sp; return sp; } sp++; } else { //if (sp == temp2) { // last child element //} else if (isText(sp) == true && vn.getTokenDepth(sp) == 1){ //System.out.println("depth ->"+vn.getTokenDepth(sp)); prevLocation = sp; return sp; } else if ((vn.getTokenType(sp)==VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(sp) < 2 ) || vn.getTokenDepth(sp)<1) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; } else { // no child element if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (sp < vn.vtdSize && d >= 1 && !(d == 1 && type == VTDNav.TOKEN_STARTING_TAG)) { if (isText(sp) == true) { prevLocation = sp; return sp; } sp++; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } //prevLocation = vtdSize-1; return -1; } } private int handleLevel2(){ int sp; if (prevLocation != -1) { sp = increment(prevLocation); } else { // fetch lclower and lcupper lcLower = vn.l2Buffer.lower32At(vn.l2index); if (lcLower != -1) { lcUpper = vn.l3Buffer.size - 1; int size = vn.l2Buffer.size; for (int i = vn.l2index + 1; i < size ; i++) { int temp = vn.l2Buffer.lower32At(i); if (temp != 0xffffffff) { lcUpper = temp - 1; break; } } } sp = index + 1; } // check for l3lower and l3upper if (lcLower != -1) { // at least one child element int temp1 = vn.l3Buffer.intAt(lcLower); int temp2 = vn.l3Buffer.intAt(lcUpper); lcIndex = (lcIndex != -1) ? lcIndex : lcLower; while (sp < vn.vtdSize) { int s = vn.l3Buffer.intAt(lcIndex); //int s = vn.l2Buffer.upper32At(lcIndex); if (sp >= temp1 && sp < temp2) { if (sp == s) { lcIndex++; sp = vn.l3Buffer.intAt(lcIndex) - 1; //boolean b = false; while (vn.getTokenDepth(sp) == 2) { sp--; // b = true; } //if (b) sp++; //continue; } if (isText(sp) == true && vn.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true && vn.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; } else { //if (sp == temp2) { // last child element //} else if ( isText(sp) == true && vn.getTokenDepth(sp) == 2) { prevLocation = sp; return sp; } else if ((vn.getTokenType(sp)==VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(sp) < 3 ) || vn.getTokenDepth(sp)<2) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; } else { // no child elements if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (sp < vn.vtdSize && d >= 2 && !(d == 2 && type == VTDNav.TOKEN_STARTING_TAG)) { // the last condition indicates the start of the next sibling element if (isText(sp) == true && vn.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } //prevLocation = vtdSize-1; return -1; } } private int handleLevel3(){ int sp; VTDNav_L5 vnl = (VTDNav_L5)vn; if (prevLocation != -1) { sp = increment(prevLocation); } else { // fetch lclower and lcupper lcLower = vnl.l3Buffer.lower32At(vnl.l3index); if (lcLower != -1) { lcUpper = vnl.l4Buffer.size - 1; int size = vnl.l3Buffer.size; for (int i = vnl.l3index + 1; i < size ; i++) { int temp = vnl.l3Buffer.lower32At(i); if (temp != 0xffffffff) { lcUpper = temp - 1; break; } } } sp = index + 1; } // check for l3lower and l3upper if (lcLower != -1) { // at least one child element int temp1 = vnl.l4Buffer.upper32At(lcLower); int temp2 = vnl.l4Buffer.upper32At(lcUpper); lcIndex = (lcIndex != -1) ? lcIndex : lcLower; while (sp < vn.vtdSize) { int s = vnl.l4Buffer.upper32At(lcIndex); //int s = vn.l2Buffer.upper32At(lcIndex); if (sp >= temp1 && sp < temp2) { if (sp == s) { lcIndex++; sp = vnl.l4Buffer.upper32At(lcIndex) - 1; //boolean b = false; while (vn.getTokenDepth(sp) == 2) { sp--; // b = true; } //if (b) sp++; //continue; } if (isText(sp) == true && vn.getTokenDepth(sp)==3) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true && vn.getTokenDepth(sp)==3) { prevLocation = sp; return sp; } sp++; } else { //if (sp == temp2) { // last child element //} else if ( isText(sp) == true && vn.getTokenDepth(sp) == 3) { prevLocation = sp; return sp; } else if ((vn.getTokenType(sp)==VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(sp) < 4 ) || vn.getTokenDepth(sp)<3) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; } else { // no child elements if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (sp < vn.vtdSize && d >= 3 && !(d == 3 && type == VTDNav.TOKEN_STARTING_TAG)) { // the last condition indicates the start of the next sibling element if (isText(sp) == true && vn.getTokenDepth(sp)==3) { prevLocation = sp; return sp; } sp++; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } //prevLocation = vtdSize-1; return -1; } } private int handleLevel4(){ //l2 int sp; VTDNav_L5 vnl = (VTDNav_L5)vn; if (prevLocation != -1) { sp = increment(prevLocation); } else { // fetch lclower and lcupper lcLower = vnl.l4Buffer.lower32At(vnl.l4index); if (lcLower != -1) { lcUpper = vnl.l5Buffer.size - 1; //5 int size = vnl.l4Buffer.size; //4 for (int i = vnl.l4index + 1; i < size ; i++) {//4 int temp = vnl.l4Buffer.lower32At(i); //4 if (temp != 0xffffffff) { lcUpper = temp - 1; break; } } } sp = index + 1; } // check for l3lower and l3upper if (lcLower != -1) { // at least one child element int temp1 = vnl.l5Buffer.intAt(lcLower); int temp2 = vnl.l5Buffer.intAt(lcUpper); lcIndex = (lcIndex != -1) ? lcIndex : lcLower; while (sp < vn.vtdSize) { int s = vnl.l5Buffer.intAt(lcIndex); //int s = vn.l2Buffer.upper32At(lcIndex); if (sp >= temp1 && sp < temp2) { if (sp == s) { lcIndex++; sp = vnl.l5Buffer.intAt(lcIndex) - 1; //boolean b = false; while (vn.getTokenDepth(sp) == 4) { sp--; // b = true; } //if (b) sp++; //continue; } if (isText(sp) == true && vn.getTokenDepth(sp)==4) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true && vn.getTokenDepth(sp)==4) { prevLocation = sp; return sp; } sp++; } else { //if (sp == temp2) { // last child element //} else if ( isText(sp) == true && vn.getTokenDepth(sp) == 4) { prevLocation = sp; return sp; } else if ((vn.getTokenType(sp)==VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(sp) < 5 ) || vn.getTokenDepth(sp)<4) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; } else { // no child elements if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (sp < vn.vtdSize && d >= 4 && !(d == 4 && type == VTDNav.TOKEN_STARTING_TAG)) { // the last condition indicates the start of the next sibling element if (isText(sp) == true && vn.getTokenDepth(sp)== 4) { prevLocation = sp; return sp; } sp++; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } //prevLocation = vtdSize-1; return -1; } } private int _handleLevel2(){ int sp; VTDNav_L5 vnl = (VTDNav_L5)vn; if (prevLocation != -1) { sp = increment(prevLocation); } else { // fetch lclower and lcupper lcLower = vnl.l2Buffer.lower32At(vnl.l2index); if (lcLower != -1) { lcUpper = vnl.l3Buffer.size - 1; int size = vnl.l2Buffer.size; for (int i = vnl.l2index + 1; i < size ; i++) { int temp = vnl.l2Buffer.lower32At(i); if (temp != 0xffffffff) { lcUpper = temp - 1; break; } } } sp = index + 1; } // check for l3lower and l3upper if (lcLower != -1) { // at least one child element int temp1 = vnl.l3Buffer.upper32At(lcLower); int temp2 = vnl.l3Buffer.upper32At(lcUpper); lcIndex = (lcIndex != -1) ? lcIndex : lcLower; while (sp < vnl.vtdSize) { int s = vnl.l3Buffer.upper32At(lcIndex); //int s = vn.l2Buffer.upper32At(lcIndex); if (sp >= temp1 && sp < temp2) { if (sp == s) { lcIndex++; sp = vnl.l3Buffer.upper32At(lcIndex) - 1; //boolean b = false; while (vnl.getTokenDepth(sp) == 2) { sp--; // b = true; } //if (b) sp++; //continue; } if (isText(sp) == true && vnl.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; } else if (sp < temp1) { if (isText(sp) == true && vnl.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; } else { //if (sp == temp2) { // last child element //} else if ( isText(sp) == true && vnl.getTokenDepth(sp) == 2) { prevLocation = sp; return sp; } else if ((vnl.getTokenType(sp)==VTDNav.TOKEN_STARTING_TAG && vnl.getTokenDepth(sp) < 3 ) || vnl.getTokenDepth(sp)<2) { break; } sp++; } } //prevLocation = vtdSize-1; return -1; } else { // no child elements if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (sp < vn.vtdSize && d >= 2 && !(d == 2 && type == VTDNav.TOKEN_STARTING_TAG)) { // the last condition indicates the start of the next sibling element if (isText(sp) == true && vn.getTokenDepth(sp)==2) { prevLocation = sp; return sp; } sp++; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } //prevLocation = vtdSize-1; return -1; } } private int handleDefault(){ //int curDepth = vn.context[0]; int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (d >= depth && !(d == depth && type == VTDNav.TOKEN_STARTING_TAG)) { if (isText(sp) == true && d == depth) { prevLocation = sp; return sp; } sp++; if(sp >= vn.vtdSize) return -1; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } return -1; } private int handleDocumentNode(){ if (sel_type == 0) return -1; int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (sp>=vn.vtdSize) return -1; //int d = vn.getTokenDepth(sp); //int type = vn.getTokenType(sp); //while (d == -1/*&& !(d == depth && type == VTDNav.TOKEN_STARTING_TAG)*/) { while(true){ if (sp< vn.rootIndex) { if (isText(sp)){ prevLocation = sp; return sp; } else sp++; } else { // rewind to the end of document if (sp == vn.rootIndex){ sp = vn.vtdSize-1; while(vn.getTokenDepth(sp)==-1){ sp--; } sp++; } if (sp>=vn.vtdSize){ return -1; } else if (isText(sp)){ prevLocation = sp; return sp; } else sp++; } } } }
28,220
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IObjectBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IObjectBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Abstract object pointer storage interface */ interface IObjectBuffer { Object objectAt(int i); /** * Modify the Object pointer at index to value val. * * @param index int * @param obj Object */ void modifyEntry(int index, Object obj); /** * Get the total number of Object pointer in the buffer. * @return int */ int size(); }
1,239
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
AutoPilot.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/AutoPilot.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.*; import java.util.*; import java.io.*; /** * XimpleWare's AutoPilot implementation encapsulating node iterator * and XPath. * */ public class AutoPilot { protected int depth; // the depth of the element at the starting point will determine when to stop iteration protected int iter_type; // see selectElement protected VTDNav vn; // the navigator object protected int index; // for iterAttr protected int endIndex; protected boolean ft; // a helper variable for protected boolean special; // This helps distinguish between // the case of node() and * for preceding axis // of xpath evaluation protected String name; // Store element name after selectElement protected String name2; // store xmlns:+name protected String localName; // Store local name after selectElemntNS protected String URL; // Store URL name after selectElementNS protected int size; // for iterateAttr protected Expr xpe; // for evalXPath protected int[] contextCopy; //for preceding axis protected int stackSize; // the stack size for xpath evaluation private FastIntBuffer fib; // for namespace axis protected Hashtable nsHash; protected boolean enableCaching; //private parser p; // defines the type of "iteration" public final static int UNDEFINED = 0; // set the mode corresponding to DOM's getElemetnbyName(string) public final static int SIMPLE = 1; // set the mode corresponding to DOM's getElementbyNameNS(string) public final static int SIMPLE_NS = 2; public final static int DESCENDANT = 3; public final static int DESCENDANT_NS = 4; public final static int FOLLOWING = 5; public final static int FOLLOWING_NS=6; public final static int PRECEDING = 7; public final static int PRECEDING_NS=8; public final static int ATTR = 9; public final static int ATTR_NS = 10; public final static int NAME_SPACE = 11; public final static int SIMPLE_NODE = 12; public final static int DESCENDANT_NODE = 13; public final static int FOLLOWING_NODE = 14; public final static int PRECEDING_NODE = 15; static private Hashtable symbolHash; //static int count=0; protected String getName(){ return name; } /** * AutoPilot constructor comment. * @exception IllegalArgumentException If the VTDNav object is null */ public AutoPilot(VTDNav v) { if (v == null) throw new IllegalArgumentException(" instance of VTDNav can't be null "); name = null; vn = v; //depth = v.getCurrentDepth(); iter_type = UNDEFINED; // not defined ft = true; size = 0; special = false; xpe = null; symbolHash = new Hashtable(); fib = null; enableCaching = true; //fib = new FastIntBuffer(4); //p = null; //count=0; } /** * Use this constructor for delayed binding to VTDNav * which allows the reuse of XPath expression * */ public AutoPilot(){ name = null; //vn = v; //depth = v.getCurrentDepth(); iter_type = UNDEFINED; // not defined ft = true; size = 0; special = false; xpe = null; symbolHash = new Hashtable(); fib = null; enableCaching = true; //count=0; } /** This function creates URL ns prefix * and is intended to be called prior to selectXPath * @param prefix * @param URL */ final public void declareXPathNameSpace(String prefix, String URL){ if (nsHash==null) nsHash = new Hashtable(); nsHash.put(prefix, URL); //System.out.println(ht); } /** * Bind is to replace rebind() and setVTDNav() * It resets the internal state of AutoPilot * so one can attach a VTDNav object to the autopilot * @param vnv * */ public void bind (VTDNav vnv){ name = null; if (vnv == null) throw new IllegalArgumentException(" instance of VTDNav can't be null "); vn = vnv; //depth = v.getCurrentDepth(); iter_type = UNDEFINED; // not defined ft = true; size = 0; special = false; //count = 0; //resetXPath(); } /** * Register the binding between a variableExpr name and variableExpr expression * @param varName * @param varExpr * @throws XPathParseException */ public void declareVariableExpr(String varName, String varExpr) throws XPathParseException { try{ parser p = new parser(new StringReader(varExpr)); p.nsHash = nsHash; p.symbolHash = symbolHash; xpe = (Expr) p.parse().value; symbolHash.put(varName, xpe); ft = true; }catch(XPathParseException e){ System.out.println("Syntax error after or around the end of ==>"+varExpr.substring(0,e.getOffset())); throw e; }catch(Exception e){ throw new XPathParseException("Error occurred"); } } /** * Remove all declared variable expressions */ final public void clearVariableExprs(){ symbolHash.clear(); } /** * Remove all namespaces bindings */ final public void clearXPathNameSpaces(){ nsHash.clear(); } public boolean iterate2() throws PilotException, NavException { //count++; //System.out.println("count-=>"+count); switch (iter_type) { case SIMPLE_NODE: if (ft && vn.atTerminal) return false; if (ft){ ft =false; return true; } return vn.iterateNode(depth); case DESCENDANT_NODE: if (ft&&vn.atTerminal) return false; else{ ft=false; return vn.iterateNode(depth); } case FOLLOWING_NODE: if (ft){ boolean b= false; do{ b = vn.toNode(VTDNav.NEXT_SIBLING); if (b){ ft = false; return true; }else{ b = vn.toNode(VTDNav.PARENT); } }while(b); return false; } return vn.iterate_following_node(); case PRECEDING_NODE: if(ft){ ft = false; vn.toNode(VTDNav.ROOT); vn.toNode(VTDNav.P); } return vn.iterate_preceding_node(contextCopy,endIndex); //case default : throw new PilotException(" iteration action type undefined"); } } /** * Iterate over all the selected element nodes in document order. * Null element name allowed, corresponding to node() in xpath * Creation date: (12/4/03 5:25:42 PM) * @return boolean * @exception com.ximpleware.NavException See description in method toElement() in VTDNav class. */ public boolean iterate() throws PilotException, NavException { //count++; //System.out.println("count-=>"+count); switch (iter_type) { case SIMPLE : //System.out.println("iterating ---> "+name+ " depth ---> "+depth); /*if (elementName == null) throw new PilotException(" Element name not set ");*/ if (vn.atTerminal) return false; if (ft == false) return vn.iterate(depth, name, special); else { ft = false; if (special || vn.matchElement(name)) { return true; } else return vn.iterate(depth, name, special); } case SIMPLE_NS : if (vn.atTerminal) return false; if (ft == false) return vn.iterateNS(depth, URL, localName); else { ft = false; if (vn.matchElementNS(URL, localName)) { return true; } else return vn.iterateNS(depth, URL, localName); } case DESCENDANT: if (vn.atTerminal) return false; return vn.iterate(depth, name, special); case DESCENDANT_NS: if (vn.atTerminal) return false; return vn.iterateNS(depth, URL, localName); case FOLLOWING: if (vn.atTerminal) return false; if (ft == false) return vn.iterate_following(name, special); else { ft = false; // find the first next sibling of while(true){ while (vn.toElement(VTDNav.NS)){ if (special || vn.matchElement(name)) { return true; } return vn.iterate_following(name, special); } if (vn.toElement(VTDNav.P)==false){ //return vn.iterate_following(name, special); return false; } } } case FOLLOWING_NS: if (vn.atTerminal) return false; if (ft == false) return vn.iterate_followingNS(URL,localName); else { ft = false; // find the first next sibling of while(true){ while (vn.toElement(VTDNav.NS)){ if (vn.matchElementNS(URL,localName)) { return true; } return vn.iterate_followingNS(URL,localName); } if (vn.toElement(VTDNav.P)==false){ return false; } } } case PRECEDING: if (vn.atTerminal) return false; if(ft){ ft = false; vn.toElement(VTDNav.ROOT); } return vn.iterate_preceding(name, contextCopy,endIndex); case PRECEDING_NS: if (vn.atTerminal) return false; if(ft){ ft = false; vn.toElement(VTDNav.ROOT); } return vn.iterate_precedingNS(URL,localName,contextCopy,endIndex); default : throw new PilotException(" iteration action type undefined"); } } /** * This method implements the namespace axis for XPath * @return * @throws PilotException * @throws NavException */ protected int iterateNameSpace() throws PilotException, NavException { if (vn.ns == false) return -1; if (ft != false) { ft = false; index = vn.getCurrentIndex2() + 1; } else index += 2; while (index < size) { int type = vn.getTokenType(index); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { if (type == VTDNav.TOKEN_ATTR_NS){ if (name.equals("*") || vn.matchRawTokenString(index, name2) ){ // check to see if the namespace has appeared before if (checkNsUniqueness(index)){ vn.LN = index; vn.atTerminal = true; return index; } } } index += 2; } else { vn.atTerminal = false; if (vn.toElement(VTDNav.P) == false) { return -1; } else { index = vn.getCurrentIndex2() + 1; } } } return -1; } protected boolean checkNsUniqueness(int i) throws NavException{ for (int j=0;j<fib.size();j++){ if (vn.compareTokens(fib.intAt(j), vn, i)==0) return false; } fib.append(i); return true; } /** * This method implements the attribute axis for XPath * * @return the integer of the selected VTD index for attribute name * @throws PilotException */ protected int iterateAttr2() throws PilotException,NavException{ switch(iter_type){ case ATTR: if (name.compareTo("*")==0){ if (ft != false){ ft = false; index = vn.getCurrentIndex2()+1; } else index +=2; if (vn.ns == false){ while(index<size){ int type = vn.getTokenType(index); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS){ vn.LN = index; //vn.atTerminal=true; return index; }else{ return -1; } } return -1; }else { while(index<size){ int type = vn.getTokenType(index); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS){ if (type == VTDNav.TOKEN_ATTR_NAME){ vn.LN = index; //vn.atTerminal=true; return index; } else index += 2; }else{ return -1; } } return -1; } }else{ if (ft == false){ return -1; } else { ft = false; int i = vn.getAttrVal(name); if(i!=-1){ vn.LN = i-1; //vn.atTerminal=true; return i-1; } else { return -1; } } } case ATTR_NS: if (ft == false){ return -1; } else { ft = false; int i = vn.getAttrValNS(URL,localName); if(i!=-1){ vn.LN = i -1; //vn.atTerminal=true; return i-1; } else { return -1; } } default: throw new PilotException("invalid iteration type"); } } /** * This method is meant to be called after calling * selectAttr() or selectAttrNs(), it will return the * vtd index attribute name or -1 if there is none left * @return vtd index attribute name or -1 if there is none left * @throws PilotException * @throws NavException */ public int iterateAttr() throws PilotException,NavException{ switch(iter_type){ case ATTR: if (name.compareTo("*")==0){ if (ft != false){ ft = false; index = vn.getCurrentIndex2()+1; } else index +=2; if (vn.ns == false){ while(index<size){ int type = vn.getTokenType(index); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS){ //vn.LN = index; return index; }else{ return -1; } } return -1; }else { while(index<size){ int type = vn.getTokenType(index); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS){ if (type == VTDNav.TOKEN_ATTR_NAME){ //vn.LN = index; return index; } else index += 2; }else{ return -1; } } return -1; } }else{ if (ft == false){ return -1; } else { ft = false; int i = vn.getAttrVal(name); if(i!=-1){ //vn.LN = i-1; return i-1; } else return -1; } } case ATTR_NS: if (ft == false){ return -1; } else { ft = false; int i = vn.getAttrValNS(URL,localName); if(i!=-1){ //vn.LN = i -1; return i-1; } else return -1; } default: throw new PilotException("invalid iteration type"); } } final protected void selectNode(){ ft = true; depth = vn.getCurrentDepth(); iter_type = SIMPLE_NODE; } final protected void selectPrecedingNode(){ ft = true; depth = vn.getCurrentDepth(); contextCopy = (int[])vn.context.clone(); if (contextCopy[0]!=-1){ for (int i=contextCopy[0]+1;i<contextCopy.length;i++){ contextCopy[i]=0; } }//else{ // for (int i=1;i<contextCopy.length;i++){ // contextCopy[i]=0; // } //} iter_type = PRECEDING_NODE; endIndex = vn.getCurrentIndex(); } final protected void selectFollowingNode(){ ft = true; depth = vn.getCurrentDepth(); iter_type = FOLLOWING_NODE; // contextCopy = (int[])vn.context.clone(); } final protected void selectDescendantNode(){ ft = true; depth = vn.getCurrentDepth(); iter_type = DESCENDANT_NODE; } /** * Select the element name before iterating. * "*" matches every element * Creation date: (12/4/03 5:51:31 PM) * @param en java.lang.String */ public void selectElement(String en) { if (en == null) throw new IllegalArgumentException("element name can't be null"); iter_type = SIMPLE; depth = vn.getCurrentDepth(); //startIndex = vn.getCurrentIndex(); name = en; ft = true; } /** * Select the element name (name space version) before iterating. URL, if set to *, * matches every namespace URL, if set to null, indicates the namespace is * undefined. localname, if set to *, matches any localname Creation date: * (12/4/03 6:05:19 PM) * * @param ns_URL String * @param ln String */ public void selectElementNS(String ns_URL, String ln) { if (ln == null) throw new IllegalArgumentException("local name can't be null"); iter_type = SIMPLE_NS; depth = vn.getCurrentDepth(); //startIndex = vn.getCurrentIndex(); localName = ln; URL = ns_URL; ft = true; } /** * Select all descendent elements along the descendent axis, without ns awareness * @param en */ protected void selectElement_D(String en) { if (en == null) throw new IllegalArgumentException("element name can't be null"); iter_type = DESCENDANT; depth = vn.getCurrentDepth(); //startIndex = vn.getCurrentIndex(); name = en; ft = true; } /** * Select all descendent elements along the Descendent axis, withns awareness * @param ns_URL * @param ln */ protected void selectElementNS_D(String ns_URL, String ln){ if (ln == null) throw new IllegalArgumentException("local name can't be null"); iter_type = DESCENDANT_NS; depth = vn.getCurrentDepth(); //startIndex = vn.getCurrentIndex(); localName = ln; URL = ns_URL; ft = true; } /** * Select all elements along the following axis, without ns, * null selects every elements and documents * @param en */ protected void selectElement_F(String en) { if (en == null) throw new IllegalArgumentException("element name can't be null"); iter_type = FOLLOWING; ft = true; name = en; } /** * Select all elements along the following axis as defined in XPath * The namespace-aware version * @param en */ protected void selectElementNS_F(String ns_URL, String ln){ if (ln == null) throw new IllegalArgumentException("local name can't be null"); iter_type = FOLLOWING_NS; ft = true; localName = ln; URL = ns_URL; } /** * Select all elements along the preceding axis as defined in XPath * @param en */ protected void selectElement_P(String en) { if (en == null) throw new IllegalArgumentException("element name can't be null"); depth = vn.getCurrentDepth(); iter_type = PRECEDING; ft = true; name = en; contextCopy = (int[])vn.context.clone(); endIndex = vn.getCurrentIndex2(); for(int i = vn.context[0]+1;i<vn.context.length;i++){ contextCopy[i]=-1; } contextCopy[0]=vn.rootIndex; } /** * Select all elements along the preceding axis as defined in XPath * This is the namespace aware version * @param ns_URL * @param ln */ protected void selectElementNS_P(String ns_URL, String ln){ if (ln == null) throw new IllegalArgumentException("local name can't be null"); depth = vn.getCurrentDepth(); iter_type = PRECEDING_NS; ft = true; localName = ln; URL = ns_URL; contextCopy = (int[])vn.context.clone(); endIndex = vn.getCurrentIndex2(); for(int i = vn.context[0]+1;i<vn.context.length;i++){ vn.context[i]=-1; } contextCopy[0]=vn.rootIndex; } /** * Select the name space nodes as defined in XPath * @param en */ protected void selectNameSpace(String en){ if (en == null) throw new IllegalArgumentException("namespace name can't be null"); iter_type = NAME_SPACE; ft = true; size = vn.getTokenCount(); name = en; if (!en.equals("*")) name2="xmlns:"+en; if (fib==null) fib = new FastIntBuffer(4); else fib.clear(); } /** * Select an attribute name for iteration, * choose all attributes of an element * @param en */ public void selectAttr(String en) { if (en == null) throw new IllegalArgumentException("attribute name can't be null"); iter_type = ATTR; ft = true; size = vn.getTokenCount(); name = en; } /** * Select an attribute name, both local part and namespace URL part * @param ns_URL * @param ln */ final public void selectAttrNS(String ns_URL, String ln){ if (ln == null) throw new IllegalArgumentException("local name of an attribute can't be null"); iter_type = ATTR_NS; ft = true; localName = ln; URL = ns_URL; } /** * This method selects the string representing XPath expression * Usually evalXPath is called afterwards * @param s * @throws XPathParseException */ public void selectXPath(String s) throws XPathParseException { try{ parser p = new parser(new StringReader(s)); p.nsHash = nsHash; p.symbolHash = symbolHash; xpe = (com.ximpleware.Expr) p.parse().value; ft = true; if (enableCaching) xpe.markCacheable(); }catch(XPathParseException e){ System.out.println("Syntax error after or around the end of ==>"+s.substring(0,e.getOffset())); throw e; }catch(Exception e){ throw new XPathParseException("Error occurred"); } } /** * Reset the XPath so the XPath Expression can * be reused and revaluated in anther context position * */ final public void resetXPath(){ if (xpe!=null && vn!=null){ xpe.reset(vn); ft = true; vn.contextStack2.size = stackSize; if (enableCaching) xpe.clearCache(); } } /** * evalXPathToNumber() evaluates the xpath expression to a double * @return double * */ final public double evalXPathToNumber(){ return xpe.evalNumber(vn); } /** * evalXPathToString() evaluates the xpath expression to a String * @return String * */ final public String evalXPathToString(){ return xpe.evalString(vn); } /** * evalXPathToBoolean() evaluates the xpath expression to a boolean * @return boolean * */ final public boolean evalXPathToBoolean(){ return xpe.evalBoolean(vn); } /** * This method returns the next node in the nodeset * it returns -1 if there is no more node * Afer finishing evaluating, don't forget to <em> reset the xpath </em> * @return int corresponding to the VTD index */ public int evalXPath() throws XPathEvalException, NavException{ if (xpe!=null){ if (ft == true){ if (vn != null){ stackSize = vn.contextStack2.size; } ft = false; xpe.adjust(vn.getTokenCount()); } return xpe.evalNodeSet(vn); } throw new PilotException(" Null XPath expression "); } /** * Setspecial is used by XPath evaluator to distinguish between * node() and * * node() corresponding to b= true; * @param b */ final protected void setSpecial(boolean b ){ special = b; } /** * Convert the expression to a string * For debugging purpose * @return String */ final public String getExprString(){ return xpe.toString(); } /** * set state to false to disable caching, which by default is enabled * @param state */ final public void enableCaching(boolean state){ enableCaching = state; } }
25,436
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FunctionalLocationPathExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FunctionalLocationPathExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.AxisType; import com.ximpleware.xpath.FuncName; import com.ximpleware.xpath.Predicate; import com.ximpleware.xpath.Step; public class FunctionalLocationPathExpr extends LocationPathExpr { public static final int FUNC_PATH=2; FuncExpr fne; public FunctionalLocationPathExpr(FuncExpr fne1){ state = START; s = null; pathType = FUNC_PATH; currentStep = null; fne = fne1; //fib = new FastIntBuffer(8);// page size 256 = 2^ 8 ih = new intHash(); } public String toString(){ String st = ""; Step ts = s; st = st + fne; if (ts == null) return st; else return st + '/'+ ts; } public int evalNodeSet(VTDNav vn) throws NavException,XPathEvalException{ int result; if (currentStep == null) { if (fne.opCode == FuncName.CURRENT) { vn.loadCurrentNode(); } currentStep = s; if (currentStep == null) { if (state == START) { state = END; return vn.getCurrentIndex2(); } else { return -1; } } } while (true) { switch (currentStep.axis_type) { case AxisType.CHILD: if ( (result = process_child(vn))!=-2) return result; break; case AxisType.DESCENDANT_OR_SELF: case AxisType.DESCENDANT: case AxisType.PRECEDING: case AxisType.FOLLOWING: if ((result = process_DDFP(vn))!= -2) return result; break; case AxisType.PARENT: if ((result = process_parent(vn))!= -2) return result; break; case AxisType.ANCESTOR: if ((result = process_ancestor(vn))!= -2) return result; break; case AxisType.ANCESTOR_OR_SELF: if ((result = process_ancestor_or_self(vn))!= -2) return result; break; case AxisType.SELF: if ((result = process_self(vn))!= -2) return result; break; case AxisType.FOLLOWING_SIBLING: if ((result = process_following_sibling(vn))!= -2) return result; break; case AxisType.PRECEDING_SIBLING: if ((result = process_preceding_sibling(vn))!= -2) return result; break; case AxisType.ATTRIBUTE: if ((result = process_attribute(vn))!= -2) return result; break; default: if ((result = process_namespace(vn))!= -2) return result; } } } }
3,286
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NodeRecorder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/NodeRecorder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Node record allows one to record the node position of VTDNav. You * can store/load multiple node position using NodeRecorder, which is * also more spatially efficient than . However, the * internal representation of node is variable in length and recording a large * number of nodes could consume much memory. It is a <em>bad</em> idea to * record every node of an document. So be careful when using it. */ public class NodeRecorder { protected VTDNav vn; protected FastIntBuffer fib; public final static int BUF_SZ_EXPO = 7;// buffer page size is now 128 int size; // in # of nodes int position; // in # of nodes int count; // in # of ints /** * The parameter-less constructor * */ public NodeRecorder() { vn = null; size = position = 0; fib = new FastIntBuffer(BUF_SZ_EXPO); } /** * * @param vn1 */ public NodeRecorder(VTDNav vn1) { bind(vn1); size = position = count = 0; fib = new FastIntBuffer(BUF_SZ_EXPO); } public void bind(VTDNav vn1) { if (vn1 == null) throw new IllegalArgumentException( "NodeRecorder can't take a null VTDNav instatnce"); vn = vn1; } /** * This function records the position of VN into the internal buffer * */ public void record() { //add the context and int i; switch (vn.context[0]) { case -1: fib.append(0xff | 0x80000000); size++; position++; count++; break; case 0: if (vn.atTerminal == false) { fib.append(0); count++; } else { fib.append(0x80000000); count += 2; } size++; position++; if (vn.atTerminal == true) fib.append(vn.LN); break; case 1: if (vn.atTerminal == false) { fib.append(1); fib.append(vn.context[1]); fib.append(vn.l1index); size++; position++; count += 3; } else { fib.append(0x80000001); fib.append(vn.context[1]); fib.append(vn.l1index); fib.append(vn.LN); size++; position++; count += 4; } break; case 2: if (vn.atTerminal == false) { fib.append(2); count += 7; } else { fib.append(0x80000002); count += 8; } fib.append(vn.context[1]); fib.append(vn.context[2]); fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); size++; position++; if (vn.atTerminal == true) fib.append(vn.LN); break; case 3: if (vn.atTerminal == false) { fib.append(3); count += 11; } else { fib.append(0x80000003); count += 12; } fib.append(vn.context[1]); fib.append(vn.context[2]); fib.append(vn.context[3]); fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); fib.append(vn.l3lower); fib.append(vn.l3upper); fib.append(vn.l3index); size++; position++; if (vn.atTerminal == true) fib.append(vn.LN); break; default: if (vn.shallowDepth) { if (vn.atTerminal == false) { i = vn.context[0]; fib.append(i); count += i + 8; } else { i = vn.context[0]; fib.append(i | 0x80000000); count += i + 9; } for (int k = 1; k <= i; k++) { fib.append(vn.context[k]); } fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); fib.append(vn.l3lower); fib.append(vn.l3upper); fib.append(vn.l3index); size++; position++; if (vn.atTerminal) fib.append(vn.LN); }else{ VTDNav_L5 vnl = (VTDNav_L5)vn; switch (vn.context[0]) { case 4: if (vn.atTerminal == false) { fib.append(4); count += 15; } else { fib.append(0x80000004); count += 16; } fib.append(vn.context[1]); fib.append(vn.context[2]); fib.append(vn.context[3]); fib.append(vn.context[4]); fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); fib.append(vn.l3lower); fib.append(vn.l3upper); fib.append(vn.l3index); fib.append(vnl.l4lower); fib.append(vnl.l4upper); fib.append(vnl.l4index); size++; position++; if (vn.atTerminal == true) fib.append(vn.LN); break; case 5: if (vn.atTerminal == false) { fib.append(5); count += 19; } else { fib.append(0x80000005); count += 20; } fib.append(vn.context[1]); fib.append(vn.context[2]); fib.append(vn.context[3]); fib.append(vn.context[4]); fib.append(vn.context[5]); fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); fib.append(vn.l3lower); fib.append(vn.l3upper); fib.append(vn.l3index); fib.append(vnl.l4lower); fib.append(vnl.l4upper); fib.append(vnl.l4index); fib.append(vnl.l5lower); fib.append(vnl.l5upper); fib.append(vnl.l5index); size++; position++; if (vn.atTerminal == true) fib.append(vn.LN); break; default: if (vn.atTerminal == false) { i = vn.context[0]; fib.append(i); count += i + 14; } else { i = vn.context[0]; fib.append(i | 0x80000000); count += i + 15; } for (int k = 1; k <= i; k++) { fib.append(vn.context[k]); } fib.append(vn.l1index); fib.append(vn.l2lower); fib.append(vn.l2upper); fib.append(vn.l2index); fib.append(vn.l3lower); fib.append(vn.l3upper); fib.append(vn.l3index); fib.append(vnl.l4lower); fib.append(vnl.l4upper); fib.append(vnl.l4index); fib.append(vnl.l5lower); fib.append(vnl.l5upper); fib.append(vnl.l5index); size++; position++; if (vn.atTerminal) fib.append(vn.LN); } } } } /** * resetPointer() will set the pointer to the first node in NodeRecorder * This method is called when one wants to read the nodes in the nodeRecorder * */ public void resetPointer() { position = 0; count=0; } /** * Clear will erase all the nodes, internal buffers are reused * */ public void clear() { size = position = count = 0; fib.clear(); } /** * This method set the cursor in VTDNav to the nodes as recorded * in NodeRecorder, and return the output of "getCurrentIndex()" * It is important to notice that you can only go forward, not * backward * @return int * */ public int iterate() { int j, i; if (count < fib.size) { i = fib.intAt(count); boolean b = (i >= 0); if (b == false) { i = i & 0x7fffffff; } switch (i) { case 0xff: vn.context[0] = -1; vn.atTerminal = false; count++; break; case 0: vn.context[0] = 0; if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 1); count += 2; } else { vn.atTerminal = false; count++; } break; case 1: vn.context[0] = 1; vn.context[1] = fib.intAt(count + 1); vn.l1index = fib.intAt(count + 2); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 3); count += 4; } else { vn.atTerminal = false; count += 3; } break; case 2: vn.context[0] = 2; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.l1index = fib.intAt(count + 3); vn.l2lower = fib.intAt(count + 4); vn.l2upper = fib.intAt(count + 5); vn.l2index = fib.intAt(count + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 7); count += 8; } else { vn.atTerminal = false; count += 7; } break; case 3: vn.context[0] = 3; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.l1index = fib.intAt(count + 4); vn.l2lower = fib.intAt(count + 5); vn.l2upper = fib.intAt(count + 6); vn.l2index = fib.intAt(count + 7); vn.l3lower = fib.intAt(count + 8); vn.l3upper = fib.intAt(count + 9); vn.l3index = fib.intAt(count + 10); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += 12; } else { vn.atTerminal = false; count += 11; } break; default: if (vn.shallowDepth) { vn.context[0] = i; for (j = 1; j < i; j++) { vn.context[j] = fib.intAt(count + j); } vn.l1index = fib.intAt(count + i); vn.l2lower = fib.intAt(count + i + 1); vn.l2upper = fib.intAt(count + i + 2); vn.l2index = fib.intAt(count + i + 3); vn.l3lower = fib.intAt(count + i + 4); vn.l3upper = fib.intAt(count + i + 5); vn.l3index = fib.intAt(count + i + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += i + 8; } else { vn.atTerminal = false; count += i + 7; } break; } else { VTDNav_L5 vnl = (VTDNav_L5) vn; switch (i) { case 4: vn.context[0] = 4; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.context[4] = fib.intAt(count + 4); vn.l1index = fib.intAt(count + 5); vn.l2lower = fib.intAt(count + 6); vn.l2upper = fib.intAt(count + 7); vn.l2index = fib.intAt(count + 8); vn.l3lower = fib.intAt(count + 9); vn.l3upper = fib.intAt(count + 10); vn.l3index = fib.intAt(count + 11); vnl.l4lower = fib.intAt(count + 12); vnl.l4upper = fib.intAt(count + 13); vnl.l4index = fib.intAt(count + 14); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 15); count += 16; } else { vn.atTerminal = false; count += 15; } break; case 5: vn.context[0] = 5; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.context[4] = fib.intAt(count + 4); vn.context[5] = fib.intAt(count + 5); vn.l1index = fib.intAt(count + 6); vn.l2lower = fib.intAt(count + 7); vn.l2upper = fib.intAt(count + 8); vn.l2index = fib.intAt(count + 9); vn.l3lower = fib.intAt(count + 10); vn.l3upper = fib.intAt(count + 11); vn.l3index = fib.intAt(count + 12); vnl.l4lower = fib.intAt(count + 13); vnl.l4upper = fib.intAt(count + 14); vnl.l4index = fib.intAt(count + 15); vnl.l5lower = fib.intAt(count + 16); vnl.l5upper = fib.intAt(count + 17); vnl.l5index = fib.intAt(count + 18); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 19); count += 20; } else { vn.atTerminal = false; count += 19; } break; default: vn.context[0] = i; for (j = 1; j < i; j++) { vn.context[j] = fib.intAt(count + j); } vn.l1index = fib.intAt(count + i); vn.l2lower = fib.intAt(count + i + 1); vn.l2upper = fib.intAt(count + i + 2); vn.l2index = fib.intAt(count + i + 3); vn.l3lower = fib.intAt(count + i + 4); vn.l3upper = fib.intAt(count + i + 5); vn.l3index = fib.intAt(count + i + 6); vnl.l4lower = fib.intAt(count + i + 7); vnl.l4upper = fib.intAt(count + i + 8); vnl.l4index = fib.intAt(count + i + 9); vnl.l5lower = fib.intAt(count + i + 10); vnl.l5upper = fib.intAt(count + i + 11); vnl.l5index = fib.intAt(count + i + 12); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + i + 13); count += i + 14; } else { vn.atTerminal = false; count += i + 13; } break; } } } position++; return vn.getCurrentIndex(); } return -1; } }
15,143
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ModifyException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ModifyException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * XMLModifier throws ModifierException when there is an * exception condition during modification of XML */ public class ModifyException extends VTDException { public ModifyException(){ super(); } public ModifyException(String s){ super(s); } }
1,128
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
LocationPathExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/LocationPathExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.*; // if the context node is text(), // then many axis simply won't work /** * LocationPathExpr implements the location path expression * as defined in XPath spec */ public class LocationPathExpr extends Expr{ public static final int ABSOLUTE_PATH =0, RELATIVE_PATH =1; Step s; Step currentStep; int pathType; int state; //FastIntBuffer fib; // for uniqueness checking intHash ih; public static final int START = 0, // initial state END= 1, // return to begin TERMINAL= 2, // no more next step FORWARD = 3, // BACKWARD= 4; public LocationPathExpr(){ state = START; s = null; pathType = RELATIVE_PATH; currentStep = null; //fib = new FastIntBuffer(8);// page size 256 = 2^ 8 ih = new intHash(); } final public void optimize2(){} final public void optimize(){ // get to last step Step ts = s; if (ts==null) return; while(ts.nextS!=null){ ts = ts.nextS; } while(ts.prevS !=null){ // logic of optmize here if (ts.axis_type == AxisType.CHILD0 || ts.axis_type == AxisType.CHILD || ts.axis_type == AxisType.ATTRIBUTE){ switch(ts.prevS.axis_type){ case AxisType.CHILD: if (ts.prevS.nt.testType == com.ximpleware.NodeTest.NODE){ ts.prevS.axis_type = AxisType.CHILD0; ts.prevS.nt.testType = NodeTest.NAMETEST; ts.prevS.nt.type= 0; ts.prevS.nt.nodeName = "*"; } break; case AxisType.DESCENDANT: ts.prevS.axis_type = AxisType.DESCENDANT0; break; case AxisType.DESCENDANT_OR_SELF: ts.prevS.axis_type = AxisType.DESCENDANT_OR_SELF0; break; case AxisType.PRECEDING: ts.prevS.axis_type = AxisType.PRECEDING0; break; case AxisType.FOLLOWING: ts.prevS.axis_type = AxisType.FOLLOWING0; break; case AxisType.FOLLOWING_SIBLING: ts.prevS.axis_type = AxisType.FOLLOWING_SIBLING0; ts.prevS.nt.testType = NodeTest.NAMETEST; ts.prevS.nt.type= 0; ts.prevS.nt.nodeName = "*"; break; case AxisType.PRECEDING_SIBLING: ts.prevS.axis_type = AxisType.PRECEDING_SIBLING0; ts.prevS.nt.testType = NodeTest.NAMETEST; ts.prevS.nt.type= 0; ts.prevS.nt.nodeName = "*"; break; } } ts= ts.prevS; } // rewrite steps } final public void setStep(Step st){ s = st; } final public void setPathType(int ptype){ pathType = ptype; } // Improved version for uniqueness checking final public boolean isUnique(int i){ return ih.isUnique(i); } final public void reset(VTDNav vn){ state = START; Step temp = s; ih.reset(); currentStep = null; while(temp!=null){ temp.reset(vn); temp = temp.nextS; } /*cached = false; if (cachedNodeSet != null){ cachedNodeSet.clear(); }*/ } public String toString(){ String st = ""; Step ts = s; if (pathType == LocationPathExpr.ABSOLUTE_PATH){ st = st+"/"; } if (ts == null) return st; else return st + ts; } final public boolean evalBoolean(VTDNav vn){ boolean a = false; vn.push2(); // record stack size int size = vn.contextStack2.size; try{ a = (evalNodeSet(vn) != -1); }catch (Exception e){ } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; } final public double evalNumber(VTDNav vn){ double d = Double.NaN; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a+1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t ==VTDNav.TOKEN_DOCUMENT) { String s = vn.getXPathStringVal(); d = Double.parseDouble(s); }else if (t == VTDNav.TOKEN_PI_NAME) { if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL) d = vn.parseDouble(a+1); }else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; } final public String evalString(VTDNav vn){ String s=""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch(t){ case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; } final public boolean isNodeSet(){ return true; } final public boolean isNumerical(){ return false; } final protected void transition_child(VTDNav vn)throws NavException{ vn.toElement(VTDNav.P); if (currentStep.prevS != null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } } /** * For processing node tests that are element specific * @param vn * @return * @throws XPathEvalException * @throws NavException */ final protected int process_child(VTDNav vn)throws XPathEvalException,NavException{ int result; boolean b = false, b1 = false; int k=1; Predicate t= null; //System.out.println(" index-============= " + vn.getCurrentIndex()); //System.out.println(" depth ==============" + vn.getCurrentDepth()); switch(state){ case START: //if (currentStep.nt.testType < NodeTest.TEXT){ // first search for any predicate that // requires contextSize // if so, compute its context size // if size > 0 // set context // if size ==0 // immediately set the state to backward or end t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ state = END; break; } b=vn.toElement(VTDNav.FIRST_CHILD); state = END; if (b ){ do { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null){ //currentStep.position++; state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)){ return result; } } break; } } while (vn.toElement(VTDNav.NS)); if (state == END) vn.toElement(VTDNav.PARENT); } break; case END: currentStep =null; // reset(); return -1; case FORWARD: //if (currentStep.nt.testType < NodeTest.TEXT){ t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; forward: if (vn.toElement(VTDNav.FC)) { do { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } break forward; } } while (vn.toElement(VTDNav.NS)); vn.toElement(VTDNav.P); if (currentStep.hasPredicate) currentStep.resetP(vn); currentStep = currentStep.prevS; } else { //vn.toElement(VTDNav.P); currentStep = currentStep.prevS; } break; case BACKWARD: //if (currentStep.nt.testType < NodeTest.TEXT) { //currentStep = currentStep.prevS; //b = false; if(currentStep.out_of_range){ currentStep.out_of_range = false; if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; } while (vn.toElement(VTDNav.NS)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { b = true; break; } } if (b ) { state = FORWARD; currentStep = currentStep.nextS; } else { if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); } break; case TERMINAL: if(currentStep.out_of_range){ currentStep.out_of_range = false; if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; } //if (currentStep.nt.testType < NodeTest.TEXT) { while (vn.toElement(VTDNav.NS)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { // state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected void transition_DDFP(VTDNav vn){ vn.pop2(); currentStep.ft = true; if(currentStep.hasPredicate) currentStep.resetP(vn); //System.out.println(" --++ pop in //"); if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; } final protected int process_DDFP(VTDNav vn) throws XPathEvalException, NavException { AutoPilot ap; boolean b = false, b1 = false; Predicate t= null; int result; switch(state){ case START: case FORWARD: if (vn.atTerminal){ if (state == START) state = END; else { // no need to set_ft to true // no need to resetP state = BACKWARD; currentStep = currentStep.prevS; } break; } t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state ==START) state = END; else { currentStep = currentStep.prevS; state = BACKWARD; } break; } String helper = null; if (currentStep.nt.testType == NodeTest.NAMETEST){ helper = currentStep.nt.nodeName; } else if (currentStep.nt.testType == NodeTest.NODE){ helper = "*"; } else throw new XPathEvalException("can't run descendant " + "following, or following-sibling axis over comment(), pi(), and text()"); if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot) currentStep.o; ap.bind(vn); } if (currentStep.ft ) { if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0 ) if (currentStep.nt.testType == NodeTest.NODE) ap.setSpecial(true); else ap.setSpecial(false); //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0) ap.selectElement(helper); else if (currentStep.axis_type == AxisType.DESCENDANT0) ap.selectElement_D(helper); else if (currentStep.axis_type == AxisType.PRECEDING0) ap.selectElement_P(helper); else ap.selectElement_F(helper); currentStep.ft = false; } if ( state == START) state = END; vn.push2(); // not the most efficient. good for now //System.out.println(" --++ push in //"); b = false; while(ap.iterate()){ if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)){ b = true; break; } } if (b == false) { vn.pop2(); //System.out.println(" --++ pop in //"); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); if ( state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.nextS != null){ state = FORWARD; currentStep = currentStep.nextS; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: //currentStep = currentStep.prevS; if (currentStep.out_of_range){ currentStep.out_of_range = false; transition_DDFP(vn); break; } ap = (AutoPilot) currentStep.o; //vn.push(); //b = false; while(ap.iterate()){ if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)){ b = true; break; } } if (b ) { if (currentStep.nextS != null) { //vn.push(); //System.out.println(" --++ push in //"); state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } else { transition_DDFP(vn); } break; case TERMINAL: if (currentStep.out_of_range){ currentStep.out_of_range = false; transition_DDFP(vn); break; } ap = (AutoPilot) currentStep.o; b = false; while (ap.iterate()) { if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)) { b = true; break; } } if (b ) { //if (currentStep.evalPredicates(vn)) { result = vn.getCurrentIndex(); if (isUnique(result)) return result; //} } else { transition_DDFP(vn); } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_DDFP2(VTDNav vn) throws XPathEvalException, NavException { AutoPilot ap; boolean b = false, b1 = false; Predicate t = null; int result; switch (state) { case START: case FORWARD: /*if (vn.atTerminal) { if (state == START) state = END; else { // no need to set_ft to true // no need to resetP state = BACKWARD; currentStep = currentStep.prevS; } break; }*/ t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { if (state == START) state = END; else { currentStep = currentStep.prevS; state = BACKWARD; } break; } String helper = null; /*if (currentStep.nt.testType == NodeTest.NAMETEST) { helper = currentStep.nt.nodeName; } else if (currentStep.nt.testType == NodeTest.NODE) { helper = "*"; } else throw new XPathEvalException( "can't run descendant " + "following, or following-sibling axis over comment(), pi(), and text()");*/ if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot) currentStep.o; ap.bind(vn); } if (currentStep.ft) { /*if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF) if (currentStep.nt.testType == NodeTest.NODE) ap.setSpecial(true); else ap.setSpecial(false);*/ // currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF) ap.selectNode(); else if (currentStep.axis_type == AxisType.DESCENDANT) ap.selectDescendantNode(); else if (currentStep.axis_type == AxisType.PRECEDING) ap.selectPrecedingNode(); else ap.selectFollowingNode(); currentStep.ft = false; } if (state == START) state = END; vn.push2(); // not the most efficient. good for now // System.out.println(" --++ push in //"); b = false; while (ap.iterate2()) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { b = true; break; } } if (b == false) { vn.pop2(); // System.out.println(" --++ pop in //"); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { // vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: if(currentStep.out_of_range){ currentStep.out_of_range = false; transition_DDFP(vn); break; } // currentStep = currentStep.prevS; ap = (AutoPilot) currentStep.o; // vn.push(); //b = false; while (ap.iterate2()) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { b = true; break; } } if (b ) { if (currentStep.nextS != null) { // vn.push(); // System.out.println(" --++ push in //"); state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } else transition_DDFP(vn); break; case TERMINAL: if(currentStep.out_of_range){ currentStep.out_of_range = false; transition_DDFP(vn); break; } ap = (AutoPilot) currentStep.o; b = false; while (ap.iterate2()) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { b = true; break; } } if (b) { //if (currentStep.evalPredicates(vn)) { result = vn.getCurrentIndex(); if (isUnique(result)) return result; //} } else{ transition_DDFP(vn); } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_parent(VTDNav vn) throws XPathEvalException, NavException{ boolean b1 = false; Predicate t= null; int result; switch ( state) { case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if (vn.getCurrentDepth() == -1) { if ( state == START) state = END; else { //vn.pop(); state = BACKWARD; currentStep = currentStep.prevS; } } else { vn.push2(); vn.toElement(VTDNav.P); // must return true if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } }else{ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if ( state == START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: case TERMINAL: if (currentStep.prevS == null) { vn.pop2(); state = END; break; }else { vn.pop2(); state = BACKWARD; currentStep = currentStep.prevS; break; } default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_parent2(VTDNav vn) throws XPathEvalException, NavException{ boolean b1 = false; Predicate t= null; int result; switch ( state) { case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if (vn.getCurrentDepth() == -1) { if ( state == START) state = END; else { //vn.pop(); state = BACKWARD; currentStep = currentStep.prevS; } } else { vn.push2(); vn.toNode(VTDNav.P); // must return true if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } }else{ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if ( state == START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: case TERMINAL: if (currentStep.prevS == null) { vn.pop2(); state = END; break; }else { vn.pop2(); state = BACKWARD; currentStep = currentStep.prevS; break; } default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_ancestor( VTDNav vn) throws XPathEvalException, NavException{ int result; boolean b = false, b1 = false; //int contextSize; Predicate t= null; switch(state){ case START: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize( t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { state = END; break; } state = END; if (vn.getCurrentDepth() != -1) { vn.push2(); while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } } if (state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); } } break; case END: currentStep =null; // reset(); return -1; case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; vn.push2(); while(vn.toElement(VTDNav.P)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS != null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep=currentStep.prevS; } break; case BACKWARD: b = false; vn.push2(); while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS!= null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.prevS!=null) { if (currentStep.hasPredicate) currentStep.resetP(vn); state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } } break; case TERMINAL: while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.prevS!=null) { if (currentStep.hasPredicate) currentStep.resetP(vn); state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_ancestor2( VTDNav vn) throws XPathEvalException, NavException{ int result; boolean b = false, b1 = false; //int contextSize; Predicate t= null; switch(state){ case START: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize( t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { state = END; break; } state = END; //if (vn.getCurrentDepth() != -1) { vn.push2(); while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } } if (state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); } // } break; case END: currentStep =null; // reset(); return -1; case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; vn.push2(); while(vn.toNode(VTDNav.P)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS != null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep=currentStep.prevS; } break; case BACKWARD: b = false; vn.push2(); while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS!= null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.prevS!=null) { if (currentStep.hasPredicate) currentStep.resetP(vn); state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } } break; case TERMINAL: while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.prevS!=null) { if (currentStep.hasPredicate) currentStep.resetP(vn); state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_ancestor_or_self(VTDNav vn) throws XPathEvalException,NavException{ boolean b = false, b1 = false; Predicate t= null; int result; switch ( state) { case START: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize( t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { state = END; break; } state = END; vn.push2(); if (currentStep.ft){ currentStep.ft = false; if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; if (vn.atTerminal) result = vn.LN; else result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); } break; case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; vn.push2(); if (currentStep.ft ) { currentStep.ft = false; if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; if (vn.atTerminal) result = vn.LN; else result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == BACKWARD) { if (currentStep.hasPredicate) currentStep.resetP(vn); currentStep.ft = true; vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: //b = false; vn.push2(); while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b == false) { vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS != null) { currentStep.ft = true; state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } } break; case TERMINAL: while (vn.toElement(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS!=null) { currentStep.ft = true; state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_ancestor_or_self2(VTDNav vn) throws XPathEvalException,NavException{ boolean b = false, b1 = false; Predicate t= null; int result; switch ( state) { case START: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize( t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { state = END; break; } state = END; vn.push2(); if (currentStep.ft){ currentStep.ft = false; if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; if (vn.atTerminal) result = vn.LN; else result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); } break; case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; vn.push2(); if (currentStep.ft ) { currentStep.ft = false; if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; if (vn.atTerminal) result = vn.LN; else result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if ( state == BACKWARD) { if (currentStep.hasPredicate) currentStep.resetP(vn); currentStep.ft = true; vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: //b = false; vn.push2(); while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b == false) { vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS != null) { currentStep.ft = true; state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } } break; case TERMINAL: while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS!=null) { currentStep.ft = true; state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_self(VTDNav vn) throws XPathEvalException,NavException{ boolean b1 = false; Predicate t= null; int result; switch( state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; } else{ state = TERMINAL; if (vn.atTerminal ) result = vn.LN; else result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } }else { if (currentStep.hasPredicate) currentStep.resetP(vn); if ( state == START) state = END; else state = BACKWARD; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: case TERMINAL: if (currentStep.prevS!=null){ state = BACKWARD; currentStep= currentStep.prevS; }else{ state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_self2(VTDNav vn) throws XPathEvalException, NavException { boolean b1 = false; Predicate t = null; int result; switch (state) { case START: case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; break; } if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; if (vn.atTerminal) result = vn.LN; else result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } else { if (currentStep.hasPredicate) currentStep.resetP(vn); if (state == START) state = END; else state = BACKWARD; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: case TERMINAL: if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_namespace(VTDNav vn) throws XPathEvalException,NavException { AutoPilot ap = null; boolean b1 = false; Predicate t= null; int temp; switch( state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if (vn.atTerminal){ if (state ==START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.ft ) { if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot) currentStep.o; ap.bind(vn); //ap.set_ft(true); } if (currentStep.nt.testType == NodeTest.NODE) ap.selectNameSpace("*"); else ap.selectNameSpace(currentStep.nt.nodeName); currentStep.ft = false; } if (state == START) state = END; vn.push2(); //vn.setAtTerminal(true); while ((temp = ap.iterateNameSpace()) != -1) { if ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn)) { break; } } if (temp == -1) { vn.pop2(); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } } else { vn.atTerminal=(true); if (currentStep.nextS != null) { vn.LN = temp; state = FORWARD; currentStep = currentStep.nextS; } else { //vn.pop(); state = TERMINAL; if (isUnique(temp)) { vn.LN = temp; return temp; } } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: ap = (AutoPilot) currentStep.o; //vn.push(); while( (temp = ap.iterateNameSpace()) != -1){ if ((!currentStep.hasPredicate)|| currentStep.evalPredicates(vn)){ break; } } if (temp == -1) { vn.pop2(); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; } else { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; if ( isUnique(temp)){ vn.LN = temp; return temp; } } } break; case TERMINAL: ap = (AutoPilot) currentStep.o; while( (temp = ap.iterateNameSpace()) != -1){ if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)){ break; } } if (temp != -1) if (isUnique(temp)){ vn.LN = temp; return temp; } vn.atTerminal=(false); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS == null) { currentStep.ft = true; vn.pop2(); state = END; } else { state = BACKWARD; vn.pop2(); currentStep.ft = true; currentStep = currentStep.prevS; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_following_sibling2(VTDNav vn) throws XPathEvalException,NavException{ boolean b = false, b1 = false; Predicate t= null; int result; switch( state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if ( state == START) state = END; else state = BACKWARD; vn.push2(); while (vn.toNode(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (state ==END){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); }else if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: while (vn.toNode(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS==null){ state = END; }else{ state = BACKWARD; currentStep = currentStep.prevS; } } break; case TERMINAL: while (vn.toNode(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ // state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if(currentStep.prevS!=null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_following_sibling(VTDNav vn) throws XPathEvalException,NavException{ boolean b = false, b1 = false; Predicate t= null; int result; switch( state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if ( state == START) state = END; else state = BACKWARD; vn.push2(); while (vn.toElement(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (state ==END){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); }else if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: while (vn.toElement(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS==null){ state = END; }else{ state = BACKWARD; currentStep = currentStep.prevS; } } break; case TERMINAL: while (vn.toElement(VTDNav.NS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ // state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if(currentStep.prevS!=null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_preceding_sibling(VTDNav vn) throws XPathEvalException,NavException { boolean b = false, b1 = false; Predicate t= null; int result; switch(state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if ( state == START) state = END; else state = BACKWARD; vn.push2(); while (vn.toElement(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (state ==END){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); }else if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: while (vn.toElement(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS==null){ state = END; }else{ state = BACKWARD; currentStep = currentStep.prevS; } } break; case TERMINAL: while (vn.toElement(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ // state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); if(currentStep.prevS!=null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_preceding_sibling2(VTDNav vn) throws XPathEvalException,NavException { boolean b = false, b1 = false; Predicate t= null; int result; switch(state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if ( state == START) state = END; else state = BACKWARD; vn.push2(); while (vn.toNode(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (state ==END){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); }else if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: while (vn.toNode(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS!=null){ state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } } if (b==false){ vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS==null){ state = END; }else{ state = BACKWARD; currentStep = currentStep.prevS; } } break; case TERMINAL: while (vn.toNode(VTDNav.PS)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ // state = TERMINAL; result = vn.getCurrentIndex(); if ( isUnique(result)) return result; } } vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if(currentStep.prevS!=null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } break; default: throw new XPathEvalException("unknown state"); } return -2; } final protected int process_attribute(VTDNav vn) throws XPathEvalException,NavException { AutoPilot ap = null; boolean b1 = false; Predicate t= null; int temp; switch( state){ case START: case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.setContextSize(i); } t = t.nextP; } if (b1){ if (state == FORWARD){ state = BACKWARD; currentStep = currentStep.prevS; }else state = END; break; } if (vn.atTerminal){ if (state ==START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.ft) { if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot) currentStep.o; ap.bind(vn); //ap.set_ft(true); } if (currentStep.nt.testType == NodeTest.NODE) ap.selectAttr("*"); else if (currentStep.nt.localName != null) ap.selectAttrNS(currentStep.nt.URL, currentStep.nt.localName); else ap.selectAttr(currentStep.nt.nodeName); currentStep.ft = false; } if (state == START) state = END; vn.atTerminal=(true); while ((temp = ap.iterateAttr2()) != -1) { if ( !currentStep.hasPredicate || currentStep.evalPredicates(vn)) { break; } } if (temp == -1) { currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.nextS != null) { vn.LN = temp; state = FORWARD; currentStep = currentStep.nextS; } else { //vn.pop(); state = TERMINAL; if (isUnique(temp)) { vn.LN = temp; return temp; } } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: ap = (AutoPilot) currentStep.o; //vn.push(); while( (temp = ap.iterateAttr2()) != -1){ if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)){ break; } } if (temp == -1) { currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; } else { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; if ( isUnique(temp)){ vn.LN = temp; return temp; } } } break; case TERMINAL: ap = (AutoPilot) currentStep.o; while( (temp = ap.iterateAttr2()) != -1){ if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)){ break; } } if (temp != -1) if (isUnique(temp)){ vn.LN = temp; return temp; } vn.atTerminal=(false); if (currentStep.hasPredicate) currentStep.resetP(vn); currentStep.ft = true; if (currentStep.prevS == null) { state = END; } else { state = BACKWARD; currentStep = currentStep.prevS; } break; default: throw new XPathEvalException("unknown state"); } return -2; } public int evalNodeSet(VTDNav vn) throws NavException,XPathEvalException{ int result; if (currentStep == null) { if ( pathType == ABSOLUTE_PATH){ vn.context[0]=-1; vn.atTerminal = false; } currentStep = s; if (currentStep == null){ if (state == START){ state = END; return 0; } else{ return -1; } } } while (true) { switch (currentStep.axis_type) { case AxisType.CHILD0: if ( (result = process_child(vn))!=-2){ return result; } break; case AxisType.CHILD: if ( (result = process_child2(vn))!=-2){ return result; } break; case AxisType.DESCENDANT_OR_SELF0: case AxisType.DESCENDANT0: case AxisType.PRECEDING0: case AxisType.FOLLOWING0: if ((result = process_DDFP(vn))!= -2) return result; break; case AxisType.DESCENDANT_OR_SELF: case AxisType.DESCENDANT: case AxisType.PRECEDING: case AxisType.FOLLOWING: if ((result = process_DDFP2(vn))!= -2) return result; break; case AxisType.PARENT: if ((result = process_parent(vn))!= -2) return result; break; case AxisType.ANCESTOR: if ((result = process_ancestor2(vn))!= -2) return result; break; case AxisType.ANCESTOR_OR_SELF: if ((result = process_ancestor_or_self2(vn))!= -2) return result; break; case AxisType.SELF: if ((result = process_self2(vn))!= -2) return result; break; case AxisType.FOLLOWING_SIBLING: if ((result = process_following_sibling2(vn))!= -2) return result; break; case AxisType.FOLLOWING_SIBLING0: if ((result = process_following_sibling(vn))!= -2) return result; break; case AxisType.PRECEDING_SIBLING: if ((result = process_preceding_sibling2(vn))!= -2) return result; break; case AxisType.PRECEDING_SIBLING0: if ((result = process_preceding_sibling(vn))!= -2) return result; break; case AxisType.ATTRIBUTE: if ((result = process_attribute(vn))!= -2) return result; break; default: if ((result = process_namespace(vn))!= -2) return result; } } } final public boolean isString(){ return false; } final public boolean isBoolean(){ return false; } // to support computer context size // needs to add final public boolean requireContextSize(){ return false; } // final public void setContextSize(int size){ } final protected int computeContextSize4PrecedingSibling(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; vn.push2(); while(vn.toElement(VTDNav.PREV_SIBLING)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; //currentStep.o = ap; return i; } final protected int computeContextSize4PrecedingSibling2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; vn.push2(); while(vn.toNode(VTDNav.PREV_SIBLING)){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; //currentStep.o = ap; return i; } final protected int computeContextSize4FollowingSibling(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; //AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); while(vn.toElement(VTDNav.NEXT_SIBLING)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; //currentStep.o = ap; return i; } final protected int computeContextSize4FollowingSibling2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; vn.push2(); while(vn.toNode(VTDNav.NEXT_SIBLING)){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; return i; } final protected int computeContextSize4Self(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i = 0; AutoPilot ap = (AutoPilot)currentStep.o; //if (vn.toElement(VTDNav.PARENT)){ if (currentStep.eval(vn,p)){ i++; } //} currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Self2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i = 0; AutoPilot ap = (AutoPilot)currentStep.o; //if (vn.toNode(VTDNav.PARENT)){ if (currentStep.eval2(vn,p)){ i++; } //} currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4AncestorOrSelf(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; do { if (currentStep.eval(vn, p)) { i++; } }while(vn.toElement(VTDNav.PARENT)); vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4AncestorOrSelf2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; do { if (currentStep.eval2(vn, p)) { i++; } }while(vn.toNode(VTDNav.PARENT)); vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Child2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; boolean b = vn.toNode(VTDNav.FIRST_CHILD); if (b) { do { if (currentStep.eval2(vn, p)) { i++; } } while (vn.toNode(VTDNav.NS)); vn.toNode(VTDNav.PARENT); currentStep.resetP(vn,p); currentStep.out_of_range=false; return i; } else return 0; } final protected int computeContextSize4Parent(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; if (vn.toElement(VTDNav.PARENT)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Parent2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; if (vn.toNode(VTDNav.PARENT)){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Ancestor2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; while (vn.toNode(VTDNav.PARENT)) { if (currentStep.eval2(vn, p)) { i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4DDFP(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ String helper = null; int i=0; AutoPilot ap = (AutoPilot)currentStep.o; if (currentStep.nt.testType == NodeTest.NODE){ helper = "*"; }else if (currentStep.nt.testType == NodeTest.NAMETEST){ helper = currentStep.nt.nodeName; }else throw new XPathEvalException("can't run descendant " + "following, or following-sibling axis over comment(), pi(), and text()"); if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0 ) if (currentStep.nt.testType == NodeTest.NODE) ap.setSpecial(true); else ap.setSpecial(false); //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0) if (currentStep.nt.localName!=null) ap.selectElementNS(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement(helper); else if (currentStep.axis_type == AxisType.DESCENDANT0) if (currentStep.nt.localName!=null) ap.selectElementNS_D(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_D(helper); else if (currentStep.axis_type == AxisType.PRECEDING0) if (currentStep.nt.localName!=null) ap.selectElementNS_P(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_P(helper); else if (currentStep.nt.localName!=null) ap.selectElementNS_F(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_F(helper); vn.push2(); while(ap.iterate()){ if (currentStep.evalPredicates(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4DDFP2(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF) ap.selectNode(); else if (currentStep.axis_type == AxisType.DESCENDANT) ap.selectDescendantNode(); else if (currentStep.axis_type == AxisType.PRECEDING) ap.selectPrecedingNode(); else ap.selectFollowingNode(); vn.push2(); while(ap.iterate2()){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Ancestor(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; while (vn.toElement(VTDNav.PARENT)) { if (currentStep.eval(vn, p)) { i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; } final protected int computeContextSize4Child(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ int i=0; boolean b = vn.toElement(VTDNav.FIRST_CHILD); if (b) { do { if (currentStep.eval(vn, p)) { i++; } } while (vn.toElement(VTDNav.NS)); vn.toElement(VTDNav.PARENT); currentStep.resetP(vn,p); currentStep.out_of_range=false; return i; } else return 0; } final public int computeContextSize(Predicate p, VTDNav vn) throws NavException,XPathEvalException{ boolean b = false; //Predicate tp = null; int i = 0; AutoPilot ap = (AutoPilot)currentStep.o; switch(currentStep.axis_type){ case AxisType.CHILD0: return computeContextSize4Child(p,vn); case AxisType.CHILD: return computeContextSize4Child2(p,vn); case AxisType.DESCENDANT_OR_SELF0: case AxisType.DESCENDANT0: case AxisType.PRECEDING0: case AxisType.FOLLOWING0: return computeContextSize4DDFP(p,vn); case AxisType.DESCENDANT_OR_SELF: case AxisType.DESCENDANT: case AxisType.PRECEDING: case AxisType.FOLLOWING: return computeContextSize4DDFP2(p,vn); case AxisType.PARENT: return computeContextSize4Parent2(p,vn); case AxisType.ANCESTOR: return computeContextSize4Ancestor2(p,vn); case AxisType.ANCESTOR_OR_SELF: return computeContextSize4AncestorOrSelf2(p,vn); case AxisType.SELF: return computeContextSize4Self2(p,vn); case AxisType.FOLLOWING_SIBLING: return computeContextSize4FollowingSibling2(p,vn); case AxisType.FOLLOWING_SIBLING0: return computeContextSize4FollowingSibling(p,vn); case AxisType.PRECEDING_SIBLING: return computeContextSize4PrecedingSibling2(p,vn); case AxisType.PRECEDING_SIBLING0: return computeContextSize4PrecedingSibling(p,vn); case AxisType.ATTRIBUTE: if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.nt.testType == NodeTest.NODE) ap.selectAttr("*"); else if (currentStep.nt.localName!=null) ap.selectAttrNS(currentStep.nt.URL, currentStep.nt.localName); else ap.selectAttr(currentStep.nt.nodeName); i = 0; while(ap.iterateAttr2()!=-1){ if (currentStep.evalPredicates(vn,p)){ i++; } } currentStep.resetP(vn,p); currentStep.o = ap; return i; case AxisType.NAMESPACE: if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.nt.testType == NodeTest.NODE) ap.selectNameSpace("*"); else ap.selectNameSpace(currentStep.nt.nodeName); i=0; vn.push2(); while(ap.iterateNameSpace()!=-1){ if (currentStep.evalPredicates(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.o = ap; return i; default: throw new XPathEvalException("axis not supported"); } //return 8; } public void setPosition(int pos){ } final public int adjust(int n) { int i; if (pathType == RELATIVE_PATH) { i = Math.min(intHash.determineHashWidth(n),6); // hash width 64 } else { i = intHash.determineHashWidth(n); } if (ih!=null && i<= ih.e) {} else ih = new intHash(i); Step temp = s; while(temp!=null){ temp.adjust(n); temp = temp.nextS; } return i; } final protected void selectNodeType(TextIter ti){ if (currentStep.nt.testType == NodeTest.TEXT ) ti.selectText(); else if (currentStep.nt.testType == NodeTest.COMMENT ) ti.selectComment(); else if (currentStep.nt.testType == NodeTest.PI0 ) ti.selectPI0(); else { ti.selectPI1(currentStep.nt.nodeName); } } final protected int process_child2(VTDNav vn)throws XPathEvalException,NavException{ int result; boolean b = false, b1 = false; Predicate t= null; switch(state){ case START: // first search for any predicate that // requires contextSize // if so, compute its context size // if size > 0 // set context // if size ==0 // immediately set the state to backward or end t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { state = END; break; } b = vn.toNode(VTDNav.FIRST_CHILD); state = END; if (b) { do { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { // currentStep.position++; state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) { return result; } } break; } } while (vn.toNode(VTDNav.NS)); if (state == END) vn.toNode(VTDNav.PARENT); } break; case END: currentStep = null; // reset(); return -1; case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.setContextSize(i); } t = t.nextP; } if (b1) { currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; forward: if (vn.toNode(VTDNav.FC)) { do { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } break forward; } } while (vn.toNode(VTDNav.NS)); vn.toNode(VTDNav.P); if (currentStep.hasPredicate) currentStep.resetP(vn); currentStep = currentStep.prevS; } else { // vn.toElement(VTDNav.P); currentStep = currentStep.prevS; } break; case BACKWARD: if (currentStep.out_of_range){ currentStep.out_of_range = false; if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; } // currentStep = currentStep.prevS; //b = false; while (vn.toNode(VTDNav.NS)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { b = true; break; } } if (b) { state = FORWARD; currentStep = currentStep.nextS; } else{ if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); } break; case TERMINAL: if (currentStep.out_of_range){ currentStep.out_of_range = false; if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; } while (vn.toNode(VTDNav.NS)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { // state = TERMINAL; result = vn.getCurrentIndex(); if (isUnique(result)) return result; } } if (currentStep.hasPredicate) currentStep.resetP(vn); transition_child(vn); break; default: throw new XPathEvalException("unknown state"); } return -2; } final public boolean isFinal(){ return (pathType == ABSOLUTE_PATH); } final public void markCacheable(){ Step temp = s; while(temp!=null){ if (temp.p!=null){ if (temp.p.expr!=null ){ if (temp.p.expr.isFinal() && temp.p.expr.isNodeSet()){ CachedExpr ce = new CachedExpr(temp.p.expr); temp.p.expr = ce; } temp.p.expr.markCacheable2(); } } temp = temp.nextS; } } final public void markCacheable2(){ markCacheable(); } final public void clearCache(){ Step temp = s; while(temp!=null){ if (temp.p!=null){ temp.p.expr.clearCache(); } temp = temp.nextS; } } }
93,175
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XPathParseException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/XPathParseException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This exception is thrown when an error occured during * the construction of XPathExpr * */ public class XPathParseException extends VTDException{ int offset; public XPathParseException(String s, int i){ super(s); offset = i; } public XPathParseException(String s){ super(s); offset = 0; } public int getOffset(){ return offset; } }
1,207
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EntityException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/EntityException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Signals exception conditions for any invalid entity reference during parsing. * Creation date: (2/16/04 4:10:05 PM) */ public class EntityException extends ParseException { /** * EntityException constructor comment. */ public EntityException() { super(); } /** * EntityException constructor comment. * @param s java.lang.String */ public EntityException(String s) { super(s); } }
1,241
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PathExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/PathExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * PathExpr implements the Path expression as defined * in XPath spec * */ public class PathExpr extends Expr { Expr fe; LocationPathExpr lpe; //boolean first_time; int evalState; //FastIntBuffer fib; intHash ih; //public int getPositon(){ // return fib.size(); //} public PathExpr(Expr f, LocationPathExpr l){ fe = f; lpe = l; //first_time = true; evalState = 0; //fib = new FastIntBuffer(8); ih = new intHash(); } final public boolean evalBoolean(VTDNav vn) { boolean a = false; vn.push2(); // record teh stack size int size = vn.contextStack2.size; try{ a = (evalNodeSet(vn) != -1); }catch (Exception e){ } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; } final public double evalNumber(VTDNav vn) { double d = Double.NaN; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a+1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t ==VTDNav.TOKEN_DOCUMENT) { String s = vn.getXPathStringVal(); d = Double.parseDouble(s); }else if (t == VTDNav.TOKEN_PI_NAME) { if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL) //s = vn.toString(a+1); d = vn.parseDouble(a+1); else d = Double.NaN; }else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; } final public int evalNodeSet(VTDNav vn) throws XPathEvalException, NavException { int a; while (true) { switch (evalState) { case 0: //this state is the initial state; a = fe.evalNodeSet(vn); if (a == -1){ evalState =4; } else evalState = 1; break; case 1: // fe returns valid value, then iterate the locationPath vn.push2(); a = lpe.evalNodeSet(vn); if (a == -1) { lpe.reset(vn); evalState = 3; } else { evalState = 2; if (isUnique(a)) return a; } break; case 2: a = lpe.evalNodeSet(vn); if (a == -1) { lpe.reset(vn); evalState = 3; } else{ if (isUnique(a)) return a; //return a; } break; case 3: vn.pop2(); a = fe.evalNodeSet(vn); if (a == -1) evalState = 4; else{ vn.push2(); evalState = 2; } break; case 4: return -1; default: throw new XPathEvalException( "Invalid state evaluating PathExpr"); } } //return -1; } final public String evalString(VTDNav vn) { String s = ""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch(t){ case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; } // The improved version, use hashtable to check for uniqueness final public boolean isUnique(int i){ return ih.isUnique(i); } final public void reset(VTDNav vn) { fe.reset(vn); lpe.reset(vn); //fib.clear(); ih.reset(); evalState = 0; } final public String toString() { return "("+fe +")/" + lpe; } final public boolean isNumerical() { return false; } final public boolean isNodeSet() { return true; } final public boolean isString(){ return false; } final public boolean isBoolean(){ return false; } // to support computer context size // needs to add final public boolean requireContextSize(){ return false; } final public void setContextSize(int size){ } final public void setPosition(int pos){ } final public int adjust(int n){ int i = fe.adjust(n); lpe.adjust(n); if (ih!=null && i==ih.e) {} else ih = new intHash(i); return i; } final public boolean isFinal(){ return fe.isFinal(); } final public void markCacheable(){ fe.markCacheable(); lpe.markCacheable(); } final public void markCacheable2(){ fe.markCacheable2(); lpe.markCacheable2(); } final public void clearCache(){ fe.clearCache(); lpe.clearCache(); } }
6,112
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
arrayList.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/arrayList.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; class arrayList { public final static int GROWTH_INC = 16; public final static int default_init_capacity = 16; public arrayList(){ oa = new Object[default_init_capacity]; capacity = default_init_capacity; } public arrayList(int initial_capacity){ oa = new Object[initial_capacity]; capacity = initial_capacity; } final public Object get(int i){ if(i>=size) throw new IndexOutOfBoundsException(); return oa[i]; } final public void add(Object o){ if (size<capacity){ oa[size]=o; size++; }else{ Object[] oa1 = new Object[capacity+GROWTH_INC]; System.arraycopy(oa, 0, oa1, 0, capacity); oa = oa1; capacity = capacity+GROWTH_INC; oa[size] = o; size++; } } final public void clear(){ size = 0; } final public int size(){ return size; } final public int getCapacity(){ return capacity; } protected int size; protected int capacity; protected Object[] oa; }
1,813
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XPathEvalException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/XPathEvalException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This exception is thrown when there is something * during XPath evaluation * */ public class XPathEvalException extends VTDException{ public XPathEvalException(String s){ super(s); } }
1,037
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ElementFragmentNs.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ElementFragmentNs.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.*; /** * ElementFragmentNs is class representing namespace compensated elementFragment * its constructor is protected, only intended to be called by getElementFragmentNs(). * */ import com.ximpleware.transcode.Transcoder; /** * ElementFragmentNs represents a name-space compensated element fragment * */ public class ElementFragmentNs { VTDNav vn; long l; FastIntBuffer fib; int stLen; // length of starting tag int UTF_8_Size; int ASCII_Size; int ISO_8859_1_Size; int UTF_16_BE_Size; int UTF_16_LE_Size; static byte[] ws; // a few byte patterns for white space and '=' static{ ws = new byte[5]; ws[0]=0; ws[1]=(byte)' '; ws[2]=0; ws[3]='='; ws[4]=0; } /** * * @param vn1 * @param l1 * @param fib1 * @param len */ protected ElementFragmentNs(VTDNav vn1, long l1, FastIntBuffer fib1, int len){ UTF_8_Size = -1; ASCII_Size = -1; ISO_8859_1_Size = -1; UTF_16_BE_Size = -1; UTF_16_LE_Size = -1; vn = vn1; l = l1; fib = fib1; stLen = len; } /** * Transcode the ElementFragmentNS object to a byte array according to the * destination encoding format * @param encoding * @return * */ public final byte[] toBytes(int dest_encoding) throws TranscodeException{ if (dest_encoding == vn.encoding){ return toBytes(); } // find out how long the output bytes are byte[] ba = new byte[getSize(dest_encoding)]; int os = (int)l; int len = (int)(l>>32); int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ Transcoder.transcodeAndFill(xml,ba,os,len,vn.encoding,dest_encoding); return ba; } int enc = vn.getEncoding(); int temp = 0; int outPosition = 0; // transcode and fill the bytes switch (enc) { case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp = (stLen + 1) << 1; break; default: temp = stLen + 1; } // transcode starting length outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, os, temp, vn.encoding, dest_encoding); //System.arraycopy(xml, os, ba, 0, temp); //namespace compensation os1 += temp; int tos = 0, tlen = 0; for (int i = 0; i < fib.size(); i++) { //System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws //System.arraycopy(ws, 0, ba, os1, 2); outPosition = Transcoder.transcodeAndFill2(outPosition, ws,ba,0,2, vn.encoding, dest_encoding); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i)) << 1; tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff) << 1; //System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml,ba,tos,tlen, vn.encoding, dest_encoding); os1 += tlen; // write a 0 and = //System.arraycopy(ws, 2, ba, os1, 2); outPosition = Transcoder.transcodeAndFill2(outPosition, ws,ba,2,2, vn.encoding, dest_encoding); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i) + 1) - 1) << 1; tlen = ((vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2) << 1; //System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, tos, tlen, vn.encoding, dest_encoding); os1 += tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 //System.arraycopy(ws, 1, ba, os1, 2); outPosition = Transcoder.transcodeAndFill2(outPosition, ws, ba, 1, 2, vn.encoding, dest_encoding); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i)) << 1; tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff) << 1; //System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, tos, tlen, vn.encoding, dest_encoding); os1 += tlen; // write a = and 0 //System.arraycopy(ws, 3, ba, os1, 2); outPosition = Transcoder.transcodeAndFill2(outPosition, ws,ba,3,2, vn.encoding, dest_encoding); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i) + 1) - 1) << 1; tlen = ((vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2) << 1; // System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, tos, tlen, vn.encoding, dest_encoding); os1 += tlen; break; default: // write a ws //System.arraycopy(ws, 1, ba, os1, 1); outPosition = Transcoder.transcodeAndFill2(outPosition, ws,ba,1,1, vn.encoding, dest_encoding); os1++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); //System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, tos, tlen, vn.encoding, dest_encoding); os1 += tlen; // write a = //System.arraycopy(ws, 3, ba, os1, 1); outPosition = Transcoder.transcodeAndFill2(outPosition, ws,ba,3,1, vn.encoding, dest_encoding); os1++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; //System.arraycopy(xml, tos, ba, os1, tlen); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, tos, tlen, vn.encoding, dest_encoding); os1 += tlen; } } //System.out.println(new String(ba)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp = (stLen + 1) << 1; break; default: temp = stLen + 1; } //System.arraycopy(xml, os + temp, ba, os1, len - temp); outPosition = Transcoder.transcodeAndFill2(outPosition, xml, ba, os + temp, len - temp, vn.encoding, dest_encoding); //System.out.println(new String(ba)); return ba; } /** * Return a byte array of an element with namespace compensation * in its orginal encoding format * @return * */ public final byte[] toBytes(){ byte[] ba = new byte[getSize()]; int os = (int)l; int len = (int)(l>>32); int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ System.arraycopy(xml,os,ba,0,len); return ba; } int enc = vn.getEncoding(); int temp = 0; switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } System.arraycopy(xml,os,ba,0,temp); //namespace compensation os1 += temp; int tos =0,tlen=0; for (int i = 0; i < fib.size(); i++) { //System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws System.arraycopy(ws,0,ba,os1,2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; // write a 0 and = System.arraycopy(ws,2,ba,os1,2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 System.arraycopy(ws,1,ba,os1,2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; // write a = and 0 System.arraycopy(ws,3,ba,os1,2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; System.arraycopy(xml,tos,ba,os1,tlen); os1 +=tlen; break; default: // write a ws System.arraycopy(ws, 1, ba, os1, 1); os1 ++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); System.arraycopy(xml, tos, ba, os1, tlen); os1 +=tlen; // write a = System.arraycopy(ws, 3, ba, os1, 1); os1 ++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; System.arraycopy(xml, tos, ba, os1, tlen); os1 +=tlen; } } //System.out.println(new String(ba)); switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } System.arraycopy(xml, os + temp, ba, os1, len - temp); //System.out.println(new String(ba)); return ba; } /** * getSize gets the byte length of ns compensated fragment in its source * encoding format * @return the byte length of ns compensated fragment in its source encoding format * */ public final int getSize(){ //int encoding = vn.encoding; int len = (int) (l >> 32); if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); if (vn.encoding < VTDNav.FORMAT_UTF_16BE ){ len += (vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4; }else{ len += ((vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4)<<1; } } return len; } /** * This method returns the size of the transcoded byte representation of * the ns compensated element fragment * @param dest_encoding * @return * @throws TranscodeException * */ public final int getSize(int dest_encoding) throws TranscodeException{ //int len = (int) (l >> 32); /*if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); len += (vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4; }*/ if (vn.encoding == dest_encoding) return getSize(); //int src_encoding= vn.encoding; byte[] ba = vn.getXML().getBytes(); int len = Transcoder.getOutLength(ba, (int)l, (int)(l>>32), vn.encoding, dest_encoding ); if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); if (vn.encoding < VTDNav.FORMAT_UTF_16BE ){ len += Transcoder.getOutLength(ba, vn.getTokenOffset(k), (vn.getTokenLength(k) & 0xffff), vn.encoding, dest_encoding) + Transcoder.getOutLength(ba, vn.getTokenOffset(k+1), vn.getTokenLength(k + 1), vn.encoding, dest_encoding) + ((dest_encoding<VTDNav.FORMAT_UTF_16BE)?4:8); }else { len += Transcoder.getOutLength(ba, vn.getTokenOffset(k)<<1, (vn.getTokenLength(k) & 0xffff)<<1, vn.encoding, dest_encoding) + Transcoder.getOutLength(ba, vn.getTokenOffset(k+1)<<1, vn.getTokenLength(k + 1)<<1, vn.encoding, dest_encoding) + ((dest_encoding<VTDNav.FORMAT_UTF_16BE)?4:8); } } return len; } /** * Write ns compensated fragments (bytes in original encoding format) to outputstream * @param ost * @throws IOException * */ public final void writeToOutputStream(OutputStream ost) throws IOException{ int os = (int)l; int len = (int)(l>>32); //int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ //System.arraycopy(xml,os,ba,0,len); ost.write(xml,os,len); return; //return ba; } int enc = vn.getEncoding(); int temp = 0; switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } ost.write(xml,os,temp); //System.arraycopy(xml,os,ba,0,temp); //namespace compensation //os1 += temp; int tos =0,tlen=0; for (int i = 0; i < fib.size(); i++) { //System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws //System.arraycopy(ws,0,ba,os1,2); ost.write(ws,0,2); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a 0 and = //System.arraycopy(ws,2,ba,os1,2); ost.write(ws,2,2); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 //System.arraycopy(ws,1,ba,os1,2); ost.write(ws,1,2); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a = and 0 //System.arraycopy(ws,3,ba,os1,2); ost.write(ws,3,2); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); ost.write(xml,tos,tlen); //os1 +=tlen; break; default: // write a ws //System.arraycopy(ws, 1, ba, os1, 1); ost.write(ws,1,1); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); //System.arraycopy(xml, tos, ba, os1, tlen); ost.write(xml,tos,tlen); //os1 +=tlen; // write a = //System.arraycopy(ws, 3, ba, os1, 1); ost.write(ws,3,1); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; //System.arraycopy(xml, tos, ba, os1, tlen); ost.write(xml,tos,tlen); //os1 +=tlen; } } //System.out.println(new String(ba)); switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } //System.arraycopy(xml, os + temp, ba, os1, len - temp); ost.write(xml,os+temp,len-temp); } /** * Write the transcode byte representation of an ns-compensated * element fragment to the output stream * @param ost * @param dest_encoding * @throws IOException * @throws TranscodeException * */ public final void writeToOutputStream(OutputStream ost,int dest_encoding) throws IOException, TranscodeException{ if (vn.encoding == dest_encoding){ writeToOutputStream(ost); return; } int os = (int)l; int len = (int)(l>>32); //int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen==0){ //System.arraycopy(xml,os,ba,0,len); //ost.write(xml,os,len); Transcoder.transcodeAndWrite(xml,ost, os,len, vn.encoding, dest_encoding ); return; //return ba; } int enc = vn.getEncoding(); int temp = 0; switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } //ost.write(xml,os,temp); Transcoder.transcodeAndWrite(xml,ost, os, temp, enc,dest_encoding ); //System.arraycopy(xml,os,ba,0,temp); //namespace compensation //os1 += temp; int tos =0,tlen=0; for (int i = 0; i < fib.size(); i++) { //System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: //write a 0 and ws //System.arraycopy(ws,0,ba,os1,2); //ost.write(ws,0,2); Transcoder.transcodeAndWrite(ws,ost,0,2, enc,dest_encoding ); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; // write a 0 and = //System.arraycopy(ws,2,ba,os1,2); //ost.write(ws,2,2); Transcoder.transcodeAndWrite(ws,ost,2,2, enc,dest_encoding ); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; break; case VTDNav.FORMAT_UTF_16LE: // write a ws and 0 //System.arraycopy(ws,1,ba,os1,2); //ost.write(ws,1,2); Transcoder.transcodeAndWrite(ws,ost,1,2, enc,dest_encoding ); //os1 += 2; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; // write a = and 0 //System.arraycopy(ws,3,ba,os1,2); //ost.write(ws,3,2); Transcoder.transcodeAndWrite(ws,ost,3,2, enc,dest_encoding ); //os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; //System.arraycopy(xml,tos,ba,os1,tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; break; default: // write a ws //System.arraycopy(ws, 1, ba, os1, 1); //ost.write(ws,1,1); Transcoder.transcodeAndWrite(ws,ost,1,1,enc, dest_encoding); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); //System.arraycopy(xml, tos, ba, os1, tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; // write a = //System.arraycopy(ws, 3, ba, os1, 1); //ost.write(ws,3,1); Transcoder.transcodeAndWrite(ws,ost,3,1, enc,dest_encoding ); //os1 ++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; //System.arraycopy(xml, tos, ba, os1, tlen); //ost.write(xml,tos,tlen); Transcoder.transcodeAndWrite(xml,ost,tos,tlen, enc,dest_encoding ); //os1 +=tlen; } } //System.out.println(new String(ba)); switch(enc){ case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp= (stLen+1)<<1; break; default: temp = stLen+1; } //System.arraycopy(xml, os + temp, ba, os1, len - temp); //ost.write(xml,os+temp,len-temp); Transcoder.transcodeAndWrite(xml,ost,os+temp,len-temp, enc,dest_encoding ); } /** * Get the long encoding the len and offset of uncompensated element fragment * @return * */ public final long getOffsetLen(){ return l; } }
24,498
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NodeTest.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/NodeTest.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; //import com.ximpleware.xpath.LocationPathNode; /** * This class is used within LocationPathExpr to represent * Nodetest * */ public class NodeTest /*implements LocationPathNode*/{ public String nodeName; public String prefix; public String localName; public String URL; boolean nsEnabled; public int testType; public int type; //0 for *, 1 for node name, 2 for local name +URL public static final int NAMETEST = 0, NODE =1, TEXT =2, PI0=3, PI1 = 4, COMMENT = 5; public NodeTest(){ nsEnabled = false; localName = null; } /*public void setNsEnabled(boolean b){ nsEnabled = b; }*/ final public void setTestType(int t){ testType = t; } final public void setNodeName(String s){ nodeName = s; if (s.equals("*")) type = 0; else type = 1; } final public void setNodeNameNS(String p, String ln){ prefix = p; localName = ln; type = 2; } public boolean eval(VTDNav vn)throws NavException{ /*if (testType == NODE) return true;*/ //else if(testType == NAMETEST){ if (vn.atTerminal) return false; switch(type){ case 0: return true; case 1: return vn.matchElement(nodeName); case 2: return vn.matchElementNS(URL,localName); } //} return false; } public boolean eval2(VTDNav vn)throws NavException{ switch(testType){ case NAMETEST: if (vn.atTerminal) return false; switch(type){ case 0: return true; case 1: return vn.matchElement(nodeName); case 2: return vn.matchElementNS(URL,localName); } case NODE: return true; case TEXT: if (!vn.atTerminal) return false; int t = vn.getTokenType(vn.LN); if (t== VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL){ return true; } return false; case PI0: if (!vn.atTerminal) return false; if (vn.getTokenType(vn.LN)== VTDNav.TOKEN_PI_NAME){ return true; } return false; case PI1: if (!vn.atTerminal) return false; if (vn.getTokenType(vn.LN)== VTDNav.TOKEN_PI_NAME){ return vn.matchTokenString(vn.LN, nodeName); } return false; default: // comment if (!vn.atTerminal) return false; if (vn.getTokenType(vn.LN)== VTDNav.TOKEN_COMMENT){ return true; } return false; } } final public String toString(){ switch (testType){ case NAMETEST : if (localName == null) return nodeName; else return prefix+":"+localName; case NODE: return "node()"; case TEXT: return "text()"; case PI0: return "processing-instruction()"; case PI1: return (nodeName.indexOf('"')>0)? "processing-instruction('"+nodeName+"')" :"processing-instruction(\""+nodeName+"\")"; default: return "comment()"; } } }
3,706
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IIntBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IIntBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Abstract int buffer storage interface. * Creation date: (11/23/03 6:14:40 PM) */ public interface IIntBuffer { /** * Get the int at the index value. * Creation date: (11/23/03 6:15:33 PM) * @param i int */ int intAt(int i); /** * Modify the int at index to value val. * Creation date: (11/23/03 6:16:56 PM) * @param index int * @param val int */ void modifyEntry(int index, int val); /** * Get the total number of int in the buffer. * Creation date: (11/23/03 7:21:25 PM) * @return int */ int size(); }
1,376
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IReader.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IReader.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Abstract Reader Class decodes underlying raw bytes. * Creation date: (3/5/04 7:18:57 PM) */ interface IReader { /** * Get next available Char from the buffer. * Creation date: (3/5/04 7:39:44 PM) * @return boolean * @exception com.ximpleware.ParseException Parse exception. * @exception com.ximpleware.EncodingException Raw char to UCS conversion exception. * @exception com.ximpleware.EOFException The end of file exception. */ int getChar() throws EOFException, ParseException, EncodingException; /** * Skip the next char if it is a match. * Creation date: (3/5/04 7:39:44 PM) * @return boolean * @exception com.ximpleware.ParseException Parse exception. * @exception com.ximpleware.EncodingException Raw char to UCS conversion exception. * @exception com.ximpleware.EOFException The end of file exception. */ boolean skipChar(int ch) throws ParseException, EncodingException, EOFException; char decode(int ch); long _getChar(int byte_offset); }
1,924
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IByteBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IByteBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Abstract XML document storage interface. */ public interface IByteBuffer { /** * Get the byte at the given index of the underlying byte storage. * @return byte */ byte byteAt(int index); /** * Return a byte array filled with content from underlying byte storage. * @return byte[] * @param offset int bytes offset (not UTF char unit) * @param len int */ byte[] getBytes(int offset, int len); /** * Total size in terms of # of bytes. * @return int */ int length(); // get the whole XML byte[] getBytes(); }
1,397
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
BookMark.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/BookMark.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* BookMark is based on (and inspired by) the concept and * implementation contributed by Rodrigo Cunha. It corresponds * to a single node position of VTDNav's cursor. * * setCursorPosition(VTDNav vn) sets the node position of vn. * setCursorPosition() sets the node position of the BookMark object's embeddd * VTDNav object * * recordCursorPosition(VTDNav vn) records the node position of the VTDNav * Object. * * recordCursorPosition() records the node position of the BookMark object's * embedded VTDNav object * * BookMark(VTDNav vn) implicitly sets the node position for * the created BookMark instance. */ package com.ximpleware; /** * Bookmark is a single instance of a node position. * You can save the cursor's position into a bookMark instance * You can also point the cursor to the node position of previously * saved bookMark instance. * */ public class BookMark { VTDNav vn1; // the reference to the corresponding VTDNav object int ba[]; /** * Constructor for BookMark * Take no argument * */ public BookMark(){ ba = null; vn1 = null; } /** * separate a bookMark object apart from its embedded * VTDNav instance * */ final public void unbind(){ vn1 = null; } /** * bind a BookMark object to a VTDNav object * the cursor position is set to an invalid state * @param vn * */ public void bind(VTDNav vn){ if (vn==null) throw new IllegalArgumentException("vn can't be null"); vn1 = vn; if (vn.shallowDepth){ if (ba == null || vn.nestingLevel+8 != ba.length) ba = new int[vn.nestingLevel + 8]; } else { if (ba == null || vn.nestingLevel+14 != ba.length) ba = new int[vn.nestingLevel + 14]; } ba[0]= -2 ; // this would never happen in a VTDNav obj's context } /** * This method returns the embedded VTDNav Object * @return VTDNav * */ final public VTDNav getNav(){ return vn1; } /** * BookMark constructor with an instance of vn * as input * @param vn */ public BookMark(VTDNav vn){ bind(vn); recordCursorPosition(vn); } /** * set cursor position * This method can only set the cursor position * of an VTDNav object identical to its internal copy * @param vn * @return * */ public boolean setCursorPosition(VTDNav vn){ if (vn1 != vn || ba == null || ba[0] == -2) return false; for (int i = 0; i < vn.nestingLevel; i++) { vn.context[i] = ba[i]; } if (vn.shallowDepth) { vn.l1index = ba[vn.nestingLevel]; vn.l2index = ba[vn.nestingLevel + 1]; vn.l3index = ba[vn.nestingLevel + 2]; vn.l2lower = ba[vn.nestingLevel + 3]; vn.l2upper = ba[vn.nestingLevel + 4]; vn.l3lower = ba[vn.nestingLevel + 5]; vn.l3upper = ba[vn.nestingLevel + 6]; if (ba[vn.nestingLevel + 7] < 0) { vn.atTerminal = true; } else vn.atTerminal = false; vn.LN = ba[vn.nestingLevel + 7] & 0x7fffffff; }else{ VTDNav_L5 vnl = (VTDNav_L5)vn; vnl.l1index = ba[vn.nestingLevel]; vnl.l2index = ba[vn.nestingLevel + 1]; vnl.l3index = ba[vn.nestingLevel + 2]; vnl.l4index = ba[vn.nestingLevel + 3]; vnl.l5index = ba[vn.nestingLevel + 4]; vnl.l2lower = ba[vn.nestingLevel + 5]; vnl.l2upper = ba[vn.nestingLevel + 6]; vnl.l3lower = ba[vn.nestingLevel + 7]; vnl.l3upper = ba[vn.nestingLevel + 8]; vnl.l4lower = ba[vn.nestingLevel + 9]; vnl.l4upper = ba[vn.nestingLevel + 10] ; vnl.l5lower = ba[vn.nestingLevel + 11] ; vnl.l5upper = ba[vn.nestingLevel + 12]; if (ba[vn.nestingLevel+13] < 0){ vn.atTerminal = true; } else vn.atTerminal = false; vn.LN = ba[vn.nestingLevel+13] & 0x7fffffff; } return true; } /** * Set the cursor position of VTDNav object corresponding to the internal reference * position of the embedded VTDNav object * @return * */ final public boolean setCursorPosition(){ return setCursorPosition(vn1); } /** * Record the cursor position * This method is implemented to be lenient on loading in * that it can load nodes from any VTDNav object * if vn is null, return false * * @param vn * @return * */ public boolean recordCursorPosition(VTDNav vn){ if (vn == null) return false; if (vn== vn1){ }else { bind(vn); } for (int i = 0; i < vn.nestingLevel; i++) { ba[i] = vn1.context[i]; } if (vn.shallowDepth) { ba[vn.nestingLevel] = vn.l1index; ba[vn.nestingLevel + 1] = vn.l2index; ba[vn.nestingLevel + 2] = vn.l3index; ba[vn.nestingLevel + 3] = vn.l2lower; ba[vn.nestingLevel + 4] = vn.l2upper; ba[vn.nestingLevel + 5] = vn.l3lower; ba[vn.nestingLevel + 6] = vn.l3upper; // ba[vn.nestingLevel + 7]=(vn.atTerminal == true)?1:0; ba[vn.nestingLevel + 7] = (vn.atTerminal == true) ? (vn.LN | 0x80000000) : vn.LN; }else{ VTDNav_L5 vnl = (VTDNav_L5) vn; ba[vn.nestingLevel]= vnl.l1index ; ba[vn.nestingLevel + 1]= vnl.l2index ; ba[vn.nestingLevel + 2]= vnl.l3index ; ba[vn.nestingLevel + 3]= vnl.l4index ; ba[vn.nestingLevel + 4]= vnl.l5index ; ba[vn.nestingLevel + 5]= vnl.l2lower ; ba[vn.nestingLevel + 6]= vnl.l2upper ; ba[vn.nestingLevel + 7]= vnl.l3lower ; ba[vn.nestingLevel + 8]= vnl.l3upper ; ba[vn.nestingLevel + 9]= vnl.l4lower ; ba[vn.nestingLevel + 10]= vnl.l4upper ; ba[vn.nestingLevel + 11]= vnl.l5lower ; ba[vn.nestingLevel + 12]= vnl.l5upper ; //ba[vn.nestingLevel + 7]=(vn.atTerminal == true)?1:0; ba[vn.nestingLevel + 13]= (vn.atTerminal == true)? (vn.LN | 0x80000000) : vn.LN ; } return true; } /** * Record cursor position of the VTDNav object as embedded in the * bookmark * * @return * */ final public boolean recordCursorPosition(){ return recordCursorPosition(vn1); } /** * Compare the bookmarks to ensure they represent the same * node in the same VTDnav instance * @param bm2 * @return */ public final boolean deepEquals(BookMark bm2) { if (bm2.vn1 == this.vn1){ if (bm2.ba[bm2.ba[0]]==this.ba[this.ba[0]]){ if (vn1.shallowDepth){ if (this.ba[this.vn1.nestingLevel+7] < 0){ if (this.ba[this.vn1.nestingLevel+7] != bm2.ba[this.vn1.nestingLevel+7]) return false; } }else{ if (this.ba[this.vn1.nestingLevel+13] < 0){ if (this.ba[this.vn1.nestingLevel+13] != bm2.ba[this.vn1.nestingLevel+13]) return false; } } return true; } } return false; } /** * Compare the bookmarks to ensure they represent the same * node in the same VTDnav instance * @param bm2 * @return */ public final boolean equals(BookMark bm2) { if (this == bm2) return true; return deepEquals(bm2); } /** * Compare two bookmarks to ensure they represent the same * node in the same VTDnav instance */ public final boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof BookMark)) return false; return deepEquals((BookMark) obj); } /** * Returns the hash code which is a unique integer for every node */ public final int hashCode(){ if (ba == null || vn1==null || ba[0]==-2) return -2; if (vn1.atTerminal) return vn1.LN; if (ba[0]==1) return vn1.rootIndex; return ba[ba[0]]; } /** * Compare the node positions of two bookMarks * @param bm1 * @return */ public boolean compare(BookMark bm1){ /*for (int i = 0; i < vn1.nestingLevel; i++) { ba[i] = bm1.ba[i]; } if (vn1.getCurrentDepth()>)*/ if (vn1.shallowDepth) { for (int i = 0; i < vn1.nestingLevel + 7; i++) { if (ba[i] != bm1.ba[i]) return false; } }else { for (int i = 0; i < vn1.nestingLevel + 14; i++) { if (ba[i] != bm1.ba[i]) return false; } } return true; } }
9,747
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDGen.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/VTDGen.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.zip.GZIPInputStream; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import com.ximpleware.parser.ISO8859_10; import com.ximpleware.parser.ISO8859_11; import com.ximpleware.parser.ISO8859_2; import com.ximpleware.parser.ISO8859_3; import com.ximpleware.parser.ISO8859_4; import com.ximpleware.parser.ISO8859_5; import com.ximpleware.parser.ISO8859_6; import com.ximpleware.parser.ISO8859_7; import com.ximpleware.parser.ISO8859_8; import com.ximpleware.parser.ISO8859_9; import com.ximpleware.parser.UTF8Char; import com.ximpleware.parser.WIN1250; import com.ximpleware.parser.WIN1251; import com.ximpleware.parser.WIN1252; import com.ximpleware.parser.WIN1253; import com.ximpleware.parser.WIN1254; import com.ximpleware.parser.WIN1255; import com.ximpleware.parser.WIN1256; import com.ximpleware.parser.WIN1257; import com.ximpleware.parser.WIN1258; import com.ximpleware.parser.XMLChar; //import com.ximpleware.parser.ISO8859_11; import com.ximpleware.parser.ISO8859_13; import com.ximpleware.parser.ISO8859_14; import com.ximpleware.parser.ISO8859_15; /** * VTD Generator implementation. * Current support built-in entities only * It parses DTD, but doesn't resolve declared entities */ public class VTDGen { class ASCIIReader implements IReader { public ASCIIReader() { } final public int getChar() throws EOFException, ParseException, EncodingException { int a; if (offset >= endOffset) throw e; a= XMLDoc[offset++]; if (a<0) throw new ParseException( "ASCII encoding error: invalid ASCII Char"); return a; } final public boolean skipChar(int ch) throws ParseException, EOFException, EncodingException { if (ch == XMLDoc[offset]) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = XMLDoc[offset]; if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return (char) XMLDoc[offset]; } } class ISO8859_10Reader implements IReader { public ISO8859_10Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_10.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_10.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_10.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_10.decode(XMLDoc[offset]); } } class ISO8859_1Reader implements IReader { public ISO8859_1Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return XMLDoc[offset++] & 0xff; } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == XMLDoc[offset]) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = 0xff & XMLDoc[offset]; if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return (char)(XMLDoc[offset] & 0xff); } } class ISO8859_2Reader implements IReader { public ISO8859_2Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_2.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_2.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_2.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_2.decode(XMLDoc[offset]); } } class ISO8859_3Reader implements IReader { public ISO8859_3Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_3.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_3.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_3.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_3.decode(XMLDoc[offset]); } } class ISO8859_4Reader implements IReader { public ISO8859_4Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_4.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_4.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_4.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_4.decode(XMLDoc[offset]); } } class ISO8859_5Reader implements IReader { public ISO8859_5Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_5.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_5.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_5.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_5.decode(XMLDoc[offset]); } } class ISO8859_6Reader implements IReader { public ISO8859_6Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_6.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_6.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_6.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_6.decode(XMLDoc[offset]); } } class ISO8859_7Reader implements IReader { public ISO8859_7Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_7.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_7.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_7.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_7.decode(XMLDoc[offset]); } } class ISO8859_8Reader implements IReader { public ISO8859_8Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_8.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_8.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_8.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_8.decode(XMLDoc[offset]); } } class ISO8859_9Reader implements IReader { public ISO8859_9Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_9.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_9.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_9.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_9.decode(XMLDoc[offset]); } } class ISO8859_11Reader implements IReader { public ISO8859_11Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_11.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_11.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_11.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_11.decode(XMLDoc[offset]); } } class ISO8859_13Reader implements IReader { public ISO8859_13Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_13.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_13.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_13.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_13.decode(XMLDoc[offset]); } } class ISO8859_14Reader implements IReader { public ISO8859_14Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_14.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_14.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_14.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_14.decode(XMLDoc[offset]); } } class ISO8859_15Reader implements IReader { public ISO8859_15Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return ISO8859_15.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == ISO8859_15.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = ISO8859_15.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return ISO8859_15.decode(XMLDoc[offset]); } } class UTF16BEReader implements IReader { public UTF16BEReader() { } final public int getChar() throws EOFException, ParseException, EncodingException { int val = 0; if (offset >= endOffset) throw e; int temp = (XMLDoc[offset]&0xff) << 8 | (XMLDoc[offset + 1]&0xff); if ((temp < 0xd800) || (temp > 0xdfff)) { // not a high surrogate offset += 2; return temp; } else { if (temp<0xd800 || temp>0xdbff) throw new EncodingException("UTF 16 BE encoding error: should never happen"); val = temp; temp = (XMLDoc[offset + 2]&0xff) << 8 | (XMLDoc[offset + 3]&0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be a low surrogate here throw new EncodingException("UTF 16 BE encoding error: should never happen"); } val = ((val - 0xd800)<<10) + (temp - 0xdc00) + 0x10000; offset += 4; return val; } } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { // implement UTF-16BE to UCS4 conversion int temp = (XMLDoc[offset]&0xff) << 8 | (XMLDoc[offset + 1]&0xff); if ((temp < 0xd800) || (temp > 0xdfff)) { // not a high surrogate //offset += 2; if (temp == ch) { offset += 2; return true; } else return false; } else { if (temp<0xd800 || temp>0xdbff) throw new EncodingException("UTF 16 BE encoding error: should never happen"); int val = temp; temp = (XMLDoc[offset + 2]&0xff) << 8 | (XMLDoc[offset + 3]&0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be a low surrogate here throw new EncodingException("UTF 16 BE encoding error: should never happen"); } val = ((val - 0xd800) << 10) + (temp - 0xdc00) + 0x10000; if (val == ch) { offset += 4; return true; } else return false; } } final public char decode(int offset){ return 0; } final public long _getChar(int offset){ long val; int temp = ((XMLDoc[offset ] & 0xff) << 8) |(XMLDoc[offset + 1]& 0xff); if ((temp < 0xd800) || (temp > 0xdfff)) { // not a high surrogate if (temp == '\r') { if (XMLDoc[offset + 3] == '\n' && XMLDoc[offset + 2] == 0) { return '\n'|(4L<<32); } else { return '\n'|(2L<<32); } } //currentOffset++; return temp| (2L<<32); } else { val = temp; temp = ((XMLDoc[offset + 2] & 0xff) << 8) | (XMLDoc[offset+ 3] & 0xff); val = ((temp - 0xd800) << 10) + (val - 0xdc00) + 0x10000; //currentOffset += 2; return val | (4L<<32); } } } class UTF16LEReader implements IReader { public UTF16LEReader() { } final public int getChar() throws EOFException, ParseException, EncodingException { int val = 0; if (offset >= endOffset) throw e; int temp = (XMLDoc[offset + 1] &0xff) << 8 | (XMLDoc[offset]& 0xff); if (temp < 0xd800 || temp > 0xdfff) { // check for low surrogate offset += 2; return temp; } else { if (temp<0xd800 || temp>0xdbff) throw new EncodingException("UTF 16 LE encoding error: should never happen"); val = temp; temp = (XMLDoc[offset + 3] &0xff) << 8 | (XMLDoc[offset + 2]&0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be high surrogate throw new EncodingException("UTF 16 LE encoding error: should never happen"); } val = ((val - 0xd800) <<10) + (temp - 0xdc00) + 0x10000; offset += 4; return val; } } final public boolean skipChar(int ch) throws EOFException, EncodingException, ParseException { int temp = (XMLDoc[offset + 1]&0xff) << 8 | (XMLDoc[offset]&0xff); if (temp < 0xd800 ||temp > 0xdfff) { // check for low surrogate if (temp == ch) { offset += 2; return true; } else { return false; } } else { if (temp<0xd800 || temp>0xdbff) throw new EncodingException("UTF 16 LE encoding error: should never happen"); int val = temp; temp = (XMLDoc[offset + 3] &0xff)<< 8 | (XMLDoc[offset + 2]&0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be high surrogate throw new EncodingException("UTF 16 LE encoding error: should never happen"); } val = ((val - 0xd800)<<10) + (temp - 0xdc00) + 0x10000; if (val == ch) { offset += 4; return true; } else return false; } } final public char decode(int offset){ return 0; } final public long _getChar(int offset){ // implement UTF-16LE to UCS4 conversion int val, temp = (XMLDoc[offset + 1 ] & 0xff) << 8 | (XMLDoc[offset] & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // check for low surrogate if (temp == '\r') { if (XMLDoc[offset + 2] == '\n' && XMLDoc[offset + 3] == 0) { return '\n' | (4L<<32) ; } else { return '\n' | (2L<<32); } } return temp | (2L<<32); } else { val = temp; temp = (XMLDoc[offset + 3]&0xff) << 8 | (XMLDoc[offset + 2] & 0xff); val = ((temp - 0xd800)<<10) + (val - 0xdc00) + 0x10000; return val | (4L<<32); } } } class UTF8Reader implements IReader { public UTF8Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; int temp = XMLDoc[offset]; //int a = 0, c = 0, d = 0, val = 0; if (temp >= 0) { ++offset; return temp; } return handleUTF8(temp); } private int handleUTF8(int temp) throws EncodingException, ParseException{ int val,c,d,a,i; temp = temp & 0xff; switch (UTF8Char.byteCount(temp)) { // handle multi-byte code case 2: c = 0x1f; // A mask determine the val portion of the first byte d = 6; // a = 1; // break; case 3: c = 0x0f; d = 12; a = 2; break; case 4: c = 0x07; d = 18; a = 3; break; case 5: c = 0x03; d = 24; a = 4; break; case 6: c = 0x01; d = 30; a = 5; break; default: throw new ParseException( "UTF 8 encoding error: should never happen"); } val = (temp & c) << d; i = a - 1; while (i >= 0) { temp = XMLDoc[offset + a - i]; if ((temp & 0xc0) != 0x80) throw new ParseException( "UTF 8 encoding error: should never happen"); val = val | ((temp & 0x3f) << ((i << 2) + (i << 1))); i--; } offset += a + 1; return val; } final public boolean skipChar(int ch) throws EOFException, EncodingException, ParseException { //int a = 0, c = 0, d = 0, val = 0; int temp = XMLDoc[offset]; if (temp >= 0) if (ch == temp) { offset++; return true; } else { return false; } return skipUTF8(temp, ch); } private boolean skipUTF8(int temp, int ch) throws EncodingException, ParseException{ int val, c, d, a, i; temp = temp & 0xff; switch (UTF8Char.byteCount(temp)) { // handle multi-byte code case 2: c = 0x1f; // A mask determine the val portion of the first byte d = 6; // a = 1; // break; case 3: c = 0x0f; d = 12; a = 2; break; case 4: c = 0x07; d = 18; a = 3; break; case 5: c = 0x03; d = 24; a = 4; break; case 6: c = 0x01; d = 30; a = 5; break; default: throw new ParseException( "UTF 8 encoding error: should never happen"); } val = (temp & c) << d; i = a - 1; while (i >= 0) { temp = XMLDoc[offset + a - i]; if ((temp & 0xc0) != 0x80) throw new ParseException( "UTF 8 encoding error: should never happen"); val = val | ((temp & 0x3f) << ((i << 2) + (i << 1))); i--; } if (val == ch){ offset += a + 1; return true; }else return false; } final public long _getChar(int offset){ int temp = XMLDoc[offset]; if (temp>=0){ if (temp == '\r') { if (XMLDoc[offset + 1] == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } //currentOffset++; return temp|(1L<<32); } return handle_utf8(temp,offset); } private long handle_utf8(int temp, int offset) { // TODO Auto-generated method stub int c=0, d=0, a=0; long val; switch (UTF8Char.byteCount((int)temp & 0xff)) { case 2: c = 0x1f; d = 6; a = 1; break; case 3: c = 0x0f; d = 12; a = 2; break; case 4: c = 0x07; d = 18; a = 3; break; case 5: c = 0x03; d = 24; a = 4; break; case 6: c = 0x01; d = 30; a = 5; break; } val = (temp & c) << d; int i = a - 1; while (i >= 0) { temp = XMLDoc[offset + a - i]; val = val | ((temp & 0x3f) << ((i << 2) + (i << 1))); i--; } //currentOffset += a + 1; return val | (((long)(a+1))<<32); } final public char decode(int offset){ return 0; } } class WIN1250Reader implements IReader { public WIN1250Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1250.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1250.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1250.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1250.decode(XMLDoc[offset]); } } class WIN1251Reader implements IReader { public WIN1251Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1251.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1251.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1251.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1251.decode(XMLDoc[offset]); } } class WIN1252Reader implements IReader { public WIN1252Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1252.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1252.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1252.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1252.decode(XMLDoc[offset]); } } class WIN1253Reader implements IReader { public WIN1253Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1253.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1253.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1253.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1253.decode(XMLDoc[offset]); } } class WIN1254Reader implements IReader { public WIN1254Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1254.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1254.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1254.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1254.decode(XMLDoc[offset]); } } class WIN1255Reader implements IReader { public WIN1255Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1255.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1255.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1255.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1255.decode(XMLDoc[offset]); } } class WIN1256Reader implements IReader { public WIN1256Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1256.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1256.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1256.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1256.decode(XMLDoc[offset]); } } class WIN1257Reader implements IReader { public WIN1257Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1257.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1257.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1257.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1257.decode(XMLDoc[offset]); } } class WIN1258Reader implements IReader { public WIN1258Reader() { } final public int getChar() throws EOFException, ParseException, EncodingException { if (offset >= endOffset) throw e; return WIN1258.decode(XMLDoc[offset++]); } final public boolean skipChar(int ch) throws EOFException, ParseException, EncodingException { if (ch == WIN1258.decode(XMLDoc[offset])) { offset++; return true; } else { return false; } } final public long _getChar(int offset){ int c = WIN1258.decode(XMLDoc[offset]); if (c=='\r' && XMLDoc[offset+1]=='\n') return (2L<<32)|'\n'; return (1L<<32)|c; } final public char decode(int offset){ return WIN1258.decode(XMLDoc[offset]); } } // attr_name_array size private final static int ATTR_NAME_ARRAY_SIZE = 16; public final static int FORMAT_ASCII = 0; public final static int FORMAT_ISO_8859_1 = 1; public final static int FORMAT_ISO_8859_10 = 11; public final static int FORMAT_ISO_8859_11 = 12; public final static int FORMAT_ISO_8859_12 = 13; public final static int FORMAT_ISO_8859_13 = 14; public final static int FORMAT_ISO_8859_14 = 15; public final static int FORMAT_ISO_8859_15 = 16; public final static int FORMAT_ISO_8859_16 = 17; public final static int FORMAT_ISO_8859_2 = 3; public final static int FORMAT_ISO_8859_3 = 4; public final static int FORMAT_ISO_8859_4 = 5; public final static int FORMAT_ISO_8859_5 = 6; public final static int FORMAT_ISO_8859_6 = 7; public final static int FORMAT_ISO_8859_7 = 8; public final static int FORMAT_ISO_8859_8 = 9; public final static int FORMAT_ISO_8859_9 = 10; public final static int FORMAT_UTF_16BE = 63; public final static int FORMAT_UTF_16LE = 64; // encoding format public final static int FORMAT_UTF8 = 2; public final static int FORMAT_WIN_1250 = 18; public final static int FORMAT_WIN_1251 = 19; public final static int FORMAT_WIN_1252 = 20; public final static int FORMAT_WIN_1253 = 21; public final static int FORMAT_WIN_1254 = 22; public final static int FORMAT_WIN_1255 = 23; public final static int FORMAT_WIN_1256 = 24; public final static int FORMAT_WIN_1257 = 25; public final static int FORMAT_WIN_1258 = 26; public final static int MAX_DEPTH = 254; // maximum depth value // max prefix length public final static int MAX_PREFIX_LENGTH = (1<<9) -1; // max Qname length public final static int MAX_QNAME_LENGTH = (1<<11) -1; // max Token length public final static int MAX_TOKEN_LENGTH = (1<<20) -1; private final static int STATE_ATTR_NAME = 3; private final static int STATE_ATTR_VAL = 4; private final static int STATE_CDATA = 12; private final static int STATE_COMMENT = 11; private final static int STATE_DEC_ATTR_NAME = 10; private final static int STATE_DOC_END = 7; // end of document private final static int STATE_DOC_START = 6; // beginning of document private final static int STATE_DOCTYPE = 13; private final static int STATE_END_COMMENT = 14; // comment appear after the last ending tag private final static int STATE_END_PI = 15; private final static int STATE_END_TAG = 2; // internal parser state private final static int STATE_LT_SEEN = 0; // encounter the first < private final static int STATE_PI_TAG =8; private final static int STATE_PI_VAL = 9; private final static int STATE_START_TAG = 1; private final static int STATE_TEXT = 5; // tag_stack size private final static int TAG_STACK_SIZE = 256; public final static int TOKEN_ATTR_NAME = 2; public final static int TOKEN_ATTR_NS = 3; public final static int TOKEN_ATTR_VAL = 4; public final static int TOKEN_CDATA_VAL = 11; public final static int TOKEN_CHARACTER_DATA = 5; public final static int TOKEN_COMMENT = 6; public final static int TOKEN_DEC_ATTR_NAME = 9; public final static int TOKEN_DEC_ATTR_VAL = 10; public final static int TOKEN_DOCUMENT = 13; public final static int TOKEN_DTD_VAL = 12; public final static int TOKEN_ENDING_TAG = 1; public final static int TOKEN_PI_NAME = 7; public final static int TOKEN_PI_VAL = 8; //private final static int STATE_END_PI_VAL = 17; // token type public final static int TOKEN_STARTING_TAG = 0; protected byte[] XMLDoc; protected IReader r; private int ch; private int ch_temp; protected int offset; protected int depth; private int length1, length2; protected boolean helper=false; protected boolean default_ns = false; //true xmlns='abc' protected boolean isXML = false; protected boolean singleByteEncoding; protected boolean shallowDepth; // true if lc depth is 3 protected boolean ns,is_ns; protected boolean br; //buffer reuse private int temp_offset; protected int endOffset; protected int prev_offset; private int increment; protected long[] tag_stack; private long[] attr_name_array; private int attr_count; private long[] prefixed_attr_name_array; private int[] prefix_URL_array; private int prefixed_attr_count; protected FastLongBuffer VTDBuffer; //protected int offset_adj; // determine the byte length for ':' for various encoding types // again, in terms of byte, not char as encoded in VTD protected FastLongBuffer l1Buffer; protected FastLongBuffer l2Buffer; protected FastIntBuffer l3Buffer; protected FastLongBuffer _l3Buffer; protected FastLongBuffer _l4Buffer; protected FastIntBuffer _l5Buffer; protected FastIntBuffer nsBuffer1; protected FastLongBuffer nsBuffer2; protected FastLongBuffer nsBuffer3; private int last_depth; private int last_l1_index; private int last_l2_index; private int last_l3_index; private int last_l4_index; protected EOFException e; protected int docLen; protected int docOffset; protected int encoding; //namespace aware flag // this is byte offset, not char offset as encoded in VTD protected boolean ws; // to prserve whitespace or not, default to false protected int rootIndex; protected int VTDDepth; // Maximum Depth of VTDs protected short LcDepth; protected long currentElementRecord; private boolean must_utf_8; private boolean BOM_detected; /** * VTDGen constructor method. */ public VTDGen() { attr_name_array = new long[ATTR_NAME_ARRAY_SIZE]; prefixed_attr_name_array = new long[ATTR_NAME_ARRAY_SIZE]; prefix_URL_array = new int[ATTR_NAME_ARRAY_SIZE]; tag_stack = new long[TAG_STACK_SIZE]; //scratch_buffer = new int[10]; VTDDepth = 0; LcDepth = 3; br = false; e = new EOFException("permature EOF reached, XML document incomplete"); ws = false; nsBuffer1 = new FastIntBuffer(4); nsBuffer2 = new FastLongBuffer(4); nsBuffer3 = new FastLongBuffer(4); currentElementRecord = 0; singleByteEncoding = true; shallowDepth =true; helper=false; default_ns = false; //true xmlns='abc' isXML = false; //offset_adj = 1; } /** * Clear internal states so VTDGEn can process the next file. */ public void clear() { if (br==false){ VTDBuffer = null; l1Buffer = null; l2Buffer = null; l3Buffer = null; _l3Buffer = null; _l4Buffer = null; _l5Buffer = null; } XMLDoc = null; offset = temp_offset =0; last_depth = last_l1_index = last_l2_index = last_l3_index=last_l4_index=0; rootIndex = 0; depth = -1; increment =1; BOM_detected = false; must_utf_8 = false; ch = ch_temp = 0; nsBuffer1.size=0; nsBuffer2.size=0; nsBuffer3.size=0; currentElementRecord = 0; } /** * Enable the parser to collect all white spaces, including the trivial white spaces * By default, trivial white spaces are ignored * @param b */ public void enableIgnoredWhiteSpace(boolean b){ ws = b; } /** * Enable VTDGen to generate Location Cache of either depth 3 or 5 * This method is meant to called before setDoc() or parseFile() * @param i */ public void selectLcDepth(int i) throws ParseException{ if (i!=3 &&i!=5) throw new IllegalArgumentException("LcDepth can only take the value of 3 or 5"); //new ParseException("LcDepth can only take the value of 3 or 5"); if (i==5) shallowDepth = false; } /** * Write white space records that are ignored by default */ private void addWhiteSpaceRecord() { if (depth > -1) { int length1 = offset - increment - temp_offset; if (length1 != 0) if (singleByteEncoding)//if (encoding < FORMAT_UTF_16BE) writeVTDText(temp_offset, length1, TOKEN_CHARACTER_DATA, depth); else writeVTDText(temp_offset >> 1, length1 >> 1, TOKEN_CHARACTER_DATA, depth); } } /** * A private method that detects the BOM and decides document encoding * @throws EncodingException * @throws ParseException */ private void decide_encoding() throws EncodingException,ParseException { if (XMLDoc.length==0) throw new EncodingException("Document is zero sized "); if (XMLDoc[offset] == -2) { increment = 2; if (XMLDoc[offset + 1] == -1) { offset += 2; encoding = FORMAT_UTF_16BE; BOM_detected = true; r = new UTF16BEReader(); } else throw new EncodingException("Unknown Character encoding: should be 0xff 0xfe"); } else if (XMLDoc[offset] == -1) { increment = 2; if (XMLDoc[offset + 1] == -2) { offset += 2; encoding = FORMAT_UTF_16LE; BOM_detected = true; r = new UTF16LEReader(); } else throw new EncodingException("Unknown Character encoding: not UTF-16LE"); } else if (XMLDoc[offset] == -17){ if (XMLDoc[offset+1] == -69 && XMLDoc[offset+2]==-65){ offset +=3; must_utf_8= true; } else throw new EncodingException("Unknown Character encoding: not UTF-8"); } else if (XMLDoc[offset]==0){ if (XMLDoc[offset+1] == 0x3c && XMLDoc[offset+2] == 0 && XMLDoc[offset+3] == 0x3f){ encoding = FORMAT_UTF_16BE; increment = 2; r = new UTF16BEReader(); } else throw new EncodingException("Unknown Character encoding: not UTF-16BE"); } else if (XMLDoc[offset]==0x3c){ if (XMLDoc[offset+1] == 0 && XMLDoc[offset+2] == 0x3f && XMLDoc[offset+3] == 0){ increment = 2; encoding = FORMAT_UTF_16LE; r = new UTF16LEReader(); } } // check for max file size exception if (encoding < FORMAT_UTF_16BE) { if (ns){ if ((offset + (long)docLen) >= 1L << 30) throw new ParseException("Other error: file size too big >=1GB "); } else { if ((offset + (long)docLen) >= 1L <<31) throw new ParseException("Other error: file size too big >=2GB "); } } else { //offset_adj = 2; if ((offset+ (long)docLen) >= 1L << 31) throw new ParseException("Other error: file size too large >= 2GB"); } if (encoding >= FORMAT_UTF_16BE ) singleByteEncoding = false; } /** * This method will detect whether the entity is valid or not and increment offset. * @return int * @throws com.ximpleware.ParseException Super class for any exception during parsing. * @throws com.ximpleware.EncodingException UTF/native encoding exception. * @throws com.ximpleware.EOFException End of file exception. */ private int entityIdentifier() throws EntityException, EncodingException,EOFException, ParseException { int ch = r.getChar(); int val = 0; switch (ch) { case '#': ch = r.getChar(); if (ch == 'x') { while (true) { ch = r.getChar(); if (ch >= '0' && ch <= '9') { val = (val << 4) + (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { val = (val << 4) + (ch - 'a' + 10); } else if (ch >= 'A' && ch <= 'F') { val = (val << 4) + (ch - 'A' + 10); } else if (ch == ';') { return val; } else throw new EntityException("Errors in char reference: Illegal char following &#x."); } } else { while (true) { if (ch >= '0' && ch <= '9') { val = val * 10 + (ch - '0'); } else if (ch == ';') { break; } else throw new EntityException("Errors in char reference: Illegal char following &#."); ch = r.getChar(); } } if (!XMLChar.isValidChar(val)) { throw new EntityException("Errors in entity reference: Invalid XML char."); } return val; //break; case 'a' : ch = r.getChar(); if (ch == 'm') { if (r.getChar() == 'p' && r.getChar() == ';') { //System.out.println(" entity for &"); return '&'; } else throw new EntityException("Errors in Entity: Illegal builtin reference"); } else if (ch == 'p') { if (r.getChar() == 'o' && r.getChar() == 's' && r.getChar() == ';') { //System.out.println(" entity for ' "); return '\''; } else throw new EntityException("Errors in Entity: Illegal builtin reference"); } else throw new EntityException("Errors in Entity: Illegal builtin reference"); case 'q' : if (r.getChar() == 'u' && r.getChar() == 'o' && r.getChar() == 't' && r.getChar() == ';') { return '"'; } else throw new EntityException("Errors in Entity: Illegal builtin reference"); case 'l' : if (r.getChar() == 't' && r.getChar() == ';') { return '<'; } else throw new EntityException("Errors in Entity: Illegal builtin reference"); //break; case 'g' : if (r.getChar() == 't' && r.getChar() == ';') { return '>'; } else throw new EntityException("Errors in Entity: Illegal builtin reference"); default : throw new EntityException("Errors in Entity: Illegal entity char"); } //return val; } /** * Write the remaining portion of LC info * */ private void finishUp(){ if (shallowDepth){ if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) | 0xffffffffL); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } }else{ if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) | 0xffffffffL); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); }else if (last_depth == 3) { _l3Buffer.append(((long) last_l3_index << 32) | 0xffffffffL); }else if (last_depth == 4) { _l4Buffer.append(((long) last_l4_index << 32) | 0xffffffffL); } } } /** * Format the string indicating the position (line number:offset)of the offset if * there is an exception. * @return java.lang.String indicating the line number and offset of the exception */ private String formatLineNumber() { return formatLineNumber(offset); } private String formatLineNumber(int os) { int so = docOffset; int lineNumber = 0; int lineOffset = 0; if (encoding < FORMAT_UTF_16BE) { while (so <= os-1) { if (XMLDoc[so] == '\n') { lineNumber++; lineOffset = so; } //lineOffset++; so++; } lineOffset = os - lineOffset; } else if (encoding == FORMAT_UTF_16BE) { while (so <= os-2) { if (XMLDoc[so + 1] == '\n' && XMLDoc[so] == 0) { lineNumber++; lineOffset = so; } so += 2; } lineOffset = (os - lineOffset) >> 1; } else { while (so <= os-2) { if (XMLDoc[so] == '\n' && XMLDoc[so + 1] == 0) { lineNumber++; lineOffset = so; } so += 2; } lineOffset = (os - lineOffset) >> 1; } return "\nLine Number: " + (lineNumber+1) + " Offset: " + (lineOffset-1); } /** * The entity ignorant version of getCharAfterS. * @return int * @throws ParseException * @throws EncodingException * @throws com.ximpleware.EOFException */ final private int getCharAfterS() throws ParseException, EncodingException, EOFException { int n; do { n = r.getChar(); if (XMLChar.isSpaceChar(n)){ } else return n; n = r.getChar(); if (XMLChar.isSpaceChar(n)){ } else return n; /*if ((n == ' ' || n == '\n' || n =='\t'|| n == '\r' ) ) { //if (XMLChar.isSpaceChar(n) ) { } else return n; n = r.getChar(); if ((n == ' ' || n == '\n' || n =='\t'|| n == '\r' ) ) { } else return n; /*if (n == ' ' || n == '\n' || n =='\t'|| n == '\r' ) { } else return n;*/ } while(true); //throw new EOFException("should never come here"); } /** * The entity aware version of getCharAfterS * @return int * @throws ParseException Super class for any exception during parsing. * @throws EncodingException UTF/native encoding exception. * @throws com.ximpleware.EOFException End of file exception. */ // private int getCharAfterSe() // throws ParseException, EncodingException, EOFException { // int n = 0; // int temp; //offset saver // while (true) { // n = r.getChar(); // if (!XMLChar.isSpaceChar(n)) { // if (n != '&') // return n; // else { // temp = offset; // if (!XMLChar.isSpaceChar(entityIdentifier())) { // offset = temp; // rewind // return '&'; // } // } // } // n = r.getChar(); // if (!XMLChar.isSpaceChar(n)) { // if (n != '&') // return n; // else { // temp = offset; // if (!XMLChar.isSpaceChar(entityIdentifier())) { // offset = temp; // rewind // return '&'; // } // } // } // } // } /** * Pre-compute the size of VTD+XML index * @return size of the index * */ public long getIndexSize(){ int size; if ( (docLen & 7)==0) size = docLen; else size = ((docLen >>3)+1)<<3; size += (VTDBuffer.size <<3)+ (l1Buffer.size <<3)+ (l2Buffer.size <<3); if ((l3Buffer.size & 1) == 0){ //even size += l3Buffer.size<<2; } else { size += (l3Buffer.size+1)<<2; //odd } return size+64; } /** * This method returns the VTDNav object after parsing, it also cleans * internal state so VTDGen can process the next file. * @return com.ximpleware.VTDNav */ public VTDNav getNav() { // call VTDNav constructor VTDNav vn; if (shallowDepth) vn = new VTDNav(rootIndex, encoding, ns, VTDDepth, new UniByteBuffer(XMLDoc), VTDBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen); else vn = new VTDNav_L5(rootIndex, encoding, ns, VTDDepth, new UniByteBuffer(XMLDoc), VTDBuffer, l1Buffer, l2Buffer, _l3Buffer, _l4Buffer, _l5Buffer, docOffset, docLen); clear(); r = new UTF8Reader(); return vn; } /** * Get the offset value of previous character. * @return int * @throws ParseException Super class for exceptions during parsing. */ private int getPrevOffset() throws ParseException { int prevOffset = offset; int temp; switch (encoding) { case FORMAT_UTF8 : do { prevOffset--; } while (XMLDoc[prevOffset] <0 && ((XMLDoc[prevOffset] & (byte)0xc0) == (byte)0x80)); return prevOffset; case FORMAT_ASCII : case FORMAT_ISO_8859_1: case FORMAT_ISO_8859_2: case FORMAT_ISO_8859_3: case FORMAT_ISO_8859_4: case FORMAT_ISO_8859_5: case FORMAT_ISO_8859_6: case FORMAT_ISO_8859_7: case FORMAT_ISO_8859_8: case FORMAT_ISO_8859_9: case FORMAT_ISO_8859_10: case FORMAT_ISO_8859_11: case FORMAT_ISO_8859_13: case FORMAT_ISO_8859_14: case FORMAT_ISO_8859_15: case FORMAT_WIN_1250: case FORMAT_WIN_1251: case FORMAT_WIN_1252: case FORMAT_WIN_1253: case FORMAT_WIN_1254: case FORMAT_WIN_1255: case FORMAT_WIN_1256: case FORMAT_WIN_1257: case FORMAT_WIN_1258: return offset - 1; case FORMAT_UTF_16LE : temp= (XMLDoc[offset]&0xff) << 8 | (XMLDoc[offset + 1]&0xff); if (temp < 0xd800 || temp > 0xdfff) { return offset - 2; } else return offset - 4; case FORMAT_UTF_16BE : temp =(XMLDoc[offset]&0xff) << 8 | (XMLDoc[offset + 1]&0xff); if (temp < 0xd800 || temp > 0xdfff) { return offset - 2; } else return offset - 4; default : throw new ParseException("Other Error: Should never happen"); } } /** * This method loads the VTD+XML from a byte array * @return VTDNav * @param ba * @throws IOException * @throws IndexReadException * */ public VTDNav loadIndex(byte[] ba)throws IOException,IndexReadException{ IndexHandler.readIndex(ba,this); return getNav(); } /** * This method loads the VTD+XML from an input stream * @return VTDNav * @param is * @throws IOException * @throws IndexReadException * */ public VTDNav loadIndex(InputStream is) throws IOException,IndexReadException{ IndexHandler.readIndex(is, this); return getNav(); } /** * This method loads the VTD+XML from a file * @return VTDNav * @param fileName * @throws IOException * @throws IndexReadException * */ public VTDNav loadIndex(String fileName)throws IOException,IndexReadException{ FileInputStream fis = null; try { fis = new FileInputStream(fileName); return loadIndex(fis); } finally { if (fis != null) fis.close(); } } /** * Load the separate VTD index and XmL file. * Refer to persistence model of separate vtd index * for more details * @param XMLFileName name of xml file * @param VTDIndexName name of the vtd index file * @return VTDNav object * @throws IOException * @throws IndexReadException * */ public VTDNav loadSeparateIndex(String XMLFileName, String VTDIndexName) throws IOException, IndexReadException{ FileInputStream xfis = null; FileInputStream vfis = null; xfis = new FileInputStream(XMLFileName); int size = (int)(new File(XMLFileName)).length(); vfis = new FileInputStream(VTDIndexName); IndexHandler.readSeparateIndex( vfis, xfis, size, this); return getNav(); } private void matchCPEncoding()throws ParseException{ if ((r.skipChar('p') || r.skipChar('P')) && r.skipChar('1') && r.skipChar('2') && r.skipChar('5')) { if (encoding <= FORMAT_UTF_16LE) { if (must_utf_8) throw new EncodingException( "Can't switch from UTF-8" + formatLineNumber()); if (r.skipChar('0')){ encoding = FORMAT_WIN_1250; r=new WIN1250Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('1')){ encoding = FORMAT_WIN_1251; r=new WIN1251Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('2')){ encoding = FORMAT_WIN_1252; r=new WIN1252Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('3')){ encoding = FORMAT_WIN_1253; r=new WIN1253Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('4')){ encoding = FORMAT_WIN_1254; r=new WIN1254Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('5') ){ encoding = FORMAT_WIN_1255; r=new WIN1255Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('6')){ encoding = FORMAT_WIN_1256; r=new WIN1256Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('7') ){ encoding = FORMAT_WIN_1257; r=new WIN1257Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('8') ){ encoding = FORMAT_WIN_1258; r=new WIN1258Reader(); _writeVTD(temp_offset, 6, TOKEN_DEC_ATTR_VAL, depth); }else throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); if (r.skipChar(ch_temp)) return; } else throw new ParseException( "XML decl error: Can't switch encoding to ISO-8859" + formatLineNumber()); } throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); } private void matchISOEncoding()throws ParseException{ if ((r.skipChar('s') || r.skipChar('S')) && (r.skipChar('o') || r.skipChar('O')) && r.skipChar('-') && r.skipChar('8') && r.skipChar('8') && r.skipChar('5') && r.skipChar('9') && r.skipChar('-')) { if (encoding <= FORMAT_UTF_16LE) { if (must_utf_8) throw new EncodingException( "Can't switch from UTF-8" + formatLineNumber()); if (r.skipChar('1')){ if (r.skipChar(ch_temp)) { encoding = FORMAT_ISO_8859_1; r = new ISO8859_1Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); return; } else if (r.skipChar('0') ){ encoding = FORMAT_ISO_8859_10; r = new ISO8859_10Reader(); _writeVTD(temp_offset, 11, TOKEN_DEC_ATTR_VAL, depth); } else if (r.skipChar('1') ){ encoding = FORMAT_ISO_8859_11; r = new ISO8859_11Reader(); _writeVTD(temp_offset, 11, TOKEN_DEC_ATTR_VAL, depth); } else if (r.skipChar('3') ){ encoding = FORMAT_ISO_8859_13; r = new ISO8859_13Reader(); _writeVTD(temp_offset, 11, TOKEN_DEC_ATTR_VAL, depth); } else if (r.skipChar('4') ){ encoding = FORMAT_ISO_8859_14; r = new ISO8859_14Reader(); _writeVTD(temp_offset, 11, TOKEN_DEC_ATTR_VAL, depth); } else if (r.skipChar('5') ){ encoding = FORMAT_ISO_8859_15; r = new ISO8859_15Reader(); _writeVTD(temp_offset, 15, TOKEN_DEC_ATTR_VAL, depth); } else throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); }else if (r.skipChar('2') ){ encoding = FORMAT_ISO_8859_2; r = new ISO8859_2Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('3')){ r = new ISO8859_3Reader(); encoding = FORMAT_ISO_8859_3; _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('4') ){ r = new ISO8859_4Reader(); encoding = FORMAT_ISO_8859_4; _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('5') ){ encoding = FORMAT_ISO_8859_5; r = new ISO8859_5Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('6') ){ encoding = FORMAT_ISO_8859_6; r = new ISO8859_6Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('7') ){ encoding = FORMAT_ISO_8859_7; r = new ISO8859_7Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('8') ){ encoding = FORMAT_ISO_8859_8; r = new ISO8859_8Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('9')){ encoding = FORMAT_ISO_8859_9; r = new ISO8859_9Reader(); _writeVTD(temp_offset, 10, TOKEN_DEC_ATTR_VAL, depth); } else throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); if (r.skipChar(ch_temp)) return; } else throw new ParseException( "XML decl error: Can't switch encoding to ISO-8859" + formatLineNumber()); } throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); } private void matchUTFEncoding() throws ParseException{ if ((r.skipChar('s') || r.skipChar('S'))) if (r.skipChar('-') && (r.skipChar('a') || r.skipChar('A')) && (r.skipChar('s') || r.skipChar('S')) && (r.skipChar('c') || r.skipChar('C')) && (r.skipChar('i') || r.skipChar('I')) && (r.skipChar('i') || r.skipChar('I')) && r.skipChar(ch_temp)) { if (singleByteEncoding) { if (must_utf_8) throw new EncodingException( "Can't switch from UTF-8" + formatLineNumber()); encoding = FORMAT_ASCII; r=new ASCIIReader(); _writeVTD(temp_offset, 8, TOKEN_DEC_ATTR_VAL, depth); return; } else throw new ParseException( "XML decl error: Can't switch encoding to US-ASCII" + formatLineNumber()); } else throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); if ((r.skipChar('t') || r.skipChar('T')) && (r.skipChar('f') || r.skipChar('F')) && r.skipChar('-')) { if (r.skipChar('8') && r.skipChar(ch_temp)) { if (singleByteEncoding) { //encoding = FORMAT_UTF8; _writeVTD(temp_offset, 5, TOKEN_DEC_ATTR_VAL, depth); return; } else throw new ParseException( "XML decl error: Can't switch encoding to UTF-8" + formatLineNumber()); } if (r.skipChar('1') && r.skipChar('6')) { if (r.skipChar(ch_temp)) { if (!singleByteEncoding) { if (!BOM_detected) throw new EncodingException( "BOM not detected for UTF-16" + formatLineNumber()); _writeVTD( temp_offset >> 1, 6, TOKEN_DEC_ATTR_VAL, depth); return; } throw new ParseException( "XML decl error: Can't switch encoding to UTF-16" + formatLineNumber()); } else if ((r.skipChar('l') || r.skipChar('L')) && (r.skipChar('e') || r.skipChar('E')) && r.skipChar(ch_temp)) { if (encoding == FORMAT_UTF_16LE) { r = new UTF16LEReader(); _writeVTD( temp_offset >> 1, 8, TOKEN_DEC_ATTR_VAL, depth); return; } throw new ParseException( "XML del error: Can't switch encoding to UTF-16LE" + formatLineNumber()); } else if ((r.skipChar('b') || r.skipChar('B')) && (r.skipChar('e') || r.skipChar('E')) && r.skipChar(ch_temp)) { if (encoding == FORMAT_UTF_16BE) { _writeVTD( temp_offset >> 1, 8, TOKEN_DEC_ATTR_VAL, depth); return; } throw new ParseException( "XML del error: Can't swtich encoding to UTF-16BE" + formatLineNumber()); } throw new ParseException( "XML decl error: Invalid encoding" + formatLineNumber()); } } } private void matchWindowsEncoding()throws ParseException{ if ((r.skipChar('i') || r.skipChar('I')) &&(r.skipChar('n') || r.skipChar('N')) &&(r.skipChar('d') || r.skipChar('D')) &&(r.skipChar('o') || r.skipChar('O')) &&(r.skipChar('w') || r.skipChar('W')) &&(r.skipChar('s') || r.skipChar('S')) && r.skipChar('-') && r.skipChar('1') && r.skipChar('2') && r.skipChar('5')) { if (encoding <= FORMAT_UTF_16LE) { if (must_utf_8) throw new EncodingException( "Can't switch from UTF-8" + formatLineNumber()); if (r.skipChar('0')){ encoding = FORMAT_WIN_1250; r=new WIN1250Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('1')){ encoding = FORMAT_WIN_1251; r=new WIN1251Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('2')){ encoding = FORMAT_WIN_1252; r=new WIN1252Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('3')){ encoding = FORMAT_WIN_1253; r=new WIN1253Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('4')){ encoding = FORMAT_WIN_1254; r=new WIN1254Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('5')){ encoding = FORMAT_WIN_1255; r=new WIN1255Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('6')){ encoding = FORMAT_WIN_1256; r=new WIN1256Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('7')){ encoding = FORMAT_WIN_1257; r=new WIN1257Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else if (r.skipChar('8')){ encoding = FORMAT_WIN_1258; r=new WIN1258Reader(); _writeVTD(temp_offset, 12, TOKEN_DEC_ATTR_VAL, depth); }else throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); if (r.skipChar(ch_temp)) return; } else throw new ParseException( "XML decl error: Can't switch encoding to ISO-8859" + formatLineNumber()); } throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); } /** * Generating VTD tokens and Location cache info. When set to true, * VTDGen conforms to XML namespace 1.0 spec * @param NS boolean Enable namespace or not * @throws ParseException Super class for any exceptions during parsing. * @throws EOFException End of file exception. * @throws EntityException Entity resolution exception. * @throws EncodingException UTF/native encoding exception. */ public void parse(boolean NS) throws EncodingException, EOFException, EntityException, ParseException { // define internal variables ns = NS; //String s1 = null,s2=null; length1 = length2 = 0; attr_count = prefixed_attr_count= 0 /*, ch = 0, ch_temp = 0*/; int parser_state = STATE_DOC_START; //boolean has_amp = false; is_ns = false; encoding = FORMAT_UTF8; helper=false; default_ns = false; //true xmlns='abc' isXML = false; //true only for xmlns:xml singleByteEncoding = true; // first check first several bytes to figure out the encoding decide_encoding(); // enter the main finite state machine try { _writeVTD(0,0,TOKEN_DOCUMENT,depth); while (true) { switch (parser_state) { case STATE_LT_SEEN : //if (depth < -1) // throw new ParseException("Other Errors: Invalid depth"); temp_offset = offset; ch = r.getChar(); if (XMLChar.isNameStartChar(ch)) { depth++; parser_state = STATE_START_TAG; } else { if (ch=='/'){ parser_state = STATE_END_TAG; } else if (ch=='!'){ parser_state = process_ex_seen(); }else if (ch=='?'){ parser_state = process_qm_seen(); }else throw new ParseException( "Other Error: Invalid char after <" + formatLineNumber()); } break; case STATE_START_TAG : //name space is handled by do { ch = r.getChar(); if (XMLChar.isNameChar(ch)) { if (ch == ':') { length2 = offset - temp_offset - increment; if (ns && checkPrefix2(temp_offset,length2)) throw new ParseException( "xmlns can't be an element prefix " + formatLineNumber(offset)); } } else break; }while (true); length1 = offset - temp_offset - increment; if (depth > MAX_DEPTH) { throw new ParseException( "Other Error: Depth exceeds MAX_DEPTH" + formatLineNumber()); } //writeVTD(offset, TOKEN_STARTING_TAG, length2:length1, depth) long x = ((long) length1 << 32) + temp_offset; tag_stack[depth] = x; // System.out.println( // " " + (temp_offset) + " " + length2 + ":" + length1 + " startingTag " + depth); if (depth > VTDDepth) VTDDepth = depth; //if (encoding < FORMAT_UTF_16BE){ if (singleByteEncoding){ if (length2>MAX_PREFIX_LENGTH || length1 > MAX_QNAME_LENGTH) throw new ParseException( "Token Length Error: Starting tag prefix or qname length too long" + formatLineNumber()); if (this.shallowDepth) writeVTD((temp_offset), (length2 << 11) | length1, TOKEN_STARTING_TAG, depth); else writeVTD_L5((temp_offset), (length2 << 11) | length1, TOKEN_STARTING_TAG, depth); } else { if (length2 > (MAX_PREFIX_LENGTH << 1) || length1 > (MAX_QNAME_LENGTH << 1)) throw new ParseException( "Token Length Error: Starting tag prefix or qname length too long" + formatLineNumber()); if (this.shallowDepth) writeVTD((temp_offset) >> 1, (length2 << 10) | (length1 >> 1), TOKEN_STARTING_TAG, depth); else writeVTD_L5((temp_offset) >> 1, (length2 << 10) | (length1 >> 1), TOKEN_STARTING_TAG, depth); } if (ns) { if (length2!=0){ length2 += increment; currentElementRecord = (((long)((length2<<16)|length1))<<32) | temp_offset; } else currentElementRecord = 0; if (depth <= nsBuffer1.size - 1) { nsBuffer1.size = depth ; int t= nsBuffer1.intAt(depth-1)+1; nsBuffer2.size=t; nsBuffer3.size=t; } } // offset += length1; length2 = 0; if (XMLChar.isSpaceChar(ch)) { ch = getCharAfterS(); if (XMLChar.isNameStartChar(ch)) { // seen an attribute here temp_offset = getPrevOffset(); parser_state = STATE_ATTR_NAME; break; } } helper = true; if (ch == '/') { depth--; helper = false; ch = r.getChar(); } if (ch == '>') { if (ns){ nsBuffer1.append(nsBuffer3.size-1); if (currentElementRecord !=0) qualifyElement(); } parser_state = processElementTail(helper); break; } throw new ParseException( "Starting tag Error: Invalid char in starting tag" + formatLineNumber()); case STATE_END_TAG : temp_offset = offset; int sos = (int) tag_stack[depth]; int sl = (int) (tag_stack[depth] >> 32); offset = temp_offset+sl; if (offset>= endOffset) throw new EOFException("permature EOF reached, XML document incomplete"); for (int i = 0; i < sl; i++) { if (XMLDoc[sos + i] != XMLDoc[temp_offset + i]) throw new ParseException( "Ending tag error: Start/ending tag mismatch" + formatLineNumber()); } depth--; ch = getCharAfterS(); if(ch != '>') throw new ParseException( "Ending tag error: Invalid char in ending tag " + formatLineNumber()); if (depth != -1) { temp_offset = offset; ch = getCharAfterS(); if (ch == '<'){ if (ws) addWhiteSpaceRecord(); parser_state = STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { parser_state = STATE_TEXT; } else { handleOtherTextChar2(ch); parser_state = STATE_TEXT; } } else parser_state = STATE_DOC_END; break; case STATE_ATTR_NAME : process_attr_name(); parser_state = STATE_ATTR_VAL; break; case STATE_ATTR_VAL : parser_state = process_attr_val(); break; case STATE_TEXT : if (depth == -1) throw new ParseException( "Error in text content: Char data at the wrong place" + formatLineNumber()); do { ch = r.getChar(); //System.out.println(""+(char)ch); if (XMLChar.isContentChar(ch)) { } else if (ch == '<') { break; }else handleOtherTextChar(ch); ch = r.getChar(); //System.out.println(""+(char)ch); if (XMLChar.isContentChar(ch)) { } else if (ch == '<') { break; }else handleOtherTextChar(ch); }while(true); length1 = offset - increment - temp_offset; if (singleByteEncoding) //if (encoding < FORMAT_UTF_16BE) writeVTDText( temp_offset, length1, TOKEN_CHARACTER_DATA, depth); else writeVTDText( temp_offset >> 1, length1 >> 1, TOKEN_CHARACTER_DATA, depth); //has_amp = true; parser_state = STATE_LT_SEEN; break; case STATE_DOC_START : parser_state = process_start_doc(); break; case STATE_DOC_END : //docEnd = true; parser_state = process_end_doc(); break; case STATE_PI_TAG : parser_state = process_pi_tag(); break; //throw new ParseException("Error in PI: Invalid char"); case STATE_PI_VAL : parser_state = process_pi_val(); break; case STATE_DEC_ATTR_NAME : parser_state = process_dec_attr(); break; case STATE_COMMENT : parser_state = process_comment(); break; case STATE_CDATA : parser_state = process_cdata(); break; case STATE_DOCTYPE : parser_state = process_doc_type(); break; case STATE_END_COMMENT : parser_state = process_end_comment(); break; case STATE_END_PI : parser_state = process_end_pi(); break; default : throw new ParseException( "Other error: invalid parser state" +formatLineNumber()); } } } catch (EOFException e) { if (parser_state != STATE_DOC_END) throw e; finishUp(); } } private void checkQualifiedAttributeUniqueness() throws ParseException { // TODO Auto-generated method stub int preLen1,os1,postLen1,URLLen1,URLOs1, preLen2, os2,postLen2, URLLen2, URLOs2,k; for (int i=0;i<prefixed_attr_count;i++){ preLen1 = (int)((prefixed_attr_name_array[i] & 0xffff0000L)>>16); postLen1 = (int) ((prefixed_attr_name_array[i] & 0xffffL))-preLen1-increment; os1 = (int) (prefixed_attr_name_array[i]>>32) + preLen1+increment; URLLen1 = nsBuffer2.lower32At(prefix_URL_array[i]); URLOs1 = nsBuffer2.upper32At(prefix_URL_array[i]); for (int j=i+1;j<prefixed_attr_count;j++){ // prefix of i matches that of j preLen2 = (int)((prefixed_attr_name_array[j] & 0xffff0000L)>>16); postLen2 = (int) ((prefixed_attr_name_array[j] & 0xffffL))-preLen2-increment; os2 = (int)(prefixed_attr_name_array[j]>>32) + preLen2 + increment; //System.out.println(new String(XMLDoc,os1, postLen1) // +" "+ new String(XMLDoc, os2, postLen2)); if (postLen1 == postLen2){ k=0; for (;k<postLen1;k++){ //System.out.println(i+" "+(char)(XMLDoc[os+k])+"<===>"+(char)(XMLDoc[preOs+k])); if (XMLDoc[os1+k]!=XMLDoc[os2+k]) break; } if (k==postLen1){ // found the match URLLen2 = nsBuffer2.lower32At(prefix_URL_array[j]); URLOs2 = nsBuffer2.upper32At(prefix_URL_array[j]); //System.out.println(" URLOs1 ===>" + URLOs1); //System.out.println("nsBuffer2 ===>"+nsBuffer2.longAt(i)+" i==>"+i); //System.out.println("URLLen2 "+ URLLen2+" URLLen1 "+ URLLen1+" "); if (matchURL(URLOs1, URLLen1, URLOs2, URLLen2)) throw new ParseException(" qualified attribute names collide " + formatLineNumber(os2)); } } } //System.out.println("======"); } } private void qualifyAttributes() throws ParseException{ int i1= nsBuffer3.size-1; int j= 0,i=0; // two cases: // 1. the current element has no prefix, look for xmlns // 2. the current element has prefix, look for xmlns:something while(j<prefixed_attr_count){ int preLen = (int)((prefixed_attr_name_array[j] & 0xffff0000L)>>16); int preOs = (int) (prefixed_attr_name_array[j]>>32); //System.out.println(new String(XMLDoc, preOs, preLen)+"==="); i = i1; while(i>=0){ int t = nsBuffer3.upper32At(i); // with prefix, get full length and prefix length if ( (t&0xffff) - (t>>16) == preLen+increment){ // doing byte comparison here int os = nsBuffer3.lower32At(i)+(t>>16)+increment; //System.out.println(new String(XMLDoc, os, preLen)+""); int k=0; for (;k<preLen;k++){ //System.out.println(i+" "+(char)(XMLDoc[os+k])+"<===>"+(char)(XMLDoc[preOs+k])); if (XMLDoc[os+k]!=XMLDoc[preOs+k]) break; } if (k==preLen){ break; // found the match } } /*if ( (nsBuffer3.upper32At(i) & 0xffff0000) == 0){ return; }*/ i--; } if (i<0) throw new ParseException("Name space qualification Exception: prefixed attribute not qualified\n" +formatLineNumber(preOs)); else prefix_URL_array[j] = i; j++; // no need to check if xml is the prefix } //for (int h=0;h<prefixed_attr_count;h++) // System.out.print(" "+prefix_URL_array[h]); //System.out.println(); // print line # column# and full element name //throw new ParseException("Name space qualification Exception: Element not qualified\n" // +formatLineNumber((int)pref)); } //return 0, 1 or 2 private int identifyNsURL(int byte_offset, int length) { // TODO Auto-generated method stub // URL points to "http://www.w3.org/XML/1998/namespace" return 1 // URL points to "http://www.w3.org/2000/xmlns/" return 2 String URL1 = "2000/xmlns/"; String URL2 = "http://www.w3.org/XML/1998/namespace"; long l; int i,t,g=byte_offset+length; int os=byte_offset; if (length <29 || (increment==2 && length<58) ) return 0; for (i=0; i<18 && os<g; i++){ l = _getCharResolved(os); //System.out.println("char ==>"+(char)l); if (URL2.charAt(i)!= (int)l) return 0; os += (int)(l>>32); } //store offset value t = os; for (i=0;i<11 && os<g;i++){ l = _getCharResolved(os); if (URL1.charAt(i)!= (int)l) break; os += (int)(l>>32); } if (os == g) return 2; //so far a match os = t; for (i=18;i<36 && os<g;i++){ l = _getCharResolved(os); if (URL2.charAt(i)!= (int)l) return 0; os += (int)(l>>32); } if (os==g) return 1; return 0; } private boolean matchXML(int byte_offset) { // TODO Auto-generated method stub if (encoding<FORMAT_UTF_16BE){ if (XMLDoc[byte_offset]=='x' && XMLDoc[byte_offset+1]=='m' && XMLDoc[byte_offset+2]=='l') return true; }else{ if (encoding==FORMAT_UTF_16LE){ if (XMLDoc[byte_offset]=='x' && XMLDoc[byte_offset+1]==0 && XMLDoc[byte_offset+2]=='m' && XMLDoc[byte_offset+3]==0 && XMLDoc[byte_offset+4]=='l' && XMLDoc[byte_offset+5]==0) return true; } else { if (XMLDoc[byte_offset]== 0 && XMLDoc[byte_offset+1]=='x' && XMLDoc[byte_offset+2]==0 && XMLDoc[byte_offset+3]=='m' && XMLDoc[byte_offset+4]==0 && XMLDoc[byte_offset+5]=='l') return true; } } return false; } private void disallow_xmlns(int byte_offset) throws ParseException{ // TODO Auto-generated method stub if (encoding<FORMAT_UTF_16BE){ if (XMLDoc[byte_offset]=='x' && XMLDoc[byte_offset+1]=='m' && XMLDoc[byte_offset+2]=='l' && XMLDoc[byte_offset+3]=='n' && XMLDoc[byte_offset+4]=='s') throw new ParseException( "xmlns as a ns prefix can't be re-declared" +formatLineNumber(byte_offset)); }else{ if (encoding==FORMAT_UTF_16LE){ if (XMLDoc[byte_offset]=='x' && XMLDoc[byte_offset+1]==0 && XMLDoc[byte_offset+2]=='m' && XMLDoc[byte_offset+3]==0 && XMLDoc[byte_offset+4]=='l' && XMLDoc[byte_offset+5]==0 && XMLDoc[byte_offset+6]=='n' && XMLDoc[byte_offset+7]==0 && XMLDoc[byte_offset+8]=='s' && XMLDoc[byte_offset+9]==0) throw new ParseException( "xmlns as a ns prefix can't be re-declared" +formatLineNumber(byte_offset)); } else { if (XMLDoc[byte_offset]== 0 && XMLDoc[byte_offset+1]=='x' && XMLDoc[byte_offset+2]==0 && XMLDoc[byte_offset+3]=='m' && XMLDoc[byte_offset+4]==0 && XMLDoc[byte_offset+5]=='l' && XMLDoc[byte_offset+6]==0 && XMLDoc[byte_offset+7]=='n' && XMLDoc[byte_offset+8]==0 && XMLDoc[byte_offset+9]=='s') throw new ParseException( "xmlns as a ns prefix can't be re-declared" +formatLineNumber(byte_offset)); } } } /** * This method parses the XML file and returns a boolean indicating * if it is successful or not.When set to true, * VTDGen conforms to XML namespace 1.0 spec * @param fileName * @param ns namespace aware or not * @return boolean indicating whether the parseFile is a success * */ public boolean parseFile(String fileName, boolean ns){ FileInputStream fis = null; File f = null; try{ f = new File(fileName); fis = new FileInputStream(f); byte[] b = new byte[(int) f.length()]; //fis.read(b); int offset = 0; int numRead = 0; int numOfBytes = 1048576;//I choose this value randomally, //any other (not too big) value also can be here. if (b.length-offset<numOfBytes) {numOfBytes=b.length-offset;} while (offset < b.length && (numRead=fis.read(b, offset, numOfBytes)) >= 0) { offset += numRead; if (b.length-offset<numOfBytes) {numOfBytes=b.length-offset;} } //fis.read(b); this.setDoc(b); this.parse(ns); // set namespace awareness to true return true; }catch(java.io.IOException e){ System.out.println("IOException: "+e); }catch (ParseException e){ System.out.println("ParserException: "+e); } finally{ if (fis!=null){ try{ fis.close(); }catch (Exception e){ } } } return false; } /** * This method inflates then parses GZIP'ed XML file and returns a boolean indicating * if it is successful or not.When set to true, * VTDGen conforms to XML namespace 1.0 spec * @param fileName * @param ns * @return */ public boolean parseGZIPFile(String GZIPfileName, boolean ns){ FileInputStream fis = null; //File f = null; try { fis = new FileInputStream(GZIPfileName); InputStream in = new GZIPInputStream(fis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] ba = new byte[65536]; int noRead; while ((noRead = in.read(ba)) != -1) { baos.write(ba, 0, noRead); } this.setDoc(baos.toByteArray()); this.parse(ns); return true; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (ParseException e){ System.out.println("ParserException: "+e); } finally{ if (fis!=null){ try{ fis.close(); }catch (Exception e){ } } } return false; } /** * This method inflates then parses ZIP'ed XML file and returns a boolean indicating * if it is successful or not.When set to true, * VTDGen conforms to XML namespace 1.0 spec * @param ZIPfileName * @param XMLName * @param ns * @return */ public boolean parseZIPFile(String ZIPfileName,String XMLName, boolean ns){ InputStream is = null; ZipFile zf = null; try { zf = new ZipFile(ZIPfileName); is = zf.getInputStream(zf.getEntry(XMLName)); //InputStream in = new ZipInputStream(fis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] ba = new byte[65536]; int noRead; while ((noRead = is.read(ba)) != -1) { baos.write(ba, 0, noRead); } this.setDoc(baos.toByteArray()); this.parse(ns); return true; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (ParseException e){ System.out.println("ParserException: "+e); } finally{ if (zf!=null){ try{ zf.close(); }catch (Exception e){ } } } return false; } /** * This method retrieves an XML document from the net using HTTP request * If the returned content type is "application xml" then it will proceed * with the parsing. Also notice that the content size can't be zero or * negative, it must be a positive integer matching the size of the * document * * no exception is thrown in the case of failure, this method will simply * return false * @param url * @return boolean (status of parsing the XML referenced by the HTTP request) * */ public boolean parseHttpUrl(String url,boolean ns){ URL url1 =null; InputStream in = null; HttpURLConnection urlConnection = null; try{ url1 = new URL(url); in = url1.openStream(); urlConnection = (HttpURLConnection)url1.openConnection(); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { int len = urlConnection.getContentLength(); if (len > 0) { //System.out.println("len ===> " + len + " " // + urlConnection.getContentType()); byte[] ba = new byte[len]; int k=len,offset=0; while(offset<len & k>0){ k=in.read(ba,offset,len-offset); offset+=k; } this.setDoc(ba); this.parse(ns); return true; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] ba = new byte[4096]; int k=-1; while((k=in.read(ba))>0){ baos.write(ba, 0, k); } this.setDoc(baos.toByteArray()); this.parse(ns); return true; //baos.w } } }catch(IOException e){ }catch(ParseException e){ }finally{ try { if (in != null) in.close(); if (urlConnection != null) urlConnection.disconnect(); } catch (Exception e) { } } return false; } //private /** * This private method processes CDATA section * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_cdata() throws ParseException, EncodingException, EOFException{ int parser_state; while (true) { ch = r.getChar(); if (XMLChar.isValidChar(ch)) { if (ch == ']' && r.skipChar(']')) { while (r.skipChar(']')); if (r.skipChar('>')) { break; } /*else throw new ParseException( "Error in CDATA: Invalid termination sequence" + formatLineNumber());*/ } } else throw new ParseException( "Error in CDATA: Invalid Char" + formatLineNumber()); } length1 = offset - temp_offset - (increment<<1) - increment; if (singleByteEncoding){//if (encoding < FORMAT_UTF_16BE){ writeVTDText( temp_offset, length1, TOKEN_CDATA_VAL, depth); } else { writeVTDText( temp_offset >> 1, length1 >> 1, TOKEN_CDATA_VAL, depth); } //System.out.println(" " + (temp_offset) + " " + length1 + " CDATA " + depth); temp_offset = offset; //ch = getCharAfterSe(); ch = getCharAfterS(); if (ch == '<') { if (ws) addWhiteSpaceRecord(); parser_state = STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { //temp_offset = offset-1; parser_state = STATE_TEXT; } else if (ch == '&') { //has_amp = true; //temp_offset = offset-1; entityIdentifier(); parser_state = STATE_TEXT; //temp_offset = offset; } else if (ch == ']') { //temp_offset = offset-1; if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } parser_state = STATE_TEXT; }else throw new ParseException( "Other Error: Invalid char in xml" + formatLineNumber()); return parser_state; } /** * This private method process comment * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_comment() throws ParseException, EncodingException, EOFException{ int parser_state; while (true) { ch = r.getChar(); if (XMLChar.isValidChar(ch)) { if (ch == '-' && r.skipChar('-')) { length1 = offset - temp_offset - (increment<<1); break; } } else throw new ParseException( "Error in comment: Invalid Char" + formatLineNumber()); } if (r.getChar() == '>') { //System.out.println(" " + (temp_offset) + " " + length1 + " comment " + depth); if (singleByteEncoding)//if (encoding < FORMAT_UTF_16BE) writeVTDText( temp_offset, length1, TOKEN_COMMENT, depth); else writeVTDText( temp_offset >> 1, length1 >> 1, TOKEN_COMMENT, depth); //length1 = 0; temp_offset = offset; //ch = getCharAfterSe(); ch = getCharAfterS(); if (ch == '<') { if (ws) addWhiteSpaceRecord(); parser_state = STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { //temp_offset = offset; parser_state = STATE_TEXT; } else if (ch == '&') { //has_amp = true; //temp_offset = offset; entityIdentifier(); parser_state = STATE_TEXT; } else if (ch == ']') { if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } parser_state = STATE_TEXT; }else throw new ParseException( "Error in text content: Invalid char" + formatLineNumber()); return parser_state; } else throw new ParseException( "Error in comment: Invalid terminating sequence" + formatLineNumber()); } /** * This private method processes declaration attributes * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_dec_attr() throws ParseException, EncodingException, EOFException{ int parser_state; if (ch == 'v' && r.skipChar('e') && r.skipChar('r') && r.skipChar('s') && r.skipChar('i') && r.skipChar('o') && r.skipChar('n')) { ch = getCharAfterS(); if (ch == '=') { /*System.out.println( " " + (temp_offset - 1) + " " + 7 + " dec attr name version " + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset - 1, 7, TOKEN_DEC_ATTR_NAME, depth); else _writeVTD( (temp_offset -2) >> 1, 7, TOKEN_DEC_ATTR_NAME, depth); } else throw new ParseException( "XML decl error: Invalid char" + formatLineNumber()); } else throw new ParseException( "XML decl error: should be version" + formatLineNumber()); ch_temp = getCharAfterS(); if (ch_temp != '\'' && ch_temp != '"') throw new ParseException( "XML decl error: Invalid char to start attr name" + formatLineNumber()); temp_offset = offset; // support 1.0 or 1.1 if (r.skipChar('1') && r.skipChar('.') && (r.skipChar('0') || r.skipChar('1'))) { /*System.out.println( " " + temp_offset + " " + 3 + " dec attr val (version)" + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset, 3, TOKEN_DEC_ATTR_VAL, depth); else _writeVTD( temp_offset >> 1, 3, TOKEN_DEC_ATTR_VAL, depth); } else throw new ParseException( "XML decl error: Invalid version(other than 1.0 or 1.1) detected" + formatLineNumber()); if (!r.skipChar(ch_temp)) throw new ParseException( "XML decl error: version not terminated properly" + formatLineNumber()); ch = r.getChar(); //? space or e if (XMLChar.isSpaceChar(ch)) { ch = getCharAfterS(); temp_offset = offset - increment; if (ch == 'e') { if (r.skipChar('n') && r.skipChar('c') && r.skipChar('o') && r.skipChar('d') && r.skipChar('i') && r.skipChar('n') && r.skipChar('g')) { ch = r.getChar(); if (XMLChar.isSpaceChar(ch)) ch = getCharAfterS(); if (ch == '=') { /*System.out.println( " " + (temp_offset) + " " + 8 + " dec attr name (encoding) " + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset, 8, TOKEN_DEC_ATTR_NAME, depth); else _writeVTD( temp_offset >> 1, 8, TOKEN_DEC_ATTR_NAME, depth); } else throw new ParseException( "XML decl error: Invalid char" + formatLineNumber()); ch_temp = getCharAfterS(); if (ch_temp != '"' && ch_temp != '\'') throw new ParseException( "XML decl error: Invalid char to start attr name" + formatLineNumber()); temp_offset = offset; ch = r.getChar(); switch (ch) { case 'a' : case 'A' : if ((r.skipChar('s') || r.skipChar('S')) && (r.skipChar('c') || r.skipChar('C')) && (r.skipChar('i') || r.skipChar('I')) && (r.skipChar('i') || r.skipChar('I')) && r.skipChar(ch_temp)) { if (encoding != FORMAT_UTF_16LE && encoding != FORMAT_UTF_16BE) { if (must_utf_8) throw new EncodingException("Can't switch from UTF-8" + formatLineNumber()); encoding = FORMAT_ASCII; r = new ASCIIReader(); /*System.out.println( " " + (temp_offset) + " " + 5 + " dec attr val (encoding) " + depth);*/ _writeVTD( temp_offset, 5, TOKEN_DEC_ATTR_VAL, depth); break; } else throw new ParseException( "XML decl error: Can't switch encoding to ASCII" + formatLineNumber()); } throw new ParseException( "XML decl error: Invalid Encoding" + formatLineNumber()); case 'c': case 'C': matchCPEncoding(); break; case 'i' : case 'I' : matchISOEncoding(); break; case 'u' : case 'U' : matchUTFEncoding(); break; // now deal with windows encoding case 'w' : case 'W' : matchWindowsEncoding(); break; default : throw new ParseException( "XML decl Error: invalid encoding" + formatLineNumber()); } ch = r.getChar(); if (XMLChar.isSpaceChar(ch)) ch = getCharAfterS(); temp_offset = offset - increment; } else throw new ParseException( "XML decl Error: Invalid char" + formatLineNumber()); } if (ch == 's') { if (r.skipChar('t') && r.skipChar('a') && r.skipChar('n') && r.skipChar('d') && r.skipChar('a') && r.skipChar('l') && r.skipChar('o') && r.skipChar('n') && r.skipChar('e')) { ch = getCharAfterS(); if (ch != '=') throw new ParseException( "XML decl error: Invalid char" + formatLineNumber()); /*System.out.println( " " + temp_offset + " " + 3 + " dec attr name (standalone) " + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset, 10, TOKEN_DEC_ATTR_NAME, depth); else _writeVTD( temp_offset >> 1, 10, TOKEN_DEC_ATTR_NAME, depth); ch_temp = getCharAfterS(); temp_offset = offset; if (ch_temp != '"' && ch_temp != '\'') throw new ParseException( "XML decl error: Invalid char to start attr name" + formatLineNumber()); ch = r.getChar(); if (ch == 'y') { if (r.skipChar('e') && r.skipChar('s') && r.skipChar(ch_temp)) { /*System.out.println( " " + (temp_offset) + " " + 3 + " dec attr val (standalone) " + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset, 3, TOKEN_DEC_ATTR_VAL, depth); else _writeVTD( temp_offset >> 1, 3, TOKEN_DEC_ATTR_VAL, depth); } else throw new ParseException( "XML decl error: invalid val for standalone" + formatLineNumber()); } else if (ch == 'n') { if (r.skipChar('o') && r.skipChar(ch_temp)) { /*System.out.println( " " + (temp_offset) + " " + 2 + " dec attr val (standalone)" + depth);*/ if (singleByteEncoding) _writeVTD( temp_offset, 2, TOKEN_DEC_ATTR_VAL, depth); else _writeVTD( temp_offset >> 1, 2, TOKEN_DEC_ATTR_VAL, depth); } else throw new ParseException( "XML decl error: invalid val for standalone" + formatLineNumber()); } else throw new ParseException( "XML decl error: invalid val for standalone" + formatLineNumber()); } else throw new ParseException( "XML decl error" + formatLineNumber()); ch = r.getChar(); if (XMLChar.isSpaceChar(ch)) ch = getCharAfterS(); } } if (ch == '?' && r.skipChar('>')) { temp_offset = offset; ch = getCharAfterS(); if (ch == '<') { parser_state = STATE_LT_SEEN; } else throw new ParseException( "Other Error: Invalid Char in XML" + formatLineNumber()); } else throw new ParseException( "XML decl Error: Invalid termination sequence" + formatLineNumber()); return parser_state; } /** * This private method process DTD * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_doc_type() throws ParseException,EncodingException, EOFException{ int z = 1,parser_state; while (true) { ch = r.getChar(); if (XMLChar.isValidChar(ch)) { if (ch == '>') z--; else if (ch == '<') z++; if (z == 0) break; } else throw new ParseException( "Error in DOCTYPE: Invalid char" + formatLineNumber()); } length1 = offset - temp_offset - increment; /*System.out.println( " " + (temp_offset) + " " + length1 + " DOCTYPE val " + depth);*/ if (singleByteEncoding){//if (encoding < FORMAT_UTF_16BE){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" +" DTD val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset, length1, TOKEN_DTD_VAL, depth); } else{ if (length1 > (MAX_TOKEN_LENGTH<<1)) throw new ParseException("Token Length Error:" +" DTD val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset >> 1, length1 >> 1, TOKEN_DTD_VAL, depth); } ch = getCharAfterS(); if (ch == '<') { parser_state = STATE_LT_SEEN; } else throw new ParseException( "Other Error: Invalid char in xml" + formatLineNumber()); return parser_state; } /** * This private method process the comment after the root document * @return the parser state after which the parser loop jumps to * @throws ParseException */ private int process_end_comment()throws ParseException { int parser_state; while (true) { ch = r.getChar(); if (XMLChar.isValidChar(ch)) { if (ch == '-' && r.skipChar('-')) { length1 = offset - temp_offset - (increment<<1); break; } } else throw new ParseException( "Error in comment: Invalid Char" + formatLineNumber()); } if (r.getChar() == '>') { //System.out.println(" " + temp_offset + " " + length1 + " comment " + depth); if (singleByteEncoding) //if (encoding < FORMAT_UTF_16BE) writeVTDText( temp_offset, length1, TOKEN_COMMENT, depth); else writeVTDText( temp_offset >> 1, length1 >> 1, TOKEN_COMMENT, depth); parser_state = STATE_DOC_END; return parser_state; } throw new ParseException( "Error in comment: '-->' expected" + formatLineNumber()); } private int process_end_doc() throws ParseException, EncodingException, EOFException { int parser_state; ch = getCharAfterS(); /* eof exception should be thrown here for premature ending*/ if (ch == '<') { if (r.skipChar('?')) { /* processing instruction after end tag of root element*/ temp_offset = offset; parser_state = STATE_END_PI; return parser_state; } else if ( r.skipChar('!') && r.skipChar('-') && r.skipChar('-')) { // comments allowed after the end tag of the root element temp_offset = offset; parser_state = STATE_END_COMMENT; return parser_state; } } throw new ParseException( "Other Error: XML not terminated properly" + formatLineNumber()); } /** * This private method processes PI after root document * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_end_pi() throws ParseException,EncodingException, EOFException{ int parser_state; ch = r.getChar(); if (XMLChar.isNameStartChar(ch)) { if ((ch == 'x' || ch == 'X') && (r.skipChar('m') || r.skipChar('M')) && (r.skipChar('l') && r.skipChar('L'))) { //temp_offset = offset; ch = r.getChar(); if (XMLChar.isSpaceChar(ch) || ch == '?') throw new ParseException( "Error in PI: [xX][mM][lL] not a valid PI target" + formatLineNumber()); //offset = temp_offset; } while (true) { //ch = getChar(); if (!XMLChar.isNameChar(ch)) { break; } ch = r.getChar(); } length1 = offset - temp_offset - increment; /*System.out.println( "" + (char) XMLDoc[temp_offset] + " " + (temp_offset) + " " + length1 + " PI Target " + depth);*/ if (singleByteEncoding){//if (encoding < FORMAT_UTF_16BE){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" +"PI name too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset, length1, TOKEN_PI_NAME, depth); } else{ if (length1 > (MAX_TOKEN_LENGTH<<1)) throw new ParseException("Token Length Error:" +"PI name too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset >> 1, length1 >> 1, TOKEN_PI_NAME, depth); } //length1 = 0; temp_offset = offset; if (XMLChar.isSpaceChar(ch)) { ch = getCharAfterS(); while (true) { if (XMLChar.isValidChar(ch)) { if (ch == '?'){ if (r.skipChar('>')) { parser_state = STATE_DOC_END; break; } else throw new ParseException( "Error in PI: invalid termination sequence" + formatLineNumber()); } } else throw new ParseException( "Error in PI: Invalid char in PI val" + formatLineNumber()); ch = r.getChar(); } length1 = offset - temp_offset - (increment<<1); if (singleByteEncoding){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" +"PI val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset, length1, TOKEN_PI_VAL, depth); } else{ if (length1 > (MAX_TOKEN_LENGTH<<1)) throw new ParseException("Token Length Error:" +"PI val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset >> 1, length1 >> 1, TOKEN_PI_VAL, depth); } //System.out.println(" " + temp_offset + " " + length1 + " PI val " + depth); } else { if (singleByteEncoding){ _writeVTD( (temp_offset), 0, TOKEN_PI_VAL, depth); } else{ _writeVTD( (temp_offset) >> 1, 0, TOKEN_PI_VAL, depth); } if ((ch == '?') && r.skipChar('>')) { parser_state = STATE_DOC_END; } else throw new ParseException( "Error in PI: invalid termination sequence" + formatLineNumber()); } //parser_state = STATE_DOC_END; } else throw new ParseException("Error in PI: invalid char in PI target" +formatLineNumber()); return parser_state; } private int process_ex_seen()throws ParseException, EncodingException, EOFException { int parser_state; boolean hasDTD = false; ch = r.getChar(); switch (ch) { case '-' : if (r.skipChar('-')) { temp_offset = offset; parser_state = STATE_COMMENT; break; } else throw new ParseException( "Error in comment: Invalid char sequence to start a comment" + formatLineNumber()); case '[' : if (r.skipChar('C') && r.skipChar('D') && r.skipChar('A') && r.skipChar('T') && r.skipChar('A') && r.skipChar('[') && (depth != -1)) { temp_offset = offset; parser_state = STATE_CDATA; break; } else { if (depth == -1) throw new ParseException( "Error in CDATA: Wrong place for CDATA" + formatLineNumber()); throw new ParseException( "Error in CDATA: Invalid char sequence for CDATA" + formatLineNumber()); } case 'D' : if (r.skipChar('O') && r.skipChar('C') && r.skipChar('T') && r.skipChar('Y') && r.skipChar('P') && r.skipChar('E') && (depth == -1) && !hasDTD) { hasDTD = true; temp_offset = offset; parser_state = STATE_DOCTYPE; break; } else { if (hasDTD == true) throw new ParseException( "Error for DOCTYPE: Only DOCTYPE allowed" + formatLineNumber()); if (depth != -1) throw new ParseException( "Error for DOCTYPE: DTD at wrong place" + formatLineNumber()); throw new ParseException( "Error for DOCTYPE: Invalid char sequence for DOCTYPE" + formatLineNumber()); } default : throw new ParseException( "Other Error: Unrecognized char after <!" + formatLineNumber()); } return parser_state; } private void process_attr_name ()throws ParseException, EncodingException, EOFException{ //parser_state = process_attr_name(); String s1=null,s2=null; if (ch == 'x') { if (r.skipChar('m') && r.skipChar('l') && r.skipChar('n') && r.skipChar('s')) { ch = r.getChar(); if (ch == '=' || XMLChar.isSpaceChar(ch)){ default_ns = true; is_ns= true; }else if( ch == ':') { default_ns = false; is_ns= true; } } } do { if (XMLChar.isNameChar(ch)) { if (ch == ':') { length2 = offset - temp_offset - increment; } } else break; ch = r.getChar(); }while (true); length1 = getPrevOffset() - temp_offset; if (is_ns && ns){ // make sure postfix isn't xmlns if (!default_ns){ if (increment==1 && (length1-length2 == 6) || (increment==2 && (length1-length2==12))) disallow_xmlns(temp_offset+length2+increment); // if the post fix is xml, signal it if (increment==1 && (length1-length2== 4) || (increment==2 && (length1-length2==8))) isXML = matchXML(temp_offset+length2+increment); } } // check for uniqueness here checkAttributeUniqueness(); // after checking, write VTD if (is_ns) { //if the prefix is xmlns: or xmlns //if (encoding < FORMAT_UTF_16BE){ s1 = "Token length overflow error: Attr NS tag prefix or qname length too long"; s2 = "Token length overflow error: Attr NS prefix or qname length too long"; if (singleByteEncoding){ if (length2>MAX_PREFIX_LENGTH || length1 > MAX_QNAME_LENGTH) throw new ParseException( s1 +formatLineNumber()); _writeVTD( temp_offset, (length2 << 11) | length1, TOKEN_ATTR_NS, depth); } else{ if (length2>(MAX_PREFIX_LENGTH << 1) || length1 > (MAX_QNAME_LENGTH <<1)) throw new ParseException( s2 + formatLineNumber()); _writeVTD( temp_offset >> 1, (length2 << 10) | (length1 >> 1), TOKEN_ATTR_NS, depth); } // append to nsBuffer2 if (ns) { //unprefixed xmlns are not recorded if (length2 != 0 && !isXML) { //nsBuffer2.append(VTDBuffer.size() - 1); long l = ((long) ((length2 << 16) | length1)) << 32 | temp_offset; nsBuffer3.append(l); // byte offset and byte // length } } } else { //if (encoding < FORMAT_UTF_16BE){ s1="Token Length Error: Attr name prefix or qname length too long"; s2="Token Length overflow error: Attr name prefix or qname length too long" ; if (singleByteEncoding) { if (length2>MAX_PREFIX_LENGTH || length1 > MAX_QNAME_LENGTH) throw new ParseException( "Token Length Error: Attr name prefix or qname length too long" + formatLineNumber()); _writeVTD( temp_offset, (length2 << 11) | length1, TOKEN_ATTR_NAME, depth); } else{ if (length2>(MAX_PREFIX_LENGTH<<1) || length1 > (MAX_QNAME_LENGTH<<1)) throw new ParseException( "Token Length overflow error: Attr name prefix or qname length too long" + formatLineNumber()); _writeVTD( temp_offset >> 1, (length2 << 10) | (length1 >> 1), TOKEN_ATTR_NAME, depth); } } /*System.out.println( " " + temp_offset + " " + length2 + ":" + length1 + " attr name " + depth);*/ length2 = 0; if (XMLChar.isSpaceChar(ch)) { ch = getCharAfterS(); } if (ch != '=') throw new ParseException( "Error in attr: invalid char" + formatLineNumber()); ch_temp = getCharAfterS(); if (ch_temp != '"' && ch_temp != '\'') throw new ParseException( "Error in attr: invalid char (should be ' or \" )" + formatLineNumber()); temp_offset = offset; } private int process_attr_val()throws ParseException, EncodingException, EOFException{ //int parser_state; do{ ch = r.getChar(); if (XMLChar.isValidChar(ch) && ch != '<') { if (ch == ch_temp) break; if (ch == '&') { // as in vtd spec, we mark attr val with entities if (!XMLChar .isValidChar(entityIdentifier())) { throw new ParseException( "Error in attr: Invalid XML char" + formatLineNumber()); } } } else throw new ParseException( "Error in attr: Invalid XML char" + formatLineNumber()); }while (true); length1 = offset - temp_offset - increment; if (ns && is_ns){ if (!default_ns && length1==0){ throw new ParseException(" non-default ns URL can't be empty" +formatLineNumber()); } //identify nsURL return 0,1,2 int t= identifyNsURL(temp_offset, length1); if (isXML){//xmlns:xml if (t!=1) //URL points to "http://www.w3.org/XML/1998/namespace" throw new ParseException("xmlns:xml can only point to" +"\"http://www.w3.org/XML/1998/namespace\"" + formatLineNumber()); } else { if (!default_ns) nsBuffer2.append(((long)temp_offset<<32) | length1); if (t!=0){ if (t==1) throw new ParseException("namespace declaration can't point to" +" \"http://www.w3.org/XML/1998/namespace\"" + formatLineNumber()); throw new ParseException("namespace declaration can't point to" +" \"http://www.w3.org/2000/xmlns/\"" + formatLineNumber()); } } // no ns URL points to //"http://www.w3.org/2000/xmlns/" // no ns URL points to //"http://www.w3.org/XML/1998/namespace" } if (singleByteEncoding){ //if (encoding < FORMAT_UTF_16BE){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" +" Attr val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset, length1, TOKEN_ATTR_VAL, depth); } else{ if (length1 > (MAX_TOKEN_LENGTH <<1)) throw new ParseException("Token Length Error:" +" Attr val too long (>0xfffff)" + formatLineNumber()); _writeVTD( temp_offset >> 1, length1 >> 1, TOKEN_ATTR_VAL, depth); } isXML = false; is_ns = false; ch = r.getChar(); if (XMLChar.isSpaceChar(ch)) { ch = getCharAfterS(); if (XMLChar.isNameStartChar(ch)) { temp_offset = offset - increment; return STATE_ATTR_NAME; //break; } } helper = true; if (ch == '/') { depth--; helper = false; ch = r.getChar(); } if (ch == '>') { if (ns){ nsBuffer1.append(nsBuffer3.size-1); if (prefixed_attr_count>0) qualifyAttributes(); if (prefixed_attr_count>1){ checkQualifiedAttributeUniqueness(); } if (currentElementRecord !=0) qualifyElement(); prefixed_attr_count=0; } attr_count = 0; return processElementTail(helper); } throw new ParseException( "Starting tag Error: Invalid char in starting tag" + formatLineNumber()); } /** * This private method processes PI tag * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_pi_tag() throws ParseException, EncodingException, EOFException{ int parser_state; while (true) { ch = r.getChar(); if (!XMLChar.isNameChar(ch)) break; //System.out.println(" ch ==> "+(char)ch); } length1 = offset - temp_offset - increment; /*System.out.println( ((char) XMLDoc[temp_offset]) + " " + (temp_offset) + " " + length1 + " PI Target " + depth); */ //if (encoding < FORMAT_UTF_16BE){ if (singleByteEncoding){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" +" PI name too long (>0xfffff)" + formatLineNumber()); _writeVTD( (temp_offset), length1, TOKEN_PI_NAME, depth); } else{ if(length1 > (MAX_TOKEN_LENGTH<<1)) throw new ParseException("Token Length Error:" +" PI name too long (>0xfffff)" + formatLineNumber()); _writeVTD( (temp_offset) >> 1, (length1 >> 1), TOKEN_PI_NAME, depth); } //length1 = 0; //temp_offset = offset; /*if (XMLChar.isSpaceChar(ch)) { ch = r.getChar(); }*/ //ch = r.getChar(); if (ch == '?') { // insert zero length pi name tag if (singleByteEncoding){ _writeVTD( (temp_offset), 0, TOKEN_PI_VAL, depth); } else{ _writeVTD( (temp_offset) >> 1, (0), TOKEN_PI_VAL, depth); } if (r.skipChar('>')) { temp_offset = offset; //ch = getCharAfterSe(); ch = getCharAfterS(); if (ch == '<') { if (ws) addWhiteSpaceRecord(); parser_state = STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { parser_state = STATE_TEXT; } else if (ch == '&') { //has_amp = true; entityIdentifier(); parser_state = STATE_TEXT; } else if (ch == ']') { if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } parser_state = STATE_TEXT; }else throw new ParseException( "Error in text content: Invalid char" + formatLineNumber()); return parser_state; } else throw new ParseException( "Error in PI: invalid termination sequence" + formatLineNumber()); } parser_state = STATE_PI_VAL; return parser_state; } /** * This private method processes PI val * @return the parser state after which the parser loop jumps to * @throws ParseException * @throws EncodingException * @throws EOFException */ private int process_pi_val() throws ParseException, EncodingException, EOFException{ int parser_state; if (!XMLChar.isSpaceChar(ch)) throw new ParseException( "Error in PI: invalid termination sequence" + formatLineNumber()); temp_offset = offset; ch = r.getChar(); while (true) { if (XMLChar.isValidChar(ch)) { //System.out.println(""+(char)ch); if (ch == '?') if (r.skipChar('>')) { break; } /*else throw new ParseException( "Error in PI: invalid termination sequence for PI" + formatLineNumber());*/ } else throw new ParseException( "Errors in PI: Invalid char in PI val" + formatLineNumber()); ch = r.getChar(); } length1 = offset - temp_offset - (increment<<1); /*System.out.println( ((char) XMLDoc[temp_offset]) + " " + (temp_offset) + " " + length1 + " PI val " + depth);*/ //if (length1 != 0) if (singleByteEncoding) {// if (encoding < FORMAT_UTF_16BE){ if (length1 > MAX_TOKEN_LENGTH) throw new ParseException("Token Length Error:" + "PI VAL too long (>0xfffff)" + formatLineNumber()); _writeVTD(temp_offset, length1, TOKEN_PI_VAL, depth); } else { if (length1 > (MAX_TOKEN_LENGTH << 1)) throw new ParseException("Token Length Error:" + "PI VAL too long (>0xfffff)" + formatLineNumber()); _writeVTD(temp_offset >> 1, length1 >> 1, TOKEN_PI_VAL, depth); } //length1 = 0; temp_offset = offset; //ch = getCharAfterSe(); ch = getCharAfterS(); if (ch == '<') { if (ws) addWhiteSpaceRecord(); parser_state = STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { //temp_offset = offset; parser_state = STATE_TEXT; } else if (ch == '&') { //has_amp = true; //temp_offset = offset; entityIdentifier(); parser_state = STATE_TEXT; } else if (ch == ']') { if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } parser_state = STATE_TEXT; }else throw new ParseException( "Error in text content: Invalid char" + formatLineNumber()); return parser_state; } private int process_qm_seen()throws ParseException, EncodingException, EOFException { temp_offset = offset; ch = r.getChar(); if (XMLChar.isNameStartChar(ch)) { //temp_offset = offset; if ((ch == 'x' || ch == 'X') && (r.skipChar('m') || r.skipChar('M')) && (r.skipChar('l') || r.skipChar('L'))) { ch = r.getChar(); if (ch == '?' || XMLChar.isSpaceChar(ch)) throw new ParseException( "Error in PI: [xX][mM][lL] not a valid PI targetname" + formatLineNumber()); offset = getPrevOffset(); } return STATE_PI_TAG; } throw new ParseException( "Other Error: First char after <? invalid" + formatLineNumber()); } private int process_start_doc()throws ParseException, EncodingException, EOFException { int c = r.getChar(); if (c == '<') { temp_offset = offset; // xml decl has to be right after the start of the document if (r.skipChar('?') && (r.skipChar('x') || r.skipChar('X')) && (r.skipChar('m') || r.skipChar('M')) && (r.skipChar('l') || r.skipChar('L'))) { if (r.skipChar(' ') || r.skipChar('\t') || r.skipChar('\n') || r.skipChar('\r')) { ch = getCharAfterS(); temp_offset = offset; return STATE_DEC_ATTR_NAME; } else if (r.skipChar('?')) throw new ParseException( "Error in XML decl: Premature ending" + formatLineNumber()); } offset = temp_offset; return STATE_LT_SEEN; } else if (c==' '||c=='\n'||c=='\r'||c=='\t'){ if (getCharAfterS()=='<'){ return STATE_LT_SEEN; } } throw new ParseException( "Other Error: XML not starting properly" + formatLineNumber()); } /** * Set the XMLDoc container. * @param ba byte[] */ public void setDoc(byte[] ba) { setDoc(ba,0,ba.length); } /** * Set the XMLDoc container. Also set the offset and len of the document * with respect to the container. * @param ba byte[] * @param os int (in byte) * @param len int (in byte) */ public void setDoc(byte[] ba, int os, int len) { if (ba == null || os < 0 || len == 0 || ba.length < os + len) { throw new IllegalArgumentException("Illegal argument for setDoc"); } int a; br = false; depth = -1; increment = 1; BOM_detected = false; must_utf_8 = false; ch = ch_temp = 0; temp_offset = 0; XMLDoc = ba; docOffset = offset = os; docLen = len; endOffset = os + len; last_l1_index = last_l2_index = last_l3_index = last_l4_index = last_depth = 0; currentElementRecord = 0; nsBuffer1.size = 0; nsBuffer2.size = 0; nsBuffer3.size = 0; r = new UTF8Reader(); if (shallowDepth) { int i1 = 8, i2 = 9, i3 = 11; if (docLen <= 1024) { // a = 1024; //set the floor a = 6; i1 = 5; i2 = 5; i3 = 5; } else if (docLen <= 4096) { a = 7; i1 = 6; i2 = 6; i3 = 6; } else if (docLen <= 1024 * 16) { a = 8; i1 = 7; i2 = 7; i3 = 7; } else if (docLen <= 1024 * 16 * 4) { // a = 2048; a = 11; } else if (docLen <= 1024 * 256) { // a = 1024 * 4; a = 12; } else { // a = 1 << 15; a = 15; } VTDBuffer = new FastLongBuffer(a, len >> (a + 1)); l1Buffer = new FastLongBuffer(i1); l2Buffer = new FastLongBuffer(i2); l3Buffer = new FastIntBuffer(i3); } else { int i1 = 7, i2 = 9, i3 = 11, i4 = 11, i5 = 11; if (docLen <= 1024) { // a = 1024; //set the floor a = 6; i1 = 5; i2 = 5; i3 = 5; i4 = 5; i5 = 5; } else if (docLen <= 4096) { a = 7; i1 = 6; i2 = 6; i3 = 6; i4 = 6; i5 = 6; } else if (docLen <= 1024 * 16) { a = 8; i1 = 7; i2 = 7; i3 = 7; i4 = 7; i5 = 7; } else if (docLen <= 1024 * 16 * 4) { // a = 2048; a = 11; i2 = 8; i3 = 8; i4 = 8; i5 = 8; } else if (docLen <= 1024 * 256) { // a = 1024 * 4; a = 12; i1 = 8; i2 = 9; i3 = 9; i4 = 9; i5 = 9; } else { // a = 1 << 15; a = 15; } VTDBuffer = new FastLongBuffer(a, len >> (a + 1)); l1Buffer = new FastLongBuffer(i1); l2Buffer = new FastLongBuffer(i2); _l3Buffer = new FastLongBuffer(i3); _l4Buffer = new FastLongBuffer(i4); _l5Buffer = new FastIntBuffer(i5); } } /** * The buffer-reuse version of setDoc * The concept is to reuse LC and VTD buffer for * XML parsing, instead of allocating every time * @param ba * */ public void setDoc_BR(byte[] ba){ setDoc_BR(ba,0,ba.length); } /** * The buffer-reuse version of setDoc * The concept is to reuse LC and VTD buffer for * XML parsing, instead of allocating every time * @param ba byte[] * @param os int (in byte) * @param len int (in byte) * */ public void setDoc_BR(byte[] ba, int os, int len) { if (ba == null || os < 0 || len == 0 || ba.length < os + len) { throw new IllegalArgumentException("Illegal argument for setDoc_BR"); } int a; br = true; depth = -1; increment = 1; BOM_detected = false; must_utf_8 = false; ch = ch_temp = 0; temp_offset = 0; XMLDoc = ba; docOffset = offset = os; docLen = len; endOffset = os + len; last_l1_index = last_l2_index = last_depth = last_l3_index = last_l4_index= 0; currentElementRecord = 0; nsBuffer1.size = 0; nsBuffer2.size = 0; nsBuffer3.size = 0; r = new UTF8Reader(); if (shallowDepth) { int i1 = 8, i2 = 9, i3 = 11; if (docLen <= 1024) { // a = 1024; //set the floor a = 6; i1 = 5; i2 = 5; i3 = 5; } else if (docLen <= 4096) { a = 7; i1 = 6; i2 = 6; i3 = 6; } else if (docLen <= 1024 * 16) { a = 8; i1 = 7; i2 = 7; i3 = 7; } else if (docLen <= 1024 * 16 * 4) { // a = 2048; a = 11; i2 = 8; i3 = 8; } else if (docLen <= 1024 * 256) { // a = 1024 * 4; a = 12; } else { // a = 1 << 15; a = 15; } if (VTDBuffer == null) { VTDBuffer = new FastLongBuffer(a, len >> (a + 1)); l1Buffer = new FastLongBuffer(i1); l2Buffer = new FastLongBuffer(i2); l3Buffer = new FastIntBuffer(i3); } else { VTDBuffer.size = 0; l1Buffer.size = 0; l2Buffer.size = 0; l3Buffer.size = 0; } } else { int i1 = 8, i2 = 9, i3 = 11, i4 = 11, i5 = 11; if (docLen <= 1024) { // a = 1024; //set the floor a = 6; i1 = 5; i2 = 5; i3 = 5; i4 = 5; i5 = 5; } else if (docLen <= 4096) { a = 7; i1 = 6; i2 = 6; i3 = 6; i4 = 6; i5 = 6; } else if (docLen <= 1024 * 16) { a = 8; i1 = 7; i2 = 7; i3 = 7; } else if (docLen <= 1024 * 16 * 4) { // a = 2048; a = 11; i2 = 8; i3 = 8; i4 = 8; i5 = 8; } else if (docLen <= 1024 * 256) { // a = 1024 * 4; a = 12; i1 = 8; i2 = 9; i3 = 9; i4 = 9; i5 = 9; } else if (docLen <= 1024 * 1024) { // a = 1024 * 4; a = 12; i1 = 8; i3 = 10; i4 = 10; i5 = 10; } else { // a = 1 << 15; a = 15; i1 = 8; } if (VTDBuffer == null) { VTDBuffer = new FastLongBuffer(a, len >> (a + 1)); l1Buffer = new FastLongBuffer(i1); l2Buffer = new FastLongBuffer(i2); _l3Buffer = new FastLongBuffer(i3); _l4Buffer = new FastLongBuffer(i4); _l5Buffer = new FastIntBuffer(i5); } else { VTDBuffer.size = 0; l1Buffer.size = 0; l2Buffer.size = 0; _l3Buffer.size = 0; _l4Buffer.size = 0; _l5Buffer.size = 0; } } } /** * This method writes the VTD+XML into an outputStream * @param os * @throws IOException * @throws IndexWriteException * */ public void writeIndex(OutputStream os) throws IOException,IndexWriteException{ if (shallowDepth) IndexHandler.writeIndex_L3((byte)1, this.encoding, this.ns, true, this.VTDDepth, 3, this.rootIndex, this.XMLDoc, this.docOffset, this.docLen, this.VTDBuffer, this.l1Buffer, this.l2Buffer, this.l3Buffer, os); else IndexHandler.writeIndex_L5((byte)1, this.encoding, this.ns, true, this.VTDDepth, 5, this.rootIndex, this.XMLDoc, this.docOffset, this.docLen, this.VTDBuffer, this.l1Buffer, this.l2Buffer, this._l3Buffer, this._l4Buffer, this._l5Buffer, os); } /** * This method writes the VTDs and LCs into an outputStream * @param os * @throws IOException * @throws IndexWriteException * */ public void writeSeparateIndex(OutputStream os) throws IOException,IndexWriteException{ if (shallowDepth) IndexHandler.writeSeparateIndex_L3((byte)2, this.encoding, this.ns, true, this.VTDDepth, 3, this.rootIndex, //this.XMLDoc, this.docOffset, this.docLen, this.VTDBuffer, this.l1Buffer, this.l2Buffer, this.l3Buffer, os); else IndexHandler.writeSeparateIndex_L5((byte)2, this.encoding, this.ns, true, this.VTDDepth, 5, this.rootIndex, //this.XMLDoc, this.docOffset, this.docLen, this.VTDBuffer, this.l1Buffer, this.l2Buffer, this._l3Buffer, this._l4Buffer, this._l5Buffer, os); } /** * This method writes the VTD+XML file into a file of the given name * @param fileName * @throws IOException * @throws IndexWriteException * */ public void writeIndex(String fileName) throws IOException,IndexWriteException{ FileOutputStream fos = new FileOutputStream(fileName); writeIndex(fos); fos.close(); } /** * This method writes the VTDs and LCs into a file of the given name * XML is not part of the index * please refer to VTD-XML web site for the spec and explanation * @param fileName * @throws IOException * @throws IndexWriteException * */ public void writeSeparateIndex(String fileName) throws IOException,IndexWriteException{ FileOutputStream fos = new FileOutputStream(fileName); writeSeparateIndex(fos); fos.close(); } /** * Write the VTD and LC into their storage container for where LC depth is 5. * @param offset int * @param length int * @param token_type int * @param depth int */ private void writeVTD(int offset, int length, int token_type, int depth) { VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | length) << 32) | offset); switch (depth) { case 0: rootIndex = VTDBuffer.size - 1; break; case 1: if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) | 0xffffffffL); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } last_l1_index = VTDBuffer.size - 1; last_depth = 1; break; case 2: if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) + l2Buffer.size); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } last_l2_index = VTDBuffer.size - 1; last_depth = 2; break; case 3: l3Buffer.append(VTDBuffer.size - 1); if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) + l3Buffer.size - 1); } last_depth = 3; break; default: //rootIndex = VTDBuffer.size() - 1; } } private void _writeVTD(int offset, int length, int token_type, int depth) { VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | length) << 32) | offset); } private void writeVTDText(int offset, int length, int token_type, int depth) { if (length > MAX_TOKEN_LENGTH) { int k; int r_offset = offset; for (k = length; k > MAX_TOKEN_LENGTH; k = k - MAX_TOKEN_LENGTH) { VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | MAX_TOKEN_LENGTH) << 32) | r_offset); r_offset += MAX_TOKEN_LENGTH; } VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | k) << 32) | r_offset); } else { VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | length) << 32) | offset); } } /** * Write the VTD and LC into their storage container. * @param offset int * @param length int * @param token_type int * @param depth int */ private void writeVTD_L5(int offset, int length, int token_type, int depth) { VTDBuffer.append(((long) ((token_type << 28) | ((depth & 0xff) << 20) | length) << 32) | offset); switch (depth) { case 0: rootIndex = VTDBuffer.size - 1; break; case 1: if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) | 0xffffffffL); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } else if (last_depth ==3) { _l3Buffer.append(((long) last_l3_index << 32) | 0xffffffffL); } else if (last_depth ==4){ _l4Buffer.append(((long) last_l4_index << 32) | 0xffffffffL); } last_l1_index = VTDBuffer.size - 1; last_depth = 1; break; case 2: if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) + l2Buffer.size); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } else if (last_depth ==3) { _l3Buffer.append(((long) last_l3_index << 32) | 0xffffffffL); } else if (last_depth ==4){ _l4Buffer.append(((long) last_l4_index << 32) | 0xffffffffL); } last_l2_index = VTDBuffer.size - 1; last_depth = 2; break; case 3: /*if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) + l2Buffer.size); } else*/ if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) + _l3Buffer.size); } else if (last_depth ==3) { _l3Buffer.append(((long) last_l3_index << 32) | 0xffffffffL); } else if (last_depth ==4){ _l4Buffer.append(((long) last_l4_index << 32) | 0xffffffffL); } last_l3_index = VTDBuffer.size - 1; last_depth = 3; break; case 4: /*if (last_depth == 1) { l1Buffer.append(((long) last_l1_index << 32) + l2Buffer.size); } else if (last_depth == 2) { l2Buffer.append(((long) last_l2_index << 32) | 0xffffffffL); } else*/ if (last_depth ==3) { _l3Buffer.append(((long) last_l3_index << 32) + _l4Buffer.size); } else if (last_depth ==4){ _l4Buffer.append(((long) last_l4_index << 32) | 0xffffffffL); } last_l4_index = VTDBuffer.size - 1; last_depth = 4; break; case 5: _l5Buffer.append(VTDBuffer.size - 1); if (last_depth == 4) { _l4Buffer.append(((long) last_l4_index << 32) + _l5Buffer.size - 1); } last_depth = 5; break; //default: //rootIndex = VTDBuffer.size() - 1; } } /** * * @throws ParseException */ private void qualifyElement() throws ParseException{ int i= nsBuffer3.size-1; // two cases: // 1. the current element has no prefix, look for xmlns // 2. the current element has prefix, look for xmlns:something int preLen = (int)((currentElementRecord & 0xffff000000000000L)>>48); int preOs = (int)currentElementRecord; while(i>=0){ int t = nsBuffer3.upper32At(i); // with prefix, get full length and prefix length if ( (t&0xffff) - (t>>16) == preLen){ // doing byte comparison here int os = nsBuffer3.lower32At(i)+(t>>16)+increment; int k=0; for (;k<preLen-increment;k++){ if (XMLDoc[os+k]!=XMLDoc[preOs+k]) break; } if (k==preLen-increment) return; // found the match } /*if ( (nsBuffer3.upper32At(i) & 0xffff0000) == 0){ return; }*/ i--; } // no need to check if xml is the prefix if (checkPrefix(preOs, preLen)) return; // print line # column# and full element name throw new ParseException("Name space qualification Exception: Element not qualified\n" +formatLineNumber((int)currentElementRecord)); } private boolean checkPrefix(int os, int len){ //int i=0; if (encoding < FORMAT_UTF_16BE){ if (len==4 && XMLDoc[os]=='x' && XMLDoc[os+1]=='m' && XMLDoc[os+2]=='l'){ return true; } }else if (encoding == FORMAT_UTF_16BE){ if (len==8 && XMLDoc[os]==0 && XMLDoc[os+1]=='x' && XMLDoc[os+2]==0 && XMLDoc[os+3]=='m' && XMLDoc[os+4]==0 && XMLDoc[os+5]=='l'){ return true; } }else { if (len==8 && XMLDoc[os]=='x' && XMLDoc[os+1]==0 && XMLDoc[os+2]=='m' && XMLDoc[os+3]==0 && XMLDoc[os+4]=='l' && XMLDoc[os+5]==0){ return true; } } return false; } private boolean checkPrefix2(int os, int len){ //int i=0; if (encoding < FORMAT_UTF_16BE){ if ( len==5 && XMLDoc[os]=='x' && XMLDoc[os+1]=='m' && XMLDoc[os+2]=='l' && XMLDoc[os+3]=='n' && XMLDoc[os+4]=='s'){ return true; } }else if (encoding == FORMAT_UTF_16BE){ if ( len==10 && XMLDoc[os]==0 && XMLDoc[os+1]=='x' && XMLDoc[os+2]==0 && XMLDoc[os+3]=='m' && XMLDoc[os+4]==0 && XMLDoc[os+5]=='l' && XMLDoc[os+6]==0 && XMLDoc[os+7]=='n' && XMLDoc[os+8]==0 && XMLDoc[os+9]=='s' ){ return true; } }else { if ( len==10 && XMLDoc[os]=='x' && XMLDoc[os+1]==0 && XMLDoc[os+2]=='m' && XMLDoc[os+3]==0 && XMLDoc[os+4]=='l' && XMLDoc[os+5]==0 && XMLDoc[os+6]=='n' && XMLDoc[os+3]==0 && XMLDoc[os+8]=='s' && XMLDoc[os+5]==0 ){ return true; } } return false; } private long _getCharResolved(int byte_offset){ int ch = 0; int val = 0; long inc = 2<<(increment-1); long l = r._getChar(byte_offset); ch = (int)l; if (ch != '&') return l; // let us handle references here //currentOffset++; byte_offset+=increment; ch = getCharUnit(byte_offset); byte_offset+=increment; switch (ch) { case '#' : ch = getCharUnit(byte_offset); if (ch == 'x') { while (true) { byte_offset+=increment; inc+=increment; ch = getCharUnit(byte_offset); if (ch >= '0' && ch <= '9') { val = (val << 4) + (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { val = (val << 4) + (ch - 'a' + 10); } else if (ch >= 'A' && ch <= 'F') { val = (val << 4) + (ch - 'A' + 10); } else if (ch == ';') { inc+=increment; break; } } } else { while (true) { ch = getCharUnit(byte_offset); byte_offset+=increment; inc+=increment; if (ch >= '0' && ch <= '9') { val = val * 10 + (ch - '0'); } else if (ch == ';') { break; } } } break; case 'a' : ch = getCharUnit(byte_offset); if (encoding<FORMAT_UTF_16BE){ if (ch == 'm') { if (getCharUnit(byte_offset + 1) == 'p' && getCharUnit(byte_offset + 2) == ';') { inc = 5; val = '&'; } } else if (ch == 'p') { if (getCharUnit(byte_offset + 1) == 'o' && getCharUnit(byte_offset + 2) == 's' && getCharUnit(byte_offset + 3) == ';') { inc = 6; val = '\''; } } }else{ if (ch == 'm') { if (getCharUnit(byte_offset + 2) == 'p' && getCharUnit(byte_offset + 4) == ';') { inc = 10; val = '&'; } } else if (ch == 'p') { if (getCharUnit(byte_offset + 2) == 'o' && getCharUnit(byte_offset + 4) == 's' && getCharUnit(byte_offset + 6) == ';') { inc = 12; val = '\''; } } } break; case 'q' : if (encoding<FORMAT_UTF_16BE){ if (getCharUnit(byte_offset) == 'u' && getCharUnit(byte_offset + 1) == 'o' && getCharUnit(byte_offset + 2) == 't' && getCharUnit(byte_offset + 3) ==';') { inc = 6; val = '\"'; } } else{ if (getCharUnit(byte_offset) == 'u' && getCharUnit(byte_offset + 2) == 'o' && getCharUnit(byte_offset + 4) == 't' && getCharUnit(byte_offset + 6) ==';') { inc = 12; val = '\"'; } } break; case 'l' : if (encoding<FORMAT_UTF_16BE){ if (getCharUnit(byte_offset) == 't' && getCharUnit(byte_offset + 1) == ';') { //offset += 2; inc = 4; val = '<'; } }else{ if (getCharUnit(byte_offset) == 't' && getCharUnit(byte_offset + 2) == ';') { //offset += 2; inc = 8; val = '<'; } } break; case 'g' : if (encoding<FORMAT_UTF_16BE){ if (getCharUnit(byte_offset) == 't' && getCharUnit(byte_offset + 1) == ';') { inc = 4; val = '>'; } }else { if (getCharUnit(byte_offset) == 't' && getCharUnit(byte_offset + 2) == ';') { inc = 8; val = '>'; } } break; } //currentOffset++; return val | (inc << 32); } //return 0; private int getCharUnit(int byte_offset) { return (encoding <= 2) ? XMLDoc[byte_offset] & 0xff : (encoding < FORMAT_UTF_16BE) ? r.decode(byte_offset):(encoding == FORMAT_UTF_16BE) ? (((int)XMLDoc[byte_offset]) << 8 | XMLDoc[byte_offset+1]) : (((int)XMLDoc[byte_offset + 1]) << 8 | XMLDoc[byte_offset]); } private boolean matchURL(int bos1, int len1, int bos2, int len2){ long l1,l2; int i1=bos1, i2=bos2, i3=bos1+len1,i4=bos2+len2; //System.out.println("--->"+new String(XMLDoc, bos1, len1)+" "+new String(XMLDoc,bos2,len2)); while(i1<i3 && i2<i4){ l1 = _getCharResolved(i1); l2 = _getCharResolved(i2); if ((int)l1!=(int)l2) return false; i1 += (int)(l1>>32); i2 += (int)(l2>>32); } if (i1==i3 && i2==i4) return true; return false; } private void checkAttributeUniqueness() throws ParseException { boolean unique = true; boolean unequal; for (int i = 0; i < attr_count; i++) { unequal = false; int prevLen = (int) attr_name_array[i]; if (length1 == prevLen) { int prevOffset = (int) (attr_name_array[i] >> 32); for (int j = 0; j < prevLen; j++) { if (XMLDoc[prevOffset + j] != XMLDoc[temp_offset + j]) { unequal = true; break; } } } else unequal = true; unique = unique && unequal; } if (!unique && attr_count != 0) throw new ParseException( "Error in attr: Attr name not unique" + formatLineNumber()); unique = true; if (attr_count < attr_name_array.length) { attr_name_array[attr_count] = ((long) (temp_offset) << 32) | length1; attr_count++; } else // grow the attr_name_array by 16 { long[] temp_array = attr_name_array; /*System.out.println( "size increase from " + temp_array.length + " to " + (attr_count + 16));*/ attr_name_array = new long[attr_count + ATTR_NAME_ARRAY_SIZE]; System.arraycopy(temp_array, 0, attr_name_array, 0, attr_count); /*for (int i = 0; i < attr_count; i++) { attr_name_array[i] = temp_array[i]; }*/ attr_name_array[attr_count] = ((long) (temp_offset) << 32) | length1; attr_count++; } // insert prefix attr node into the prefixed_attr_name array // xml:something will not be inserted //System.out.println(" prefixed attr count ===>"+prefixed_attr_count); //System.out.println(" length2 ===>"+length2); if (ns && !is_ns && length2!=0 ){ if ((increment==1 && length2 ==3 && matchXML(temp_offset)) || (increment==2 &&length2 ==6 && matchXML(temp_offset))){ return; } else if (prefixed_attr_count < prefixed_attr_name_array.length){ prefixed_attr_name_array[prefixed_attr_count] = ((long) (temp_offset) << 32) | (length2<<16)| length1; prefixed_attr_count++; }else { long[] temp_array1 = prefixed_attr_name_array; prefixed_attr_name_array = new long[prefixed_attr_count + ATTR_NAME_ARRAY_SIZE]; prefix_URL_array = new int[prefixed_attr_count + ATTR_NAME_ARRAY_SIZE]; System.arraycopy(temp_array1, 0, prefixed_attr_name_array, 0, prefixed_attr_count); //System.arraycopy(temp_array1, 0, prefixed_attr_val_array, 0, prefixed_attr_count) /*for (int i = 0; i < attr_count; i++) { attr_name_array[i] = temp_array[i]; }*/ prefixed_attr_name_array[prefixed_attr_count] = ((long) (temp_offset) << 32) | (length2<<16)| length1; prefixed_attr_count++; } } } private void handleOtherTextChar(int ch) throws ParseException{ if (ch == '&') { //has_amp = true; if (!XMLChar.isValidChar(entityIdentifier())) throw new ParseException( "Error in text content: Invalid char in text content " + formatLineNumber()); //parser_state = STATE_TEXT; } else if (ch == ']') { if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } } else throw new ParseException( "Error in text content: Invalid char in text content " + formatLineNumber()); } private void handleOtherTextChar2(int ch) throws ParseException{ if (ch == '&') { //has_amp = true; //temp_offset = offset; entityIdentifier(); //parser_state = STATE_TEXT; } else if (ch == ']') { if (r.skipChar(']')) { while (r.skipChar(']')) { } if (r.skipChar('>')) throw new ParseException( "Error in text content: ]]> in text content" + formatLineNumber()); } //parser_state = STATE_TEXT; }else throw new ParseException( "Error in text content: Invalid char" + formatLineNumber()); } private int processElementTail(boolean helper) throws ParseException, EncodingException, EOFException{ if (depth != -1) { temp_offset = offset; //ch = getCharAfterSe(); ch = getCharAfterS(); if (ch == '<') { if (ws) addWhiteSpaceRecord(); //parser_state = STATE_LT_SEEN; if (r.skipChar('/')) { if (helper) { length1 = offset - temp_offset - (increment << 1); //if (length1 > 0) { if (singleByteEncoding)//if (encoding < FORMAT_UTF_16BE) writeVTDText((temp_offset), length1, TOKEN_CHARACTER_DATA, depth); else writeVTDText((temp_offset) >> 1, (length1 >> 1), TOKEN_CHARACTER_DATA, depth); //} } return STATE_END_TAG; } return STATE_LT_SEEN; } else if (XMLChar.isContentChar(ch)) { //temp_offset = offset; return STATE_TEXT; } else { handleOtherTextChar2(ch); return STATE_TEXT; } } return STATE_DOC_END; } }
148,588
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ILongBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ILongBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Abstract long buffer storage interface * Creation date: (11/23/03 6:13:38 PM) */ public interface ILongBuffer { /** * Get the long at the given index. * Creation date: (11/23/03 6:29:53 PM) * @return long * @param index int */ long longAt(int index); /** * Get the lower 32 bit of the long at given index. * Creation date: (11/23/03 6:45:27 PM) * @return int * @param index int */ int lower32At(int index); /** * Modify the entry at given index with a new val. * Creation date: (11/23/03 6:42:57 PM) * @param index int * @param newVal long */ void modifyEntry(int index, long newVal); /** * Get the number of long in the buffer. * Creation date: (11/23/03 7:22:25 PM) * @return int */ int size(); /** * Get the upper 32 bit of the long at the given index. * Creation date: (11/23/03 6:45:27 PM) * @return int * @param index int */ int upper32At(int index); }
1,758
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ContextBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ContextBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; //import java.lang.NullPointerException; import java.lang.IllegalArgumentException; import java.util.ArrayList; //import com.ximpleware.NavException; /** * This class is used as the global stack in VTDNav class. * The VTDNav object instantiates a context Buffer object, then everytime * load/store is called, current context information gets pushed/popped to/from the * ContextBuffer. * Creation date: (11/16/03 4:30:45 PM) */ public class ContextBuffer{ private arrayList bufferArrayList; private int capacity; private int pageSize; protected int size; private int incSize; private int n; // for fast divide private int r; // mask for remainder /** * ContextBuffer constructor comment. * inc is the # of int to be pushed/pop to/from the underlying storage * @param i int */ public ContextBuffer(int i) { super(); pageSize =1024; n = 10; //1<<10 == 1024 r = pageSize - 1; incSize = i; if (incSize<0) throw new IllegalArgumentException(); bufferArrayList = new arrayList(); } /** * ContextBuffer constructor comment. * incSize is the # of int to be pushed/pop to/from the underlying storage * Creation date: (11/16/03 8:02:21 PM) * @param p int (pageSize equals (1<<p) * @param i int */ public ContextBuffer(int p, int i) { if (p<0)throw new IllegalArgumentException("invalid Buffer size"); pageSize = (1<<p); r = pageSize - 1; n = p; incSize = i; if (incSize < 0) throw new IllegalArgumentException("context buffer's incremental size must be greater than zero"); bufferArrayList = new arrayList(); } /** * Pop the content value back into an integer array. * Creation date: (11/17/03 1:07:42 AM) * @param output int[] * @return boolean If load is successful. **/ public boolean load(int[] output){ if (size < incSize) { return false; } int startingOffset = size - incSize; int len = incSize; //int[] result = new int[len]; // allocate result array //if (pageSize != 1) { //int first_index = (int) (startingOffset / pageSize); //int last_index = (int) ((startingOffset + len) / pageSize); //if ((startingOffset + len) % pageSize == 0) { int first_index = (startingOffset >> n); int last_index = ((startingOffset + len) >>n); if (((startingOffset + len)& r)== 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (int[]) (bufferArrayList.get(first_index)), //startingOffset % pageSize, startingOffset & r, output, 0, len); } else { int int_array_offset = 0; for (int i = first_index; i <= last_index; i++) { int[] currentChunk = (int[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, //startingOffset % pageSize startingOffset & r, output, 0, // pageSize - (startingOffset % pageSize)); pageSize - (startingOffset & r)); //int_array_offset += pageSize - (startingOffset) % pageSize; int_array_offset += pageSize - (startingOffset &r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, output, int_array_offset, len - int_array_offset); } else { System.arraycopy(currentChunk, 0, output, int_array_offset, pageSize); int_array_offset += pageSize; } } } size -= incSize; return true; } /** * Test the load and store functions. * Creation date: (11/19/03 3:51:17 PM) * @param args java.lang.String[] */ public static void main(String[] args) { try { int[] ia = new int[18]; ContextBuffer cb = new ContextBuffer(18); for (int i = 0; i < 57; i++) { for (int j = 0; j < 17; j++) { ia[j] = i; } ia[17] = -1; cb.store(ia); } //cb.store(ia); for (int i = 56; i >= 0; i--) { cb.load(ia); System.out.println(""+ia[0]); if (ia[17]!=-1) System.out.println("store error "+i+ " "+17+" "+ia[17]); for (int j = 16; j >= 0; j--) { if (ia[j] != i) { System.out.println(" store error " + i + " " + j + " " + ia[j]); } } } System.out.println("cb.clear()"); cb.clear(); for (int i = 0; i < 157; i++) { for (int j = 0; j < 18; j++) { ia[j] = i; } cb.store(ia); } //cb.store(ia); for (int i = 156; i >= 0; i--) { cb.load(ia); System.out.println(""+ia[0]); for (int j = 17; j >= 0; j--) { if (ia[j] != i) { System.out.println(" store error " + i + " " + j + " " + ia[j]); } } } cb.clear(); for (int i = 0; i < 257; i++) { for (int j = 0; j < 18; j++) { ia[j] = i; } cb.store(ia); } //cb.store(ia); for (int i = 256; i >= 0; i--) { cb.load(ia); System.out.println(""+ia[0]); for (int j = 17; j >= 0; j--) { if (ia[j] != i) { System.out.println(" store error " + i + " " + j + " " + ia[j]); } } } System.out.println("success"); System.out.println("test fastIntBuffer"); ia = new int[1000000]; for (int k=0;k<1000000;k++){ ia[k]= k; } FastIntBuffer fib = new FastIntBuffer(13); //for(int i=0;i<10;i++){ fib.append(ia); //} fib.clear(); fib.append(ia); //for(int i=0;i<10;i++){ // fib.append(ia); //} int ib[] = fib.toIntArray(); for (int i = 0;i<1000000;i++){ if (ib[i]!=i){ System.out.println("error occurred at "+i ); //break; } } System.out.println("test fastLongBuffer"); long[] la = new long[1000000]; for (int k=0;k<1000000;k++){ la[k]= k; } FastLongBuffer flb = new FastLongBuffer(14); flb.append(la); flb.clear(); flb.append(la); long lb[] = flb.toLongArray(); for (int i = 0;i<1000000;i++){ if (lb[i]!=i){ System.out.println("error occurred at "+i); } } System.out.println("success"); } catch (Exception e) { e.printStackTrace(); System.out.println(" exception caught "); } } /** * Set the context buffer size to zero * capacity untouched */ public void clear(){ size = 0; } /** * Push the array content on to the stack. * Creation date: (11/17/03 1:06:43 AM) * @param input int[] */ public void store(int[] input){ if (input == null) { throw new IllegalArgumentException("context buffer can't store a null pointer"); } //if (input.length != incSize) { // throw a derivative of runtime exceptions // throw new NavException("Store: Input size doesn't match increment size"); //} // no additional buffer space needed int lastBufferIndex; int[] lastBuffer; if (bufferArrayList.size() == 0) { lastBuffer = new int[pageSize]; bufferArrayList.add(lastBuffer); lastBufferIndex = 0; capacity = pageSize; } else { lastBufferIndex = Math.min((size>>n),//+(((size&r)==0)? 0:1), bufferArrayList.size() - 1); lastBuffer = (int[]) bufferArrayList.get(lastBufferIndex); } if ((this.size + input.length) < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(input, 0, lastBuffer, size % pageSize, input.length); if (this.size + input.length< ((lastBufferIndex+1)<<n)){ System.arraycopy(input, 0, lastBuffer, size & r, input.length); } else { int offset = pageSize - (size &r); // copy the first part System.arraycopy(input, 0, lastBuffer, size & r, offset); // copy the middle part int l = input.length - (offset); int k = (l)>> n; int z; for (z=1;z<=k;z++){ System.arraycopy(input,offset, (int[]) bufferArrayList.get(lastBufferIndex+z), 0, pageSize); offset += pageSize; } // copy the last part System.arraycopy(input,offset,(int[]) bufferArrayList.get(lastBufferIndex+z), 0, l & r); } size += input.length; return; //System.out.println(" --+++ buffer size "+size); //size += input.length; } else // new buffers needed { // compute the number of additional buffers needed int k = //((int) ((input.length + size) / pageSize)) ((input.length + size) >>n) //+ (((input.length + size) % pageSize) > 0 ? 1 : 0) + (((input.length + size) & r ) > 0 ? 1 : 0) - (capacity >> n); // create these buffers // add to bufferArrayList //System.arraycopy(input, 0, lastBuffer, size % pageSize, capacity - size); System.arraycopy(input, 0, lastBuffer, size & r, capacity - size); for (int i = 0; i < k; i++) { int[] newBuffer = new int[pageSize]; if (i < k - 1) { // full copy System.arraycopy(input, pageSize * i + capacity - size, newBuffer, 0, pageSize); } else { // last page System.arraycopy( input, pageSize * i + capacity - size, newBuffer, 0, (input.length + size) - pageSize * i - capacity); } bufferArrayList.add(newBuffer); } // update length size += input.length; // update capacity capacity += (k <<n); // update } } }
11,947
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
PilotException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/PilotException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This class is the base class of all the exceptions of autopilot. * Creation date: (11/30/03 6:14:43 PM) */ public class PilotException extends NavException { /** * PilotException constructor comment. */ public PilotException() { super(); } /** * PilotException constructor comment. * @param s java.lang.String */ public PilotException(String s) { super(s); } }
1,222
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EncodingException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/EncodingException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * Signals character encoding exception during parsing. * Creation date: (2/2/04 1:08:09 PM) */ public class EncodingException extends ParseException { /** * EncodingException constructor comment. */ public EncodingException() { super(); } /** * EncodingException constructor comment. * @param s java.lang.String */ public EncodingException(String s) { super(s); } }
1,225
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/VTDException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * VTDException is the root exception for all VTD-XML's exception * */ public class VTDException extends Exception{ public VTDException(String s){ super(s); } public VTDException(){ } }
1,044
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FastObjectBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FastObjectBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.util.ArrayList; /** * Fast object array implementation * */ public class FastObjectBuffer implements IObjectBuffer { /* bufferArrayList is a resizable array list of int buffers * */ private arrayList bufferArrayList; /** * Total capacity of the ObjectBuffer */ private int capacity; /** * Page size of the incremental growth of the object Buffer */ private int pageSize; /** * Total number of objects in the IntBuffer */ protected int size; private int exp; private int r; /** * FastIntBuffer constructor comment. */ public FastObjectBuffer() { size = 0; capacity = 0; pageSize = 1024; exp = 10; r = 1023; bufferArrayList = new arrayList(); } /** * Constructor with adjustable buffer page size of the value bfz * @param e int */ public FastObjectBuffer(int e) { if (e < 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = 1<<e; exp = e; r = pageSize -1; bufferArrayList = new arrayList(); } /** * Append an object array to the end of this buffer instance * @param obj_array Object[] */ public void append(Object[] obj_array) { if (obj_array == null) { throw new NullPointerException(); } // no additional buffer space needed int lastBufferIndex; Object[] lastBuffer; if (bufferArrayList.size == 0) { lastBuffer = new Object[pageSize]; bufferArrayList.add(lastBuffer); lastBufferIndex = 0; capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (Object[]) bufferArrayList.get(lastBufferIndex); } if ((this.size + obj_array.length) < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(input, 0, lastBuffer, size % pageSize, input.length); if (this.size + obj_array.length< ((lastBufferIndex+1)<<exp)){ System.arraycopy(obj_array, 0, lastBuffer, size & r, obj_array.length); } else { int offset = pageSize -(size&r); // copy the first part System.arraycopy(obj_array, 0, lastBuffer, size & r, offset); // copy the middle part int l = obj_array.length - offset; int k = (l)>> exp; int z; for (z=1;z<=k;z++){ System.arraycopy(obj_array,offset, (Object[]) bufferArrayList.get(lastBufferIndex+z), 0, pageSize); offset += pageSize; } // copy the last part System.arraycopy(obj_array, offset, (Object[]) bufferArrayList.get(lastBufferIndex+z), 0, l & r); } size += obj_array.length; return; } else // new buffers needed { // compute the number of additional buffers needed // int n = // ((int) ((int_array.length + size) / pageSize)) // + (((int_array.length + size) % pageSize) > 0 ? 1 : 0) // - (int) (capacity / pageSize); int n = ((obj_array.length + size) >> exp) + (((obj_array.length + size) &r) > 0 ? 1 : 0) - (capacity >> exp); // create these buffers // add to bufferArrayList //System.arraycopy(int_array, 0, lastBuffer, size % pageSize, capacity - size); System.arraycopy(obj_array, 0, lastBuffer, size& r, capacity - size); for (int i = 0; i < n; i++) { Object[] newBuffer = new Object[pageSize]; if (i < n - 1) { // full copy System.arraycopy( obj_array, pageSize * i + capacity - size, newBuffer, 0, pageSize); } else { // last page System.arraycopy( obj_array, pageSize * i + capacity - size, newBuffer, 0, obj_array.length + this.size - capacity - pageSize*i); } bufferArrayList.add(newBuffer); } // update length size += obj_array.length; // update capacity capacity += n * pageSize; // update } } /** * Append a single object to the end of this buffer Instance * @param obj */ final public void append(Object obj) { //Object[] lastBuffer; //int lastBufferIndex; /*if (bufferArrayList.size == 0) { lastBuffer = new Object[pageSize]; bufferArrayList.add(lastBuffer); capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (Object[]) bufferArrayList.oa[lastBufferIndex]; //lastBuffer = (int[]) bufferArrayList.get(bufferArrayList.size() - 1); }*/ if (this.size < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, long_array.length); ((Object[])bufferArrayList.oa[size>>exp])[size & r] = obj; // lastBuffer[size % pageSize] = i; size += 1; } else // new buffers needed { Object[] newBuffer = new Object[pageSize]; size++; capacity += pageSize; bufferArrayList.add(newBuffer); newBuffer[0] = obj; } } /** * Returns the total allocated capacity of this buffer instance. * @return int */ final public int getCapacity() { return capacity; } /** * Returns a single object array representing every object in this buffer instance * @return Object[] (null if there isn't anything left in the buffer * @param startingOffset int * @param len int * @return Object[] */ public Object[] getObjectArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size) { throw (new IndexOutOfBoundsException()); } Object[] result = new Object[len]; // allocate result array // int first_index = (int) (startingOffset / pageSize); // int last_index = (int) ((startingOffset + len) / pageSize); // if ((startingOffset + len) % pageSize == 0) { // last_index--; // } int first_index = startingOffset >> exp; int last_index = (startingOffset + len)>> exp; if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (Object[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int obj_array_offset = 0; for (int i = first_index; i <= last_index; i++) { Object[] currentChunk = (Object[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % pageSize)); pageSize - (startingOffset & r)); // int_array_offset += pageSize - (startingOffset) % pageSize; obj_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, obj_array_offset, len - obj_array_offset); } else { System.arraycopy(currentChunk, 0, result, obj_array_offset, pageSize); obj_array_offset += pageSize; } } } return result; } /** * Returns the page size of this buffer instance. * Creation date: (7/17/03 6:38:02 PM) * @return int */ public final int getPageSize() { return pageSize; } /** * Get the object at the location specified by index. * @return int * @param index int */ public final Object objectAt(int index) { if ( index > size-1) { throw new IndexOutOfBoundsException(); } // int pageNum = (int) index / pageSize; int pageNum = index>>exp; //System.out.println("page Number is "+pageNum); // int offset = index % pageSize; int offset = index & r; return ((Object[]) bufferArrayList.get(pageNum))[offset]; } /** * Assigns a new int value to location index of the buffer instance. * @param index int * @param newValue int */ public final void modifyEntry(int index, Object newValue) { if (index > size - 1) { throw new IndexOutOfBoundsException(); } // ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((Object[]) bufferArrayList.get((index >> exp)))[index & r] = newValue; } /** * Returns the total number of objects in the buffer instance * @return int */ public final int size() { return size; } /** * Returns the object array corresponding to all objects in this buffer instance * @return Object[] (null if the buffer is empty) */ public Object[] toObjectArray() { if (size > 0) { int s = size; Object[] resultArray = new Object[size]; //copy all the content int into the resultArray int array_offset = 0; for (int i = 0; s>0; i++) { System.arraycopy( (Object[]) bufferArrayList.get(i), 0, resultArray, array_offset, (s<pageSize) ? s : pageSize); // (i == (bufferArrayList.size() - 1)) ? size() % pageSize : pageSize); s = s - pageSize; array_offset += pageSize; } return resultArray; } return null; } /** * set the size of object buffer to zero, capacity * untouched so object buffer can be reused without * any unnecessary and additional allocation * */ public final void clear(){ size = 0; } }
11,651
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
CachedExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/CachedExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; public class CachedExpr extends Expr { Expr e; boolean cached; boolean eb; double en; String es; FastIntBuffer ens; int count; VTDNav vn1; public CachedExpr(Expr e1){ e=e1; cached = false; ens=null; count=0; vn1=null; } @Override public boolean evalBoolean(VTDNav vn) { // TODO Auto-generated method stub if (cached){ return eb; }else{ eb = e.evalBoolean(vn); return eb; } } @Override public double evalNumber(VTDNav vn) { // TODO Auto-generated method stub if (cached){ return en; }else{ cached = true; en = e.evalNumber(vn); return en; } } @Override public int evalNodeSet(VTDNav vn) throws XPathEvalException, NavException { // TODO Auto-generated method stub int i=-1; if (cached){ if (count<ens.size){ i=ens.intAt(count); vn.recoverNode(i); count++; return i; }else return -1; }else{ cached = true; if (ens==null){ ens = new FastIntBuffer(8);//page size 64 } //record node set while((i=e.evalNodeSet(vn))!=-1){ ens.append(i); } e.reset(vn); if(ens.size>0){ i=ens.intAt(count);//count should be zero vn.recoverNode(i); count++; return i; }else return -1; } } public String evalString(VTDNav vn) { if (cached){ return es; }else{ cached = true; es = e.evalString(vn); return es; } } public void reset(VTDNav vn) { count=0; if (e!=null && vn!=null) e.reset(vn); /*if (vn1!=vn){ cached = false; if (ens!=null) ens.clear(); e.reset(vn); }*/ // TODO Auto-generated method stub } @Override public String toString() { // TODO Auto-generated method stub return "cached("+e.toString()+")"; } @Override public boolean isNumerical() { // TODO Auto-generated method stub return e.isNumerical(); } @Override public boolean isNodeSet() { // TODO Auto-generated method stub return e.isNodeSet(); } @Override public boolean isString() { // TODO Auto-generated method stub return e.isString(); } @Override public boolean isBoolean() { // TODO Auto-generated method stub return e.isBoolean(); } @Override public boolean requireContextSize() { // TODO Auto-generated method stub return e.requireContextSize(); } @Override public void setContextSize(int size) { // TODO Auto-generated method stub e.setContextSize(size); } @Override public void setPosition(int pos) { // TODO Auto-generated method stub e.setPosition(pos); } @Override public int adjust(int n) { // TODO Auto-generated method stub return e.adjust(n); } @Override public boolean isFinal() { // TODO Auto-generated method stub return e.isFinal(); } public void markCacheable() { // TODO Auto-generated method stub e.markCacheable(); } @Override public void markCacheable2() { // TODO Auto-generated method stub e.markCacheable2(); } public void clearCache(){ cached = false; if (ens!=null) ens.clear(); e.clearCache(); } }
4,016
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IndexHandler.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IndexHandler.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.*; import java.nio.*; /** * IndexWrite adjusts the offset so that the XML segment * contains only the XML document * IndexRead, if from byte array, will move adjust the offset * */ class IndexHandler { public static final int OFFSET_ADJUSTMENT =32; /** * Write VTD+XML index to OutputStream * @param version * @param encodingType * @param ns * @param byteOrder * @param nestDepth * @param LCLevel * @param rootIndex * @param xmlDoc * @param docOffset * @param docLen * @param vtdBuffer * @param l1Buffer * @param l2Buffer * @param l3Buffer * @param os * @throws IndexWriteException * @throws IOException * */ public static void writeIndex_L3(byte version, int encodingType, boolean ns, boolean byteOrder, // true is big endien int nestDepth, int LCLevel, int rootIndex, byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastIntBuffer l3Buffer, OutputStream os ) throws IndexWriteException, IOException{ if ( xmlDoc == null || docLen <=0 || vtdBuffer == null // impossible to occur || l1Buffer == null // setDoc not called || l2Buffer == null || l3Buffer == null || LCLevel !=3 ){ throw new IndexWriteException("Invalid VTD index "); } if (vtdBuffer.size()==0) throw new IndexWriteException("VTDBuffer can't be zero length"); int i; DataOutputStream dos = new DataOutputStream(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 2 ba[1] = (byte)encodingType; ba[2] = (byte)(ns? 0xe0 : 0xa0); // big endien ba[3] = (byte)nestDepth; dos.write(ba); // second 4 bytes ba[0] = 0; ba[1] = 4; ba[2] = (byte) ((rootIndex & 0xff00)>> 8 ); ba[3] = (byte) (rootIndex & 0xff); dos.write(ba); // 2 reserved 64-bit words set to zero ba[1]= ba[2] = ba[3] = 0; dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); // write XML doc in bytes dos.writeLong(docLen); dos.write(xmlDoc,docOffset,docLen); // zero padding to make it integer multiple of 64 bits if ((docLen & 0x07) !=0 ){ int t = (((docLen>>3)+1)<<3) - docLen; for (;t>0;t--) dos.write(0); } // write VTD offset adjusted if the start offset is not zero dos.writeLong(vtdBuffer.size); if (docOffset == 0) for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(vtdBuffer.longAt(i)); } else for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(adjust(vtdBuffer.longAt(i), -docOffset)); } // write L1 dos.writeLong(l1Buffer.size); for(i=0;i< l1Buffer.size;i++){ dos.writeLong(l1Buffer.longAt(i)); } // write L2 dos.writeLong(l2Buffer.size); for(i=0;i< l2Buffer.size;i++){ dos.writeLong(l2Buffer.longAt(i)); } // write L3 dos.writeLong(l3Buffer.size); for(i=0;i< l3Buffer.size;i++){ dos.writeInt(l3Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ( (l3Buffer.size & 1) !=0) dos.writeInt(0); dos.close(); } /** * Write VTD+XML index to OutputStream * @param version * @param encodingType * @param ns * @param byteOrder * @param nestDepth * @param LCLevel * @param rootIndex * @param xmlDoc * @param docOffset * @param docLen * @param vtdBuffer * @param l1Buffer * @param l2Buffer * @param l3Buffer * @param os * @throws IndexWriteException * @throws IOException * */ public static void writeIndex_L5(byte version, int encodingType, boolean ns, boolean byteOrder, // true is big endien int nestDepth, int LCLevel, //has to be 5 int rootIndex, byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastLongBuffer l3Buffer, FastLongBuffer l4Buffer, FastIntBuffer l5Buffer, OutputStream os ) throws IndexWriteException, IOException{ if ( xmlDoc == null || docLen <=0 || vtdBuffer == null // impossible to occur || l1Buffer == null // setDoc not called || l2Buffer == null || l3Buffer == null || l4Buffer == null || l5Buffer == null || LCLevel !=5 ){ throw new IndexWriteException("Invalid VTD index "); } if (vtdBuffer.size==0) throw new IndexWriteException("VTDBuffer can't be zero length"); int i; DataOutputStream dos = new DataOutputStream(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 2 ba[1] = (byte)encodingType; ba[2] = (byte)(ns? 0xe0 : 0xa0); // big endien ba[3] = (byte)nestDepth; dos.write(ba); // second 4 bytes ba[0] = 0; ba[1] = 6; ba[2] = (byte) ((rootIndex & 0xff00)>> 8 ); ba[3] = (byte) (rootIndex & 0xff); dos.write(ba); // 2 reserved 64-bit words set to zero ba[1]= ba[2] = ba[3] = 0; dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); // write XML doc in bytes dos.writeLong(docLen); dos.write(xmlDoc,docOffset,docLen); // zero padding to make it integer multiple of 64 bits if ((docLen & 0x07) !=0 ){ int t = (((docLen>>3)+1)<<3) - docLen; for (;t>0;t--) dos.write(0); } // write VTD offset adjusted if the start offset is not zero dos.writeLong(vtdBuffer.size); if (docOffset == 0) for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(vtdBuffer.longAt(i)); } else for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(adjust(vtdBuffer.longAt(i), -docOffset)); } // write L1 dos.writeLong(l1Buffer.size); for(i=0;i< l1Buffer.size;i++){ dos.writeLong(l1Buffer.longAt(i)); } // write L2 dos.writeLong(l2Buffer.size); for(i=0;i< l2Buffer.size;i++){ dos.writeLong(l2Buffer.longAt(i)); } // write L3 dos.writeLong(l3Buffer.size); for(i=0;i< l3Buffer.size;i++){ dos.writeLong(l3Buffer.longAt(i)); } // write L4 dos.writeLong(l4Buffer.size); for(i=0;i< l4Buffer.size;i++){ dos.writeLong(l4Buffer.longAt(i)); } // write L5 dos.writeLong(l5Buffer.size); for(i=0;i< l5Buffer.size;i++){ dos.writeInt(l5Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ( (l5Buffer.size & 1) !=0) dos.writeInt(0); dos.close(); } /** * Write VTD and Location cache into output stream (which is separate from XML) * Notice that VTD index assumes that XML bytes starts at the beginning * * @param version * @param encodingType * @param ns * @param byteOrder * @param nestDepth * @param LCLevel * @param rootIndex * @param xmlDoc * @param docOffset * @param docLen * @param vtdBuffer * @param l1Buffer * @param l2Buffer * @param l3Buffer * @param os * @throws IndexWriteException * @throws IOException * */ public static void writeSeparateIndex_L3(byte version, int encodingType, boolean ns, boolean byteOrder, // true is big endien int nestDepth, int LCLevel, int rootIndex, //byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastIntBuffer l3Buffer, OutputStream os ) throws IndexWriteException, IOException{ if ( //xmlDoc == null docLen <=0 || vtdBuffer == null // impossible to occur || l1Buffer == null // setDoc not called || l2Buffer == null || l3Buffer == null || LCLevel !=3 ){ throw new IndexWriteException("Invalid VTD index "); } if (vtdBuffer.size==0) throw new IndexWriteException("VTDBuffer can't be zero length"); int i; DataOutputStream dos = new DataOutputStream(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 2 ba[1] = (byte)encodingType; ba[2] = (byte)(ns? 0xe0 : 0xa0); // big endien ba[3] = (byte)nestDepth; dos.write(ba); // second 4 bytes ba[0] = 0; ba[1] = 4; ba[2] = (byte) ((rootIndex & 0xff00)>> 8 ); ba[3] = (byte) (rootIndex & 0xff); dos.write(ba); // 2 reserved 64-bit words set to zero ba[1]= ba[2] = ba[3] = 0; dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); // write XML doc in bytes dos.writeLong(docLen); // 16 bytes reserved bytes dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); //dos.write(xmlDoc,docOffset,docLen); // zero padding to make it integer multiple of 64 bits //if ((docLen & 0x07) !=0 ){ // int t = (((docLen>>3)+1)<<3) - docLen; // for (;t>0;t--) // dos.write(0); //} // write VTD dos.writeLong(vtdBuffer.size); if (docOffset == 0) for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(vtdBuffer.longAt(i)); } else for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(adjust(vtdBuffer.longAt(i), -docOffset)); } // write L1 dos.writeLong(l1Buffer.size); for(i=0;i< l1Buffer.size;i++){ dos.writeLong(l1Buffer.longAt(i)); } // write L2 dos.writeLong(l2Buffer.size); for(i=0;i< l2Buffer.size();i++){ dos.writeLong(l2Buffer.longAt(i)); } // write L3 dos.writeLong(l3Buffer.size); for(i=0;i< l3Buffer.size;i++){ dos.writeInt(l3Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ( (l3Buffer.size & 1) !=0) dos.writeInt(0); dos.close(); } /** * Write VTD and Location cache into output stream (which is separate from XML) * Notice that VTD index assumes that XML bytes starts at the beginning * * @param version * @param encodingType * @param ns * @param byteOrder * @param nestDepth * @param LCLevel * @param rootIndex * @param xmlDoc * @param docOffset * @param docLen * @param vtdBuffer * @param l1Buffer * @param l2Buffer * @param l3Buffer * @param os * @throws IndexWriteException * @throws IOException * */ public static void writeSeparateIndex_L5(byte version, int encodingType, boolean ns, boolean byteOrder, // true is big endien int nestDepth, int LCLevel, int rootIndex, //byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastLongBuffer l3Buffer, FastLongBuffer l4Buffer, FastIntBuffer l5Buffer, OutputStream os ) throws IndexWriteException, IOException{ if ( //xmlDoc == null docLen <=0 || vtdBuffer == null // impossible to occur || l1Buffer == null // setDoc not called || l2Buffer == null || l3Buffer == null || l4Buffer == null || l5Buffer == null || LCLevel !=5 ){ throw new IndexWriteException("Invalid VTD index "); } if (vtdBuffer.size==0) throw new IndexWriteException("VTDBuffer can't be zero length"); int i; DataOutputStream dos = new DataOutputStream(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 2 ba[1] = (byte)encodingType; ba[2] = (byte)(ns? 0xe0 : 0xa0); // big endien ba[3] = (byte)nestDepth; dos.write(ba); // second 4 bytes ba[0] = 0; ba[1] = 6; ba[2] = (byte) ((rootIndex & 0xff00)>> 8 ); ba[3] = (byte) (rootIndex & 0xff); dos.write(ba); // 2 reserved 64-bit words set to zero ba[1]= ba[2] = ba[3] = 0; dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); // write XML doc in bytes dos.writeLong(docLen); // 16 bytes reserved bytes dos.write(ba); dos.write(ba); dos.write(ba); dos.write(ba); //dos.write(xmlDoc,docOffset,docLen); // zero padding to make it integer multiple of 64 bits //if ((docLen & 0x07) !=0 ){ // int t = (((docLen>>3)+1)<<3) - docLen; // for (;t>0;t--) // dos.write(0); //} // write VTD dos.writeLong(vtdBuffer.size); if (docOffset == 0) for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(vtdBuffer.longAt(i)); } else for (i = 0; i < vtdBuffer.size; i++) { dos.writeLong(adjust(vtdBuffer.longAt(i), -docOffset)); } // write L1 dos.writeLong(l1Buffer.size); for(i=0;i< l1Buffer.size;i++){ dos.writeLong(l1Buffer.longAt(i)); } // write L2 dos.writeLong(l2Buffer.size); for(i=0;i< l2Buffer.size();i++){ dos.writeLong(l2Buffer.longAt(i)); } // write L3 dos.writeLong(l3Buffer.size); for(i=0;i< l3Buffer.size;i++){ dos.writeLong(l3Buffer.longAt(i)); } // write L4 dos.writeLong(l4Buffer.size); for(i=0;i< l4Buffer.size;i++){ dos.writeLong(l4Buffer.longAt(i)); } // write L5 dos.writeLong(l5Buffer.size); for(i=0;i< l5Buffer.size;i++){ dos.writeInt(l5Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ( (l5Buffer.size & 1) !=0) dos.writeInt(0); dos.close(); } /** * The assumption for this function is that when VTD+XML index * is loaded into memory (ba), the first 32 bytes are not XML bytes * @param ba * @param vg * @throws IndexReadException * */ public static void readIndex(byte[] ba, VTDGen vg) throws IndexReadException{ if (ba == null || vg == null) throw new IllegalArgumentException("Invalid argument(s) for readIndex()"); ByteBuffer bb = ByteBuffer.wrap(ba); byte b= bb.get(); // first byte if (b!=1) throw new IndexReadException("Invalid version number for readIndex()"); // no check on version number for now // second byte vg.encoding = bb.get(); int adj = OFFSET_ADJUSTMENT; if (vg.encoding >= VTDGen.FORMAT_UTF_16BE){ adj = OFFSET_ADJUSTMENT>>1; } int intLongSwitch; //int ns; int endian; // third byte b= bb.get(); if ((b&0x80)!=0) intLongSwitch = 1; //use ints else intLongSwitch = 0; if ((b & 0x40)!=0) vg.ns = true; else vg.ns = false; if ((b & 0x20) !=0) endian = 1; else endian = 0; if ((b & 0x1f) != 0) throw new IndexReadException("Last 5 bits of the third byte should be zero"); // fourth byte vg.VTDDepth = bb.get(); // 5th and 6th byte int LCLevel = (((int)bb.get())<<8) | bb.get(); if (LCLevel != 4 && LCLevel !=6) throw new IndexReadException("LC levels must be at least 3"); // 7th and 8th byte if (LCLevel ==4) vg.shallowDepth = true; else vg.shallowDepth = false; // 7th and 8th byte vg.rootIndex = (((int)bb.get())<<8) | bb.get(); // skip a long bb.getLong(); bb.getLong(); int size = 0; // read XML size if (endian == 1) size = (int)bb.getLong(); else size = (int)reverseLong(bb.getLong()); // read XML bytes //byte[] XMLDoc = new byte[size]; //bb.get(XMLDoc); int t=0; if ((size & 0x7)!= 0){ t = (((size>>3)+1)<<3) - size; } vg.setDoc_BR(ba,32,size); bb = ByteBuffer.wrap(ba,32+size+t,ba.length-32-size-t); if (endian ==1){ // read vtd records int vtdSize = (int)bb.getLong(); while(vtdSize>0){ vg.VTDBuffer.append(adjust(bb.getLong(),adj)); vtdSize--; } // read L1 LC records int l1Size = (int)bb.getLong(); while(l1Size > 0){ long l = bb.getLong(); // System.out.println(" l-==> "+Long.toHexString(l)); vg.l1Buffer.append(l); l1Size--; } //System.out.println("++++++++++ "); // read L2 LC records int l2Size = (int)bb.getLong(); while(l2Size > 0){ vg.l2Buffer.append(bb.getLong()); l2Size--; } //System.out.println("++++++++++ "); // read L3 LC records int l3Size = (int)bb.getLong(); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(bb.getInt()); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer.append((int) (bb.getLong() >> 32)); l3Size--; } } }else{ while (l3Size > 0) { vg._l3Buffer.append(bb.getLong()); l3Size--; } int l4Size = (int) bb.getLong(); while (l4Size > 0) { vg._l4Buffer.append(bb.getLong()); l4Size--; } int l5Size = (int) bb.getLong(); if (intLongSwitch == 1) { // l5 uses ints while (l5Size > 0) { vg._l5Buffer.append(bb.getInt()); l5Size--; } } else { while (l5Size > 0) { vg._l5Buffer.append((int) (bb.getLong() >> 32)); l5Size--; } } } } else { // read vtd records int vtdSize = (int)reverseLong(bb.getLong()); while(vtdSize>0){ vg.VTDBuffer.append(adjust(reverseLong(bb.getLong()),adj)); vtdSize--; } // read L1 LC records //System.out.println(" ++++++++++ "); int l1Size = (int)reverseLong(bb.getLong()); while(l1Size > 0){ long l = reverseLong(bb.getLong()); vg.l1Buffer.append(l); l1Size--; } //System.out.println(" ++++++++++ "); // read L2 LC records int l2Size = (int)reverseLong(bb.getLong()); while(l2Size > 0){ long l = reverseLong(bb.getLong()); //System.out.println(" l--=->"+Long.toHexString(l)); vg.l2Buffer.append(l); l2Size--; } //System.out.println(" ++++++++++ "); // read L3 LC records int l3Size = (int)reverseLong(bb.getLong()); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(reverseInt(bb.getInt())); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer .append(reverseInt((int) (bb.getLong() >> 32))); l3Size--; } } }else{ while (l3Size > 0) { vg._l3Buffer.append(reverseLong(bb.getLong())); l3Size--; } int l4Size = (int) reverseLong(bb.getLong()); while (l4Size > 0) { vg._l4Buffer.append(reverseLong(bb.getLong())); l4Size--; } int l5Size = (int) reverseLong(bb.getLong()); if (intLongSwitch == 1) { // l5 uses ints while (l5Size > 0) { vg._l5Buffer.append(reverseInt(bb.getInt())); l5Size--; } } else { while (l5Size > 0) { vg._l5Buffer.append((reverseInt((int) (bb.getLong() >> 32)))); l5Size--; } } } } } /** * Load VTD+XML index from an inputStream * @param is * @param vg * @throws IndexReadException * @throws IOException * */ public static void readIndex(InputStream is, VTDGen vg) throws IndexReadException,IOException{ if (is == null || vg == null) throw new IndexReadException("Invalid argument(s) for readIndex()"); DataInputStream dis = new DataInputStream(is); byte b= dis.readByte(); // first byte if (b!=1) throw new IndexReadException("Invalid version number for readIndex()"); // no check on version number for now // second byte vg.encoding = dis.readByte(); int intLongSwitch; //int ns; int endian; // third byte b= dis.readByte(); if ((b&0x80)!=0) intLongSwitch = 1; //use ints else intLongSwitch = 0; if ((b & 0x40)!=0) vg.ns = true; else vg.ns = false; if ((b & 0x20) !=0) endian = 1; else endian = 0; if ((b & 0x1f) != 0) throw new IndexReadException("Last 5 bits of the third byte should be zero"); // fourth byte vg.VTDDepth = dis.readByte(); // 5th and 6th byte int LCLevel = (((int)dis.readByte())<<8) | dis.readByte(); if (LCLevel != 4 && LCLevel != 6) throw new IndexReadException("LC levels must be at least 3"); // 7th and 8th byte if (LCLevel ==4) vg.shallowDepth = true; else vg.shallowDepth = false; vg.rootIndex = (((int)dis.readByte())<<8) | dis.readByte(); // skip a long dis.readLong(); dis.readLong(); int size = 0; // read XML size if (endian == 1) size = (int)dis.readLong(); else size = (int)reverseLong(dis.readLong()); // read XML bytes byte[] XMLDoc = new byte[size]; dis.read(XMLDoc); if ((size & 0x7)!= 0){ int t = (((size>>3)+1)<<3) - size; while(t>0){ dis.readByte(); t--; } } vg.setDoc(XMLDoc); if (endian ==1){ // read vtd records int vtdSize = (int)dis.readLong(); while(vtdSize>0){ vg.VTDBuffer.append(dis.readLong()); vtdSize--; } // read L1 LC records int l1Size = (int)dis.readLong(); while(l1Size > 0){ long l = dis.readLong(); // System.out.println(" l-==> "+Long.toHexString(l)); vg.l1Buffer.append(l); l1Size--; } //System.out.println("++++++++++ "); // read L2 LC records int l2Size = (int)dis.readLong(); while(l2Size > 0){ vg.l2Buffer.append(dis.readLong()); l2Size--; } //System.out.println("++++++++++ "); // read L3 LC records int l3Size = (int) dis.readLong(); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(dis.readInt()); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer.append((int) (dis.readLong() >> 32)); l3Size--; } } } else { while (l3Size > 0) { vg._l3Buffer.append(dis.readLong()); l3Size--; } int l4Size = (int)dis.readLong(); while(l4Size > 0){ vg._l4Buffer.append(dis.readLong()); l4Size--; } int l5Size = (int)dis.readLong(); if (intLongSwitch == 1) { // l5 uses ints while(l5Size > 0){ vg._l5Buffer.append(dis.readInt()); l5Size--; } }else { while (l5Size > 0) { vg._l5Buffer.append((int) (dis.readLong() >> 32)); l5Size--; } } } } else { // read vtd records int vtdSize = (int)reverseLong(dis.readLong()); while(vtdSize>0){ vg.VTDBuffer.append(reverseLong(dis.readLong())); vtdSize--; } // read L1 LC records //System.out.println(" ++++++++++ "); int l1Size = (int)reverseLong(dis.readLong()); while(l1Size > 0){ long l = reverseLong(dis.readLong()); vg.l1Buffer.append(l); l1Size--; } //System.out.println(" ++++++++++ "); // read L2 LC records int l2Size = (int)reverseLong(dis.readLong()); while(l2Size > 0){ long l = reverseLong(dis.readLong()); //System.out.println(" l--=->"+Long.toHexString(l)); vg.l2Buffer.append(l); l2Size--; } //System.out.println(" ++++++++++ "); // read L3 LC records int l3Size = (int)reverseLong(dis.readLong()); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(reverseInt(dis.readInt())); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer .append(reverseInt((int) (dis.readLong() >> 32))); l3Size--; } } }else{ while (l3Size > 0) { vg._l3Buffer.append(reverseLong(dis.readLong())); l3Size--; } int l4Size = (int)reverseLong(dis.readLong()); while(l4Size > 0){ long l = reverseLong(dis.readLong()); vg._l4Buffer.append(l); l4Size--; } int l5Size = (int)reverseLong(dis.readLong()); if (intLongSwitch == 1) { // l5 uses ints while(l5Size > 0){ vg._l5Buffer.append(reverseInt(dis.readInt())); l5Size--; } }else { while (l5Size > 0) { vg._l5Buffer.append(reverseInt((int) (dis.readLong() >> 32))); l5Size--; } } } } } /** * read in XML and index file separately * @param index * @param XMLBytes * @param XMLSize * @param vg * @throws IndexReadException * @throws IOException * */ public static void readSeparateIndex(InputStream index, InputStream XMLBytes, int XMLSize, VTDGen vg) throws IndexReadException,IOException{ if (index == null || vg == null || XMLBytes == null) throw new IndexReadException("Invalid argument(s) for readSeparateIndex()"); DataInputStream dis = new DataInputStream(index); byte b= dis.readByte(); // first byte if (b!=2) throw new IndexReadException("Invalid version number for readIndex()"); // no check on version number for now // second byte vg.encoding = dis.readByte(); int intLongSwitch; //int ns; int endian; // third byte b= dis.readByte(); if ((b&0x80)!=0) intLongSwitch = 1; //use ints else intLongSwitch = 0; if ((b & 0x40)!=0) vg.ns = true; else vg.ns = false; if ((b & 0x20) !=0) endian = 1; else endian = 0; if ((b & 0x1f) != 0) throw new IndexReadException("Last 5 bits of the third byte should be zero"); // fourth byte vg.VTDDepth = dis.readByte(); // 5th and 6th byte int LCLevel = (((int)dis.readByte())<<8) | dis.readByte(); if (LCLevel != 4 && LCLevel !=6) throw new IndexReadException("LC levels must be at least 3"); // 7th and 8th byte if (LCLevel ==4) vg.shallowDepth = true; else vg.shallowDepth = false; // 7th and 8th byte vg.rootIndex = (((int)dis.readByte())<<8) | dis.readByte(); // skip two longs dis.readLong(); dis.readLong(); int size = 0; // read XML size if (endian == 1) size = (int)dis.readLong(); else size = (int)reverseLong(dis.readLong()); // read XML bytes if (size!= XMLSize) throw new IndexReadException("XML size mismatch"); byte[] XMLDoc = new byte[size]; XMLBytes.read(XMLDoc); vg.setDoc(XMLDoc); dis.readLong(); dis.readLong(); if (endian ==1){ // read vtd records int vtdSize = (int)dis.readLong(); while(vtdSize>0){ vg.VTDBuffer.append(dis.readLong()); vtdSize--; } // read L1 LC records int l1Size = (int)dis.readLong(); while(l1Size > 0){ long l = dis.readLong(); // System.out.println(" l-==> "+Long.toHexString(l)); vg.l1Buffer.append(l); l1Size--; } //System.out.println("++++++++++ "); // read L2 LC records int l2Size = (int)dis.readLong(); while(l2Size > 0){ vg.l2Buffer.append(dis.readLong()); l2Size--; } //System.out.println("++++++++++ "); // read L3 LC records int l3Size = (int)dis.readLong(); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(dis.readInt()); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer.append((int) (dis.readLong() >> 32)); l3Size--; } } } else { while (l3Size > 0) { vg._l3Buffer.append(dis.readLong()); l3Size--; } int l4Size = (int)dis.readLong(); while(l2Size > 0){ vg._l4Buffer.append(dis.readLong()); l4Size--; } int l5Size = (int)dis.readLong(); if (intLongSwitch == 1) { // l5 uses ints while(l2Size > 0){ vg._l5Buffer.append(dis.readInt()); l5Size--; } }else { while (l5Size > 0) { vg._l5Buffer.append((int) (dis.readLong() >> 32)); l5Size--; } } } } else { // read vtd records int vtdSize = (int)reverseLong(dis.readLong()); while(vtdSize>0){ vg.VTDBuffer.append(reverseLong(dis.readLong())); vtdSize--; } // read L1 LC records //System.out.println(" ++++++++++ "); int l1Size = (int)reverseLong(dis.readLong()); while(l1Size > 0){ long l = reverseLong(dis.readLong()); vg.l1Buffer.append(l); l1Size--; } //System.out.println(" ++++++++++ "); // read L2 LC records int l2Size = (int)reverseLong(dis.readLong()); while(l2Size > 0){ long l = reverseLong(dis.readLong()); //System.out.println(" l--=->"+Long.toHexString(l)); vg.l2Buffer.append(l); l2Size--; } //System.out.println(" ++++++++++ "); // read L3 LC records int l3Size = (int)reverseLong(dis.readLong()); if (vg.shallowDepth) { if (intLongSwitch == 1) { // l3 uses ints while (l3Size > 0) { vg.l3Buffer.append(reverseInt(dis.readInt())); l3Size--; } } else { while (l3Size > 0) { vg.l3Buffer .append(reverseInt((int) (dis.readLong() >> 32))); l3Size--; } } }else{ while (l3Size > 0) { vg._l3Buffer.append(reverseLong(dis.readLong())); l3Size--; } int l4Size = (int)reverseLong(dis.readLong()); while(l4Size > 0){ long l = reverseLong(dis.readLong()); vg._l4Buffer.append(l); l4Size--; } int l5Size = (int)reverseLong(dis.readLong()); if (intLongSwitch == 1) { // l5 uses ints while(l5Size > 0){ vg._l5Buffer.append(reverseInt(dis.readInt())); l5Size--; } }else { while (l5Size > 0) { vg._l5Buffer.append(reverseInt((int) (dis.readLong() >> 32))); l5Size--; } } } } } /** * reverse a long's endianess * @param l * @return * */ private static long reverseLong(long l){ long t = ((l & 0xff00000000000000L)>>>56) | ((l & 0xff000000000000L)>>40) | ((l & 0xff0000000000L)>>24) | ((l & 0xff00000000L)>>8) | ((l & 0xff000000L)<<8) | ((l & 0xff0000L)<<24) | ((l & 0xff00L)<<40) | ((l & 0xffL)<<56); //System.out.println(" t ==> "+Long.toHexString(l)); return t; } /** * reverse the endianess of an int * @param i * @return * */ private static int reverseInt(int i){ int t = ((i & 0xff000000) >>> 24) | ((i & 0xff0000) >> 8) | ((i & 0xff00) << 8) | ((i & 0xff) << 24); return t; } private static long adjust(long l, int i){ long l1 = (l & 0xffffffffL)+ i; long l2 = l & 0xffffffff00000000L; return l1|l2; } }
37,901
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FilterExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FilterExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import com.ximpleware.xpath.Predicate; /** * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class FilterExpr extends Expr { public Expr e; public Predicate p; //FastIntBuffer fib; //int stackSize; boolean first_time; public boolean out_of_range; //public int position; public FilterExpr(Expr l, Predicate pr){ e = l; p = pr; //cacheable =false; //stackSize = 0; //position = 1; //fib = new FastIntBuffer(8); first_time = true; out_of_range=false; pr.fe=this; } /*public int getPositon(){ return fib.size(); }*/ final public boolean evalBoolean(VTDNav vn) { //if (e.isBoolean()) // return e.evalBoolean(vn); boolean a = false; vn.push2(); //record stack size int size = vn.contextStack2.size; try{ a = (evalNodeSet(vn) != -1); }catch (Exception e){ } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; } final public double evalNumber(VTDNav vn) { //String s = ""; double d = Double.NaN; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a+1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t ==VTDNav.TOKEN_DOCUMENT) { String s = vn.getXPathStringVal(); d = Double.parseDouble(s); }else if (t == VTDNav.TOKEN_PI_NAME) { if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL) //s = vn.toString(a+1); d = vn.parseDouble(a+1); }else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; } final public int evalNodeSet(VTDNav vn) throws XPathEvalException, NavException { // if tne predicate require context size // needs to precompute the context size // vn.push2(); // computerContext(); // set contxt(); // vn.pop2() // if the context size is zero // get immediately set teh state to end // or backward if (first_time && p.requireContext){ first_time = false; int i = 0; //vn.push2(); e.adjust(vn.getTokenCount()); while(e.evalNodeSet(vn)!=-1) i++; //vn.pop2(); p.setContextSize(i); reset2(vn); } if(out_of_range) return -1; int a = e.evalNodeSet(vn); while (a!=-1){ if (p.eval(vn)==true){ //p.reset(); return a; }else { //p.reset(); a = e.evalNodeSet(vn); } } return -1; } final public String evalString(VTDNav vn) { String s = ""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch(t){ case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; } final public void reset(VTDNav vn) { reset2(vn); //vn.contextStack2.size = stackSize; //position = 1; first_time = true; /*cached = false; if (cachedNodeSet != null){ cachedNodeSet.clear(); }*/ } final public void reset2(VTDNav vn){ out_of_range=false; e.reset(vn); p.reset(vn); //fib.clear(); } final public String toString() { return "("+e+") "+p; } final public boolean isNumerical() { return false; } final public boolean isNodeSet() { return true; } /*public boolean isUnique(int i){ int size = fib.size(); for (int j=0; j<size;j++){ if (i == fib.intAt(j)) return false; } fib.append(i); return true; }*/ final public boolean isString(){ return false; } final public boolean isBoolean(){ return false; } // to support computer context size // needs to add final public boolean requireContextSize(){ return false; } final public void setContextSize(int size){ } final public void setPosition(int pos){ } final public int adjust(int n){ return e.adjust(n); //p.adjust(n); } final public boolean isFinal(){ return e.isFinal(); } final public void markCacheable2(){ e.markCacheable2(); if (p.expr!=null){ if (p.expr.isFinal()&&p.expr.isNodeSet()){ CachedExpr ce = new CachedExpr(p.expr); p.expr = ce; } p.expr.markCacheable2(); } } final public void markCacheable(){ e.markCacheable(); if (p.expr!=null){ if (p.expr.isFinal()&&p.expr.isNodeSet()){ CachedExpr ce = new CachedExpr(p.expr); p.expr = ce; } p.expr.markCacheable2(); } } final public void clearCache(){ e.clearCache(); if (p.expr!=null){ p.expr.clearCache(); } } }
6,594
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ParseException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/ParseException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * This class is for any exception condition in the parsing phase. * Creation date: (11/19/03 11:43:03 AM) */ public class ParseException extends VTDException { /** * ParseException constructor comment. */ public ParseException() { super(); } /** * ParseException constructor comment. * @param s java.lang.String */ public ParseException(String s) { super(s); } }
1,224
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XMLByteOutputStream.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/XMLByteOutputStream.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.IOException; import java.io.OutputStream; public class XMLByteOutputStream extends OutputStream { private byte[] XMLDoc; private int offset=0; final public byte[] getXML(){ return XMLDoc; } @Override public void write(int b) throws IOException { // TODO Auto-generated method stub // not yet implemented XMLDoc[offset]= (byte)b; offset++; } public void write(byte[] ba) throws IOException{ if (ba.length+offset>XMLDoc.length) throw new IOException("XMLDoc size exceeds maximum size"); System.arraycopy(ba, 0, XMLDoc, offset, ba.length); offset+=ba.length; } public void write(byte[] ba, int os, int len) throws IOException{ if (len+offset>XMLDoc.length) throw new IOException("XMLDoc size exceeds maximum size"); System.arraycopy(ba, os, XMLDoc, offset, len); offset +=len; } public void close(){ offset = 0; } public XMLByteOutputStream(int size){ XMLDoc = new byte[size]; offset =0; } public String toString(){ StringBuilder sb = new StringBuilder(XMLDoc.length); for(int i=0;i<XMLDoc.length;i++) //sb.charAt(i) = XMLDoc[i]; sb.append((char) XMLDoc[i]); //sb.setCharAt(i,(char) XMLDoc[i] ); return sb.toString(); } }
2,102
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XMLModifier.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/XMLModifier.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.io.*; import com.ximpleware.transcode.*; /** * XMLModifier offers an easy-to-use interface for users to * take advantage of the incremental update of VTD-XML * The XML modifier assumes there is a master document on which * the modification is applied: users can remove an element, update * a token, replace an element name, or insert new content anywhere in the document * transcoding methods are built-in * * The process: * * The modification operations are recorded first * * The output() is called to generate output document * */ public class XMLModifier { protected VTDNav md; // master document private static final long MASK_DELETE = 0x00000000000000000L; //0000 private static final long MASK_INSERT_SEGMENT_BYTE = 0x2000000000000000L; //0010 private static final long MASK_INSERT_BYTE = 0x4000000000000000L;//0100 private static final long MASK_INSERT_SEGMENT_BYTE_ENCLOSED = 0x6000000000000000L; //0110 private static final long MASK_INSERT_BYTE_ENCLOSED = 0x8000000000000000L; //1000 private static final long MASK_INSERT_FRAGMENT_NS = 0xa000000000000000L; //1010 private static final long MASK_INSERT_FRAGMENT_NS_ENCLOSED = 0xe000000000000000L; //1110 private static final long MASK_NULL = 0xc000000000000000L; //1100 private static final byte[] ba1 = {0x3e,0}; private static final byte[] ba2 = {0x3c,0}; private static final byte[] ba3 = {0,0x3e}; private static final byte[] ba4 = {0,0x3c}; protected FastObjectBuffer fob; protected FastLongBuffer flb; protected intHash deleteHash; // one deletion per offset val protected intHash insertHash; // one insert per offset val protected String charSet; int encoding; public class ByteSegment{ byte[] ba; int offset; int len; } /** * Constructor for XMLModifier that takes VTDNav object as the master document * @param masterDocument is the document on which the modification is applied */ public XMLModifier(VTDNav masterDocument) throws ModifyException{ bind(masterDocument); } /** * Argument-less constructor for XMLModifier, * needs to call bind to attach the master document to an instance * of XMLModifier * */ public XMLModifier(){ md = null; } /** * Attach master document to this instance of XMLModifier * so all the operations occuring aftewards are based on this instance * of VTDNav * @param masterDocument * */ public void bind(VTDNav masterDocument) throws ModifyException{ if (masterDocument == null) throw new IllegalArgumentException("MasterDocument can't be null"); md = masterDocument; flb = new FastLongBuffer(); fob = new FastObjectBuffer(); int i = intHash.determineHashWidth(md.vtdSize); insertHash = new intHash(i); deleteHash = new intHash(i); //determine encoding charset string here encoding = md.getEncoding(); switch(encoding){ case VTDNav.FORMAT_ASCII: charSet = "ASCII"; break; case VTDNav.FORMAT_ISO_8859_1: charSet = "ISO8859_1"; break; case VTDNav.FORMAT_UTF8: charSet = "UTF8"; break; case VTDNav.FORMAT_UTF_16BE: charSet = "UnicodeBigUnmarked"; break; case VTDNav.FORMAT_UTF_16LE: charSet = "UnicodeLittleUnmarked"; break; case VTDNav.FORMAT_ISO_8859_2: charSet = "ISO8859_2"; break; case VTDNav.FORMAT_ISO_8859_3: charSet = "ISO8859_3"; break; case VTDNav.FORMAT_ISO_8859_4: charSet = "ISO8859_4"; break; case VTDNav.FORMAT_ISO_8859_5: charSet = "ISO8859_5"; break; case VTDNav.FORMAT_ISO_8859_6: charSet = "ISO8859_6"; break; case VTDNav.FORMAT_ISO_8859_7: charSet = "ISO8859_7"; break; case VTDNav.FORMAT_ISO_8859_8: charSet = "ISO8859_8"; break; case VTDNav.FORMAT_ISO_8859_9: charSet = "ISO8859_9"; break; case VTDNav.FORMAT_ISO_8859_10: charSet = "ISO8859_10"; break; case VTDNav.FORMAT_ISO_8859_11: charSet = "x-iso-8859-11"; break; case VTDNav.FORMAT_ISO_8859_12: charSet = "ISO8859_12"; break; case VTDNav.FORMAT_ISO_8859_13: charSet = "ISO8859_13"; break; case VTDNav.FORMAT_ISO_8859_14: charSet = "ISO8859_14"; break; case VTDNav.FORMAT_ISO_8859_15: charSet = "ISO8859_15"; break; case VTDNav.FORMAT_WIN_1250: charSet = "Cp1250"; break; case VTDNav.FORMAT_WIN_1251: charSet = "Cp1251"; break; case VTDNav.FORMAT_WIN_1252: charSet = "Cp1252"; break; case VTDNav.FORMAT_WIN_1253: charSet = "Cp1253"; break; case VTDNav.FORMAT_WIN_1254: charSet = "Cp1254"; break; case VTDNav.FORMAT_WIN_1255: charSet = "Cp1255"; break; case VTDNav.FORMAT_WIN_1256: charSet = "Cp1256"; break; case VTDNav.FORMAT_WIN_1257: charSet = "Cp1257"; break; case VTDNav.FORMAT_WIN_1258: charSet = "Cp1258"; break; default: throw new ModifyException ("Master document encoding not yet supported by XML modifier"); } } /** * Removes content from the master XML document * It first calls getCurrentIndex() if the result is * a starting tag, then the entire element referred to * by the starting tag is removed * If the result is an attribute name or ns node, then * the corresponding attribute name/value pair is removed * If the token type is one of text, CDATA or commment, * then the entire node, including the starting and ending * delimiting text surrounding the content, is removed * */ public void remove() throws NavException,ModifyException{ int i = md.getCurrentIndex(); int type = md.getTokenType(i); if (type==VTDNav.TOKEN_STARTING_TAG){ long l = md.getElementFragment(); removeContent((int)l, (int)(l>>32)); } else if (type == VTDNav.TOKEN_ATTR_NAME || type==VTDNav.TOKEN_ATTR_NS){ removeAttribute(i); } else { removeToken(i); } } /** * Remove a byte segment from XML. * l's upper 32 bits is length in # of bytes * l's lower 32 bits is byte offset * @param l * @throws NavException * @throws ModifyException * */ public void remove(long l) throws NavException,ModifyException{ removeContent((int)l, (int)(l>>32)); } /** * Remove the token content. If the token type is text, CDATA * or comment, then the entire node, including the starting and * ending delimiting text, will be removed as well * @param i the index for the content * */ public void removeToken(int i) throws ModifyException{ int type = md.getTokenType(i); int os = md.getTokenOffset(i); //int len = md.getTokenLength(i)&0xffff; int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md.getTokenLength(i) & 0xffff : md.getTokenLength(i); switch(type){ case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os - 9, len + 12 ); else removeContent((os - 9)<<1,(len+12)<<1); return; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os-4, len+7); else removeContent((os-4) << 1, (len+7) << 1); return; default: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os, len); else removeContent((os) << 1, (len) << 1); return; } } /** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); } /** * Remove a segment of byte content from master XML doc. * The segment is denoted by its offset and len. * @param offset * @param len * */ public void removeContent(int offset, int len) throws ModifyException{ if (offset < md.docOffset || len > md.docLen || offset + len > md.docOffset + md.docLen){ throw new ModifyException("Invalid offset or length for removeContent"); } if (deleteHash.isUnique(offset)==false) throw new ModifyException("There can be only one deletion per offset value"); while(len > (1<<29)-1){ flb.append(((long)((1<<29)-1))<<32 | offset | MASK_DELETE); fob.append((Object)null); len -= (1<<29)-1; offset += (1<<29)-1; } flb.append(((long)len)<<32 | offset | MASK_DELETE); fob.append((Object)null); } /** * insert the byte content into XML and surround it with ">" and "<" * @param offset (in char, not byte) * @param content * */ private void insertBytesEnclosedAt(int offset, byte[] content) throws ModifyException{ if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } flb.append( (long)offset | MASK_INSERT_BYTE_ENCLOSED); fob.append(content); } /** * insert the byte content into XML * @param offset (in char, not byte) * @param content * */ public void insertBytesAt(int offset, byte[] content) throws ModifyException{ if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } flb.append( (long)offset | MASK_INSERT_BYTE); fob.append(content); } /** * Insert ns compensated element fragment into the document * @param ef * */ private void insertElementFragmentNsAt(int offset, ElementFragmentNs ef) throws ModifyException{ if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } flb.append((long)offset | MASK_INSERT_FRAGMENT_NS); fob.append(ef); } private void insertElementFragmentNsEnclosedAt(int offset, ElementFragmentNs ef) throws ModifyException{ if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } flb.append((long)offset | MASK_INSERT_FRAGMENT_NS_ENCLOSED); fob.append(ef); } /** * Insert a segment of the byte content into XML * @param offset * @param content * @param contentOffset * @param contentLen * @throws ModifyException * */ public void insertBytesAt(int offset, byte[] content, int contentOffset, int contentLen) throws ModifyException { if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } if (contentOffset < 0 || contentLen <0 || contentOffset+contentLen > content.length){ throw new ModifyException("Invalid contentOffset and/or contentLen"); } flb.append( (long)offset | MASK_INSERT_SEGMENT_BYTE); ByteSegment bs = new ByteSegment(); bs.ba = content; bs.len = contentLen; bs.offset = contentOffset; fob.append(bs); } /** * * @param offset * @param content * @param contentOffset * @param contentLen * @throws ModifyException */ private void insertBytesEnclosedAt(int offset, byte[] content, int contentOffset, int contentLen) throws ModifyException { if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } if (contentOffset < 0 || contentLen <0 || contentOffset+contentLen > content.length){ throw new ModifyException("Invalid contentOffset and/or contentLen"); } flb.append( (long)offset | MASK_INSERT_SEGMENT_BYTE_ENCLOSED); ByteSegment bs = new ByteSegment(); bs.ba = content; bs.len = contentLen; bs.offset = contentOffset; fob.append(bs); } /** * Insert a segment of content into XML * l (a long)'s upper 32 bit is length, lower 32 bit is offset * @param offset * @param content * @param l * @throws ModifyException * */ private void insertBytesAt(int offset, byte[] content, long l) throws ModifyException { if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } int contentOffset = (int)l; int contentLen = (int)(l>>32); if (contentOffset < 0 || contentLen <0 || contentOffset+contentLen > content.length){ throw new ModifyException("Invalid contentOffset and/or contentLen"); } flb.append( (long)offset | MASK_INSERT_SEGMENT_BYTE); ByteSegment bs = new ByteSegment(); bs.ba = content; bs.len = contentLen; bs.offset = contentOffset; fob.append(bs); } private void insertBytesEnclosedAt(int offset, byte[] content, long l) throws ModifyException { if (insertHash.isUnique(offset)==false){ throw new ModifyException("There can be only one insert per offset"); } int contentOffset = (int)l; int contentLen = (int)(l>>32); if (contentOffset < 0 || contentLen <0 || contentOffset+contentLen > content.length){ throw new ModifyException("Invalid contentOffset and/or contentLen"); } flb.append( (long)offset | MASK_INSERT_SEGMENT_BYTE_ENCLOSED); ByteSegment bs = new ByteSegment(); bs.ba = content; bs.len = contentLen; bs.offset = contentOffset; fob.append(bs); } /** * Update the token with the given byte array content, * @param index * @param newContentBytes * @throws ModifyException * @throws UnsupportedEncodingException * */ public void updateToken(int index, byte[] newContentBytes) throws ModifyException,UnsupportedEncodingException{ if (newContentBytes==null) throw new IllegalArgumentException ("newContentBytes can't be null"); int offset = md.getTokenOffset(index); int type = md.getTokenType(index); /*int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md.getTokenLength(index) & 0xffff : md.getTokenLength(index);*/ // one insert switch(type){ case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-9,newContentBytes); else insertBytesAt((offset-9)>>1,newContentBytes); break; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-4,newContentBytes); else insertBytesAt((offset-4)>>1,newContentBytes); break; default: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,newContentBytes); else insertBytesAt(offset<<1,newContentBytes); } // one delete removeToken(index); } /** * Update the token with the transcoded representation of * given byte array content, * @param index * @param newContentBytes * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, byte[] newContentBytes, int src_encoding) throws ModifyException,UnsupportedEncodingException,TranscodeException{ if (src_encoding == encoding){ updateToken(index,newContentBytes); return; } if (newContentBytes==null) throw new IllegalArgumentException ("newContentBytes can't be null"); int offset = md.getTokenOffset(index); int type = md.getTokenType(index); /*int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md.getTokenLength(index) & 0xffff : md.getTokenLength(index);*/ // one insert byte[] bo = Transcoder.transcode(newContentBytes,0, newContentBytes.length,src_encoding,encoding); switch(type){ case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-9, bo); else insertBytesAt((offset-9)>>1, bo); break; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-4, bo); else insertBytesAt((offset-4)>>1, bo); break; default: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt(offset<<1, bo); } // one delete removeToken(index); } /** * Update token with a segment of byte array (in terms of offset and length) * @param index * @param newContentBytes * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * */ public void updateToken(int index, byte[] newContentBytes, int contentOffset, int contentLen) throws ModifyException,UnsupportedEncodingException{ if (newContentBytes==null) throw new IllegalArgumentException ("newContentBytes can't be null"); int offset = md.getTokenOffset(index); //int len = md.getTokenLength(index); int type = md.getTokenType(index); /*int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md.getTokenLength(index) & 0xffff : md.getTokenLength(index);*/ // one insert switch(type){ case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-9,newContentBytes,contentOffset, contentLen); else insertBytesAt((offset-9)<<1,newContentBytes,contentOffset, contentLen); break; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-4,newContentBytes,contentOffset, contentLen); else insertBytesAt((offset-4)<<1,newContentBytes,contentOffset, contentLen); break; default: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,newContentBytes,contentOffset, contentLen); else insertBytesAt(offset<<1,newContentBytes,contentOffset, contentLen); } // one delete removeToken(index); } /** * Update token with the transcoded representation of * a segment of byte array (in terms of offset and length) * @param index * @param newContentBytes * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, byte[] newContentBytes, int contentOffset, int contentLen, int src_encoding) throws ModifyException,UnsupportedEncodingException, TranscodeException{ if (src_encoding == encoding) { updateToken(index, newContentBytes, contentOffset, contentLen); return; } if (newContentBytes == null) throw new IllegalArgumentException("newContentBytes can't be null"); int offset = md.getTokenOffset(index); //int len = md.getTokenLength(index); int type = md.getTokenType(index); /*int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md .getTokenLength(index) & 0xffff : md.getTokenLength(index);*/ // one insert byte[] bo = Transcoder.transcode(newContentBytes,contentOffset, contentLen, src_encoding, encoding); switch (type) { case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset - 9, bo); else insertBytesAt((offset - 9) << 1, bo); break; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset - 4, bo); else insertBytesAt((offset - 4) << 1, bo); break; default: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt(offset << 1, bo); } // one delete removeToken(index); } /** * Update token with the transcoded representation of * a segment of byte array contained in vn (in terms of offset and length) * @param index * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, VTDNav vn, int contentOffset, int contentLen) throws ModifyException,UnsupportedEncodingException, TranscodeException{ updateToken(index, vn.XMLDoc.getBytes(), contentOffset, contentLen, vn.encoding); } /** * Update the token with the given string value, * notice that string will be converted into byte array * according to the encoding of the master document * @param index * @param newContent * @throws ModifyException * @throws UnsupportedEncodingException * */ public void updateToken(int index, String newContent) throws ModifyException,UnsupportedEncodingException{ if (newContent==null) throw new IllegalArgumentException ("String newContent can't be null"); int offset = md.getTokenOffset(index); //int len = md.getTokenLength(index); int type = md.getTokenType(index); /*int len = (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) ? md.getTokenLength(index) & 0xffff : md.getTokenLength(index);*/ // one insert switch(type){ case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-9,newContent.getBytes(charSet)); else insertBytesAt((offset-9)<<1,newContent.getBytes(charSet)); break; case VTDNav.TOKEN_COMMENT: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset-4,newContent.getBytes(charSet)); else insertBytesAt((offset-4)<<1,newContent.getBytes(charSet)); break; default: if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,newContent.getBytes(charSet)); else insertBytesAt(offset<<1,newContent.getBytes(charSet)); } // one delete removeToken(index); } /** * * * */ protected void sort(){ if (flb.size>0) quickSort(0,flb.size-1); } /** * * This function will do the range checking and make * sure there is no overlapping or invalid deletion * There can be only one deletion at one offset value * Delete can't overlap with, nor contains, another delete * */ protected void check() throws ModifyException{ int os1, os2, temp; int size = flb.size; for (int i=0;i<size;i++){ os1 = flb.lower32At(i); os2 = flb.lower32At(i)+ (flb.upper32At(i)& 0x1fffffff)-1; if (i+1<size){ temp = flb.lower32At(i+1); if (temp!= os1 && temp<=os2) throw new ModifyException ("Invalid insertion/deletion condition detected between offset " +os1 + " and offset "+os2); } } } protected void check2() throws ModifyException{ int os1, os2, temp; int size = flb.size; for (int i=0;i<size;){ os1 = flb.lower32At(i); os2 = flb.lower32At(i)+ (flb.upper32At(i)& 0x1fffffff)-1; int z=1; while (i + z < size) { temp = flb.lower32At(i+z); if (temp==os1){ if ((flb.upper32At(i+z)& 0x1fffffff)!=0) // not an insert os2=flb.lower32At(i+z)+ (flb.upper32At(i+z)& 0x1fffffff)-1; z++; } else if (temp > os1 && temp <= os2) { int k= flb.lower32At(i+z)+ (flb.upper32At(i+z)& 0x1fffffff)-1; if (k>os2) // take care of overlapping conditions throw new ModifyException ("Invalid insertion/deletion condition detected between offset " +os1 + " and offset "+os2); else flb.modifyEntry(i+z,(flb.longAt(i+z)& 0x1fffffffffffffffL)|MASK_NULL); //System.out.println(" hex ==> "+Long.toHexString(flb.longAt(k+z))); z++; } else break; } i+=z; } } /** * Compute the size of the updated XML document without composing it * @return updated document size * */ public int getUpdatedDocumentSize() throws ModifyException,TranscodeException{ int size = flb.size; int docSize = md.getXML().getBytes().length; int inc = (md.encoding<VTDNav.FORMAT_UTF_16BE)?2:4; long l; sort(); check2(); for (int i=0;i<size;i++){ l= flb.longAt(i); if ((l & (~0x1fffffffffffffffL)) == MASK_DELETE) { docSize -= (int) ((l & (0x1fffffffffffffffL))>> 32); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE){ docSize += ((byte[])fob.objectAt(i)).length; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE){ // MASK_INSERT_SEGMENT_BYTE docSize += ((ByteSegment)fob.objectAt(i)).len; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS) { docSize += ((ElementFragmentNs)fob.objectAt(i)).getSize(md.encoding); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE_ENCLOSED){ docSize += ((byte[])fob.objectAt(i)).length+inc; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE_ENCLOSED){ docSize += ((ByteSegment)fob.objectAt(i)).len+inc; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS_ENCLOSED) { docSize += ((ElementFragmentNs)fob.objectAt(i)).getSize(md.encoding)+inc; } } return docSize; } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte array b after the element * @param b * @throws ModifyException * @throws NavException * */ public void insertAfterElement(byte[] b) throws ModifyException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,b); } /** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); } /*private byte[] getEnclosedBytes(byte[] ba) { byte[] out; if (md.encoding<VTDNav.FORMAT_UTF_16BE){ out = new byte[ba.length+2]; out[0]=(byte)'>'; out[out.length-1]='<'; System.arraycopy(ba, 0, out, 1, ba.length); return out; }else if (md.encoding == VTDNav.FORMAT_UTF_16BE){ out = new byte[ba.length+4]; out[1]=(byte)'>'; out[out.length-1]='<'; }else{ out = new byte[ba.length+4]; out[0]=(byte)'>'; out[out.length-2]='<'; } System.arraycopy(ba, 0, out, 2, ba.length); return out; }*/ /*private byte[] getEnclosedBytes(byte[] ba, int offset, int length) { byte[] out; if (md.encoding<VTDNav.FORMAT_UTF_16BE){ out = new byte[length+2]; out[0]=(byte)'>'; out[out.length-1]='<'; System.arraycopy(ba, 0, out, 1, ba.length); return out; }else if (md.encoding == VTDNav.FORMAT_UTF_16BE){ out = new byte[length+4]; out[1]=(byte)'>'; out[out.length-1]='<'; }else{ out = new byte[length+4]; out[0]=(byte)'>'; out[out.length-2]='<'; } System.arraycopy(ba, 0, out, offset, length); return out; }*/ /** * This method will insert byte array b after the head of cursor element, * @param b * @return * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertBytesEnclosedAt((int)i-1,b); insertEndingTag(i); return; } insertBytesAt((int)i,b); } /** * This method will insert byte array b right before the tail of cursor element, * @param b * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b) throws ModifyException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(b); return; } insertBytesAt((int)i,b); } /** * This method will insert byte content of string right before the tail of cursor element, * @param s * @throws ModifyException * @throws NavException */ public void insertBeforeTail(String s) throws ModifyException,UnsupportedEncodingException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(s.getBytes(charSet)); return; } insertBytesAt((int)i,s.getBytes()); } /** * This method will insert the transcoded representation of byte array b right before the tail of cursor element, * @param src_encoding * @param b * @throws ModifyException * @throws NavException * @throws TranscodeException */ public void insertBeforeTail(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertBeforeTail(b); }else{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(src_encoding,b); return; } byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt((int)i,bo); } } /** * This method will insert the transcoded representation of a segment of byte array b right before the tail of cursor element, * @param src_encoding * @param b * @param offset * @param length * @throws ModifyException * @throws NavException * @throws TranscodeException */ public void insertBeforeTail(int src_encoding, byte[] b, int offset, int length) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterHead(b,offset,length); }else{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(src_encoding,b,offset, length); return; } byte[] bo = Transcoder.transcode(b, offset, length, src_encoding, encoding); insertBytesAt((int)i,bo,offset, length); } } /** * This method will insert a segment of the byte array (contained in vn, and * transcode into a byte array) before the tail of cursor element, * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * @throws TranscodeException */ public void insertBeforeTail(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { insertBeforeTail(vn.XMLDoc.getBytes(),contentOffset, contentLen); } /** * This method will insert the transcoded representation of a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param src_encoding * @param b * @param l * @throws ModifyException * @throws NavException * @throws TranscodeException */ public void insertBeforeTail(int src_encoding, byte[] b, long l) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertBeforeTail(b,l); }else{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(src_encoding,b,l); return; } byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt((int)i,bo,l); } } /** * This method will insert a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b,l); return; } insertBytesAt((int)i,b,l); } /** * This method will insert a namespace compensated fragment before the tail of cursor element, * @param ef * @throws ModifyException * @throws NavException */ public void insertBeforeTail(ElementFragmentNs ef) throws ModifyException, NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(ef); return; } insertElementFragmentNsAt((int)i, ef); } /** * This method will insert a segment of the byte array (contained in vn, and * transcode into a byte array) before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * * @param vn * @param l1 * @throws ModifyException * @throws NavException * @throws TranscodeException */ public void insertBeforeTail(VTDNav vn, long l1) throws ModifyException, NavException, TranscodeException { insertBeforeTail(vn.encoding, vn.XMLDoc.getBytes(), l1); } /** * This method will insert a segment of the byte array before the tail of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b, offset, len); return; } insertBytesAt((int)i,b,offset, len); } /** * This method will insert the transcoded representation of * byte array b after the head of cursor element, * @param src_encoding * @param b * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterHead(b); }else{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesEnclosedAt((int)i-1,bo); insertEndingTag(i); return; } byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt((int)i,bo); } } /** * This method will insert the transcoded representation of * a segment of the byte array b after the head of cursor element, * @param src_encoding * @param b * @param offset * @param length * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(int src_encoding, byte[] b, int offset, int length) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterHead(b,offset,length); }else{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); byte[] bo = Transcoder.transcode(b, offset, length, src_encoding, encoding); insertBytesEnclosedAt((int)i-1,bo); insertEndingTag(i); return; } byte[] bo = Transcoder.transcode(b, offset, length, src_encoding, encoding); insertBytesAt((int)i,bo,offset, length); } } /** * This method will insert the transcoded representation of * a segment of the byte array b after the head of cursor element, * @param src_encoding * @param b * @param l * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(int src_encoding, byte[] b, long l) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterHead(b,l); }else{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesEnclosedAt((int)i-1,bo,l); insertEndingTag(i); return; } byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt((int)i,bo,l); } } /** * This method will insert s' byte array representation * of the string after the head of cursor element, * @param s * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(String s) throws ModifyException, UnsupportedEncodingException, NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,s.getBytes(charSet)); insertEndingTag(i); return; } insertBytesAt((int)i,s.getBytes(charSet)); } /** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param contentOffset in byte * @param contentLen in byte * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { insertAfterHead(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); } /** * This method will insert a segment of the byte array b after the head of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,b, offset,len ); insertEndingTag(i); return; } insertBytesAt((int)i,b,offset, len); } /** * This method will insert a segment of the byte array b after the head of cursor element * @param b * @param l * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,b, (int)l,(int)(l<<32)); insertEndingTag(i); return; } insertBytesAt((int)i,b,l); } /** * This method will insert an ElementFragmentNs instance * after the head of cursor element, * @param efn * @throws ModifyException * @throws NavException * */ public void insertAfterHead(ElementFragmentNs ef) throws ModifyException, NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertElementFragmentNsEnclosedAt((int)i-1, ef); insertEndingTag(i); return; } insertElementFragmentNsAt((int)i, ef); } /** * Insert a namespace compensated element after cursor element * @param ef (an ElementFragmentNs object) * @throws ModifyException * @throws NavException * */ public void insertAfterElement(ElementFragmentNs ef) throws ModifyException, NavException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); insertElementFragmentNsAt(offset + len, ef); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * */ public void insertAfterElement(byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); insertBytesAt(offset + len, b, contentOffset, contentLen); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { if (src_encoding == encoding) { insertAfterElement(b,contentOffset,contentLen); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); // transcode in here byte[] bo = Transcoder.transcode(b, contentOffset, contentLen, src_encoding, encoding); insertBytesAt(offset + len, bo); } } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * the VTDNav object is the container of the XML document in byte array * * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, NavException,TranscodeException { insertAfterElement(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * */ public void insertAfterElement(byte[] b, long l1) throws ModifyException,NavException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); insertBytesAt(offset + len, b, l1); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { if (src_encoding == encoding){ insertAfterElement(b,l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt(offset + len, bo, l1); } } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { insertAfterElement(vn.encoding, vn.XMLDoc.getBytes(), l1); } /** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param l1 * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, long l1) throws ModifyException, NavException, TranscodeException { insertAfterHead(vn.encoding, vn.XMLDoc.getBytes(), l1); } /** * Insert a byte array of given encoding into the master document * transcoding is done underneath to ensure the correctness of output * @param encoding The encoding format of the byte array * @param b * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterElement(b); } else { int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); // transcoding logic byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt(offset+len,bo); } } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s after the element * @param s the string whose byte content will be inserted into the master document * */ public void insertAfterElement(String s) throws ModifyException,UnsupportedEncodingException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,s.getBytes(charSet)); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * */ public void insertBeforeElement(byte[] b) throws ModifyException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,b); else insertBytesAt((offset)<<1,b); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representatin of the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b) throws ModifyException,TranscodeException{ if (src_encoding == md.encoding) { insertBeforeElement(b); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b,0,b.length,src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt((offset) << 1, bo); } } /** * Insert a namespace compensated fragment before the cursor element * @param ef * @throws ModifyException * * */ public void insertBeforeElement(ElementFragmentNs ef) throws ModifyException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertElementFragmentNsAt(offset,ef); else insertElementFragmentNsAt((offset)<<1,ef); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b before the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * */ public void insertBeforeElement(byte[] b,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, b, contentOffset, contentLen); else insertBytesAt((offset) << 1, b, contentOffset, contentLen); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array b * before the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, TranscodeException { if (src_encoding == encoding) { insertBeforeElement(b,contentOffset, contentLen); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; // do transcoding here byte[] bo = Transcoder.transcode(b,contentOffset,contentLen,src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt((offset) << 1, bo); } } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained * in vn before the element * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),contentOffset, contentLen); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * */ public void insertBeforeElement(byte[] b, long l1) throws ModifyException, UnsupportedEncodingException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, b, l1); else insertBytesAt((offset) << 1, b, l1); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array b before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, TranscodeException { if (src_encoding == md.encoding) { insertBeforeElement(b, l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b, (int)l1, (int)(l1>>32),src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo ); else insertBytesAt((offset) << 1, bo); } } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained in * vn before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn, long l) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),l); } /** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s before the element * @param s * */ public void insertBeforeElement(String s) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,s.getBytes(charSet)); else insertBytesAt((offset)<<1,s.getBytes(charSet)); } /** * Insert an attribute after the starting tag * This method will first call getCurrentIndex() to get the cursor index value * if the index is of type "starting tag", then the attribute is inserted * after the starting tag * @param attr e.g. " attrName='attrVal' ",notice the starting and ending * white space * */ public void insertAttribute(String attr) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex); int len = md.getTokenLength(startTagIndex)&0xffff; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset+len,attr.getBytes(charSet)); else insertBytesAt((offset+len)<<1,attr.getBytes(charSet)); //insertBytesAt() } /** * Insert a byte arry of an attribute after the starting tag * This method will first call getCurrentIndex() to get the cursor index value * if the index is of type "starting tag", then teh attribute is inserted * after the starting tag * @param b the byte content of e.g. " attrName='attrVal' ",notice the starting and ending * white space * */ public void insertAttribute(byte[] b) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex); int len = md.getTokenLength(startTagIndex) & 0xffff; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset+len,b); else insertBytesAt((offset+len)<<1,b); //insertBytesAt() } /** * Insert the transcoded representation of a byte arry of an attribute * after the starting tag This method will first call getCurrentIndex() * to get the cursor index value if the index is of type "starting tag", * then teh attribute is inserted after the starting tag * @param b the byte content of e.g. " attrName='attrVal' ",notice the * starting and ending white space * */ public void insertAttribute(int src_encoding, byte[] b) throws ModifyException,UnsupportedEncodingException,TranscodeException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex); int len = md.getTokenLength(startTagIndex)&0xffff; byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset+len,bo); else insertBytesAt((offset+len)<<1,bo); //insertBytesAt() } /** * This method applies the modification to the XML document * and writes the output byte content accordingly to an outputStream * Notice that output is not guaranteed to be well-formed * @param os * */ public void output(OutputStream os) throws IOException, ModifyException, TranscodeException { if (os == null) throw new IllegalArgumentException("OutputStream can't be null"); sort(); check2(); long l; byte[] ba = md.getXML().getBytes(); // for(int i=0;i<flb.size();i++){ // System.out.println(" offset value is ==>"+flb.lower32At(i)); // } int t = md.vtdBuffer.lower32At(0); int start = (t == 0) ? md.docOffset : 32; int len = (t == 0) ? md.docLen : (md.docLen - 32); if (flb.size == 0) { os.write(ba, start, len); } else if (md.encoding < VTDNav.FORMAT_UTF_16BE) { int offset = start; int inc = 1; for (int i = 0; i < flb.size; i = i + inc) { if (i + 1 == flb.size) { inc = 1; } else if (flb.lower32At(i) == flb.lower32At(i + 1)) { inc = 2; } else inc = 1; /* * if (i==1021){ System.out.println("inc ==> "+ inc); * System.out.println(" i ==> "+i); } */ l = flb.longAt(i); if (inc == 1) { if ((l & (~0x1fffffffffffffffL)) == MASK_DELETE) { os.write(ba, offset, flb.lower32At(i) - offset); offset = flb.lower32At(i) + (flb.upper32At(i) & 0x1fffffff); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE) { // insert os.write(ba, offset, flb.lower32At(i) - offset); os.write((byte[]) fob.objectAt(i)); offset = flb.lower32At(i); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE) { // XML_INSERT_SEGMENT_BYTE os.write(ba, offset, flb.lower32At(i) - offset); ByteSegment bs = (ByteSegment) fob.objectAt(i); os.write(bs.ba, bs.offset, bs.len); offset = flb.lower32At(i); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS) { // ElementFragmentNs os.write(ba, offset, flb.lower32At(i) - offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i); ef.writeToOutputStream(os, md.encoding); offset = flb.lower32At(i); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE_ENCLOSED) { // insert os.write(ba, offset, flb.lower32At(i) - offset); os.write(0x3e); os.write((byte[]) fob.objectAt(i)); os.write(0x3c); offset = flb.lower32At(i); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE_ENCLOSED) { // XML_INSERT_SEGMENT_BYTE os.write(ba, offset, flb.lower32At(i) - offset); ByteSegment bs = (ByteSegment) fob.objectAt(i); os.write(0x3e); os.write(bs.ba, bs.offset, bs.len); os.write(0x3c); offset = flb.lower32At(i); } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS_ENCLOSED) { // ElementFragmentNs os.write(ba, offset, flb.lower32At(i) - offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i); os.write(0x3e); ef.writeToOutputStream(os, md.encoding); os.write(0x3c); offset = flb.lower32At(i); } } else { // share the same offset value one insert, one delete // to make sure that l's offset val is >= k's // also to make sure that the first token is a delete long k = flb.longAt(i + 1), temp; int i1 = i, temp2; int i2 = i + 1; if ((l & (~0x1fffffffffffffffL)) != MASK_DELETE) { temp = l; l = k; k = temp; temp2 = i1; i1 = i2; i2 = temp2; } // first (i1) is definitely if ((l & (~0x1fffffffffffffffL)) == MASK_NULL) { } else { os.write(ba, offset, flb.lower32At(i1) - offset); // os.write((byte[])fob.objectAt(i2)); // offset = flb.lower32At(i1) + (flb.upper32At(i1) & // 0x1fffffff); if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE) { // insert // os.write(ba,offset, flb.lower32At(i2)-offset); os.write((byte[]) fob.objectAt(i2)); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE) { // XML_INSERT_SEGMENT_BYTE // os.write(ba,offset, flb.lower32At(i2)-offset); ByteSegment bs = (ByteSegment) fob.objectAt(i2); os.write(bs.ba, bs.offset, bs.len); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS) { // ElementFragmentNs // os.write(ba,offset, flb.lower32At(i2)-offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i2); ef.writeToOutputStream(os, md.encoding); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE_ENCLOSED) { // insert os.write(0x3e); os.write((byte[]) fob.objectAt(i2)); os.write(0x3c); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE_ENCLOSED) { // XML_INSERT_SEGMENT_BYTE ByteSegment bs = (ByteSegment) fob.objectAt(i2); os.write(0x3e); os.write(bs.ba, bs.offset, bs.len); os.write(0x3c); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS_ENCLOSED) { // ElementFragmentNs ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i2); os.write(0x3e); ef.writeToOutputStream(os, md.encoding); os.write(0x3c); offset = flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff); } } } } os.write(ba, offset, start + len - offset); } else { byte[] b1 = ba1; byte[] b2 = ba2; if (md.encoding == VTDNav.FORMAT_UTF_16BE) { b1 = ba3; b2 = ba4; } int offset = start; int inc = 1; for (int i = 0; i < flb.size; i = i + inc) { if (i + 1 == flb.size) { inc = 1; } else if (flb.lower32At(i) == flb.lower32At(i + 1)) { inc = 2; } else inc = 1; /* * if (i==1021){ System.out.println("inc ==> "+ inc); * System.out.println(" i ==> "+i); } */ l = flb.longAt(i); if (inc == 1) { if ((l & (~0x1fffffffffffffffL)) == MASK_DELETE) { os.write(ba, offset, (flb.lower32At(i) << 1) - offset); offset = (flb.lower32At(i) + (flb.upper32At(i) & 0x1fffffff)) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE) { // insert os.write(ba, offset, (flb.lower32At(i) << 1) - offset); os.write((byte[]) fob.objectAt(i)); offset = flb.lower32At(i) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE) { // XML_INSERT_SEGMENT_BYTE os.write(ba, offset, (flb.lower32At(i) << 1) - offset); ByteSegment bs = (ByteSegment) fob.objectAt(i); os.write(bs.ba, bs.offset, bs.len); offset = flb.lower32At(i) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS) { // ElementFragmentNs os.write(ba, offset, (flb.lower32At(i) << 1) - offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i); ef.writeToOutputStream(os, md.encoding); offset = flb.lower32At(i) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE_ENCLOSED) { // insert // XML_INSERT_SEGMENT_BYTE os.write(ba, offset, (flb.lower32At(i) << 1) - offset); os.write(b1); os.write((byte[]) fob.objectAt(i)); os.write(b2); offset = flb.lower32At(i) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE_ENCLOSED) { // XML_INSERT_SEGMENT_BYTE os.write(ba, offset, (flb.lower32At(i) << 1) - offset); ByteSegment bs = (ByteSegment) fob.objectAt(i); os.write(b1); os.write(bs.ba, bs.offset, bs.len); os.write(b2); offset = flb.lower32At(i) << 1; } else if ((l & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS_ENCLOSED) { // ElementFragmentNs os.write(ba, offset, (flb.lower32At(i) << 1) - offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i); os.write(b1); ef.writeToOutputStream(os, md.encoding); os.write(b2); offset = flb.lower32At(i) << 1; } } else { // share the same offset value one insert, one delete // to make sure that l's offset val is >= k's // also to make sure that the first token is a delete long k = flb.longAt(i + 1), temp; int i1 = i, temp2; int i2 = i + 1; if ((l & (~0x1fffffffffffffffL)) != MASK_DELETE) { temp = l; l = k; k = temp; temp2 = i1; i1 = i2; i2 = temp2; } // first is definitely delete if ((l & (~0x1fffffffffffffffL)) == MASK_NULL) { } else { os.write(ba, offset, (flb.lower32At(i1) << 1) - offset); // os.write((byte[])fob.objectAt(i2)); // offset = flb.lower32At(i1) + (flb.upper32At(i1) & // 0x1fffffff); if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE) { // insert // os.write(ba,offset, flb.lower32At(i2)-offset); os.write((byte[]) fob.objectAt(i2)); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE) { // XML_INSERT_SEGMENT_BYTE // os.write(ba,offset, flb.lower32At(i2)-offset); ByteSegment bs = (ByteSegment) fob.objectAt(i2); os.write(bs.ba, bs.offset, bs.len); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS) { // ElementFragmentNs // os.write(ba,offset, flb.lower32At(i2)-offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i2); ef.writeToOutputStream(os, md.encoding); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_BYTE_ENCLOSED) { // insert // XML_INSERT_SEGMENT_BYTE // os.write(ba,offset, flb.lower32At(i2)-offset); os.write(b1); os.write((byte[]) fob.objectAt(i2)); os.write(b2); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_SEGMENT_BYTE_ENCLOSED) { // XML_INSERT_SEGMENT_BYTE ByteSegment bs = (ByteSegment) fob.objectAt(i2); os.write(b1); os.write(bs.ba, bs.offset, bs.len); os.write(b2); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } else if ((k & (~0x1fffffffffffffffL)) == MASK_INSERT_FRAGMENT_NS_ENCLOSED) { // ElementFragmentNs // os.write(ba,offset, flb.lower32At(i2)-offset); ElementFragmentNs ef = (ElementFragmentNs) fob .objectAt(i2); os.write(b1); ef.writeToOutputStream(os, md.encoding); os.write(b2); offset = (flb.lower32At(i1) + (flb.upper32At(i1) & 0x1fffffff)) << 1; } } } } os.write(ba, offset, start + len - offset); } } /** * Generate the updated output XML document and write it into * a file of given name * @param fileName * @throws IOException * @throws ModifyException * */ public void output(String fileName) throws IOException, ModifyException,TranscodeException{ FileOutputStream fos = new FileOutputStream(fileName); output(fos); fos.close(); } void quickSort (int lo, int hi) { // lo is the lower index, hi is the upper index // of the region of array a that is to be sorted //System.out.println("lo ==>"+lo); //System.out.println("hi ==>"+hi); int i=lo, j=hi; long h; Object o; int x=flb.lower32At((lo+hi)/2); // partition do { while (flb.lower32At(i)<x) i++; while (flb.lower32At(j)>x) j--; if (i<=j) { h=flb.longAt(i); o = fob.objectAt(i); flb.modifyEntry(i,flb.longAt(j)); fob.modifyEntry(i,fob.objectAt(j)); flb.modifyEntry(j,h); fob.modifyEntry(j,o); i++; j--; } } while (i<=j); // recursion if (lo<j) quickSort(lo, j); if (i<hi) quickSort(i, hi); } /** * This method resets the internal state of XMLModify instance so * it can be reused * * */ public void reset(){ if (flb!=null) flb.size=0; if (fob!=null) fob.size=0; if (insertHash!=null) insertHash.reset(); if (deleteHash!=null) deleteHash.reset(); } /** * Replace the cursor element's name with a new name * @param newElementName * @throws ModifyException * @throws NavException * */ public void updateElementName(String newElementName) throws ModifyException, NavException,UnsupportedEncodingException{ int i = md.getCurrentIndex(); int type = md.getTokenType(i); if (type!=VTDNav.TOKEN_STARTING_TAG){ throw new ModifyException("You can only update an element name"); } //int offset = md.getTokenOffset(i); int len = md.getTokenLength(i)& 0xffff; updateToken(i,newElementName); long l = md.getElementFragment(); int encoding = md.getEncoding(); byte[] xml = md.getXML().getBytes(); int temp = (int)l+(int)(l>>32); if (encoding < VTDNav.FORMAT_UTF_16BE) { //scan backwards for /> //int temp = (int)l+(int)(l>>32); if (xml[temp - 2] == (byte) '/') return; //look for </ temp--; while (xml[temp] != (byte) '/') { temp--; } insertBytesAt(temp + 1, newElementName.getBytes(charSet)); removeContent(temp + 1, len); return; // } else if (encoding == VTDNav.FORMAT_UTF_16BE) { //scan backwards for /> if (xml[temp - 3] == (byte) '/' && xml[temp - 4] == 0) return; temp-=2; while (!(xml[temp+1] == (byte) '/' && xml[temp ] == 0)) { temp-=2; } insertBytesAt(temp+2, newElementName.getBytes(charSet)); removeContent(temp+2, len<<1); } else { //scan backwards for /> if (xml[temp - 3] == 0 && xml[temp - 4] == '/') return; temp-=2; while (!(xml[temp] == (byte) '/' && xml[temp+1 ] == 0) ) { temp-=2; } insertBytesAt(temp+2 , newElementName.getBytes(charSet)); removeContent(temp+2 , len<<1); } } /** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); } }
85,445
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
IndexWriteException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/IndexWriteException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; /** * * IndexWriteException is thrown when there are exception * condition when wrting VTD+XML index */ public class IndexWriteException extends VTDException { public IndexWriteException(String s){ super(s); } public IndexWriteException(){ } }
1,111
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FastIntBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/FastIntBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware; import java.lang.IndexOutOfBoundsException; import java.lang.NullPointerException; import java.lang.IllegalArgumentException; import java.util.ArrayList; /** * A fast, unsynchronized, chunk-based int buffer * */ public class FastIntBuffer implements IIntBuffer { /* bufferArrayList is a resizable array list of int buffers * */ public final static int ASCENDING = 0; public final static int DESCENDING = 1; private arrayList bufferArrayList; /** * Total capacity of the IntBuffer */ private int capacity; /** * Page size of the incremental growth of the Int Buffer */ private int pageSize; /** * Total number of integers in the IntBuffer */ protected int size; private int exp; private int r; /** * FastIntBuffer constructor comment. */ public FastIntBuffer() { size = 0; capacity = 0; pageSize = 1024; exp = 10; r = 1023; bufferArrayList = new arrayList(); } /** * Constructor with adjustable buffer page size of the value bfz * The actually page size is 1<<e * @param e int is the size of the internal buffer */ public FastIntBuffer(int e) { if (e < 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = 1<<e; exp = e; r = pageSize -1; bufferArrayList = new arrayList(); } /** * Append an int array to the end of this buffer instance * @param int_array int[] */ public final void append(int[] int_array) { /*if (int_array == null) { throw new NullPointerException(); }*/ // no additional buffer space needed int lastBufferIndex; int[] lastBuffer; if (bufferArrayList.size == 0) { lastBuffer = new int[pageSize]; bufferArrayList.add(lastBuffer); lastBufferIndex = 0; capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (int[]) bufferArrayList.get(lastBufferIndex); } if ((this.size + int_array.length) < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(input, 0, lastBuffer, size % pageSize, input.length); if (this.size + int_array.length< ((lastBufferIndex+1)<<exp)){ System.arraycopy(int_array, 0, lastBuffer, size & r, int_array.length); } else { int offset = pageSize -(size&r); // copy the first part System.arraycopy(int_array, 0, lastBuffer, size & r, offset); // copy the middle part int l = int_array.length - offset; int k = (l)>> exp; int z; for (z=1;z<=k;z++){ System.arraycopy(int_array,offset, (int[]) bufferArrayList.get(lastBufferIndex+z), 0, pageSize); offset += pageSize; } // copy the last part System.arraycopy(int_array, offset, (int[]) bufferArrayList.get(lastBufferIndex+z), 0, l & r); } size += int_array.length; return; } else // new buffers needed { // compute the number of additional buffers needed // int n = // ((int) ((int_array.length + size) / pageSize)) // + (((int_array.length + size) % pageSize) > 0 ? 1 : 0) // - (int) (capacity / pageSize); int n = ((int_array.length + size) >> exp) + (((int_array.length + size) &r) > 0 ? 1 : 0) - (capacity >> exp); // create these buffers // add to bufferArrayList //System.arraycopy(int_array, 0, lastBuffer, size % pageSize, capacity - size); System.arraycopy(int_array, 0, lastBuffer, size& r, capacity - size); for (int i = 0; i < n; i++) { int[] newBuffer = new int[pageSize]; if (i < n - 1) { // full copy System.arraycopy( int_array, pageSize * i + capacity - size, newBuffer, 0, pageSize); } else { // last page System.arraycopy( int_array, pageSize * i + capacity - size, newBuffer, 0, int_array.length + this.size - capacity - pageSize*i); } bufferArrayList.add(newBuffer); } // update length size += int_array.length; // update capacity capacity += n * pageSize; // update } } /** * Append a single int to the end of this buffer Instance * @param i int */ public final void append(int i) { //int[] lastBuffer; //int lastBufferIndex; /*if (bufferArrayList.size == 0) { lastBuffer = new int[pageSize]; bufferArrayList.add(lastBuffer); capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size - 1); lastBuffer = (int[]) bufferArrayList.oa[lastBufferIndex]; //lastBuffer = (int[]) bufferArrayList.get(bufferArrayList.size() - 1); }*/ if (this.size < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, long_array.length); ((int[]) bufferArrayList.oa[size >> exp])[size & r] = i; //((int[])bufferArrayList.oa[bufferArrayList.size-1])[size & r] = i; // lastBuffer[size % pageSize] = i; size += 1; } else // new buffers needed { int[] newBuffer = new int[pageSize]; size++; capacity += pageSize; bufferArrayList.add(newBuffer); newBuffer[0] = i; } } /** * Returns the total allocated capacity of this buffer instance. * @return int */ public final int getCapacity() { return capacity; } /** * Returns a single int array representing every int in this buffer instance * @return int[] (null if there isn't anything left in the buffer * @param startingOffset int * @param len int * @return int[] */ public int[] getIntArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size) { throw (new IndexOutOfBoundsException()); } int[] result = new int[len]; // allocate result array // int first_index = (int) (startingOffset / pageSize); // int last_index = (int) ((startingOffset + len) / pageSize); // if ((startingOffset + len) % pageSize == 0) { // last_index--; // } int first_index = startingOffset >> exp; int last_index = (startingOffset + len)>> exp; if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (int[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int int_array_offset = 0; for (int i = first_index; i <= last_index; i++) { int[] currentChunk = (int[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % pageSize)); pageSize - (startingOffset & r)); // int_array_offset += pageSize - (startingOffset) % pageSize; int_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, int_array_offset, len - int_array_offset); } else { System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize); int_array_offset += pageSize; } } } return result; } /** * Returns the page size of this buffer instance. * Creation date: (7/17/03 6:38:02 PM) * @return int */ public final int getPageSize() { return pageSize; } /** * Get the int at the location specified by index. * @return int * @param index int */ public final int intAt(int index) { /*if (index > size-1) { throw new IndexOutOfBoundsException(); }*/ // int pageNum = (int) index / pageSize; int pageNum = index>>exp; //System.out.println("page Number is "+pageNum); // int offset = index % pageSize; int offset = index & r; return ((int[]) bufferArrayList.get(pageNum))[offset]; } /** * Assigns a new int value to location index of the buffer instance. * @param index int * @param newValue int */ public final void modifyEntry(int index, int newValue) { /*if (index > size - 1) { throw new IndexOutOfBoundsException(" index out of range"); }*/ // ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((int[]) bufferArrayList.oa[index >> exp])[index & r] = newValue; } /** * Returns the total number of int values in the buffer instance * @return int */ public final int size() { return size; } /** * Returns the int array corresponding to all int values in this buffer instance * @return int[] (null if the buffer is empty) */ public int[] toIntArray() { if (size > 0) { int s = size; int[] resultArray = new int[size]; //copy all the content int into the resultArray int array_offset = 0; for (int i = 0; s>0; i++) { System.arraycopy( (int[]) bufferArrayList.get(i), 0, resultArray, array_offset, (s<pageSize) ? s : pageSize); // (i == (bufferArrayList.size() - 1)) ? size() % pageSize : pageSize); s = s - pageSize; array_offset += pageSize; } return resultArray; } return null; } /** * set the size of int buffer to zero, capacity * untouched so int buffer can be reused without * any unnecessary and additional allocation * */ public final void clear(){ size = 0; } /** * Set the size of FastIntBuffer to newSz if newSz is less than the * capacity, otherwise return false * @param newSz * @return status of resize * */ public final boolean resize(int newSz){ if (newSz <= capacity && newSz >=0){ size = newSz; return true; } else return false; } /** * Sort the integers in the buffer * @param order (as of version 2.9) * it can be either ASCENDING or DESCENDING */ public void sort(int order) { switch (order) { case ASCENDING: if (size > 0) quickSort_ascending(0, size - 1); break; case DESCENDING: if (size > 0) quickSort_descending(0, size - 1); break; default: throw new IllegalArgumentException("Sort type undefined"); } } void quickSort_ascending (int lo, int hi) { // lo is the lower index, hi is the upper index // of the region of array a that is to be sorted //System.out.println("lo ==>"+lo); //System.out.println("hi ==>"+hi); int i=lo, j=hi; int h; //Object o; int x=this.intAt((lo+hi)/2); // partition do { while (intAt(i)<x) i++; while (intAt(j)>x) j--; if (i<=j) { h=this.intAt(i); modifyEntry(i,this.intAt(j)); modifyEntry(j,h); i++; j--; } } while (i<=j); // recursion if (lo<j) quickSort_ascending(lo, j); if (i<hi) quickSort_ascending(i, hi); } void quickSort_descending (int lo, int hi) { // lo is the lower index, hi is the upper index // of the region of array a that is to be sorted //System.out.println("lo ==>"+lo); //System.out.println("hi ==>"+hi); int i=lo, j=hi; int h; //Object o; int x=this.intAt((lo+hi)/2); // partition do { while (intAt(i)>x) i++; while (intAt(j)<x) j--; if (i<=j) { h=this.intAt(i); modifyEntry(i,this.intAt(j)); modifyEntry(j,h); i++; j--; } } while (i<=j); // recursion if (lo<j) quickSort_descending(lo, j); if (i<hi) quickSort_descending(i, hi); } }
14,534
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_2.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_2.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-3 char * into a Unicode char * */ public class ISO8859_2 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0]= 0x00A0; // NO-BREAK SPACE chars[0xA1]= 0x0104;// LATIN CAPITAL LETTER A WITH OGONEK chars[0xA2]= 0x02D8;// BREVE chars[0xA3]= 0x0141; // LATIN CAPITAL LETTER L WITH STROKE chars[0xA4]= 0x00A4; // CURRENCY SIGN chars[0xA5]= 0x013D; // LATIN CAPITAL LETTER L WITH CARON chars[0xA6]= 0x015A; // LATIN CAPITAL LETTER S WITH ACUTE chars[0xA7]= 0x00A7; // SECTION SIGN chars[0xA8]= 0x00A8; // DIAERESIS chars[0xA9]= 0x0160; // LATIN CAPITAL LETTER S WITH CARON chars[0xAA]= 0x015E; // LATIN CAPITAL LETTER S WITH CEDILLA chars[0xAB]= 0x0164; // LATIN CAPITAL LETTER T WITH CARON chars[0xAC]= 0x0179; // LATIN CAPITAL LETTER Z WITH ACUTE chars[0xAD]= 0x00AD; // SOFT HYPHEN chars[0xAE]= 0x017D; // LATIN CAPITAL LETTER Z WITH CARON chars[0xAF]= 0x017B; // LATIN CAPITAL LETTER Z WITH DOT ABOVE chars[0xB0]= 0x00B0; // DEGREE SIGN chars[0xB1]= 0x0105; // LATIN SMALL LETTER A WITH OGONEK chars[0xB2]= 0x02DB; // OGONEK chars[0xB3]= 0x0142; // LATIN SMALL LETTER L WITH STROKE chars[0xB4]= 0x00B4; // ACUTE ACCENT chars[0xB5]= 0x013E; // LATIN SMALL LETTER L WITH CARON chars[0xB6]= 0x015B; // LATIN SMALL LETTER S WITH ACUTE chars[0xB7]= 0x02C7; // CARON chars[0xB8]= 0x00B8; // CEDILLA chars[0xB9]= 0x0161; // LATIN SMALL LETTER S WITH CARON chars[0xBA]= 0x015F; // LATIN SMALL LETTER S WITH CEDILLA chars[0xBB]= 0x0165; // LATIN SMALL LETTER T WITH CARON chars[0xBC]= 0x017A; // LATIN SMALL LETTER Z WITH ACUTE chars[0xBD]= 0x02DD; // DOUBLE ACUTE ACCENT chars[0xBE]= 0x017E; // LATIN SMALL LETTER Z WITH CARON chars[0xBF]= 0x017C; // LATIN SMALL LETTER Z WITH DOT ABOVE chars[0xC0]= 0x0154; // LATIN CAPITAL LETTER R WITH ACUTE chars[0xC1]= 0x00C1; // LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2]= 0x00C2; // LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3]= 0x0102; // LATIN CAPITAL LETTER A WITH BREVE chars[0xC4]= 0x00C4; // LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5]= 0x0139; // LATIN CAPITAL LETTER L WITH ACUTE chars[0xC6]= 0x0106; // LATIN CAPITAL LETTER C WITH ACUTE chars[0xC7]= 0x00C7; // LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8]= 0x010C; // LATIN CAPITAL LETTER C WITH CARON chars[0xC9]= 0x00C9; // LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA]= 0x0118 ; //LATIN CAPITAL LETTER E WITH OGONEK chars[0xCB]= 0x00CB; // LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC]= 0x011A; // LATIN CAPITAL LETTER E WITH CARON chars[0xCD]= 0x00CD; // LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE]= 0x00CE; // LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF]= 0x010E; // LATIN CAPITAL LETTER D WITH CARON chars[0xD0]= 0x0110; // LATIN CAPITAL LETTER D WITH STROKE chars[0xD1]= 0x0143; // LATIN CAPITAL LETTER N WITH ACUTE chars[0xD2]= 0x0147; // LATIN CAPITAL LETTER N WITH CARON chars[0xD3]= 0x00D3; // LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4]= 0x00D4; // LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5]= 0x0150; // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE chars[0xD6]= 0x00D6; // LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7]= 0x00D7; // MULTIPLICATION SIGN chars[0xD8]= 0x0158; // LATIN CAPITAL LETTER R WITH CARON chars[0xD9]= 0x016E; // LATIN CAPITAL LETTER U WITH RING ABOVE chars[0xDA]= 0x00DA; // LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB]= 0x0170; // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE chars[0xDC]= 0x00DC; // LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD]= 0x00DD; // LATIN CAPITAL LETTER Y WITH ACUTE chars[0xDE]= 0x0162; // LATIN CAPITAL LETTER T WITH CEDILLA chars[0xDF]= 0x00DF; // LATIN SMALL LETTER SHARP S chars[0xE0]= 0x0155; // LATIN SMALL LETTER R WITH ACUTE chars[0xE1]= 0x00E1; // LATIN SMALL LETTER A WITH ACUTE chars[0xE2]= 0x00E2; // LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3]= 0x0103; // LATIN SMALL LETTER A WITH BREVE chars[0xE4]= 0x00E4; // LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5]= 0x013A; // LATIN SMALL LETTER L WITH ACUTE chars[0xE6]= 0x0107; // LATIN SMALL LETTER C WITH ACUTE chars[0xE7]= 0x00E7; // LATIN SMALL LETTER C WITH CEDILLA chars[0xE8]= 0x010D; // LATIN SMALL LETTER C WITH CARON chars[0xE9]= 0x00E9; // LATIN SMALL LETTER E WITH ACUTE chars[0xEA]= 0x0119; // LATIN SMALL LETTER E WITH OGONEK chars[0xEB]= 0x00EB; // LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC]= 0x011B; // LATIN SMALL LETTER E WITH CARON chars[0xED]= 0x00ED; // LATIN SMALL LETTER I WITH ACUTE chars[0xEE]= 0x00EE; // LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF]= 0x010F; // LATIN SMALL LETTER D WITH CARON chars[0xF0]= 0x0111; // LATIN SMALL LETTER D WITH STROKE chars[0xF1]= 0x0144; // LATIN SMALL LETTER N WITH ACUTE chars[0xF2]= 0x0148; // LATIN SMALL LETTER N WITH CARON chars[0xF3]= 0x00F3; // LATIN SMALL LETTER O WITH ACUTE chars[0xF4]= 0x00F4; // LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5]= 0x0151; // LATIN SMALL LETTER O WITH DOUBLE ACUTE chars[0xF6]= 0x00F6; // LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7]= 0x00F7; // DIVISION SIGN chars[0xF8]= 0x0159; // LATIN SMALL LETTER R WITH CARON chars[0xF9]= 0x016F; //LATIN SMALL LETTER U WITH RING ABOVE chars[0xFA]= 0x00FA; // LATIN SMALL LETTER U WITH ACUTE chars[0xFB]= 0x0171; // LATIN SMALL LETTER U WITH DOUBLE ACUTE chars[0xFC]= 0x00FC; //LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD]= 0x00FD; // LATIN SMALL LETTER Y WITH ACUTE chars[0xFE]= 0x0163; //LATIN SMALL LETTER T WITH CEDILLA chars[0xFF]= 0x02D9; // DOT ABOVE } public static char decode(byte b){ return chars[b & 0xff]; } }
7,409
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_7.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_7.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-7 char * into a Unicode char * */ public class ISO8859_7 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA1 ]=0x02BD; chars[0xA2 ]=0x02BC; chars[0xA3 ]=0x00A3; chars[0xA6 ]=0x00A6; chars[0xA7 ]=0x00A7; chars[0xA8 ]=0x00A8; chars[0xA9 ]=0x00A9; chars[0xAB ]=0x00AB; chars[0xAC ]=0x00AC; chars[0xAD ]=0x00AD; chars[0xAF ]=0x2015; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x00B1; chars[0xB2 ]=0x00B2; chars[0xB3 ]=0x00B3; chars[0xB4 ]=0x0384; chars[0xB5 ]=0x0385; chars[0xB6 ]=0x0386; chars[0xB7 ]=0x00B7; chars[0xB8 ]=0x0388; chars[0xB9 ]=0x0389; chars[0xBA ]=0x038A; chars[0xBB ]=0x00BB; chars[0xBC ]=0x038C; chars[0xBD ]=0x00BD; chars[0xBE ]=0x038E; chars[0xBF ]=0x038F; chars[0xC0 ]=0x0390; chars[0xC1 ]=0x0391; chars[0xC2 ]=0x0392; chars[0xC3 ]=0x0393; chars[0xC4 ]=0x0394; chars[0xC5 ]=0x0395; chars[0xC6 ]=0x0396; chars[0xC7 ]=0x0397; chars[0xC8 ]=0x0398; chars[0xC9 ]=0x0399; chars[0xCA ]=0x039A; chars[0xCB ]=0x039B; chars[0xCC ]=0x039C; chars[0xCD ]=0x039D; chars[0xCE ]=0x039E; chars[0xCF ]=0x039F; chars[0xD0 ]=0x03A0; chars[0xD1 ]=0x03A1; chars[0xD3 ]=0x03A3; chars[0xD4 ]=0x03A4; chars[0xD5 ]=0x03A5; chars[0xD6 ]=0x03A6; chars[0xD7 ]=0x03A7; chars[0xD8 ]=0x03A8; chars[0xD9 ]=0x03A9; chars[0xDA ]=0x03AA; chars[0xDB ]=0x03AB; chars[0xDC ]=0x03AC; chars[0xDD ]=0x03AD; chars[0xDE ]=0x03AE; chars[0xDF ]=0x03AF; chars[0xE0 ]=0x03B0; chars[0xE1 ]=0x03B1; chars[0xE2 ]=0x03B2; chars[0xE3 ]=0x03B3; chars[0xE4 ]=0x03B4; chars[0xE5 ]=0x03B5; chars[0xE6 ]=0x03B6; chars[0xE7 ]=0x03B7; chars[0xE8 ]=0x03B8; chars[0xE9 ]=0x03B9; chars[0xEA ]=0x03BA; chars[0xEB ]=0x03BB; chars[0xEC ]=0x03BC; chars[0xED ]=0x03BD; chars[0xEE ]=0x03BE; chars[0xEF ]=0x03BF; chars[0xF0 ]=0x03C0; chars[0xF1 ]=0x03C1; chars[0xF2 ]=0x03C2; chars[0xF3 ]=0x03C3; chars[0xF4 ]=0x03C4; chars[0xF5 ]=0x03C5; chars[0xF6 ]=0x03C6; chars[0xF7 ]=0x03C7; chars[0xF8 ]=0x03C8; chars[0xF9 ]=0x03C9; chars[0xFA ]=0x03CA; chars[0xFB ]=0x03CB; chars[0xFC ]=0x03CC; chars[0xFD ]=0x03CD; chars[0xFE ]=0x03CE; } public static char decode(byte b){ return chars[b & 0xff]; } }
3,979
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_9.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_9.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-9 char * into a Unicode char * */ public class ISO8859_9 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA1 ]=0x00A1; chars[0xA2 ]=0x00A2; chars[0xA3 ]=0x00A3; chars[0xA4 ]=0x00A4; chars[0xA5 ]=0x00A5; chars[0xA6 ]=0x00A6; chars[0xA7 ]=0x00A7; chars[0xA8 ]=0x00A8; chars[0xA9 ]=0x00A9; chars[0xAA ]=0x00AA; chars[0xAB ]=0x00AB; chars[0xAC ]=0x00AC; chars[0xAD ]=0x00AD; chars[0xAE ]=0x00AE; chars[0xAF ]=0x00AF; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x00B1; chars[0xB2 ]=0x00B2; chars[0xB3 ]=0x00B3; chars[0xB4 ]=0x00B4; chars[0xB5 ]=0x00B5; chars[0xB6 ]=0x00B6; chars[0xB7 ]=0x00B7; chars[0xB8 ]=0x00B8; chars[0xB9 ]=0x00B9; chars[0xBA ]=0x00BA; chars[0xBB ]=0x00BB; chars[0xBC ]=0x00BC; chars[0xBD ]=0x00BD; chars[0xBE ]=0x00BE; chars[0xBF ]=0x00BF; chars[0xC0 ]=0x00C0; chars[0xC1 ]=0x00C1; chars[0xC2 ]=0x00C2; chars[0xC3 ]=0x00C3; chars[0xC4 ]=0x00C4; chars[0xC5 ]=0x00C5; chars[0xC6 ]=0x00C6; chars[0xC7 ]=0x00C7; chars[0xC8 ]=0x00C8; chars[0xC9 ]=0x00C9; chars[0xCA ]=0x00CA; chars[0xCB ]=0x00CB; chars[0xCC ]=0x00CC; chars[0xCD ]=0x00CD; chars[0xCE ]=0x00CE; chars[0xCF ]=0x00CF; chars[0xD0 ]=0x011E; chars[0xD1 ]=0x00D1; chars[0xD2 ]=0x00D2; chars[0xD3 ]=0x00D3; chars[0xD4 ]=0x00D4; chars[0xD5 ]=0x00D5; chars[0xD6 ]=0x00D6; chars[0xD7 ]=0x00D7; chars[0xD8 ]=0x00D8; chars[0xD9 ]=0x00D9; chars[0xDA ]=0x00DA; chars[0xDB ]=0x00DB; chars[0xDC ]=0x00DC; chars[0xDD ]=0x0130; chars[0xDE ]=0x015E; chars[0xDF ]=0x00DF; chars[0xE0 ]=0x00E0; chars[0xE1 ]=0x00E1; chars[0xE2 ]=0x00E2; chars[0xE3 ]=0x00E3; chars[0xE4 ]=0x00E4; chars[0xE5 ]=0x00E5; chars[0xE6 ]=0x00E6; chars[0xE7 ]=0x00E7; chars[0xE8 ]=0x00E8; chars[0xE9 ]=0x00E9; chars[0xEA ]=0x00EA; chars[0xEB ]=0x00EB; chars[0xEC ]=0x00EC; chars[0xED ]=0x00ED; chars[0xEE ]=0x00EE; chars[0xEF ]=0x00EF; chars[0xF0 ]=0x011F; chars[0xF1 ]=0x00F1; chars[0xF2 ]=0x00F2; chars[0xF3 ]=0x00F3; chars[0xF4 ]=0x00F4; chars[0xF5 ]=0x00F5; chars[0xF6 ]=0x00F6; chars[0xF7 ]=0x00F7; chars[0xF8 ]=0x00F8; chars[0xF9 ]=0x00F9; chars[0xFA ]=0x00FA; chars[0xFB ]=0x00FB; chars[0xFC ]=0x00FC; chars[0xFD ]=0x0131; chars[0xFE ]=0x015F; chars[0xFF ]=0x00FF; } public static char decode(byte b){ return chars[b & 0xff]; } }
4,153
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_6.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_6.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-6 char * into a Unicode char * */ public class ISO8859_6 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA4 ]=0x00A4; chars[0xAC ]=0x060C; chars[0xAD ]=0x00AD; chars[0xBB ]=0x061B; chars[0xBF ]=0x061F; chars[0xC1 ]=0x0621; chars[0xC2 ]=0x0622; chars[0xC3 ]=0x0623; chars[0xC4 ]=0x0624; chars[0xC5 ]=0x0625; chars[0xC6 ]=0x0626; chars[0xC7 ]=0x0627; chars[0xC8 ]=0x0628; chars[0xC9 ]=0x0629; chars[0xCA ]=0x062A; chars[0xCB ]=0x062B; chars[0xCC ]=0x062C; chars[0xCD ]=0x062D; chars[0xCE ]=0x062E; chars[0xCF ]=0x062F; chars[0xD0 ]=0x0630; chars[0xD1 ]=0x0631; chars[0xD2 ]=0x0632; chars[0xD3 ]=0x0633; chars[0xD4 ]=0x0634; chars[0xD5 ]=0x0635; chars[0xD6 ]=0x0636; chars[0xD7 ]=0x0637; chars[0xD8 ]=0x0638; chars[0xD9 ]=0x0639; chars[0xDA ]=0x063A; chars[0xE0 ]=0x0640; chars[0xE1 ]=0x0641; chars[0xE2 ]=0x0642; chars[0xE3 ]=0x0643; chars[0xE4 ]=0x0644; chars[0xE5 ]=0x0645; chars[0xE6 ]=0x0646; chars[0xE7 ]=0x0647; chars[0xE8 ]=0x0648; chars[0xE9 ]=0x0649; chars[0xEA ]=0x064A; chars[0xEB ]=0x064B; chars[0xEC ]=0x064C; chars[0xED ]=0x064D; chars[0xEE ]=0x064E; chars[0xEF ]=0x064F; chars[0xF0 ]=0x0650; chars[0xF1 ]=0x0651; chars[0xF2 ]=0x0652; } public static char decode(byte b){ return chars[b & 0xff]; } }
2,801
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1258.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1258.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1258 char * into a Unicode char * */ public class WIN1258 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x02C6 ;// MODIFIER LETTER CIRCUMFLEX ACCENT chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x0152 ;// LATIN CAPITAL LIGATURE OE chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x98 ]=0x02DC ;// SMALL TILDE chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x0153 ;// LATIN SMALL LIGATURE OE chars[0x9F ]=0x0178 ;// LATIN CAPITAL LETTER Y WITH DIAERESIS chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x00A1 ;// INVERTED EXCLAMATION MARK chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x00AA ;// FEMININE ORDINAL INDICATOR chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00AF ;// MACRON chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x00BA ;// MASCULINE ORDINAL INDICATOR chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x00BF ;// INVERTED QUESTION MARK chars[0xC0 ]=0x00C0 ;// LATIN CAPITAL LETTER A WITH GRAVE chars[0xC1 ]=0x00C1 ;// LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2 ;// LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3 ]=0x0102 ;// LATIN CAPITAL LETTER A WITH BREVE chars[0xC4 ]=0x00C4 ;// LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;// LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x00C6 ;// LATIN CAPITAL LETTER AE chars[0xC7 ]=0x00C7 ;// LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x00C8 ;// LATIN CAPITAL LETTER E WITH GRAVE chars[0xC9 ]=0x00C9 ;// LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x00CA ;// LATIN CAPITAL LETTER E WITH CIRCUMFLEX chars[0xCB ]=0x00CB ;// LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x0300 ;// COMBINING GRAVE ACCENT chars[0xCD ]=0x00CD ;// LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE ;// LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x00CF ;// LATIN CAPITAL LETTER I WITH DIAERESIS chars[0xD0 ]=0x0110 ;// LATIN CAPITAL LETTER D WITH STROKE chars[0xD1 ]=0x00D1 ;// LATIN CAPITAL LETTER N WITH TILDE chars[0xD2 ]=0x0309 ;// COMBINING HOOK ABOVE chars[0xD3 ]=0x00D3 ;// LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4 ;// LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x01A0 ;// LATIN CAPITAL LETTER O WITH HORN chars[0xD6 ]=0x00D6 ;// LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x00D8 ;// LATIN CAPITAL LETTER O WITH STROKE chars[0xD9 ]=0x00D9 ;// LATIN CAPITAL LETTER U WITH GRAVE chars[0xDA ]=0x00DA ;// LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x00DB ;// LATIN CAPITAL LETTER U WITH CIRCUMFLEX chars[0xDC ]=0x00DC ;// LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x01AF ;// LATIN CAPITAL LETTER U WITH HORN chars[0xDE ]=0x0303 ;// COMBINING TILDE chars[0xDF ]=0x00DF ;// LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x00E0 ;// LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x00E1 ;// LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2 ;// LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x0103 ;// LATIN SMALL LETTER A WITH BREVE chars[0xE4 ]=0x00E4 ;// LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;// LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x00E6 ;// LATIN SMALL LETTER AE chars[0xE7 ]=0x00E7 ;// LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8 ;// LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA ;// LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB ;// LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x0301 ;// COMBINING ACUTE ACCENT chars[0xED ]=0x00ED ;// LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE ;// LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF ;// LATIN SMALL LETTER I WITH DIAERESIS chars[0xF0 ]=0x0111 ;// LATIN SMALL LETTER D WITH STROKE chars[0xF1 ]=0x00F1 ;// LATIN SMALL LETTER N WITH TILDE chars[0xF2 ]=0x0323 ;// COMBINING DOT BELOW chars[0xF3 ]=0x00F3 ;// LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4 ;// LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x01A1 ;// LATIN SMALL LETTER O WITH HORN chars[0xF6 ]=0x00F6 ;// LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x00F8 ;// LATIN SMALL LETTER O WITH STROKE chars[0xF9 ]=0x00F9 ;// LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x00FA ;// LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x00FB ;// LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x01B0 ;// LATIN SMALL LETTER U WITH HORN chars[0xFE ]=0x20AB ;// DONG SIGN chars[0xFF ]=0x00FF ;// LATIN SMALL LETTER Y WITH DIAERESIS } public static char decode(byte b){ return chars[b & 0xff]; } }
8,467
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1255.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1255.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1255 char * into a Unicode char * */ public class WIN1255 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x02C6 ;// MODIFIER LETTER CIRCUMFLEX ACCENT chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x98 ]=0x02DC ;// SMALL TILDE chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x00A1 ;// INVERTED EXCLAMATION MARK chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x20AA ;// NEW SHEQEL SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00AF ;// MACRON chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x00F7 ;// DIVISION SIGN chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x00BF ;// INVERTED QUESTION MARK chars[0xC0 ]=0x05B0 ;// HEBREW POINT SHEVA chars[0xC1 ]=0x05B1 ;// HEBREW POINT HATAF SEGOL chars[0xC2 ]=0x05B2 ;// HEBREW POINT HATAF PATAH chars[0xC3 ]=0x05B3 ;// HEBREW POINT HATAF QAMATS chars[0xC4 ]=0x05B4 ;// HEBREW POINT HIRIQ chars[0xC5 ]=0x05B5 ;// HEBREW POINT TSERE chars[0xC6 ]=0x05B6 ;// HEBREW POINT SEGOL chars[0xC7 ]=0x05B7 ;// HEBREW POINT PATAH chars[0xC8 ]=0x05B8 ;// HEBREW POINT QAMATS chars[0xC9 ]=0x05B9 ;// HEBREW POINT HOLAM chars[0xCB ]=0x05BB ;// HEBREW POINT QUBUTS chars[0xCC ]=0x05BC ;// HEBREW POINT DAGESH OR MAPIQ chars[0xCD ]=0x05BD ;// HEBREW POINT METEG chars[0xCE ]=0x05BE ;// HEBREW PUNCTUATION MAQAF chars[0xCF ]=0x05BF ;// HEBREW POINT RAFE chars[0xD0 ]=0x05C0 ;// HEBREW PUNCTUATION PASEQ chars[0xD1 ]=0x05C1 ;// HEBREW POINT SHIN DOT chars[0xD2 ]=0x05C2 ;// HEBREW POINT SIN DOT chars[0xD3 ]=0x05C3 ;// HEBREW PUNCTUATION SOF PASUQ chars[0xD4 ]=0x05F0 ;// HEBREW LIGATURE YIDDISH DOUBLE VAV chars[0xD5 ]=0x05F1 ;// HEBREW LIGATURE YIDDISH VAV YOD chars[0xD6 ]=0x05F2 ;// HEBREW LIGATURE YIDDISH DOUBLE YOD chars[0xD7 ]=0x05F3 ;// HEBREW PUNCTUATION GERESH chars[0xD8 ]=0x05F4 ;// HEBREW PUNCTUATION GERSHAYIM chars[0xE0 ]=0x05D0 ;// HEBREW LETTER ALEF chars[0xE1 ]=0x05D1 ;// HEBREW LETTER BET chars[0xE2 ]=0x05D2 ;// HEBREW LETTER GIMEL chars[0xE3 ]=0x05D3 ;// HEBREW LETTER DALET chars[0xE4 ]=0x05D4 ;// HEBREW LETTER HE chars[0xE5 ]=0x05D5 ;// HEBREW LETTER VAV chars[0xE6 ]=0x05D6 ;// HEBREW LETTER ZAYIN chars[0xE7 ]=0x05D7 ;// HEBREW LETTER HET chars[0xE8 ]=0x05D8 ;// HEBREW LETTER TET chars[0xE9 ]=0x05D9 ;// HEBREW LETTER YOD chars[0xEA ]=0x05DA ;// HEBREW LETTER FINAL KAF chars[0xEB ]=0x05DB ;// HEBREW LETTER KAF chars[0xEC ]=0x05DC ;// HEBREW LETTER LAMED chars[0xED ]=0x05DD ;// HEBREW LETTER FINAL MEM chars[0xEE ]=0x05DE ;// HEBREW LETTER MEM chars[0xEF ]=0x05DF ;// HEBREW LETTER FINAL NUN chars[0xF0 ]=0x05E0 ;// HEBREW LETTER NUN chars[0xF1 ]=0x05E1 ;// HEBREW LETTER SAMEKH chars[0xF2 ]=0x05E2 ;// HEBREW LETTER AYIN chars[0xF3 ]=0x05E3 ;// HEBREW LETTER FINAL PE chars[0xF4 ]=0x05E4 ;// HEBREW LETTER PE chars[0xF5 ]=0x05E5 ;// HEBREW LETTER FINAL TSADI chars[0xF6 ]=0x05E6 ;// HEBREW LETTER TSADI chars[0xF7 ]=0x05E7 ;// HEBREW LETTER QOF chars[0xF8 ]=0x05E8 ;// HEBREW LETTER RESH chars[0xF9 ]=0x05E9 ;// HEBREW LETTER SHIN chars[0xFA ]=0x05EA ;// HEBREW LETTER TAV chars[0xFD ]=0x200E ;// LEFT-TO-RIGHT MARK chars[0xFE ]=0x200F ;// RIGHT-TO-LEFT MARK } public static char decode(byte b){ return chars[b & 0xff]; } }
6,955
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_13.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_13.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; public class ISO8859_13 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0 ; chars[0xA1 ]=0x201D ; chars[0xA2 ]=0x00A2 ; chars[0xA3 ]=0x00A3; chars[0xA4 ]=0x00A4; chars[0xA5 ]=0x201E; chars[0xA6 ]=0x00A6; chars[0xA7 ]=0x00A7; chars[0xA8 ]=0x00D8; chars[0xA9 ]=0x00A9; chars[0xAA ]=0x0156; chars[0xAB ]=0x00AB; chars[0xAC ]=0x00AC; chars[0xAD ]=0x00AD; chars[0xAE ]=0x00AE; chars[0xAF ]=0x00C6; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x00B1; chars[0xB2 ]=0x00B2; chars[0xB3 ]=0x00B3; chars[0xB4 ]=0x201C; chars[0xB5 ]=0x00B5; chars[0xB6 ]=0x00B6; chars[0xB7 ]=0x00B7; chars[0xB8 ]=0x00F8; chars[0xB9 ]=0x00B9; chars[0xBA ]=0x0157 ;//LATIN SMALL LETTER R WITH CEDILLA chars[0xBB ]=0x00BB; chars[0xBC ]=0x00BC; chars[0xBD ]=0x00BD; chars[0xBE ]=0x00BE; chars[0xBF ]=0x00E6 ;//LATIN SMALL LETTER AE chars[0xC0 ]=0x0104 ;//LATIN CAPITAL LETTER A WITH OGONEK chars[0xC1 ]=0x012E ;//LATIN CAPITAL LETTER I WITH OGONEK chars[0xC2 ]=0x0100 ;//LATIN CAPITAL LETTER A WITH MACRON chars[0xC3 ]=0x0106 ;//LATIN CAPITAL LETTER C WITH ACUTE chars[0xC4 ]=0x00C4 ;//LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;//LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x0118 ;//LATIN CAPITAL LETTER E WITH OGONEK chars[0xC7 ]=0x0112 ;//LATIN CAPITAL LETTER E WITH MACRON chars[0xC8 ]=0x010C ;//LATIN CAPITAL LETTER C WITH CARON chars[0xC9 ]=0x00C9 ;//LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x0179 ;//LATIN CAPITAL LETTER Z WITH ACUTE chars[0xCB ]=0x0116 ;//LATIN CAPITAL LETTER E WITH DOT ABOVE chars[0xCC ]=0x0122 ;//LATIN CAPITAL LETTER G WITH CEDILLA chars[0xCD ]=0x0136 ;//LATIN CAPITAL LETTER K WITH CEDILLA chars[0xCE ]=0x012A ;//LATIN CAPITAL LETTER I WITH MACRON chars[0xCF ]=0x013B ;//LATIN CAPITAL LETTER L WITH CEDILLA chars[0xD0 ]=0x0160 ;//LATIN CAPITAL LETTER S WITH CARON chars[0xD1 ]=0x0143 ;//LATIN CAPITAL LETTER N WITH ACUTE chars[0xD2 ]=0x0145 ;//LATIN CAPITAL LETTER N WITH CEDILLA chars[0xD3 ]=0x00D3 ;//LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x014C ;//LATIN CAPITAL LETTER O WITH MACRON chars[0xD5 ]=0x00D5 ;//LATIN CAPITAL LETTER O WITH TILDE chars[0xD6 ]=0x00D6 ;//LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ; chars[0xD8 ]=0x0172 ;//LATIN CAPITAL LETTER U WITH OGONEK chars[0xD9 ]=0x0141 ;//LATIN CAPITAL LETTER L WITH STROKE chars[0xDA ]=0x015A ;//LATIN CAPITAL LETTER S WITH ACUTE chars[0xDB ]=0x016A ;//LATIN CAPITAL LETTER U WITH MACRON chars[0xDC ]=0x00DC ;//LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x017B ;//LATIN CAPITAL LETTER Z WITH DOT ABOVE chars[0xDE ]=0x017D ;//LATIN CAPITAL LETTER Z WITH CARON chars[0xDF ]=0x00DF ;//LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x0105 ;//LATIN SMALL LETTER A WITH OGONEK chars[0xE1 ]=0x012F ;//LATIN SMALL LETTER I WITH OGONEK chars[0xE2 ]=0x0101 ;//LATIN SMALL LETTER A WITH MACRON chars[0xE3 ]=0x0107 ;//LATIN SMALL LETTER C WITH ACUTE chars[0xE4 ]=0x00E4 ;//LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;//LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x0119 ;//LATIN SMALL LETTER E WITH OGONEK chars[0xE7 ]=0x0113 ;//LATIN SMALL LETTER E WITH MACRON chars[0xE8 ]=0x010D ;//LATIN SMALL LETTER C WITH CARON chars[0xE9 ]=0x00E9 ;//LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x017A ;//LATIN SMALL LETTER Z WITH ACUTE chars[0xEB ]=0x0117 ;//LATIN SMALL LETTER E WITH DOT ABOVE chars[0xEC ]=0x0123 ;//LATIN SMALL LETTER G WITH CEDILLA chars[0xED ]=0x0137 ;//LATIN SMALL LETTER K WITH CEDILLA chars[0xEE ]=0x012B ;//LATIN SMALL LETTER I WITH MACRON chars[0xEF ]=0x013C ;//LATIN SMALL LETTER L WITH CEDILLA chars[0xF0 ]=0x0161 ;//LATIN SMALL LETTER S WITH CARON chars[0xF1 ]=0x0144 ;//LATIN SMALL LETTER N WITH ACUTE chars[0xF2 ]=0x0146 ;//LATIN SMALL LETTER N WITH CEDILLA chars[0xF3 ]=0x00F3 ;//LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x014D ;//LATIN SMALL LETTER O WITH MACRON chars[0xF5 ]=0x00F5 ;//LATIN SMALL LETTER O WITH TILDE chars[0xF6 ]=0x00F6 ;//LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ; chars[0xF8 ]=0x0173 ;//LATIN SMALL LETTER U WITH OGONEK chars[0xF9 ]=0x0142 ;//LATIN SMALL LETTER L WITH STROKE chars[0xFA ]=0x015B ;//LATIN SMALL LETTER S WITH ACUTE chars[0xFB ]=0x016B ;//LATIN SMALL LETTER U WITH MACRON chars[0xFC ]=0x00FC ;//LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x017C ;//LATIN SMALL LETTER Z WITH DOT ABOVE chars[0xFE ]=0x017E ;//LATIN SMALL LETTER Z WITH CARON chars[0xFF ]=0x2019; } public static char decode(byte b){ return chars[b & 0xff]; } }
6,341
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1257.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1257.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1257 char * into a Unicode char * */ public class WIN1257 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8D ]=0x00A8 ;// DIAERESIS chars[0x8E ]=0x02C7 ;// CARON chars[0x8F ]=0x00B8 ;// CEDILLA chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9D ]=0x00AF ;// MACRON chars[0x9E ]=0x02DB ;// OGONEK chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00D8 ;// LATIN CAPITAL LETTER O WITH STROKE chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x0156 ;// LATIN CAPITAL LETTER R WITH CEDILLA chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00C6 ;// LATIN CAPITAL LETTER AE chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00F8 ;// LATIN SMALL LETTER O WITH STROKE chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x0157 ;// LATIN SMALL LETTER R WITH CEDILLA chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x00E6 ;// LATIN SMALL LETTER AE chars[0xC0 ]=0x0104 ;// LATIN CAPITAL LETTER A WITH OGONEK chars[0xC1 ]=0x012E ;// LATIN CAPITAL LETTER I WITH OGONEK chars[0xC2 ]=0x0100 ;// LATIN CAPITAL LETTER A WITH MACRON chars[0xC3 ]=0x0106 ;// LATIN CAPITAL LETTER C WITH ACUTE chars[0xC4 ]=0x00C4 ;// LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;// LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x0118 ;// LATIN CAPITAL LETTER E WITH OGONEK chars[0xC7 ]=0x0112 ;// LATIN CAPITAL LETTER E WITH MACRON chars[0xC8 ]=0x010C ;// LATIN CAPITAL LETTER C WITH CARON chars[0xC9 ]=0x00C9 ;// LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x0179 ;// LATIN CAPITAL LETTER Z WITH ACUTE chars[0xCB ]=0x0116 ;// LATIN CAPITAL LETTER E WITH DOT ABOVE chars[0xCC ]=0x0122 ;// LATIN CAPITAL LETTER G WITH CEDILLA chars[0xCD ]=0x0136 ;// LATIN CAPITAL LETTER K WITH CEDILLA chars[0xCE ]=0x012A ;// LATIN CAPITAL LETTER I WITH MACRON chars[0xCF ]=0x013B ;// LATIN CAPITAL LETTER L WITH CEDILLA chars[0xD0 ]=0x0160 ;// LATIN CAPITAL LETTER S WITH CARON chars[0xD1 ]=0x0143 ;// LATIN CAPITAL LETTER N WITH ACUTE chars[0xD2 ]=0x0145 ;// LATIN CAPITAL LETTER N WITH CEDILLA chars[0xD3 ]=0x00D3 ;// LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x014C ;// LATIN CAPITAL LETTER O WITH MACRON chars[0xD5 ]=0x00D5 ;// LATIN CAPITAL LETTER O WITH TILDE chars[0xD6 ]=0x00D6 ;// LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x0172 ;// LATIN CAPITAL LETTER U WITH OGONEK chars[0xD9 ]=0x0141 ;// LATIN CAPITAL LETTER L WITH STROKE chars[0xDA ]=0x015A ;// LATIN CAPITAL LETTER S WITH ACUTE chars[0xDB ]=0x016A ;// LATIN CAPITAL LETTER U WITH MACRON chars[0xDC ]=0x00DC ;// LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x017B ;// LATIN CAPITAL LETTER Z WITH DOT ABOVE chars[0xDE ]=0x017D ;// LATIN CAPITAL LETTER Z WITH CARON chars[0xDF ]=0x00DF ;// LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x0105 ;// LATIN SMALL LETTER A WITH OGONEK chars[0xE1 ]=0x012F ;// LATIN SMALL LETTER I WITH OGONEK chars[0xE2 ]=0x0101 ;// LATIN SMALL LETTER A WITH MACRON chars[0xE3 ]=0x0107 ;// LATIN SMALL LETTER C WITH ACUTE chars[0xE4 ]=0x00E4 ;// LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;// LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x0119 ;// LATIN SMALL LETTER E WITH OGONEK chars[0xE7 ]=0x0113 ;// LATIN SMALL LETTER E WITH MACRON chars[0xE8 ]=0x010D ;// LATIN SMALL LETTER C WITH CARON chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x017A ;// LATIN SMALL LETTER Z WITH ACUTE chars[0xEB ]=0x0117 ;// LATIN SMALL LETTER E WITH DOT ABOVE chars[0xEC ]=0x0123 ;// LATIN SMALL LETTER G WITH CEDILLA chars[0xED ]=0x0137 ;// LATIN SMALL LETTER K WITH CEDILLA chars[0xEE ]=0x012B ;// LATIN SMALL LETTER I WITH MACRON chars[0xEF ]=0x013C ;// LATIN SMALL LETTER L WITH CEDILLA chars[0xF0 ]=0x0161 ;// LATIN SMALL LETTER S WITH CARON chars[0xF1 ]=0x0144 ;// LATIN SMALL LETTER N WITH ACUTE chars[0xF2 ]=0x0146 ;// LATIN SMALL LETTER N WITH CEDILLA chars[0xF3 ]=0x00F3 ;// LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x014D ;// LATIN SMALL LETTER O WITH MACRON chars[0xF5 ]=0x00F5 ;// LATIN SMALL LETTER O WITH TILDE chars[0xF6 ]=0x00F6 ;// LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x0173 ;// LATIN SMALL LETTER U WITH OGONEK chars[0xF9 ]=0x0142 ;// LATIN SMALL LETTER L WITH STROKE chars[0xFA ]=0x015B ;// LATIN SMALL LETTER S WITH ACUTE chars[0xFB ]=0x016B ;// LATIN SMALL LETTER U WITH MACRON chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x017C ;// LATIN SMALL LETTER Z WITH DOT ABOVE chars[0xFE ]=0x017E ;// LATIN SMALL LETTER Z WITH CARON chars[0xFF ]=0x02D9 ;// DOT ABOVE } public static char decode(byte b){ return chars[b & 0xff]; } }
8,347
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UTF8Char.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/UTF8Char.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * UTF 8 char range finder. * Creation date: (3/3/04 6:01:49 PM) * @author: */ public class UTF8Char { static final byte[] charLen = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, -1, -1, }; static public int byteCount(int n) { return charLen[n]; } }
2,037
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1252.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1252.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1252 char * into a Unicode char * */ public class WIN1252 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x02C6 ;// MODIFIER LETTER CIRCUMFLEX ACCENT chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8A ]=0x0160 ;// LATIN CAPITAL LETTER S WITH CARON chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x0152 ;// LATIN CAPITAL LIGATURE OE chars[0x8E ]=0x017D ;// LATIN CAPITAL LETTER Z WITH CARON chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x98 ]=0x02DC ;// SMALL TILDE chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9A ]=0x0161 ;// LATIN SMALL LETTER S WITH CARON chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x0153 ;// LATIN SMALL LIGATURE OE chars[0x9E ]=0x017E ;// LATIN SMALL LETTER Z WITH CARON chars[0x9F ]=0x0178 ;// LATIN CAPITAL LETTER Y WITH DIAERESIS chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x00A1 ;// INVERTED EXCLAMATION MARK chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x00AA ;// FEMININE ORDINAL INDICATOR chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00AF ;// MACRON chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x00BA ;// MASCULINE ORDINAL INDICATOR chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x00BF ;// INVERTED QUESTION MARK chars[0xC0 ]=0x00C0 ;// LATIN CAPITAL LETTER A WITH GRAVE chars[0xC1 ]=0x00C1 ;// LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2 ;// LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3 ]=0x00C3 ;// LATIN CAPITAL LETTER A WITH TILDE chars[0xC4 ]=0x00C4 ;// LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;// LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x00C6 ;// LATIN CAPITAL LETTER AE chars[0xC7 ]=0x00C7 ;// LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x00C8 ;// LATIN CAPITAL LETTER E WITH GRAVE chars[0xC9 ]=0x00C9 ;// LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x00CA ;// LATIN CAPITAL LETTER E WITH CIRCUMFLEX chars[0xCB ]=0x00CB ;// LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x00CC ;// LATIN CAPITAL LETTER I WITH GRAVE chars[0xCD ]=0x00CD ;// LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE ;// LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x00CF ;// LATIN CAPITAL LETTER I WITH DIAERESIS chars[0xD0 ]=0x00D0 ;// LATIN CAPITAL LETTER ETH chars[0xD1 ]=0x00D1 ;// LATIN CAPITAL LETTER N WITH TILDE chars[0xD2 ]=0x00D2 ;// LATIN CAPITAL LETTER O WITH GRAVE chars[0xD3 ]=0x00D3 ;// LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4 ;// LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x00D5 ;// LATIN CAPITAL LETTER O WITH TILDE chars[0xD6 ]=0x00D6 ;// LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x00D8 ;// LATIN CAPITAL LETTER O WITH STROKE chars[0xD9 ]=0x00D9 ;// LATIN CAPITAL LETTER U WITH GRAVE chars[0xDA ]=0x00DA ;// LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x00DB ;// LATIN CAPITAL LETTER U WITH CIRCUMFLEX chars[0xDC ]=0x00DC ;// LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x00DD ;// LATIN CAPITAL LETTER Y WITH ACUTE chars[0xDE ]=0x00DE ;// LATIN CAPITAL LETTER THORN chars[0xDF ]=0x00DF ;// LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x00E0 ;// LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x00E1 ;// LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2 ;// LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x00E3 ;// LATIN SMALL LETTER A WITH TILDE chars[0xE4 ]=0x00E4 ;// LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;// LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x00E6 ;// LATIN SMALL LETTER AE chars[0xE7 ]=0x00E7 ;// LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8 ;// LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA ;// LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB ;// LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x00EC ;// LATIN SMALL LETTER I WITH GRAVE chars[0xED ]=0x00ED ;// LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE ;// LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF ;// LATIN SMALL LETTER I WITH DIAERESIS chars[0xF0 ]=0x00F0 ;// LATIN SMALL LETTER ETH chars[0xF1 ]=0x00F1 ;// LATIN SMALL LETTER N WITH TILDE chars[0xF2 ]=0x00F2 ;// LATIN SMALL LETTER O WITH GRAVE chars[0xF3 ]=0x00F3 ;// LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4 ;// LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x00F5 ;// LATIN SMALL LETTER O WITH TILDE chars[0xF6 ]=0x00F6 ;// LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x00F8 ;// LATIN SMALL LETTER O WITH STROKE chars[0xF9 ]=0x00F9 ;// LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x00FA ;// LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x00FB ;// LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x00FD ;// LATIN SMALL LETTER Y WITH ACUTE chars[0xFE ]=0x00FE ;// LATIN SMALL LETTER THORN chars[0xFF ]=0x00FF ;// LATIN SMALL LETTER Y WITH DIAERESIS } public static char decode(byte b){ return chars[b & 0xff]; } }
8,792
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_8.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_8.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-8 char * into a Unicode char * */ public class ISO8859_8 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xAA ]=0x00D7; chars[0xAB ]=0x00AB; chars[0xAC ]=0x00AC; chars[0xAD ]=0x00AD; chars[0xAE ]=0x00AE; chars[0xAF ]=0x203E; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x00B1; chars[0xB2 ]=0x00B2; chars[0xB3 ]=0x00B3; chars[0xB4 ]=0x00B4; chars[0xB5 ]=0x00B5; chars[0xB6 ]=0x00B6; chars[0xB7 ]=0x00B7; chars[0xB8 ]=0x00B8; chars[0xB9 ]=0x00B9; chars[0xBA ]=0x00F7; chars[0xBB ]=0x00BB; chars[0xBC ]=0x00BC; chars[0xBD ]=0x00BD; chars[0xBE ]=0x00BE; chars[0xDF ]=0x2017; chars[0xE0 ]=0x05D0; chars[0xE1 ]=0x05D1; chars[0xE2 ]=0x05D2; chars[0xE3 ]=0x05D3; chars[0xE4 ]=0x05D4; chars[0xE5 ]=0x05D5; chars[0xE6 ]=0x05D6; chars[0xE7 ]=0x05D7; chars[0xE8 ]=0x05D8; chars[0xE9 ]=0x05D9; chars[0xEA ]=0x05DA; chars[0xEB ]=0x05DB; chars[0xEC ]=0x05DC; chars[0xED ]=0x05DD; chars[0xEE ]=0x05DE; chars[0xEF ]=0x05DF; chars[0xF0 ]=0x05E0; chars[0xF1 ]=0x05E1; chars[0xF2 ]=0x05E2; chars[0xF3 ]=0x05E3; chars[0xF4 ]=0x05E4; chars[0xF5 ]=0x05E5; chars[0xF6 ]=0x05E6; chars[0xF7 ]=0x05E7; chars[0xF8 ]=0x05E8; chars[0xF9 ]=0x05E9; chars[0xFA ]=0x05EA; } public static char decode(byte b){ return chars[b & 0xff]; } }
2,743
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_3.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_3.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-3 char * into a Unicode char * */ public class ISO8859_3 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; // NO-BREAK SPACE chars[0xA1 ]=0x0126; // LATIN CAPITAL LETTER H WITH STROKE chars[0xA2 ]=0x02D8; // BREVE chars[0xA3 ]=0x00A3; // POUND SIGN chars[0xA4 ]=0x00A4; // CURRENCY SIGN chars[0xA6 ]=0x0124; // LATIN CAPITAL LETTER H WITH CIRCUMFLEX chars[0xA7 ]=0x00A7; // SECTION SIGN chars[0xA8 ]=0x00A8; // DIAERESIS chars[0xA9 ]=0x0130; // LATIN CAPITAL LETTER I WITH DOT ABOVE chars[0xAA ]=0x015E; // LATIN CAPITAL LETTER S WITH CEDILLA chars[0xAB ]=0x011E; // LATIN CAPITAL LETTER G WITH BREVE chars[0xAC ]=0x0134; // LATIN CAPITAL LETTER J WITH CIRCUMFLEX chars[0xAD ]=0x00AD; // SOFT HYPHEN chars[0xAF ]=0x017B; // LATIN CAPITAL LETTER Z WITH DOT ABOVE chars[0xB0 ]=0x00B0; // DEGREE SIGN chars[0xB1 ]=0x0127; // LATIN SMALL LETTER H WITH STROKE chars[0xB2 ]=0x00B2; // SUPERSCRIPT TWO chars[0xB3 ]=0x00B3; // SUPERSCRIPT THREE chars[0xB4 ]=0x00B4; // ACUTE ACCENT chars[0xB5 ]=0x00B5; // MICRO SIGN chars[0xB6 ]=0x0125; // LATIN SMALL LETTER H WITH CIRCUMFLEX chars[0xB7 ]=0x00B7; // MIDDLE DOT chars[0xB8 ]=0x00B8; // CEDILLA chars[0xB9 ]=0x0131; // LATIN SMALL LETTER DOTLESS I chars[0xBA ]=0x015F; // LATIN SMALL LETTER S WITH CEDILLA chars[0xBB ]=0x011F; // LATIN SMALL LETTER G WITH BREVE chars[0xBC ]=0x0135; // LATIN SMALL LETTER J WITH CIRCUMFLEX chars[0xBD ]=0x00BD; // VULGAR FRACTION ONE HALF chars[0xBF ]=0x017C; // LATIN SMALL LETTER Z WITH DOT ABOVE chars[0xC0 ]=0x00C0; // LATIN CAPITAL LETTER A WITH GRAVE chars[0xC1 ]=0x00C1; // LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2; // LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC4 ]=0x00C4; // LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x010A; // LATIN CAPITAL LETTER C WITH DOT ABOVE chars[0xC6 ]=0x0108; // LATIN CAPITAL LETTER C WITH CIRCUMFLEX chars[0xC7 ]=0x00C7; // LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x00C8; // LATIN CAPITAL LETTER E WITH GRAVE chars[0xC9 ]=0x00C9; // LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x00CA; // LATIN CAPITAL LETTER E WITH CIRCUMFLEX chars[0xCB ]=0x00CB; // LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x00CC; // LATIN CAPITAL LETTER I WITH GRAVE chars[0xCD ]=0x00CD; // LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE; // LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x00CF; // LATIN CAPITAL LETTER I WITH DIAERESIS chars[0xD1 ]=0x00D1; // LATIN CAPITAL LETTER N WITH TILDE chars[0xD2 ]=0x00D2; // LATIN CAPITAL LETTER O WITH GRAVE chars[0xD3 ]=0x00D3; // LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4; // LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x0120; // LATIN CAPITAL LETTER G WITH DOT ABOVE chars[0xD6 ]=0x00D6; // LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7; // MULTIPLICATION SIGN chars[0xD8 ]=0x011C; // LATIN CAPITAL LETTER G WITH CIRCUMFLEX chars[0xD9 ]=0x00D9; // LATIN CAPITAL LETTER U WITH GRAVE chars[0xDA ]=0x00DA; // LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x00DB; // LATIN CAPITAL LETTER U WITH CIRCUMFLEX chars[0xDC ]=0x00DC; // LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x016C; // LATIN CAPITAL LETTER U WITH BREVE chars[0xDE ]=0x015C; // LATIN CAPITAL LETTER S WITH CIRCUMFLEX chars[0xDF ]=0x00DF; // LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x00E0; // LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x00E1; // LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2; // LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE4 ]=0x00E4; // LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x010B; // LATIN SMALL LETTER C WITH DOT ABOVE chars[0xE6 ]=0x0109; // LATIN SMALL LETTER C WITH CIRCUMFLEX chars[0xE7 ]=0x00E7; // LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8; // LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9; // LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA; // LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB; // LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x00EC; // LATIN SMALL LETTER I WITH GRAVE chars[0xED ]=0x00ED; // LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE; // LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF; // LATIN SMALL LETTER I WITH DIAERESIS chars[0xF1 ]=0x00F1; // LATIN SMALL LETTER N WITH TILDE chars[0xF2 ]=0x00F2; // LATIN SMALL LETTER O WITH GRAVE chars[0xF3 ]=0x00F3; // LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4; // LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x0121; // LATIN SMALL LETTER G WITH DOT ABOVE chars[0xF6 ]=0x00F6; // LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7; // DIVISION SIGN chars[0xF8 ]=0x011D; // LATIN SMALL LETTER G WITH CIRCUMFLEX chars[0xF9 ]=0x00F9; // LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x00FA; // LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x00FB; // LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC; // LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x016D; // LATIN SMALL LETTER U WITH BREVE chars[0xFE ]=0x015D; // LATIN SMALL LETTER S WITH CIRCUMFLEX chars[0xFF ]=0x02D9; // } public static char decode(byte b){ return chars[b & 0xff]; } }
6,950
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_14.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_14.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; public class ISO8859_14 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0 ;//NO-BREAK SPACE chars[0xA1 ]=0x1E02 ;//LATIN CAPITAL LETTER B WITH DOT ABOVE chars[0xA2 ]=0x1E03 ;//LATIN SMALL LETTER B WITH DOT ABOVE chars[0xA3 ]=0x00A3 ;//POUND SIGN chars[0xA4 ]=0x010A ;//LATIN CAPITAL LETTER C WITH DOT ABOVE chars[0xA5 ]=0x010B ;//LATIN SMALL LETTER C WITH DOT ABOVE chars[0xA6 ]=0x1E0A ;//LATIN CAPITAL LETTER D WITH DOT ABOVE chars[0xA7 ]=0x00A7 ;//SECTION SIGN chars[0xA8 ]=0x1E80 ;//LATIN CAPITAL LETTER W WITH GRAVE chars[0xA9 ]=0x00A9 ;//COPYRIGHT SIGN chars[0xAA ]=0x1E82 ;//LATIN CAPITAL LETTER W WITH ACUTE chars[0xAB ]=0x1E0B ;//LATIN SMALL LETTER D WITH DOT ABOVE chars[0xAC ]=0x1EF2 ;//LATIN CAPITAL LETTER Y WITH GRAVE chars[0xAD ]=0x00AD ;//SOFT HYPHEN chars[0xAE ]=0x00AE ;//REGISTERED SIGN chars[0xAF ]=0x0178 ;//LATIN CAPITAL LETTER Y WITH DIAERESIS chars[0xB0 ]=0x1E1E ;//LATIN CAPITAL LETTER F WITH DOT ABOVE chars[0xB1 ]=0x1E1F ;//LATIN SMALL LETTER F WITH DOT ABOVE chars[0xB2 ]=0x0120 ;//LATIN CAPITAL LETTER G WITH DOT ABOVE chars[0xB3 ]=0x0121 ;//LATIN SMALL LETTER G WITH DOT ABOVE chars[0xB4 ]=0x1E40 ;//LATIN CAPITAL LETTER M WITH DOT ABOVE chars[0xB5 ]=0x1E41 ;//LATIN SMALL LETTER M WITH DOT ABOVE chars[0xB6 ]=0x00B6 ;//PILCROW SIGN chars[0xB7 ]=0x1E56 ;//LATIN CAPITAL LETTER P WITH DOT ABOVE chars[0xB8 ]=0x1E81 ;//LATIN SMALL LETTER W WITH GRAVE chars[0xB9 ]=0x1E57 ;//LATIN SMALL LETTER P WITH DOT ABOVE chars[0xBA ]=0x1E83 ;//LATIN SMALL LETTER W WITH ACUTE chars[0xBB ]=0x1E60 ;//LATIN CAPITAL LETTER S WITH DOT ABOVE chars[0xBC ]=0x1EF3 ;//LATIN SMALL LETTER Y WITH GRAVE chars[0xBD ]=0x1E84 ;//LATIN CAPITAL LETTER W WITH DIAERESIS chars[0xBE ]=0x1E85 ;//LATIN SMALL LETTER W WITH DIAERESIS chars[0xBF ]=0x1E61 ;//LATIN SMALL LETTER S WITH DOT ABOVE chars[0xC0 ]=0x00C0 ;//LATIN CAPITAL LETTER A WITH GRAVE chars[0xC1 ]=0x00C1 ;//LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2 ;//LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3 ]=0x00C3 ;//LATIN CAPITAL LETTER A WITH TILDE chars[0xC4 ]=0x00C4 ;//LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;//LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x00C6 ;//LATIN CAPITAL LETTER AE chars[0xC7 ]=0x00C7 ;//LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x00C8 ;//LATIN CAPITAL LETTER E WITH GRAVE chars[0xC9 ]=0x00C9 ;//LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x00CA ;//LATIN CAPITAL LETTER E WITH CIRCUMFLEX chars[0xCB ]=0x00CB ;//LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x00CC ;//LATIN CAPITAL LETTER I WITH GRAVE chars[0xCD ]=0x00CD ;//LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE ;//LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x00CF ;//LATIN CAPITAL LETTER I WITH DIAERESIS chars[0xD0 ]=0x0174 ;//LATIN CAPITAL LETTER W WITH CIRCUMFLEX chars[0xD1 ]=0x00D1 ;//LATIN CAPITAL LETTER N WITH TILDE chars[0xD2 ]=0x00D2 ;//LATIN CAPITAL LETTER O WITH GRAVE chars[0xD3 ]=0x00D3 ;//LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4 ;//LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x00D5 ;//LATIN CAPITAL LETTER O WITH TILDE chars[0xD6 ]=0x00D6 ;//LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x1E6A ;//LATIN CAPITAL LETTER T WITH DOT ABOVE chars[0xD8 ]=0x00D8 ;//LATIN CAPITAL LETTER O WITH STROKE chars[0xD9 ]=0x00D9 ;//LATIN CAPITAL LETTER U WITH GRAVE chars[0xDA ]=0x00DA ;//LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x00DB ;//LATIN CAPITAL LETTER U WITH CIRCUMFLEX chars[0xDC ]=0x00DC ;//LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x00DD ;//LATIN CAPITAL LETTER Y WITH ACUTE chars[0xDE ]=0x0176 ;//LATIN CAPITAL LETTER Y WITH CIRCUMFLEX chars[0xDF ]=0x00DF ;//LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x00E0 ;//LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x00E1 ;//LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2 ;//LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x00E3 ;//LATIN SMALL LETTER A WITH TILDE chars[0xE4 ]=0x00E4 ;//LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;//LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x00E6 ;//LATIN SMALL LETTER AE chars[0xE7 ]=0x00E7 ;//LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8 ;//LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9 ;//LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA ;//LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB ;//LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x00EC ;//LATIN SMALL LETTER I WITH GRAVE chars[0xED ]=0x00ED ;//LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE ;//LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF ;//LATIN SMALL LETTER I WITH DIAERESIS chars[0xF0 ]=0x0175 ;//LATIN SMALL LETTER W WITH CIRCUMFLEX chars[0xF1 ]=0x00F1 ;//LATIN SMALL LETTER N WITH TILDE chars[0xF2 ]=0x00F2 ;//LATIN SMALL LETTER O WITH GRAVE chars[0xF3 ]=0x00F3 ;//LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4 ;//LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x00F5 ;//LATIN SMALL LETTER O WITH TILDE chars[0xF6 ]=0x00F6 ;//LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x1E6B ;//LATIN SMALL LETTER T WITH DOT ABOVE chars[0xF8 ]=0x00F8 ;//LATIN SMALL LETTER O WITH STROKE chars[0xF9 ]=0x00F9 ;//LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x00FA ;//LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x00FB ;//LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC ;//LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x00FD ;//LATIN SMALL LETTER Y WITH ACUTE chars[0xFE ]=0x0177 ;//LATIN SMALL LETTER Y WITH CIRCUMFLEX chars[0xFF ]=0x00FF ;//LATIN SMALL LETTER Y WITH DIAERESIS } public static char decode(byte b){ return chars[b & 0xff]; } }
7,471
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_11.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_11.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; public class ISO8859_11 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA1 ]=0x0E01 ;//THAI CHARACTER KO KAI chars[0xA2 ]=0x0E02 ;//THAI CHARACTER KHO KHAI chars[0xA3 ]=0x0E03 ;//THAI CHARACTER KHO KHUAT chars[0xA4 ]=0x0E04 ;//THAI CHARACTER KHO KHWAI chars[0xA5 ]=0x0E05 ;//THAI CHARACTER KHO KHON chars[0xA6 ]=0x0E06 ;//THAI CHARACTER KHO RAKHANG chars[0xA7 ]=0x0E07 ;//THAI CHARACTER NGO NGU chars[0xA8 ]=0x0E08 ;//THAI CHARACTER CHO CHAN chars[0xA9 ]=0x0E09 ;//THAI CHARACTER CHO CHING chars[0xAA ]=0x0E0A ;//THAI CHARACTER CHO CHANG chars[0xAB ]=0x0E0B ;//THAI CHARACTER SO SO chars[0xAC ]=0x0E0C ;//THAI CHARACTER CHO CHOE chars[0xAD ]=0x0E0D ;//THAI CHARACTER YO YING chars[0xAE ]=0x0E0E ;//THAI CHARACTER DO CHADA chars[0xAF ]=0x0E0F ;//THAI CHARACTER TO PATAK chars[0xB0 ]=0x0E10 ;//THAI CHARACTER THO THAN chars[0xB1 ]=0x0E11 ;//THAI CHARACTER THO NANGMONTHO chars[0xB2 ]=0x0E12 ;//THAI CHARACTER THO PHUTHAO chars[0xB3 ]=0x0E13 ;//THAI CHARACTER NO NEN chars[0xB4 ]=0x0E14 ;//THAI CHARACTER DO DEK chars[0xB5 ]=0x0E15 ;//THAI CHARACTER TO TAO chars[0xB6 ]=0x0E16 ;//THAI CHARACTER THO THUNG chars[0xB7 ]=0x0E17 ;//THAI CHARACTER THO THAHAN chars[0xB8 ]=0x0E18 ;//THAI CHARACTER THO THONG chars[0xB9 ]=0x0E19 ;//THAI CHARACTER NO NU chars[0xBA ]=0x0E1A ;//THAI CHARACTER BO BAIMAI chars[0xBB ]=0x0E1B ;//THAI CHARACTER PO PLA chars[0xBC ]=0x0E1C ;//THAI CHARACTER PHO PHUNG chars[0xBD ]=0x0E1D ;//THAI CHARACTER FO FA chars[0xBE ]=0x0E1E ;//THAI CHARACTER PHO PHAN chars[0xBF ]=0x0E1F ;//THAI CHARACTER FO FAN chars[0xC0 ]=0x0E20 ;//THAI CHARACTER PHO SAMPHAO chars[0xC1 ]=0x0E21 ;//THAI CHARACTER MO MA chars[0xC2 ]=0x0E22 ;//THAI CHARACTER YO YAK chars[0xC3 ]=0x0E23 ;//THAI CHARACTER RO RUA chars[0xC4 ]=0x0E24 ;//THAI CHARACTER RU chars[0xC5 ]=0x0E25 ;//THAI CHARACTER LO LING chars[0xC6 ]=0x0E26 ;//THAI CHARACTER LU chars[0xC7 ]=0x0E27 ;//THAI CHARACTER WO WAEN chars[0xC8 ]=0x0E28 ;//THAI CHARACTER SO SALA chars[0xC9 ]=0x0E29 ;//THAI CHARACTER SO RUSI chars[0xCA ]=0x0E2A ;//THAI CHARACTER SO SUA chars[0xCB ]=0x0E2B ;//THAI CHARACTER HO HIP chars[0xCC ]=0x0E2C ;//THAI CHARACTER LO CHULA chars[0xCD ]=0x0E2D ;//THAI CHARACTER O ANG chars[0xCE ]=0x0E2E ;//THAI CHARACTER HO NOKHUK chars[0xCF ]=0x0E2F ;//THAI CHARACTER PAIYANNOI chars[0xD0 ]=0x0E30 ;//THAI CHARACTER SARA A chars[0xD1 ]=0x0E31 ;//THAI CHARACTER MAI HAN-AKAT chars[0xD2 ]=0x0E32 ;//THAI CHARACTER SARA AA chars[0xD3 ]=0x0E33 ;//THAI CHARACTER SARA AM chars[0xD4 ]=0x0E34 ;//THAI CHARACTER SARA I chars[0xD5 ]=0x0E35 ;//THAI CHARACTER SARA II chars[0xD6 ]=0x0E36 ;//THAI CHARACTER SARA UE chars[0xD7 ]=0x0E37 ;//THAI CHARACTER SARA UEE chars[0xD8 ]=0x0E38 ;//THAI CHARACTER SARA U chars[0xD9 ]=0x0E39 ;//THAI CHARACTER SARA UU chars[0xDA ]=0x0E3A ;//THAI CHARACTER PHINTHU chars[0xDF ]=0x0E3F ;//THAI CURRENCY SYMBOL BAHT chars[0xE0 ]=0x0E40 ;//THAI CHARACTER SARA E chars[0xE1 ]=0x0E41 ;//THAI CHARACTER SARA AE chars[0xE2 ]=0x0E42 ;//THAI CHARACTER SARA O chars[0xE3 ]=0x0E43 ;//THAI CHARACTER SARA AI MAIMUAN chars[0xE4 ]=0x0E44 ;//THAI CHARACTER SARA AI MAIMALAI chars[0xE5 ]=0x0E45 ;//THAI CHARACTER LAKKHANGYAO chars[0xE6 ]=0x0E46 ;//THAI CHARACTER MAIYAMOK chars[0xE7 ]=0x0E47 ;//THAI CHARACTER MAITAIKHU chars[0xE8 ]=0x0E48 ;//THAI CHARACTER MAI EK chars[0xE9 ]=0x0E49 ;//THAI CHARACTER MAI THO chars[0xEA ]=0x0E4A ;//THAI CHARACTER MAI TRI chars[0xEB ]=0x0E4B ;//THAI CHARACTER MAI CHATTAWA chars[0xEC ]=0x0E4C ;//THAI CHARACTER THANTHAKHAT chars[0xED ]=0x0E4D ;//THAI CHARACTER NIKHAHIT chars[0xEE ]=0x0E4E ;//THAI CHARACTER YAMAKKAN chars[0xEF ]=0x0E4F ;//THAI CHARACTER FONGMAN chars[0xF0 ]=0x0E50 ;//THAI DIGIT ZERO chars[0xF1 ]=0x0E51 ;//THAI DIGIT ONE chars[0xF2 ]=0x0E52 ;//THAI DIGIT TWO chars[0xF3 ]=0x0E53 ;//THAI DIGIT THREE chars[0xF4 ]=0x0E54 ;//THAI DIGIT FOUR chars[0xF5 ]=0x0E55 ;//THAI DIGIT FIVE chars[0xF6 ]=0x0E56 ;//THAI DIGIT SIX chars[0xF7 ]=0x0E57 ;//THAI DIGIT SEVEN chars[0xF8 ]=0x0E58 ;//THAI DIGIT EIGHT chars[0xF9 ]=0x0E59 ;//THAI DIGIT NINE chars[0xFA ]=0x0E5A ;//THAI CHARACTER ANGKHANKHU chars[0xFB ]=0x0E5B ;//THAI CHARACTER KHOMUT } public static char decode(byte b){ return chars[b & 0xff]; } }
5,951
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1251.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1251.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * This class contains method to map a windows-1251 char * into a Unicode char * */ public class WIN1251 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x0402 ;// CYRILLIC CAPITAL LETTER DJE chars[0x81 ]=0x0403 ;// CYRILLIC CAPITAL LETTER GJE chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0453 ;// CYRILLIC SMALL LETTER GJE chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x20AC ;// EURO SIGN chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8A ]=0x0409 ;// CYRILLIC CAPITAL LETTER LJE chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x040A ;// CYRILLIC CAPITAL LETTER NJE chars[0x8D ]=0x040C ;// CYRILLIC CAPITAL LETTER KJE chars[0x8E ]=0x040B ;// CYRILLIC CAPITAL LETTER TSHE chars[0x8F ]=0x040F ;// CYRILLIC CAPITAL LETTER DZHE chars[0x90 ]=0x0452 ;// CYRILLIC SMALL LETTER DJE chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9A ]=0x0459 ;// CYRILLIC SMALL LETTER LJE chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x045A ;// CYRILLIC SMALL LETTER NJE chars[0x9D ]=0x045C ;// CYRILLIC SMALL LETTER KJE chars[0x9E ]=0x045B ;// CYRILLIC SMALL LETTER TSHE chars[0x9F ]=0x045F ;// CYRILLIC SMALL LETTER DZHE chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x040E ;// CYRILLIC CAPITAL LETTER SHORT U chars[0xA2 ]=0x045E ;// CYRILLIC SMALL LETTER SHORT U chars[0xA3 ]=0x0408 ;// CYRILLIC CAPITAL LETTER JE chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x0490 ;// CYRILLIC CAPITAL LETTER GHE WITH UPTURN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x0401 ;// CYRILLIC CAPITAL LETTER IO chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x0404 ;// CYRILLIC CAPITAL LETTER UKRAINIAN IE chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x0407 ;// CYRILLIC CAPITAL LETTER YI chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x0406 ;// CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I chars[0xB3 ]=0x0456 ;// CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I chars[0xB4 ]=0x0491 ;// CYRILLIC SMALL LETTER GHE WITH UPTURN chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x0451 ;// CYRILLIC SMALL LETTER IO chars[0xB9 ]=0x2116 ;// NUMERO SIGN chars[0xBA ]=0x0454 ;// CYRILLIC SMALL LETTER UKRAINIAN IE chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x0458 ;// CYRILLIC SMALL LETTER JE chars[0xBD ]=0x0405 ;// CYRILLIC CAPITAL LETTER DZE chars[0xBE ]=0x0455 ;// CYRILLIC SMALL LETTER DZE chars[0xBF ]=0x0457 ;// CYRILLIC SMALL LETTER YI chars[0xC0 ]=0x0410 ;// CYRILLIC CAPITAL LETTER A chars[0xC1 ]=0x0411 ;// CYRILLIC CAPITAL LETTER BE chars[0xC2 ]=0x0412 ;// CYRILLIC CAPITAL LETTER VE chars[0xC3 ]=0x0413 ;// CYRILLIC CAPITAL LETTER GHE chars[0xC4 ]=0x0414 ;// CYRILLIC CAPITAL LETTER DE chars[0xC5 ]=0x0415 ;// CYRILLIC CAPITAL LETTER IE chars[0xC6 ]=0x0416 ;// CYRILLIC CAPITAL LETTER ZHE chars[0xC7 ]=0x0417 ;// CYRILLIC CAPITAL LETTER ZE chars[0xC8 ]=0x0418 ;// CYRILLIC CAPITAL LETTER I chars[0xC9 ]=0x0419 ;// CYRILLIC CAPITAL LETTER SHORT I chars[0xCA ]=0x041A ;// CYRILLIC CAPITAL LETTER KA chars[0xCB ]=0x041B ;// CYRILLIC CAPITAL LETTER EL chars[0xCC ]=0x041C ;// CYRILLIC CAPITAL LETTER EM chars[0xCD ]=0x041D ;// CYRILLIC CAPITAL LETTER EN chars[0xCE ]=0x041E ;// CYRILLIC CAPITAL LETTER O chars[0xCF ]=0x041F ;// CYRILLIC CAPITAL LETTER PE chars[0xD0 ]=0x0420 ;// CYRILLIC CAPITAL LETTER ER chars[0xD1 ]=0x0421 ;// CYRILLIC CAPITAL LETTER ES chars[0xD2 ]=0x0422 ;// CYRILLIC CAPITAL LETTER TE chars[0xD3 ]=0x0423 ;// CYRILLIC CAPITAL LETTER U chars[0xD4 ]=0x0424 ;// CYRILLIC CAPITAL LETTER EF chars[0xD5 ]=0x0425 ;// CYRILLIC CAPITAL LETTER HA chars[0xD6 ]=0x0426 ;// CYRILLIC CAPITAL LETTER TSE chars[0xD7 ]=0x0427 ;// CYRILLIC CAPITAL LETTER CHE chars[0xD8 ]=0x0428 ;// CYRILLIC CAPITAL LETTER SHA chars[0xD9 ]=0x0429 ;// CYRILLIC CAPITAL LETTER SHCHA chars[0xDA ]=0x042A ;// CYRILLIC CAPITAL LETTER HARD SIGN chars[0xDB ]=0x042B ;// CYRILLIC CAPITAL LETTER YERU chars[0xDC ]=0x042C ;// CYRILLIC CAPITAL LETTER SOFT SIGN chars[0xDD ]=0x042D ;// CYRILLIC CAPITAL LETTER E chars[0xDE ]=0x042E ;// CYRILLIC CAPITAL LETTER YU chars[0xDF ]=0x042F ;// CYRILLIC CAPITAL LETTER YA chars[0xE0 ]=0x0430 ;// CYRILLIC SMALL LETTER A chars[0xE1 ]=0x0431 ;// CYRILLIC SMALL LETTER BE chars[0xE2 ]=0x0432 ;// CYRILLIC SMALL LETTER VE chars[0xE3 ]=0x0433 ;// CYRILLIC SMALL LETTER GHE chars[0xE4 ]=0x0434 ;// CYRILLIC SMALL LETTER DE chars[0xE5 ]=0x0435 ;// CYRILLIC SMALL LETTER IE chars[0xE6 ]=0x0436 ;// CYRILLIC SMALL LETTER ZHE chars[0xE7 ]=0x0437 ;// CYRILLIC SMALL LETTER ZE chars[0xE8 ]=0x0438 ;// CYRILLIC SMALL LETTER I chars[0xE9 ]=0x0439 ;// CYRILLIC SMALL LETTER SHORT I chars[0xEA ]=0x043A ;// CYRILLIC SMALL LETTER KA chars[0xEB ]=0x043B ;// CYRILLIC SMALL LETTER EL chars[0xEC ]=0x043C ;// CYRILLIC SMALL LETTER EM chars[0xED ]=0x043D ;// CYRILLIC SMALL LETTER EN chars[0xEE ]=0x043E ;// CYRILLIC SMALL LETTER O chars[0xEF ]=0x043F ;// CYRILLIC SMALL LETTER PE chars[0xF0 ]=0x0440 ;// CYRILLIC SMALL LETTER ER chars[0xF1 ]=0x0441 ;// CYRILLIC SMALL LETTER ES chars[0xF2 ]=0x0442 ;// CYRILLIC SMALL LETTER TE chars[0xF3 ]=0x0443 ;// CYRILLIC SMALL LETTER U chars[0xF4 ]=0x0444 ;// CYRILLIC SMALL LETTER EF chars[0xF5 ]=0x0445 ;// CYRILLIC SMALL LETTER HA chars[0xF6 ]=0x0446 ;// CYRILLIC SMALL LETTER TSE chars[0xF7 ]=0x0447 ;// CYRILLIC SMALL LETTER CHE chars[0xF8 ]=0x0448 ;// CYRILLIC SMALL LETTER SHA chars[0xF9 ]=0x0449 ;// CYRILLIC SMALL LETTER SHCHA chars[0xFA ]=0x044A ;// CYRILLIC SMALL LETTER HARD SIGN chars[0xFB ]=0x044B ;// CYRILLIC SMALL LETTER YERU chars[0xFC ]=0x044C ;// CYRILLIC SMALL LETTER SOFT SIGN chars[0xFD ]=0x044D ;// CYRILLIC SMALL LETTER E chars[0xFE ]=0x044E ;// CYRILLIC SMALL LETTER YU chars[0xFF ]=0x044F ;// CYRILLIC SMALL LETTER YA } public static char decode(byte b){ return chars[b & 0xff]; } }
8,816
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_5.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_5.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-5 char * into a Unicode char * */ public class ISO8859_5 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA1 ]=0x0401; chars[0xA2 ]=0x0402; chars[0xA3 ]=0x0403; chars[0xA4 ]=0x0404; chars[0xA5 ]=0x0405; chars[0xA6 ]=0x0406; chars[0xA7 ]=0x0407; chars[0xA8 ]=0x0408; chars[0xA9 ]=0x0409; chars[0xAA ]=0x040A; chars[0xAB ]=0x040B; chars[0xAC ]=0x040C; chars[0xAD ]=0x00AD; chars[0xAE ]=0x040E; chars[0xAF ]=0x040F; chars[0xB0 ]=0x0410; chars[0xB1 ]=0x0411; chars[0xB2 ]=0x0412; chars[0xB3 ]=0x0413; chars[0xB4 ]=0x0414; chars[0xB5 ]=0x0415; chars[0xB6 ]=0x0416; chars[0xB7 ]=0x0417; chars[0xB8 ]=0x0418; chars[0xB9 ]=0x0419; chars[0xBA ]=0x041A; chars[0xBB ]=0x041B; chars[0xBC ]=0x041C; chars[0xBD ]=0x041D; chars[0xBE ]=0x041E; chars[0xBF ]=0x041F; chars[0xC0 ]=0x0420; chars[0xC1 ]=0x0421; chars[0xC2 ]=0x0422; chars[0xC3 ]=0x0423; chars[0xC4 ]=0x0424; chars[0xC5 ]=0x0425; chars[0xC6 ]=0x0426; chars[0xC7 ]=0x0427; chars[0xC8 ]=0x0428; chars[0xC9 ]=0x0429; chars[0xCA ]=0x042A; chars[0xCB ]=0x042B; chars[0xCC ]=0x042C; chars[0xCD ]=0x042D; chars[0xCE ]=0x042E; chars[0xCF ]=0x042F; chars[0xD0 ]=0x0430; chars[0xD1 ]=0x0431; chars[0xD2 ]=0x0432; chars[0xD3 ]=0x0433; chars[0xD4 ]=0x0434; chars[0xD5 ]=0x0435; chars[0xD6 ]=0x0436; chars[0xD7 ]=0x0437; chars[0xD8 ]=0x0438; chars[0xD9 ]=0x0439; chars[0xDA ]=0x043A; chars[0xDB ]=0x043B; chars[0xDC ]=0x043C; chars[0xDD ]=0x043D; chars[0xDE ]=0x043E; chars[0xDF ]=0x043F; chars[0xE0 ]=0x0440; chars[0xE1 ]=0x0441; chars[0xE2 ]=0x0442; chars[0xE3 ]=0x0443; chars[0xE4 ]=0x0444; chars[0xE5 ]=0x0445; chars[0xE6 ]=0x0446; chars[0xE7 ]=0x0447; chars[0xE8 ]=0x0448; chars[0xE9 ]=0x0449; chars[0xEA ]=0x044A; chars[0xEB ]=0x044B; chars[0xEC ]=0x044C; chars[0xED ]=0x044D; chars[0xEE ]=0x044E; chars[0xEF ]=0x044F; chars[0xF0 ]=0x2116; chars[0xF1 ]=0x0451; chars[0xF2 ]=0x0452; chars[0xF3 ]=0x0453; chars[0xF4 ]=0x0454; chars[0xF5 ]=0x0455; chars[0xF6 ]=0x0456; chars[0xF7 ]=0x0457; chars[0xF8 ]=0x0458; chars[0xF9 ]=0x0459; chars[0xFA ]=0x045A; chars[0xFB ]=0x045B; chars[0xFC ]=0x045C; chars[0xFD ]=0x00A7; chars[0xFE ]=0x045E; chars[0xFF ]=0x045F; } public static char decode(byte b){ return chars[b & 0xff]; } }
4,153
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
XMLChar.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/XMLChar.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * XimpleWare's XMLChar implementation. * Creation date: (2/9/04 6:27:46 PM) */ public class XMLChar { /** * XMLChar constructor comment. */ // // Constants // /** Character flags. */ public static final byte[] UNI_CHARS = new byte[0x10000]; /** Valid character mask. */ public static final int XML_VALID = 0x01; /** Space character mask. */ public static final int XML_SPACE = 0x02; /** Name start character mask. */ public static final int XML_NAME_START = 0x04; /** Name character mask. */ public static final int XML_NAME = 0x08; /** Pubid character mask. */ public static final int XML_PUBID = 0x10; /** * Content character mask. Special characters are those that can * be considered the start of markup, such as '&lt;' and '&amp;'. * The various newline characters are considered special as well. * All other valid XML characters can be considered content. * <p> * This is an optimization for the inner loop of character scanning. */ public static final int XML_CONTENT = 0x20; /** NCName start character mask. */ public static final int XML_NCNAME_START = 0x40; /** NCName character mask. */ public static final int XML_NCNAME = 0x80; // // Static initialization // static { // // [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | // [#xE000-#xFFFD] | [#x10000-#x10FFFF] // int xmlCharRange[][] = { { 0x0009, 0x000A }, { 0x000D, 0x000D }, { 0x0020, 0xD7FF }, { 0xE000, 0xFFFD }, }; // // [3] S ::= (#x20 | #x9 | #xD | #xA)+ // int xmlSpaceChar[] = { 0x0020, 0x0009, 0x000D, 0x000A, }; // // [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | // CombiningChar | Extender // int xmlNameChar[] = { 0x002D, 0x002E, // '-' and '.' }; // // [5] Name ::= (Letter | '_' | ':') (NameChar)* // int xmlNameStartChar[] = { 0x003A, 0x005F, // ':' and '_' }; // // [13] PubidChar ::= #x20 | 0xD | 0xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] // int xmlPubidChar[] = { 0x000A, 0x000D, 0x0020, 0x0021, 0x0023, 0x0024, 0x0025, 0x003D, 0x005F }; int xmlPubidRange[][] = { { 0x0027, 0x003B }, { 0x003F, 0x005A }, { 0x0061, 0x007A } }; // // [84] Letter ::= BaseChar | Ideographic // int xmlLetterRange[][] = { // BaseChar { 0x0041, 0x005A }, { 0x0061, 0x007A }, { 0x00C0, 0x00D6 }, { 0x00D8, 0x00F6 }, { 0x00F8, 0x0131 }, { 0x0134, 0x013E }, { 0x0141, 0x0148 }, { 0x014A, 0x017E }, { 0x0180, 0x01C3 }, { 0x01CD, 0x01F0 }, { 0x01F4, 0x01F5 }, { 0x01FA, 0x0217 }, { 0x0250, 0x02A8 }, { 0x02BB, 0x02C1 }, { 0x0388, 0x038A }, { 0x038E, 0x03A1 }, { 0x03A3, 0x03CE }, { 0x03D0, 0x03D6 }, { 0x03E2, 0x03F3 }, { 0x0401, 0x040C }, { 0x040E, 0x044F }, { 0x0451, 0x045C }, { 0x045E, 0x0481 }, { 0x0490, 0x04C4 }, { 0x04C7, 0x04C8 }, { 0x04CB, 0x04CC }, { 0x04D0, 0x04EB }, { 0x04EE, 0x04F5 }, { 0x04F8, 0x04F9 }, { 0x0531, 0x0556 }, { 0x0561, 0x0586 }, { 0x05D0, 0x05EA }, { 0x05F0, 0x05F2 }, { 0x0621, 0x063A }, { 0x0641, 0x064A }, { 0x0671, 0x06B7 }, { 0x06BA, 0x06BE }, { 0x06C0, 0x06CE }, { 0x06D0, 0x06D3 }, { 0x06E5, 0x06E6 }, { 0x0905, 0x0939 }, { 0x0958, 0x0961 }, { 0x0985, 0x098C }, { 0x098F, 0x0990 }, { 0x0993, 0x09A8 }, { 0x09AA, 0x09B0 }, { 0x09B6, 0x09B9 }, { 0x09DC, 0x09DD }, { 0x09DF, 0x09E1 }, { 0x09F0, 0x09F1 }, { 0x0A05, 0x0A0A }, { 0x0A0F, 0x0A10 }, { 0x0A13, 0x0A28 }, { 0x0A2A, 0x0A30 }, { 0x0A32, 0x0A33 }, { 0x0A35, 0x0A36 }, { 0x0A38, 0x0A39 }, { 0x0A59, 0x0A5C }, { 0x0A72, 0x0A74 }, { 0x0A85, 0x0A8B }, { 0x0A8F, 0x0A91 }, { 0x0A93, 0x0AA8 }, { 0x0AAA, 0x0AB0 }, { 0x0AB2, 0x0AB3 }, { 0x0AB5, 0x0AB9 }, { 0x0B05, 0x0B0C }, { 0x0B0F, 0x0B10 }, { 0x0B13, 0x0B28 }, { 0x0B2A, 0x0B30 }, { 0x0B32, 0x0B33 }, { 0x0B36, 0x0B39 }, { 0x0B5C, 0x0B5D }, { 0x0B5F, 0x0B61 }, { 0x0B85, 0x0B8A }, { 0x0B8E, 0x0B90 }, { 0x0B92, 0x0B95 }, { 0x0B99, 0x0B9A }, { 0x0B9E, 0x0B9F }, { 0x0BA3, 0x0BA4 }, { 0x0BA8, 0x0BAA }, { 0x0BAE, 0x0BB5 }, { 0x0BB7, 0x0BB9 }, { 0x0C05, 0x0C0C }, { 0x0C0E, 0x0C10 }, { 0x0C12, 0x0C28 }, { 0x0C2A, 0x0C33 }, { 0x0C35, 0x0C39 }, { 0x0C60, 0x0C61 }, { 0x0C85, 0x0C8C }, { 0x0C8E, 0x0C90 }, { 0x0C92, 0x0CA8 }, { 0x0CAA, 0x0CB3 }, { 0x0CB5, 0x0CB9 }, { 0x0CE0, 0x0CE1 }, { 0x0D05, 0x0D0C }, { 0x0D0E, 0x0D10 }, { 0x0D12, 0x0D28 }, { 0x0D2A, 0x0D39 }, { 0x0D60, 0x0D61 }, { 0x0E01, 0x0E2E }, { 0x0E32, 0x0E33 }, { 0x0E40, 0x0E45 }, { 0x0E81, 0x0E82 }, { 0x0E87, 0x0E88 }, { 0x0E94, 0x0E97 }, { 0x0E99, 0x0E9F }, { 0x0EA1, 0x0EA3 }, { 0x0EAA, 0x0EAB }, { 0x0EAD, 0x0EAE }, { 0x0EB2, 0x0EB3 }, { 0x0EC0, 0x0EC4 }, { 0x0F40, 0x0F47 }, { 0x0F49, 0x0F69 }, { 0x10A0, 0x10C5 }, { 0x10D0, 0x10F6 }, { 0x1102, 0x1103 }, { 0x1105, 0x1107 }, { 0x110B, 0x110C }, { 0x110E, 0x1112 }, { 0x1154, 0x1155 }, { 0x115F, 0x1161 }, { 0x116D, 0x116E }, { 0x1172, 0x1173 }, { 0x11AE, 0x11AF }, { 0x11B7, 0x11B8 }, { 0x11BC, 0x11C2 }, { 0x1E00, 0x1E9B }, { 0x1EA0, 0x1EF9 }, { 0x1F00, 0x1F15 }, { 0x1F18, 0x1F1D }, { 0x1F20, 0x1F45 }, { 0x1F48, 0x1F4D }, { 0x1F50, 0x1F57 }, { 0x1F5F, 0x1F7D }, { 0x1F80, 0x1FB4 }, { 0x1FB6, 0x1FBC }, { 0x1FC2, 0x1FC4 }, { 0x1FC6, 0x1FCC }, { 0x1FD0, 0x1FD3 }, { 0x1FD6, 0x1FDB }, { 0x1FE0, 0x1FEC }, { 0x1FF2, 0x1FF4 }, { 0x1FF6, 0x1FFC }, { 0x212A, 0x212B }, { 0x2180, 0x2182 }, { 0x3041, 0x3094 }, { 0x30A1, 0x30FA }, { 0x3105, 0x312C }, { 0xAC00, 0xD7A3 }, // Ideographic { 0x3021, 0x3029 }, { 0x4E00, 0x9FA5 }, }; int xmlLetterChar[] = { // BaseChar 0x0386, 0x038C, 0x03DA, 0x03DC, 0x03DE, 0x03E0, 0x0559, 0x06D5, 0x093D, 0x09B2, 0x0A5E, 0x0A8D, 0x0ABD, 0x0AE0, 0x0B3D, 0x0B9C, 0x0CDE, 0x0E30, 0x0E84, 0x0E8A, 0x0E8D, 0x0EA5, 0x0EA7, 0x0EB0, 0x0EBD, 0x1100, 0x1109, 0x113C, 0x113E, 0x1140, 0x114C, 0x114E, 0x1150, 0x1159, 0x1163, 0x1165, 0x1167, 0x1169, 0x1175, 0x119E, 0x11A8, 0x11AB, 0x11BA, 0x11EB, 0x11F0, 0x11F9, 0x1F59, 0x1F5B, 0x1F5D, 0x1FBE, 0x2126, 0x212E, // Ideographic 0x3007, }; // // [87] CombiningChar ::= ... // int xmlCombiningCharRange[][] = { { 0x0300, 0x0345 }, { 0x0360, 0x0361 }, { 0x0483, 0x0486 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 }, { 0x05BB, 0x05BD }, { 0x05C1, 0x05C2 }, { 0x064B, 0x0652 }, { 0x06D6, 0x06DC }, { 0x06DD, 0x06DF }, { 0x06E0, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x0901, 0x0903 }, { 0x093E, 0x094C }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0983 }, { 0x09C0, 0x09C4 }, { 0x09C7, 0x09C8 }, { 0x09CB, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A40, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A83 }, { 0x0ABE, 0x0AC5 }, { 0x0AC7, 0x0AC9 }, { 0x0ACB, 0x0ACD }, { 0x0B01, 0x0B03 }, { 0x0B3E, 0x0B43 }, { 0x0B47, 0x0B48 }, { 0x0B4B, 0x0B4D }, { 0x0B56, 0x0B57 }, { 0x0B82, 0x0B83 }, { 0x0BBE, 0x0BC2 }, { 0x0BC6, 0x0BC8 }, { 0x0BCA, 0x0BCD }, { 0x0C01, 0x0C03 }, { 0x0C3E, 0x0C44 }, { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0C82, 0x0C83 }, { 0x0CBE, 0x0CC4 }, { 0x0CC6, 0x0CC8 }, { 0x0CCA, 0x0CCD }, { 0x0CD5, 0x0CD6 }, { 0x0D02, 0x0D03 }, { 0x0D3E, 0x0D43 }, { 0x0D46, 0x0D48 }, { 0x0D4A, 0x0D4D }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F71, 0x0F84 }, { 0x0F86, 0x0F8B }, { 0x0F90, 0x0F95 }, { 0x0F99, 0x0FAD }, { 0x0FB1, 0x0FB7 }, { 0x20D0, 0x20DC }, { 0x302A, 0x302F }, }; int xmlCombiningCharChar[] = { 0x05BF, 0x05C4, 0x0670, 0x093C, 0x094D, 0x09BC, 0x09BE, 0x09BF, 0x09D7, 0x0A02, 0x0A3C, 0x0A3E, 0x0A3F, 0x0ABC, 0x0B3C, 0x0BD7, 0x0D57, 0x0E31, 0x0EB1, 0x0F35, 0x0F37, 0x0F39, 0x0F3E, 0x0F3F, 0x0F97, 0x0FB9, 0x20E1, 0x3099, 0x309A, }; // // [88] Digit ::= ... // int xmlDigitRange[][] = { { 0x0030, 0x0039 }, { 0x0660, 0x0669 }, { 0x06F0, 0x06F9 }, { 0x0966, 0x096F }, { 0x09E6, 0x09EF }, { 0x0A66, 0x0A6F }, { 0x0AE6, 0x0AEF }, { 0x0B66, 0x0B6F }, { 0x0BE7, 0x0BEF }, { 0x0C66, 0x0C6F }, { 0x0CE6, 0x0CEF }, { 0x0D66, 0x0D6F }, { 0x0E50, 0x0E59 }, { 0x0ED0, 0x0ED9 }, { 0x0F20, 0x0F29 }, }; // // [89] Extender ::= ... // int xmlExtenderRange[][] = { { 0x3031, 0x3035 }, { 0x309D, 0x309E }, { 0x30FC, 0x30FE }, }; int xmlExtenderChar[] = { 0x00B7, 0x02D0, 0x02D1, 0x0387, 0x0640, 0x0E46, 0x0EC6, 0x3005, }; // // SpecialChar ::= '<', '&', '\n', '\r', ']' // //int specialChar[] = { // '<', '&', '\n', '\r', ']', //}; int xmlSpecialChar[] = { '<', '&', ']' }; // // Static Initialization of all chars and their masks // // set valid characters for (int i = 0; i < xmlCharRange.length; i++) { for (int j = xmlCharRange[i][0]; j <= xmlCharRange[i][1]; j++) { UNI_CHARS[j] |= XML_VALID | XML_CONTENT; } } // remove special characters for (int i = 0; i < xmlSpecialChar.length; i++) { UNI_CHARS[xmlSpecialChar[i]] = (byte) (UNI_CHARS[xmlSpecialChar[i]] & ~XML_CONTENT); } // set space characters for (int i = 0; i < xmlSpaceChar.length; i++) { UNI_CHARS[xmlSpaceChar[i]] |= XML_SPACE; } // set name start characters for (int i = 0; i < xmlNameStartChar.length; i++) { UNI_CHARS[xmlNameStartChar[i]] |= XML_NAME_START | XML_NAME | XML_NCNAME_START | XML_NCNAME; } for (int i = 0; i < xmlLetterRange.length; i++) { for (int j = xmlLetterRange[i][0]; j <= xmlLetterRange[i][1]; j++) { UNI_CHARS[j] |= XML_NAME_START | XML_NAME | XML_NCNAME_START | XML_NCNAME; } } for (int i = 0; i < xmlLetterChar.length; i++) { UNI_CHARS[xmlLetterChar[i]] |= XML_NAME_START | XML_NAME | XML_NCNAME_START | XML_NCNAME; } // set name characters for (int i = 0; i < xmlNameChar.length; i++) { UNI_CHARS[xmlNameChar[i]] |= XML_NAME | XML_NCNAME; } for (int i = 0; i < xmlDigitRange.length; i++) { for (int j = xmlDigitRange[i][0]; j <= xmlDigitRange[i][1]; j++) { UNI_CHARS[j] |= XML_NAME | XML_NCNAME; } } for (int i = 0; i < xmlCombiningCharRange.length; i++) { for (int j = xmlCombiningCharRange[i][0]; j <= xmlCombiningCharRange[i][1]; j++) { UNI_CHARS[j] |= XML_NAME | XML_NCNAME; } } for (int i = 0; i < xmlCombiningCharChar.length; i++) { UNI_CHARS[xmlCombiningCharChar[i]] |= XML_NAME | XML_NCNAME; } for (int i = 0; i < xmlExtenderRange.length; i++) { for (int j = xmlExtenderRange[i][0]; j <= xmlExtenderRange[i][1]; j++) { UNI_CHARS[j] |= XML_NAME | XML_NCNAME; } } for (int i = 0; i < xmlExtenderChar.length; i++) { UNI_CHARS[xmlExtenderChar[i]] |= XML_NAME | XML_NCNAME; } // remove ':' from allowable XML_NCNAME_START and XML_NCNAME chars UNI_CHARS[':'] &= ~(XML_NCNAME_START | XML_NCNAME); // set Pubid characters for (int i = 0; i < xmlPubidChar.length; i++) { UNI_CHARS[xmlPubidChar[i]] |= XML_PUBID; } for (int i = 0; i < xmlPubidRange.length; i++) { for (int j = xmlPubidRange[i][0]; j <= xmlPubidRange[i][1]; j++) { UNI_CHARS[j] |= XML_PUBID; } } } /** * Returns the high surrogate from a Unicode scalar value * * @param c * The Unicode scalar value to "split". */ public static char highSurrogate(int c) { //H = (S - 0x10000) / 0x400 + 0xD800 return (char) ((c >> 10) + 0xd7c0); } /** * Returns true if the specified character can be considered XML content. * * @param c * The character to check. */ public static boolean isContentChar(int c) { return (c < 0x10000 && (UNI_CHARS[c] & XML_CONTENT) != 0) || (0x10000 <= c && c <= 0x10FFFF); } /** * Returns whether the given Unicode scalar value is a high surrogate * * @param c * The character to check. */ public static boolean isHighSurrogate(int c) { return (0xD800 <= c && c <= 0xDBFF); } /** * Returns true if the specified character is invalid. * * @param c * The character to check. */ public static boolean isInvalidChar(int c) { return ((c < 0x10000) && (UNI_CHARS[c] & XML_VALID) == 0) || (c >= 0x10ffff); } /** * Returns whether the given Unicode scalar value is a low surrogate * * @param c * The character to check. */ public static boolean isLowSurrogate(int c) { return (0xDC00 <= c && c <= 0xDFFF); } /** * Returns true if the specified character can be considered markup. * Markup characters include '&lt;', '&amp;', and '%'. * * @param c The character to check. */ public static boolean isMarkupChar(int c) { return c == '<' || c == '&' || c == '%'; } /** * Returns true if the specified character is a valid name * character as defined by production [4] in the XML 1.0 * specification. * * @param c The character to check. */ public static boolean isNameChar(int c) { return c < 0x10000 && (UNI_CHARS[c] & XML_NAME) != 0; } /** * Returns true if the specified character is a valid name start * character as defined by production [5] in the XML 1.0 * specification. * * @param c The character to check. */ public static boolean isNameStartChar(int c) { return c < 0x10000 && (UNI_CHARS[c] & XML_NAME_START) != 0; } /** * Returns true if the specified character is a valid NCName * character as defined by production [5] in Namespaces in XML * recommendation. * * @param c The character to check. */ public static boolean isNCNameChar(int c) { return c < 0x10000 && (UNI_CHARS[c] & XML_NCNAME) != 0; } /** * Returns true if the specified character is a valid NCName start * character as defined by production [4] in Namespaces in XML * recommendation. * * @param c The character to check. */ public static boolean isNCNameStartChar(int c) { return c < 0x10000 && (UNI_CHARS[c] & XML_NCNAME_START) != 0; } /* * [7] Nmtoken ::= (NameChar)+ * * Check to see if a string is a valid Nmtoken according to [7] * in the XML 1.0 Recommendation * * @param nmToken string to check * @return true if nmtoken is a valid Nmtoken */ public static boolean isNmtoken(String nmToken) { if (nmToken.length() == 0) return false; for (int i = 0; i < nmToken.length(); i++ ) if(!isNameChar( nmToken.charAt(i))) return false; return true; } /** * Returns true if the specified character is a valid Pubid * character as defined by production [13] in the XML 1.0 * specification. * * @param c The character to check. */ public static boolean isPubidChar(int c) { return c < 0x10000 && (UNI_CHARS[c] & XML_PUBID) != 0; } /** * Returns true if the specified character is a space character * as defined by production [3] in the XML 1.0 specification. * * @param c The character to check. */ public static boolean isSpaceChar(int c) { return c <= 0x20 && (UNI_CHARS[c] & XML_SPACE) != 0; } /** * Returns true if the specified character is a supplemental character. * * @param c The character to check. */ public static boolean isSupplementalChar(int c) { return (c >= 0x10000 && c <= 0x10FFFF); } /** * Returns true if the specified character is valid. This method * also checks the surrogate character range from 0x10000 to 0x10FFFF. * <p> * If the program chooses to apply the mask directly to the * <code>UNI_CHARS</code> array, then they are responsible for checking * the surrogate character range. * * @param c The character to check. */ public static boolean isValidChar(int c) { return (c < 0x10000 && (UNI_CHARS[c] & XML_VALID) != 0) || (0x10000 <= c && c <= 0x10FFFF); } /** * Returns the low surrogate from a Unicode scalar value * * @param c The Unicode scalar value to "split". */ public static char lowSurrogate(int c) { //L = (S - 0x10000) % 0x400 + 0xDC00 return (char) (((c - 0x00010000) & 0x3FF) + 0xDC00); } /** * Returns Unicode scalar value corresponding to the given * surrogates. * * @param hi The high surrogate. * @param lo The low surrogate. */ public static int scalarValueSurrogate(char hi, char lo) { //N = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000 return ((hi - 0xd800) << 10) + lo - 0x2400; } }
19,091
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1256.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1256.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1256 char * into a Unicode char * */ public class WIN1256 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x81 ]=0x067E ;// ARABIC LETTER PEH chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x02C6 ;// MODIFIER LETTER CIRCUMFLEX ACCENT chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8A ]=0x0679 ;// ARABIC LETTER TTEH chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x0152 ;// LATIN CAPITAL LIGATURE OE chars[0x8D ]=0x0686 ;// ARABIC LETTER TCHEH chars[0x8E ]=0x0698 ;// ARABIC LETTER JEH chars[0x8F ]=0x0688 ;// ARABIC LETTER DDAL chars[0x90 ]=0x06AF ;// ARABIC LETTER GAF chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x98 ]=0x06A9 ;// ARABIC LETTER KEHEH chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9A ]=0x0691 ;// ARABIC LETTER RREH chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x0153 ;// LATIN SMALL LIGATURE OE chars[0x9D ]=0x200C ;// ZERO WIDTH NON-JOINER chars[0x9E ]=0x200D ;// ZERO WIDTH JOINER chars[0x9F ]=0x06BA ;// ARABIC LETTER NOON GHUNNA chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x060C ;// ARABIC COMMA chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x06BE ;// ARABIC LETTER HEH DOACHASHMEE chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00AF ;// MACRON chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x061B ;// ARABIC SEMICOLON chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x061F ;// ARABIC QUESTION MARK chars[0xC0 ]=0x06C1 ;// ARABIC LETTER HEH GOAL chars[0xC1 ]=0x0621 ;// ARABIC LETTER HAMZA chars[0xC2 ]=0x0622 ;// ARABIC LETTER ALEF WITH MADDA ABOVE chars[0xC3 ]=0x0623 ;// ARABIC LETTER ALEF WITH HAMZA ABOVE chars[0xC4 ]=0x0624 ;// ARABIC LETTER WAW WITH HAMZA ABOVE chars[0xC5 ]=0x0625 ;// ARABIC LETTER ALEF WITH HAMZA BELOW chars[0xC6 ]=0x0626 ;// ARABIC LETTER YEH WITH HAMZA ABOVE chars[0xC7 ]=0x0627 ;// ARABIC LETTER ALEF chars[0xC8 ]=0x0628 ;// ARABIC LETTER BEH chars[0xC9 ]=0x0629 ;// ARABIC LETTER TEH MARBUTA chars[0xCA ]=0x062A ;// ARABIC LETTER TEH chars[0xCB ]=0x062B ;// ARABIC LETTER THEH chars[0xCC ]=0x062C ;// ARABIC LETTER JEEM chars[0xCD ]=0x062D ;// ARABIC LETTER HAH chars[0xCE ]=0x062E ;// ARABIC LETTER KHAH chars[0xCF ]=0x062F ;// ARABIC LETTER DAL chars[0xD0 ]=0x0630 ;// ARABIC LETTER THAL chars[0xD1 ]=0x0631 ;// ARABIC LETTER REH chars[0xD2 ]=0x0632 ;// ARABIC LETTER ZAIN chars[0xD3 ]=0x0633 ;// ARABIC LETTER SEEN chars[0xD4 ]=0x0634 ;// ARABIC LETTER SHEEN chars[0xD5 ]=0x0635 ;// ARABIC LETTER SAD chars[0xD6 ]=0x0636 ;// ARABIC LETTER DAD chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x0637 ;// ARABIC LETTER TAH chars[0xD9 ]=0x0638 ;// ARABIC LETTER ZAH chars[0xDA ]=0x0639 ;// ARABIC LETTER AIN chars[0xDB ]=0x063A ;// ARABIC LETTER GHAIN chars[0xDC ]=0x0640 ;// ARABIC TATWEEL chars[0xDD ]=0x0641 ;// ARABIC LETTER FEH chars[0xDE ]=0x0642 ;// ARABIC LETTER QAF chars[0xDF ]=0x0643 ;// ARABIC LETTER KAF chars[0xE0 ]=0x00E0 ;// LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x0644 ;// ARABIC LETTER LAM chars[0xE2 ]=0x00E2 ;// LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x0645 ;// ARABIC LETTER MEEM chars[0xE4 ]=0x0646 ;// ARABIC LETTER NOON chars[0xE5 ]=0x0647 ;// ARABIC LETTER HEH chars[0xE6 ]=0x0648 ;// ARABIC LETTER WAW chars[0xE7 ]=0x00E7 ;// LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8 ;// LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA ;// LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB ;// LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x0649 ;// ARABIC LETTER ALEF MAKSURA chars[0xED ]=0x064A ;// ARABIC LETTER YEH chars[0xEE ]=0x00EE ;// LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF ;// LATIN SMALL LETTER I WITH DIAERESIS chars[0xF0 ]=0x064B ;// ARABIC FATHATAN chars[0xF1 ]=0x064C ;// ARABIC DAMMATAN chars[0xF2 ]=0x064D ;// ARABIC KASRATAN chars[0xF3 ]=0x064E ;// ARABIC FATHA chars[0xF4 ]=0x00F4 ;// LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x064F ;// ARABIC DAMMA chars[0xF6 ]=0x0650 ;// ARABIC KASRA chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x0651 ;// ARABIC SHADDA chars[0xF9 ]=0x00F9 ;// LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x0652 ;// ARABIC SUKUN chars[0xFB ]=0x00FB ;// LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x200E ;// LEFT-TO-RIGHT MARK chars[0xFE ]=0x200F ;// RIGHT-TO-LEFT MARK chars[0xFF ]=0x06D2 ;// ARABIC LETTER YEH BARREE } public static char decode(byte b){ return chars[b & 0xff]; } }
8,315
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1253.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1253.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1253 char * into a Unicode char * */ public class WIN1253 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x0385 ;// GREEK DIALYTIKA TONOS chars[0xA2 ]=0x0386 ;// GREEK CAPITAL LETTER ALPHA WITH TONOS chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x2015 ;// HORIZONTAL BAR chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x0384 ;// GREEK TONOS chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x0388 ;// GREEK CAPITAL LETTER EPSILON WITH TONOS chars[0xB9 ]=0x0389 ;// GREEK CAPITAL LETTER ETA WITH TONOS chars[0xBA ]=0x038A ;// GREEK CAPITAL LETTER IOTA WITH TONOS chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x038C ;// GREEK CAPITAL LETTER OMICRON WITH TONOS chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x038E ;// GREEK CAPITAL LETTER UPSILON WITH TONOS chars[0xBF ]=0x038F ;// GREEK CAPITAL LETTER OMEGA WITH TONOS chars[0xC0 ]=0x0390 ;// GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS chars[0xC1 ]=0x0391 ;// GREEK CAPITAL LETTER ALPHA chars[0xC2 ]=0x0392 ;// GREEK CAPITAL LETTER BETA chars[0xC3 ]=0x0393 ;// GREEK CAPITAL LETTER GAMMA chars[0xC4 ]=0x0394 ;// GREEK CAPITAL LETTER DELTA chars[0xC5 ]=0x0395 ;// GREEK CAPITAL LETTER EPSILON chars[0xC6 ]=0x0396 ;// GREEK CAPITAL LETTER ZETA chars[0xC7 ]=0x0397 ;// GREEK CAPITAL LETTER ETA chars[0xC8 ]=0x0398 ;// GREEK CAPITAL LETTER THETA chars[0xC9 ]=0x0399 ;// GREEK CAPITAL LETTER IOTA chars[0xCA ]=0x039A ;// GREEK CAPITAL LETTER KAPPA chars[0xCB ]=0x039B ;// GREEK CAPITAL LETTER LAMDA chars[0xCC ]=0x039C ;// GREEK CAPITAL LETTER MU chars[0xCD ]=0x039D ;// GREEK CAPITAL LETTER NU chars[0xCE ]=0x039E ;// GREEK CAPITAL LETTER XI chars[0xCF ]=0x039F ;// GREEK CAPITAL LETTER OMICRON chars[0xD0 ]=0x03A0 ;// GREEK CAPITAL LETTER PI chars[0xD1 ]=0x03A1 ;// GREEK CAPITAL LETTER RHO chars[0xD3 ]=0x03A3 ;// GREEK CAPITAL LETTER SIGMA chars[0xD4 ]=0x03A4 ;// GREEK CAPITAL LETTER TAU chars[0xD5 ]=0x03A5 ;// GREEK CAPITAL LETTER UPSILON chars[0xD6 ]=0x03A6 ;// GREEK CAPITAL LETTER PHI chars[0xD7 ]=0x03A7 ;// GREEK CAPITAL LETTER CHI chars[0xD8 ]=0x03A8 ;// GREEK CAPITAL LETTER PSI chars[0xD9 ]=0x03A9 ;// GREEK CAPITAL LETTER OMEGA chars[0xDA ]=0x03AA ;// GREEK CAPITAL LETTER IOTA WITH DIALYTIKA chars[0xDB ]=0x03AB ;// GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA chars[0xDC ]=0x03AC ;// GREEK SMALL LETTER ALPHA WITH TONOS chars[0xDD ]=0x03AD ;// GREEK SMALL LETTER EPSILON WITH TONOS chars[0xDE ]=0x03AE ;// GREEK SMALL LETTER ETA WITH TONOS chars[0xDF ]=0x03AF ;// GREEK SMALL LETTER IOTA WITH TONOS chars[0xE0 ]=0x03B0 ;// GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS chars[0xE1 ]=0x03B1 ;// GREEK SMALL LETTER ALPHA chars[0xE2 ]=0x03B2 ;// GREEK SMALL LETTER BETA chars[0xE3 ]=0x03B3 ;// GREEK SMALL LETTER GAMMA chars[0xE4 ]=0x03B4 ;// GREEK SMALL LETTER DELTA chars[0xE5 ]=0x03B5 ;// GREEK SMALL LETTER EPSILON chars[0xE6 ]=0x03B6 ;// GREEK SMALL LETTER ZETA chars[0xE7 ]=0x03B7 ;// GREEK SMALL LETTER ETA chars[0xE8 ]=0x03B8 ;// GREEK SMALL LETTER THETA chars[0xE9 ]=0x03B9 ;// GREEK SMALL LETTER IOTA chars[0xEA ]=0x03BA ;// GREEK SMALL LETTER KAPPA chars[0xEB ]=0x03BB ;// GREEK SMALL LETTER LAMDA chars[0xEC ]=0x03BC ;// GREEK SMALL LETTER MU chars[0xED ]=0x03BD ;// GREEK SMALL LETTER NU chars[0xEE ]=0x03BE ;// GREEK SMALL LETTER XI chars[0xEF ]=0x03BF ;// GREEK SMALL LETTER OMICRON chars[0xF0 ]=0x03C0 ;// GREEK SMALL LETTER PI chars[0xF1 ]=0x03C1 ;// GREEK SMALL LETTER RHO chars[0xF2 ]=0x03C2 ;// GREEK SMALL LETTER FINAL SIGMA chars[0xF3 ]=0x03C3 ;// GREEK SMALL LETTER SIGMA chars[0xF4 ]=0x03C4 ;// GREEK SMALL LETTER TAU chars[0xF5 ]=0x03C5 ;// GREEK SMALL LETTER UPSILON chars[0xF6 ]=0x03C6 ;// GREEK SMALL LETTER PHI chars[0xF7 ]=0x03C7 ;// GREEK SMALL LETTER CHI chars[0xF8 ]=0x03C8 ;// GREEK SMALL LETTER PSI chars[0xF9 ]=0x03C9 ;// GREEK SMALL LETTER OMEGA chars[0xFA ]=0x03CA ;// GREEK SMALL LETTER IOTA WITH DIALYTIKA chars[0xFB ]=0x03CB ;// GREEK SMALL LETTER UPSILON WITH DIALYTIKA chars[0xFC ]=0x03CC ;// GREEK SMALL LETTER OMICRON WITH TONOS chars[0xFD ]=0x03CD ;// GREEK SMALL LETTER UPSILON WITH TONOS chars[0xFE ]=0x03CE ;// GREEK SMALL LETTER OMEGA WITH TONOS } public static char decode(byte b){ return chars[b & 0xff]; } }
7,847
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_10.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_10.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-10 char * into a Unicode char * */ public class ISO8859_10 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA1 ]=0x0104; chars[0xA2 ]=0x0112; chars[0xA3 ]=0x0122; chars[0xA4 ]=0x012A; chars[0xA5 ]=0x0128; chars[0xA6 ]=0x0136; chars[0xA7 ]=0x00A7; chars[0xA8 ]=0x013B; chars[0xA9 ]=0x0110; chars[0xAA ]=0x0160; chars[0xAB ]=0x0166; chars[0xAC ]=0x017D; chars[0xAD ]=0x00AD; chars[0xAE ]=0x016A; chars[0xAF ]=0x014A; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x0105; chars[0xB2 ]=0x0113; chars[0xB3 ]=0x0123; chars[0xB4 ]=0x012B; chars[0xB5 ]=0x0129; chars[0xB6 ]=0x0137; chars[0xB7 ]=0x00B7; chars[0xB8 ]=0x013CA; chars[0xB9 ]=0x0111; chars[0xBA ]=0x0161; chars[0xBB ]=0x0167; chars[0xBC ]=0x017E; chars[0xBD ]=0x2015; chars[0xBE ]=0x016B; chars[0xBF ]=0x014B; chars[0xC0 ]=0x0100; chars[0xC1 ]=0x00C1; chars[0xC2 ]=0x00C2; chars[0xC3 ]=0x00C3; chars[0xC4 ]=0x00C4; chars[0xC5 ]=0x00C5; chars[0xC6 ]=0x00C6; chars[0xC7 ]=0x012E; chars[0xC8 ]=0x010C; chars[0xC9 ]=0x00C9; chars[0xCA ]=0x0118; chars[0xCB ]=0x00CB; chars[0xCC ]=0x0116; chars[0xCD ]=0x00CD; chars[0xCE ]=0x00CE; chars[0xCF ]=0x00CF; chars[0xD0 ]=0x00D0; chars[0xD1 ]=0x0145; chars[0xD2 ]=0x014C; chars[0xD3 ]=0x00D3; chars[0xD4 ]=0x00D4; chars[0xD5 ]=0x00D5; chars[0xD6 ]=0x00D6; chars[0xD7 ]=0x0168; chars[0xD8 ]=0x00D8; chars[0xD9 ]=0x0172; chars[0xDA ]=0x00DA; chars[0xDB ]=0x00DB; chars[0xDC ]=0x00DC; chars[0xDD ]=0x00DD; chars[0xDE ]=0x00DE; chars[0xDF ]=0x00DF; chars[0xE0 ]=0x0101; chars[0xE1 ]=0x00E1; chars[0xE2 ]=0x00E2; chars[0xE3 ]=0x00E3; chars[0xE4 ]=0x00E4; chars[0xE5 ]=0x00E5; chars[0xE6 ]=0x00E6; chars[0xE7 ]=0x012F; chars[0xE8 ]=0x010D; chars[0xE9 ]=0x00E9; chars[0xEA ]=0x0119; chars[0xEB ]=0x00EB; chars[0xEC ]=0x0117; chars[0xED ]=0x00ED; chars[0xEE ]=0x00EE; chars[0xEF ]=0x00EF; chars[0xF0 ]=0x00F0; chars[0xF1 ]=0x0146; chars[0xF2 ]=0x014D; chars[0xF3 ]=0x00F3; chars[0xF4 ]=0x00F4; chars[0xF5 ]=0x00F5; chars[0xF6 ]=0x00F6; chars[0xF7 ]=0x0169; chars[0xF8 ]=0x00F8; chars[0xF9 ]=0x0173; chars[0xFA ]=0x00FA; chars[0xFB ]=0x00FB; chars[0xFC ]=0x00FC; chars[0xFD ]=0x00FD; chars[0xFE ]=0x00FE; chars[0xFF ]=0x0138; } public static char decode(byte b){ return chars[b & 0xff]; } }
4,160
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_4.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_4.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a ISO-8859-4 char * into a Unicode char * */ public class ISO8859_4 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0xA0 ]=0x00A0; chars[0xA1 ]=0x0104; chars[0xA2 ]=0x0138; chars[0xA3 ]=0x0156; chars[0xA4 ]=0x00A4; chars[0xA5 ]=0x0128; chars[0xA6 ]=0x013B; chars[0xA7 ]=0x00A7; chars[0xA8 ]=0x00A8; chars[0xA9 ]=0x0160; chars[0xAA ]=0x0112; chars[0xAB ]=0x0122; chars[0xAC ]=0x0166; chars[0xAD ]=0x00AD; chars[0xAE ]=0x017D; chars[0xAF ]=0x00AF; chars[0xB0 ]=0x00B0; chars[0xB1 ]=0x0105; chars[0xB2 ]=0x02DB; chars[0xB3 ]=0x0157; chars[0xB4 ]=0x00B4; chars[0xB5 ]=0x0129; chars[0xB6 ]=0x013C; chars[0xB7 ]=0x02C7; chars[0xB8 ]=0x00B8; chars[0xB9 ]=0x0161; chars[0xBA ]=0x0113; chars[0xBB ]=0x0123; chars[0xBC ]=0x0167; chars[0xBD ]=0x014A; chars[0xBE ]=0x017E; chars[0xBF ]=0x014B; chars[0xC0 ]=0x0100; chars[0xC1 ]=0x00C1; chars[0xC2 ]=0x00C2; chars[0xC3 ]=0x00C3; chars[0xC4 ]=0x00C4; chars[0xC5 ]=0x00C5; chars[0xC6 ]=0x00C6; chars[0xC7 ]=0x012E; chars[0xC8 ]=0x010C; chars[0xC9 ]=0x00C9; chars[0xCA ]=0x0118; chars[0xCB ]=0x00CB; chars[0xCC ]=0x0116; chars[0xCD ]=0x00CD; chars[0xCE ]=0x00CE; chars[0xCF ]=0x012A; chars[0xD0 ]=0x0110; chars[0xD1 ]=0x0145; chars[0xD2 ]=0x014C; chars[0xD3 ]=0x0136; chars[0xD4 ]=0x00D4; chars[0xD5 ]=0x00D5; chars[0xD6 ]=0x00D6; chars[0xD7 ]=0x00D7; chars[0xD8 ]=0x00D8; chars[0xD9 ]=0x0172; chars[0xDA ]=0x00DA; chars[0xDB ]=0x00DB; chars[0xDC ]=0x00DC; chars[0xDD ]=0x0168; chars[0xDE ]=0x016A; chars[0xDF ]=0x00DF; chars[0xE0 ]=0x0101; chars[0xE1 ]=0x00E1; chars[0xE2 ]=0x00E2; chars[0xE3 ]=0x00E3; chars[0xE4 ]=0x00E4; chars[0xE5 ]=0x00E5; chars[0xE6 ]=0x00E6; chars[0xE7 ]=0x012F; chars[0xE8 ]=0x010D; chars[0xE9 ]=0x00E9; chars[0xEA ]=0x0119; chars[0xEB ]=0x00EB; chars[0xEC ]=0x0117; chars[0xED ]=0x00ED; chars[0xEE ]=0x00EE; chars[0xEF ]=0x012B; chars[0xF0 ]=0x0111; chars[0xF1 ]=0x0146; chars[0xF2 ]=0x014D; chars[0xF3 ]=0x0137; chars[0xF4 ]=0x00F4; chars[0xF5 ]=0x00F5; chars[0xF6 ]=0x00F6; chars[0xF7 ]=0x00F7; chars[0xF8 ]=0x00F8; chars[0xF9 ]=0x0173; chars[0xFA ]=0x00FA; chars[0xFB ]=0x00FB; chars[0xFC ]=0x00FC; chars[0xFD ]=0x0169; chars[0xFE ]=0x016B; chars[0xFF ]=0x02D9; } public static char decode(byte b){ return chars[b & 0xff]; } }
4,151
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1250.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1250.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1250 char * into a Unicode char * */ public class WIN1250 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8A ]=0x0160 ;// LATIN CAPITAL LETTER S WITH CARON chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x015A ;// LATIN CAPITAL LETTER S WITH ACUTE chars[0x8D ]=0x0164 ;// LATIN CAPITAL LETTER T WITH CARON chars[0x8E ]=0x017D ;// LATIN CAPITAL LETTER Z WITH CARON chars[0x8F ]=0x0179 ;// LATIN CAPITAL LETTER Z WITH ACUTE chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9A ]=0x0161 ;// LATIN SMALL LETTER S WITH CARON chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x015B ;// LATIN SMALL LETTER S WITH ACUTE chars[0x9D ]=0x0165 ;// LATIN SMALL LETTER T WITH CARON chars[0x9E ]=0x017E ;// LATIN SMALL LETTER Z WITH CARON chars[0x9F ]=0x017A ;// LATIN SMALL LETTER Z WITH ACUTE chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x02C7 ;// CARON chars[0xA2 ]=0x02D8 ;// BREVE chars[0xA3 ]=0x0141 ;// LATIN CAPITAL LETTER L WITH STROKE chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x0104 ;// LATIN CAPITAL LETTER A WITH OGONEK chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x015E ;// LATIN CAPITAL LETTER S WITH CEDILLA chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x017B ;// LATIN CAPITAL LETTER Z WITH DOT ABOVE chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x02DB ;// OGONEK chars[0xB3 ]=0x0142 ;// LATIN SMALL LETTER L WITH STROKE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x0105 ;// LATIN SMALL LETTER A WITH OGONEK chars[0xBA ]=0x015F ;// LATIN SMALL LETTER S WITH CEDILLA chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x013D ;// LATIN CAPITAL LETTER L WITH CARON chars[0xBD ]=0x02DD ;// DOUBLE ACUTE ACCENT chars[0xBE ]=0x013E ;// LATIN SMALL LETTER L WITH CARON chars[0xBF ]=0x017C ;// LATIN SMALL LETTER Z WITH DOT ABOVE chars[0xC0 ]=0x0154 ;// LATIN CAPITAL LETTER R WITH ACUTE chars[0xC1 ]=0x00C1 ;// LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2 ;// LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3 ]=0x0102 ;// LATIN CAPITAL LETTER A WITH BREVE chars[0xC4 ]=0x00C4 ;// LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x0139 ;// LATIN CAPITAL LETTER L WITH ACUTE chars[0xC6 ]=0x0106 ;// LATIN CAPITAL LETTER C WITH ACUTE chars[0xC7 ]=0x00C7 ;// LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x010C ;// LATIN CAPITAL LETTER C WITH CARON chars[0xC9 ]=0x00C9 ;// LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x0118 ;// LATIN CAPITAL LETTER E WITH OGONEK chars[0xCB ]=0x00CB ;// LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x011A ;// LATIN CAPITAL LETTER E WITH CARON chars[0xCD ]=0x00CD ;// LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE ;// LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x010E ;// LATIN CAPITAL LETTER D WITH CARON chars[0xD0 ]=0x0110 ;// LATIN CAPITAL LETTER D WITH STROKE chars[0xD1 ]=0x0143 ;// LATIN CAPITAL LETTER N WITH ACUTE chars[0xD2 ]=0x0147 ;// LATIN CAPITAL LETTER N WITH CARON chars[0xD3 ]=0x00D3 ;// LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4 ;// LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x0150 ;// LATIN CAPITAL LETTER O WITH DOUBLE ACUTE chars[0xD6 ]=0x00D6 ;// LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x0158 ;// LATIN CAPITAL LETTER R WITH CARON chars[0xD9 ]=0x016E ;// LATIN CAPITAL LETTER U WITH RING ABOVE chars[0xDA ]=0x00DA ;// LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x0170 ;// LATIN CAPITAL LETTER U WITH DOUBLE ACUTE chars[0xDC ]=0x00DC ;// LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x00DD ;// LATIN CAPITAL LETTER Y WITH ACUTE chars[0xDE ]=0x0162 ;// LATIN CAPITAL LETTER T WITH CEDILLA chars[0xDF ]=0x00DF ;// LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x0155 ;// LATIN SMALL LETTER R WITH ACUTE chars[0xE1 ]=0x00E1 ;// LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2 ;// LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x0103 ;// LATIN SMALL LETTER A WITH BREVE chars[0xE4 ]=0x00E4 ;// LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x013A ;// LATIN SMALL LETTER L WITH ACUTE chars[0xE6 ]=0x0107 ;// LATIN SMALL LETTER C WITH ACUTE chars[0xE7 ]=0x00E7 ;// LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x010D ;// LATIN SMALL LETTER C WITH CARON chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x0119 ;// LATIN SMALL LETTER E WITH OGONEK chars[0xEB ]=0x00EB ;// LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x011B ;// LATIN SMALL LETTER E WITH CARON chars[0xED ]=0x00ED ;// LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE ;// LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x010F ;// LATIN SMALL LETTER D WITH CARON chars[0xF0 ]=0x0111 ;// LATIN SMALL LETTER D WITH STROKE chars[0xF1 ]=0x0144 ;// LATIN SMALL LETTER N WITH ACUTE chars[0xF2 ]=0x0148 ;// LATIN SMALL LETTER N WITH CARON chars[0xF3 ]=0x00F3 ;// LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4 ;// LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x0151 ;// LATIN SMALL LETTER O WITH DOUBLE ACUTE chars[0xF6 ]=0x00F6 ;// LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x0159 ;// LATIN SMALL LETTER R WITH CARON chars[0xF9 ]=0x016F ;// LATIN SMALL LETTER U WITH RING ABOVE chars[0xFA ]=0x00FA ;// LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x0171 ;// LATIN SMALL LETTER U WITH DOUBLE ACUTE chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x00FD ;// LATIN SMALL LETTER Y WITH ACUTE chars[0xFE ]=0x0163 ;// LATIN SMALL LETTER T WITH CEDILLA chars[0xFF ]=0x02D9 ;// DOT ABOVE } public static char decode(byte b){ return chars[b & 0xff]; } }
8,967
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
WIN1254.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/WIN1254.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; /** * this class contains method to map a windows-1254 char * into a Unicode char * */ public class WIN1254 { static final char[] chars = new char[0x100]; static { for (int i=0;i<128;i++){ chars[i] = (char)i; } for (int i=128;i<256;i++){ chars[i]=0xfffd; } chars[0x80 ]=0x20AC ;// EURO SIGN chars[0x82 ]=0x201A ;// SINGLE LOW-9 QUOTATION MARK chars[0x83 ]=0x0192 ;// LATIN SMALL LETTER F WITH HOOK chars[0x84 ]=0x201E ;// DOUBLE LOW-9 QUOTATION MARK chars[0x85 ]=0x2026 ;// HORIZONTAL ELLIPSIS chars[0x86 ]=0x2020 ;// DAGGER chars[0x87 ]=0x2021 ;// DOUBLE DAGGER chars[0x88 ]=0x02C6 ;// MODIFIER LETTER CIRCUMFLEX ACCENT chars[0x89 ]=0x2030 ;// PER MILLE SIGN chars[0x8A ]=0x0160 ;// LATIN CAPITAL LETTER S WITH CARON chars[0x8B ]=0x2039 ;// SINGLE LEFT-POINTING ANGLE QUOTATION MARK chars[0x8C ]=0x0152 ;// LATIN CAPITAL LIGATURE OE chars[0x91 ]=0x2018 ;// LEFT SINGLE QUOTATION MARK chars[0x92 ]=0x2019 ;// RIGHT SINGLE QUOTATION MARK chars[0x93 ]=0x201C ;// LEFT DOUBLE QUOTATION MARK chars[0x94 ]=0x201D ;// RIGHT DOUBLE QUOTATION MARK chars[0x95 ]=0x2022 ;// BULLET chars[0x96 ]=0x2013 ;// EN DASH chars[0x97 ]=0x2014 ;// EM DASH chars[0x98 ]=0x02DC ;// SMALL TILDE chars[0x99 ]=0x2122 ;// TRADE MARK SIGN chars[0x9A ]=0x0161 ;// LATIN SMALL LETTER S WITH CARON chars[0x9B ]=0x203A ;// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK chars[0x9C ]=0x0153 ;// LATIN SMALL LIGATURE OE chars[0x9F ]=0x0178 ;// LATIN CAPITAL LETTER Y WITH DIAERESIS chars[0xA0 ]=0x00A0 ;// NO-BREAK SPACE chars[0xA1 ]=0x00A1 ;// INVERTED EXCLAMATION MARK chars[0xA2 ]=0x00A2 ;// CENT SIGN chars[0xA3 ]=0x00A3 ;// POUND SIGN chars[0xA4 ]=0x00A4 ;// CURRENCY SIGN chars[0xA5 ]=0x00A5 ;// YEN SIGN chars[0xA6 ]=0x00A6 ;// BROKEN BAR chars[0xA7 ]=0x00A7 ;// SECTION SIGN chars[0xA8 ]=0x00A8 ;// DIAERESIS chars[0xA9 ]=0x00A9 ;// COPYRIGHT SIGN chars[0xAA ]=0x00AA ;// FEMININE ORDINAL INDICATOR chars[0xAB ]=0x00AB ;// LEFT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xAC ]=0x00AC ;// NOT SIGN chars[0xAD ]=0x00AD ;// SOFT HYPHEN chars[0xAE ]=0x00AE ;// REGISTERED SIGN chars[0xAF ]=0x00AF ;// MACRON chars[0xB0 ]=0x00B0 ;// DEGREE SIGN chars[0xB1 ]=0x00B1 ;// PLUS-MINUS SIGN chars[0xB2 ]=0x00B2 ;// SUPERSCRIPT TWO chars[0xB3 ]=0x00B3 ;// SUPERSCRIPT THREE chars[0xB4 ]=0x00B4 ;// ACUTE ACCENT chars[0xB5 ]=0x00B5 ;// MICRO SIGN chars[0xB6 ]=0x00B6 ;// PILCROW SIGN chars[0xB7 ]=0x00B7 ;// MIDDLE DOT chars[0xB8 ]=0x00B8 ;// CEDILLA chars[0xB9 ]=0x00B9 ;// SUPERSCRIPT ONE chars[0xBA ]=0x00BA ;// MASCULINE ORDINAL INDICATOR chars[0xBB ]=0x00BB ;// RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK chars[0xBC ]=0x00BC ;// VULGAR FRACTION ONE QUARTER chars[0xBD ]=0x00BD ;// VULGAR FRACTION ONE HALF chars[0xBE ]=0x00BE ;// VULGAR FRACTION THREE QUARTERS chars[0xBF ]=0x00BF ;// INVERTED QUESTION MARK chars[0xC0 ]=0x00C0 ;// LATIN CAPITAL LETTER A WITH GRAVE chars[0xC1 ]=0x00C1 ;// LATIN CAPITAL LETTER A WITH ACUTE chars[0xC2 ]=0x00C2 ;// LATIN CAPITAL LETTER A WITH CIRCUMFLEX chars[0xC3 ]=0x00C3 ;// LATIN CAPITAL LETTER A WITH TILDE chars[0xC4 ]=0x00C4 ;// LATIN CAPITAL LETTER A WITH DIAERESIS chars[0xC5 ]=0x00C5 ;// LATIN CAPITAL LETTER A WITH RING ABOVE chars[0xC6 ]=0x00C6 ;// LATIN CAPITAL LETTER AE chars[0xC7 ]=0x00C7 ;// LATIN CAPITAL LETTER C WITH CEDILLA chars[0xC8 ]=0x00C8 ;// LATIN CAPITAL LETTER E WITH GRAVE chars[0xC9 ]=0x00C9 ;// LATIN CAPITAL LETTER E WITH ACUTE chars[0xCA ]=0x00CA ;// LATIN CAPITAL LETTER E WITH CIRCUMFLEX chars[0xCB ]=0x00CB ;// LATIN CAPITAL LETTER E WITH DIAERESIS chars[0xCC ]=0x00CC ;// LATIN CAPITAL LETTER I WITH GRAVE chars[0xCD ]=0x00CD ;// LATIN CAPITAL LETTER I WITH ACUTE chars[0xCE ]=0x00CE ;// LATIN CAPITAL LETTER I WITH CIRCUMFLEX chars[0xCF ]=0x00CF ;// LATIN CAPITAL LETTER I WITH DIAERESIS chars[0xD0 ]=0x011E ;// LATIN CAPITAL LETTER G WITH BREVE chars[0xD1 ]=0x00D1 ;// LATIN CAPITAL LETTER N WITH TILDE chars[0xD2 ]=0x00D2 ;// LATIN CAPITAL LETTER O WITH GRAVE chars[0xD3 ]=0x00D3 ;// LATIN CAPITAL LETTER O WITH ACUTE chars[0xD4 ]=0x00D4 ;// LATIN CAPITAL LETTER O WITH CIRCUMFLEX chars[0xD5 ]=0x00D5 ;// LATIN CAPITAL LETTER O WITH TILDE chars[0xD6 ]=0x00D6 ;// LATIN CAPITAL LETTER O WITH DIAERESIS chars[0xD7 ]=0x00D7 ;// MULTIPLICATION SIGN chars[0xD8 ]=0x00D8 ;// LATIN CAPITAL LETTER O WITH STROKE chars[0xD9 ]=0x00D9 ;// LATIN CAPITAL LETTER U WITH GRAVE chars[0xDA ]=0x00DA ;// LATIN CAPITAL LETTER U WITH ACUTE chars[0xDB ]=0x00DB ;// LATIN CAPITAL LETTER U WITH CIRCUMFLEX chars[0xDC ]=0x00DC ;// LATIN CAPITAL LETTER U WITH DIAERESIS chars[0xDD ]=0x0130 ;// LATIN CAPITAL LETTER I WITH DOT ABOVE chars[0xDE ]=0x015E ;// LATIN CAPITAL LETTER S WITH CEDILLA chars[0xDF ]=0x00DF ;// LATIN SMALL LETTER SHARP S chars[0xE0 ]=0x00E0 ;// LATIN SMALL LETTER A WITH GRAVE chars[0xE1 ]=0x00E1 ;// LATIN SMALL LETTER A WITH ACUTE chars[0xE2 ]=0x00E2 ;// LATIN SMALL LETTER A WITH CIRCUMFLEX chars[0xE3 ]=0x00E3 ;// LATIN SMALL LETTER A WITH TILDE chars[0xE4 ]=0x00E4 ;// LATIN SMALL LETTER A WITH DIAERESIS chars[0xE5 ]=0x00E5 ;// LATIN SMALL LETTER A WITH RING ABOVE chars[0xE6 ]=0x00E6 ;// LATIN SMALL LETTER AE chars[0xE7 ]=0x00E7 ;// LATIN SMALL LETTER C WITH CEDILLA chars[0xE8 ]=0x00E8 ;// LATIN SMALL LETTER E WITH GRAVE chars[0xE9 ]=0x00E9 ;// LATIN SMALL LETTER E WITH ACUTE chars[0xEA ]=0x00EA ;// LATIN SMALL LETTER E WITH CIRCUMFLEX chars[0xEB ]=0x00EB ;// LATIN SMALL LETTER E WITH DIAERESIS chars[0xEC ]=0x00EC ;// LATIN SMALL LETTER I WITH GRAVE chars[0xED ]=0x00ED ;// LATIN SMALL LETTER I WITH ACUTE chars[0xEE ]=0x00EE ;// LATIN SMALL LETTER I WITH CIRCUMFLEX chars[0xEF ]=0x00EF ;// LATIN SMALL LETTER I WITH DIAERESIS chars[0xF0 ]=0x011F ;// LATIN SMALL LETTER G WITH BREVE chars[0xF1 ]=0x00F1 ;// LATIN SMALL LETTER N WITH TILDE chars[0xF2 ]=0x00F2 ;// LATIN SMALL LETTER O WITH GRAVE chars[0xF3 ]=0x00F3 ;// LATIN SMALL LETTER O WITH ACUTE chars[0xF4 ]=0x00F4 ;// LATIN SMALL LETTER O WITH CIRCUMFLEX chars[0xF5 ]=0x00F5 ;// LATIN SMALL LETTER O WITH TILDE chars[0xF6 ]=0x00F6 ;// LATIN SMALL LETTER O WITH DIAERESIS chars[0xF7 ]=0x00F7 ;// DIVISION SIGN chars[0xF8 ]=0x00F8 ;// LATIN SMALL LETTER O WITH STROKE chars[0xF9 ]=0x00F9 ;// LATIN SMALL LETTER U WITH GRAVE chars[0xFA ]=0x00FA ;// LATIN SMALL LETTER U WITH ACUTE chars[0xFB ]=0x00FB ;// LATIN SMALL LETTER U WITH CIRCUMFLEX chars[0xFC ]=0x00FC ;// LATIN SMALL LETTER U WITH DIAERESIS chars[0xFD ]=0x0131 ;// LATIN SMALL LETTER DOTLESS I chars[0xFE ]=0x015F ;// LATIN SMALL LETTER S WITH CEDILLA chars[0xFF ]=0x00FF ;// LATIN SMALL LETTER Y WITH DIAERESIS } public static char decode(byte b){ return chars[b & 0xff]; } }
8,695
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_15.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/parser/ISO8859_15.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.parser; public class ISO8859_15 { static final char[] chars = new char[0x100]; static { for (int i=0;i<256;i++){ chars[i] = (char)i; } chars[0xA4]= 0x20AC; chars[0xA6]= 0x0160; chars[0xA8]= 0x0161; chars[0xB4]= 0x017D; chars[0xB8]= 0x017E; chars[0xBC]= 0x0152; chars[0xBD]= 0x0153; chars[0xBE]= 0x0178; } public static char decode(byte b){ return chars[b & 0xff]; } }
1,346
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UTF16BE_Coder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/UTF16BE_Coder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import java.io.IOException; import java.io.OutputStream; import com.ximpleware.TranscodeException; public class UTF16BE_Coder { public static int encode(byte[] output, int offset,int ch){ if (ch<0x10000){ output[offset+1] = (byte)(ch & 0xff); output[offset] = (byte)((ch & 0xff00) >> 8); return 2 + offset; } else { int tmp = ch-0x10000; int w1 = 0xd800 | (tmp & 0xffc00); int w2 = 0xdc00 | (tmp & 0x3ff); output[offset] = (byte)((w1 & 0xff00) >> 8); output[offset+1] = (byte)(w1 & 0xff); output[offset+2] =(byte)((w2 & 0xff00) >> 8); output[offset+3] =(byte)((w2 & 0xff)); return 4 + offset; } } public static long decode(byte[] input, int offset ){ int val; long l; int temp = (input[offset] << 8) | input[offset+1]; if (temp < 0xd800 || temp > 0xdfff) { l = offset+2; return (l<<32)|temp; }else { val = temp; temp = (input[offset+2] << 8) | input[offset+3]; val = ((temp - 0xd800) << 10) + (val - 0xdc00) + 0x10000; l = offset+4; return (l<<32)|temp; } } public static int getLen(int ch){ if (ch <0x10000) return 2; else return 4; } public static final void encodeAndWrite(OutputStream os, int ch) throws IOException, TranscodeException { if (ch<0x10000){ //output[offset] = (byte)((ch & 0xff00) >> 8); os.write((ch & 0xff00) >> 8); //output[offset+1] = (byte)(ch & 0xff); os.write(ch); //return 2 + offset; } else { int tmp = ch-0x10000; int w1 = 0xd800 | (tmp & 0xffc00); int w2 = 0xdc00 | (tmp & 0x3ff); os.write((byte)((w1 & 0xff00) >> 8)); os.write((byte)(w1 & 0xff)); os.write((byte)((w2 & 0xff00) >> 8)); os.write((byte)(w2 & 0xff)); } } }
3,028
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ASCII_Coder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/ASCII_Coder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import com.ximpleware.TranscodeException; import java.io.*; public class ASCII_Coder { /** * * @param ch * @return * @throws TranscodeException * */ public static final int getLen(int ch) throws TranscodeException{ if (ch>=128) throw new TranscodeException("Invalid UCS char for ASCII format"); else return 1; } /** * * @param input * @param offset * @return a 64-bit integer upper 32 bits is offset value for * lower 32 bits is the UCS char * */ public static final long decode(byte[] input, int offset ){ long l = input[offset]; return (((long)(offset+1))<<32) | l ; } /** * * @param output * @param offset * @param ch * @return * */ public static final int encode(byte[] output, int offset, int ch ){ output[offset] = (byte) ch; return offset+1; } /** * * @param os * @param offset * @param ch * */ public static final void encodeAndWrite(OutputStream os, int ch) throws IOException, TranscodeException { if (ch>=128) throw new TranscodeException("Invalid UCS char for ASCII format"); os.write(ch); } }
2,209
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
Transcoder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/Transcoder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import com.ximpleware.TranscodeException; import com.ximpleware.VTDNav; import java.io.IOException; import java.io.OutputStream; public class Transcoder { /** * * @param input * @param offset * @param length * @param input_encoding * @param output_encoding * @return * */ public static byte[] transcode(byte[] input, int offset, int length, int input_encoding, int output_encoding) throws TranscodeException { //check input and output encoding // calculate the length of the output byte array int i = getOutLength(input, offset, length, input_encoding, output_encoding); // allocate the byte array byte[] output = new byte[i]; // fill the byte array with output encoding transcodeAndFill(input, output, offset, length, input_encoding, output_encoding); return output; } /** * * @param input * @param offset * @param length * @param input_encoding * @param output_encoding * @return * @throws TranscodeException * */ public static final int getOutLength(byte[] input, int offset, int length, int input_encoding, int output_encoding) throws TranscodeException { int len = 0; int k = offset; int c; while (k < offset + length) { long l = decode(input, k, input_encoding); k = (int) (l >>32); c = (int) l; len = len + getLen(c, output_encoding); } return len; } /** * Fill the byte array with transcoded characters * * @param input * @param output * @param offset * @param length * @param input_encoding * @param output_encoding * */ public static final void transcodeAndFill(byte[] input, byte[] output, int offset, int length, int input_encoding, int output_encoding) throws TranscodeException { //int len = 0; int k = offset; int c, i = 0; while (k < offset + length) { long l = decode(input, k, input_encoding); k = (int) (l >> 32); c = (int) l; i = encode(output, i, c, output_encoding); } } public static final int transcodeAndFill2(int initOutPosition, byte[] input, byte[] output, int offset, int length, int input_encoding, int output_encoding) throws TranscodeException { //int len = 0; int k = offset; int c, i = initOutPosition; while (k < offset + length) { long l = decode(input, k, input_encoding); k = (int) (l >> 32); c = (int) l; i = encode(output, i, c, output_encoding); } return i; } public static final void transcodeAndWrite(byte[] input, java.io.OutputStream os, int offset, int length, int input_encoding, int output_encoding) throws TranscodeException, IOException { //int len = 0; int k = offset; int c; while (k < offset + length) { long l = decode(input, k, input_encoding); k = (int) (l >> 32); c = (int) l; encodeAndWrite(os, c, output_encoding); } } /** * * @param ch * @param output_encoding * @return * @throws TranscodeException * */ public static final int getLen(int ch, int output_encoding) throws TranscodeException { switch (output_encoding) { case VTDNav.FORMAT_ASCII: return ASCII_Coder.getLen(ch); case VTDNav.FORMAT_UTF8: return UTF8_Coder.getLen(ch); case VTDNav.FORMAT_ISO_8859_1: return ISO8859_1Coder.getLen(ch); case VTDNav.FORMAT_UTF_16LE: return UTF16LE_Coder.getLen(ch); case VTDNav.FORMAT_UTF_16BE: return UTF16BE_Coder.getLen(ch); default: throw new com.ximpleware.TranscodeException("Unsupported encoding"); } } /** * * @param input * @param offset * @param input_encoding * @return * @throws TranscodeException * */ public static final long decode(byte[] input, int offset, int input_encoding) throws TranscodeException { switch (input_encoding) { case VTDNav.FORMAT_ASCII: return ASCII_Coder.decode(input, offset); case VTDNav.FORMAT_UTF8: return UTF8_Coder.decode(input, offset); case VTDNav.FORMAT_ISO_8859_1: return ISO8859_1Coder.decode(input, offset); case VTDNav.FORMAT_UTF_16LE: return UTF16LE_Coder.decode(input, offset); case VTDNav.FORMAT_UTF_16BE: return UTF16BE_Coder.decode(input, offset); default: throw new com.ximpleware.TranscodeException("Unsupported encoding"); } } /** * * @param output * @param offset * @param ch * @param output_encoding * @return * @throws TranscodeException * */ public static final int encode(byte[] output, int offset, int ch, int output_encoding) throws TranscodeException { switch (output_encoding) { case VTDNav.FORMAT_ASCII: return ASCII_Coder.encode(output, offset, ch); case VTDNav.FORMAT_UTF8: return UTF8_Coder.encode(output, offset, ch); case VTDNav.FORMAT_ISO_8859_1: return ISO8859_1Coder.encode(output, offset, ch); case VTDNav.FORMAT_UTF_16LE: return UTF16LE_Coder.encode(output, offset, ch); case VTDNav.FORMAT_UTF_16BE: return UTF16BE_Coder.encode(output, offset, ch); default: throw new com.ximpleware.TranscodeException("Unsupported encoding"); } } public static final void encodeAndWrite(OutputStream os, int ch, int output_encoding) throws TranscodeException, IOException { switch (output_encoding) { case VTDNav.FORMAT_ASCII: ASCII_Coder.encodeAndWrite(os, ch); return; case VTDNav.FORMAT_UTF8: UTF8_Coder.encodeAndWrite(os, ch); return; case VTDNav.FORMAT_ISO_8859_1: ISO8859_1Coder.encodeAndWrite(os, ch); return; case VTDNav.FORMAT_UTF_16LE: UTF16LE_Coder.encodeAndWrite(os, ch); return; case VTDNav.FORMAT_UTF_16BE: UTF16BE_Coder.encodeAndWrite(os, ch); return; default: throw new com.ximpleware.TranscodeException("Unsupported encoding"); } } }
7,904
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UTF16LE_Coder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/UTF16LE_Coder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import java.io.IOException; import java.io.OutputStream; import com.ximpleware.TranscodeException; public class UTF16LE_Coder { public static int encode(byte[] output, int offset,int ch){ if (ch<0x10000){ output[offset] = (byte)(ch & 0xff); output[offset+1] = (byte)((ch & 0xff00) >> 8); return 2 + offset; } else { int tmp = ch - 0x10000; int w1 = 0xd800 | (tmp & 0xffc00); int w2 = 0xdc00 | (tmp & 0x3ff); output[offset] = (byte)(w1 & 0xff); output[offset+1] = (byte)((w1 & 0xff00) >> 8); output[offset+2] =(byte)(w2 & 0xff); output[offset+3] = (byte)((w2 & 0xff00) >> 8); return 4 + offset; } } public static final void encodeAndWrite(OutputStream os, int ch) throws IOException, TranscodeException { if (ch<0x10000){ os.write((ch & 0xff)); os.write((ch & 0xff00) >> 8); } else { int tmp = ch - 0x10000; int w1 = 0xd800 | (tmp & 0xffc00); int w2 = 0xdc00 | (tmp & 0x3ff); os.write(w1 & 0xff); os.write((w1 & 0xff00) >> 8); os.write(w2 & 0xff); os.write((w2 & 0xff00) >> 8); } } public static long decode(byte[] input, int offset ){ int val; long l; int temp = (input[offset+1] << 8) | input[offset]; if (temp < 0xd800 || temp > 0xdfff) { l = offset+2; return (l<<32)|temp; }else { val = temp; temp = (input[offset+3] << 8) | input[offset+2]; val = ((temp - 0xd800) << 10) + (val - 0xdc00) + 0x10000; l = offset+4; return (l<<32)|temp; } } public static int getLen(int ch){ if (ch <0x10000) return 2; else return 4; } }
2,826
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
ISO8859_1Coder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/ISO8859_1Coder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import java.io.IOException; import java.io.OutputStream; import com.ximpleware.TranscodeException; public class ISO8859_1Coder { public static int getLen(int ch) throws TranscodeException{ if (ch>255) throw new TranscodeException("Invalid UCS char for ASCII format"); return 1; } public static long decode(byte[] input, int offset ){ long l = input[offset] & 0xff; return (((long)(offset+1))<<32) | l ; } /** * * @param output * @param offset * @param ch * @return * */ public static int encode(byte[] output, int offset, int ch ){ output[offset] = (byte) ch; return offset+1; } /** * Write the iso-8859-1 representation of ch into outputstrem * @param os * @param offset * @param ch * @throws IOException * @throws TranscodeException * */ public static final void encodeAndWrite(OutputStream os, int ch) throws IOException, TranscodeException { if (ch>255) throw new TranscodeException("Invalid UCS char for ISO-8859-1 format"); os.write(ch); } }
2,057
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UTF8_Coder.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/transcode/UTF8_Coder.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.transcode; import java.io.IOException; import java.io.OutputStream; import com.ximpleware.*; public class UTF8_Coder { /** * Encode a UCS Char to a UTF-8 representation and write it into the output * buffer * @param output the output byte buffer * @param offset offset value to which the UTF-8 bytes are written * @param ch the UCS char to be encoded * @return the offset value of the next char to be written * */ public static int encode(byte[] output, int offset, int ch ){ if (ch < 128){ output[offset] = (byte)ch; return offset+1; } if (ch < 0x800){ output[offset]= (byte)(((ch & 0x7c0) >> 6) | 0xc0); output[offset+1] = (byte)((ch & 0x3f) | 0x80); return offset+2; } if (ch < 0xe000){ output[offset]= (byte)(((ch & 0xf000) >> 12) | 0xe0); output[offset+1] = (byte)(((ch & 0xfc) >> 6) | 0x80); output[offset+2] = (byte)((ch & 0x3f) | 0x80); return offset+3; } output[offset]= (byte)(((ch & 0x1c0000) >> 18) | 0xf0); output[offset+1] = (byte)(((ch & 0x3f0) >> 12) | 0x80); output[offset+2] = (byte)(((ch & 0xfc) >> 6) | 0x80); output[offset+3] = (byte)((ch & 0x3f) | 0x80); return offset+4; } public static final void encodeAndWrite(OutputStream os, int ch) throws IOException, TranscodeException { if (ch < 128){ os.write(ch); return; } if (ch < 0x800){ os.write(((ch & 0x7c0) >> 6) | 0xc0); os.write((ch & 0x3f) | 0x80); return; } if (ch < 0xe000){ os.write(((ch & 0xf000) >> 12) | 0xe0); os.write(((ch & 0xfc) >> 6) | 0x80); os.write((ch & 0x3f) | 0x80); return; } os.write(((ch & 0x1c0000) >> 18) | 0xf0); os.write(((ch & 0x3f0) >> 12) | 0x80); os.write(((ch & 0xfc) >> 6) | 0x80); os.write((ch & 0x3f) | 0x80); } /** * Decode a UTF-8 char in the input buffer * @param input the byte array containing UTF-8 chars * @return a long whose lower 32-bits is the char at the given offset * upper 32-bits is the offset of next char in input * */ public static long decode(byte[] input, int offset){ long l = 0; int c=0; byte val = input[offset]; if (val > 0){ l = offset + 1; return (l<<32) | val; } if ((val & 0xe0 )== 0xc0){ l = offset + 2; c = (((int) (val& 0x1f))<< 6)| (input[offset+1] & 0x3f); return (l<<32) | c; } if ((val & 0xf0) == 0xe0){ l = offset + 3; c = (((int) (val& 0x0f))<<12) | (((int)input[offset+1] & 0x3f)<<6) | (input[offset+2] & 0x3f); return (l<<32) | c; } l = offset+4; c = (((int) (val& 0x07))<<18) | (((int)input[offset+1] & 0x3f)<<12) | (((int)input[offset+2] & 0x3f)<< 6) | (input[offset+3] & 0x3f); return (l<<32) | c; } /** * Get the length (in UTF-8 representation) of the UCS char at the offset value * @param input * @return a long whose upper 32-bits is next offset value * and whose lower 32-bits is length in byte * */ public static int getLen(int ch) throws TranscodeException{ if (ch < 128) return 1; if (ch < 0x800) return 2; if (ch < 0xe000) return 3; if (ch < 0x10000) return 4; return 5; } }
4,723
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
NavException.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/NavException.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; /** * This exception is for any exception conditions during navigation phase. * Creation date: (11/19/03 11:42:28 AM) */ public class NavException extends Exception { /** * NavException constructor comment. */ public NavException() { super(); } /** * NavException constructor comment. * @param s java.lang.String */ public NavException(String s) { super(s); } }
1,226
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FastLongBuffer.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/FastLongBuffer.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; import java.lang.IndexOutOfBoundsException; import java.lang.NullPointerException; import java.lang.IllegalArgumentException; import java.util.ArrayList; /** * A fast, unsynchronized, chunk-based long buffer for storing LCs and VTD. * Creation date: (7/17/03 6:07:46 PM) */ public class FastLongBuffer implements ILongBuffer { /* bufferArrayList is a resizable array list of int buffers * */ private ArrayList bufferArrayList; /** * Total capacity of the IntBuffer */ private int capacity; /** * Page size of the incremental growth of the Int Buffer */ private int pageSize; /** * Total number of integers in the IntBuffer */ private int size; private int exp; private int r; /** * FastLongBuffer constructor comment. */ public FastLongBuffer() { size = 0; capacity = 0; pageSize = 1024; exp = 10; r = 1023; bufferArrayList = new ArrayList(); } /** * Construct a FastLongBuffer instance with specified page size * @param e int (so that pageSize = (1<<e)) */ public FastLongBuffer(int e) { if (e <= 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = (1<<e); exp = e; r = pageSize -1; bufferArrayList = new ArrayList(); } /** * Construct a FastLongBuffer instance with specified page size * @param e int (so that pageSize = (1<<e)) * @param c int (suggest initial capacity of ArrayList */ public FastLongBuffer(int e,int c) { if (e <= 0) { throw new IllegalArgumentException(); } capacity = size = 0; pageSize = (1<<e); exp = e; r = pageSize -1; bufferArrayList = new ArrayList(c); } /** * Append single long to the end of array buffer. * @param long_array long[] */ public void append(long[] long_array) { if (long_array == null) { throw new NullPointerException(); } // no additional buffer space needed int lastBufferIndex; long[] lastBuffer; if (bufferArrayList.size() == 0) { lastBuffer = new long[pageSize]; bufferArrayList.add(lastBuffer); lastBufferIndex = 0; capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size() - 1); lastBuffer = (long[]) bufferArrayList.get(lastBufferIndex); } if ((this.size + long_array.length) < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length if (this.size + long_array.length< ((lastBufferIndex+1)<<exp)){ System.arraycopy(long_array, 0, lastBuffer, size & r, long_array.length); } else { int offset = pageSize -(size&r); // copy the first part System.arraycopy(long_array, 0, lastBuffer, size & r, offset); // copy the middle part int l = long_array.length - offset; int k = (l)>> exp; int z; for (z=1;z<=k;z++){ System.arraycopy(long_array,offset,(long[]) bufferArrayList.get(lastBufferIndex+z), 0, pageSize); offset += pageSize; } // copy the last part System.arraycopy(long_array,offset,(long[]) bufferArrayList.get(lastBufferIndex+z), 0, l & r); } size += long_array.length; return; } else // new buffers needed { // compute the number of additional buffers needed // int n = // ((int) ((long_array.length + size) / pageSize)) // + (((long_array.length + size) % pageSize) > 0 ? 1 : 0) // - (int) (capacity / pageSize); int n = ((long_array.length + size) >> exp) + (((long_array.length + size)&r) > 0 ? 1 : 0) - (capacity >> exp); // create these buffers // add to bufferArrayList //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, capacity - size); System.arraycopy(long_array, 0, lastBuffer, size & r, capacity - size); for (int i = 0; i < n; i++) { long[] newBuffer = new long[pageSize]; if (i < n - 1) { // full copy System.arraycopy( long_array, pageSize * i + capacity - size, newBuffer, 0, pageSize); } else { // last page System.arraycopy( long_array, pageSize * i + capacity - size, newBuffer, 0, long_array.length+ size - pageSize*i - capacity); } bufferArrayList.add(newBuffer); } // update length size += long_array.length; // update capacity capacity += n * pageSize; // update } } /** * Append an integer to the end of this array buffer * @param i long */ public void append(long i) { long[] lastBuffer; int lastBufferIndex; if (bufferArrayList.size() == 0) { lastBuffer = new long[pageSize]; bufferArrayList.add(lastBuffer); capacity = pageSize; } else { lastBufferIndex = Math.min((size>>exp),//+(((size&r)==0)? 0:1), bufferArrayList.size() - 1); lastBuffer = (long[]) bufferArrayList.get(lastBufferIndex); //lastBuffer = (long[]) bufferArrayList.get(bufferArrayList.size() - 1); } if (this.size < this.capacity) { //get the last buffer from the bufferListArray //obtain the starting offset in that buffer to which the data is to be copied //update length //System.arraycopy(long_array, 0, lastBuffer, size % pageSize, long_array.length); //lastBuffer[size % pageSize] = i; lastBuffer[size & r] = i; size += 1; } else // new buffers needed { long[] newBuffer = new long[pageSize]; size++; capacity += pageSize; bufferArrayList.add(newBuffer); newBuffer[0] = i; } } /** * Get the capacity of the buffer. * @return int */ public int getCapacity() { return capacity; } /** * Return a selected chuck of long buffer as a long array. * @return long[] * @param startingOffset int * @param len int */ public long[] getLongArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size()) { throw (new IndexOutOfBoundsException()); } long[] result = new long[len]; // allocate result array int first_index = (startingOffset >> exp); int last_index = ((startingOffset + len) >>exp); //if ((startingOffset + len) % pageSize == 0) { if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (long[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int long_array_offset = 0; for (int i = first_index; i <= last_index; i++) { long[] currentChunk = (long[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % r)); pageSize - (startingOffset & r)); long_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, long_array_offset, len - long_array_offset); } else { System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize); long_array_offset += pageSize; } } } return result; } /** * Get the buffer page size. * @return int */ public int getPageSize() { return pageSize; } /** * Get the long val at given index value. * @return long * @param index int */ public long longAt(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >> exp); // int offset = index % r; int offset = index &r; return ((long[]) bufferArrayList.get(pageNum))[offset]; } /** * Get the lower 32 bit of the integer at the given index. * @return int * @param index int */ public int lower32At(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >> exp); // int offset = index % pageSize; int offset = index & r; return (int) ((long[]) bufferArrayList.get(pageNum))[offset]; } /** * Modify the value at the index to a new val. * @param index int * @param newValue long */ public void modifyEntry(int index, long newValue) { if (index < 0 || index > size + 1) { throw new IndexOutOfBoundsException(); } //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((long[]) bufferArrayList.get(index >> exp))[index & r] = newValue; } /** * Get the total number of longs in the buffer. * @return int */ public int size() { return size; } /** * Convert all longs into a long array. * @return long[] */ public long[] toLongArray() { if (size > 0) { int s = size; long[] resultArray = new long[size]; //copy all the content int into the resultArray int array_offset = 0; for (int i = 0; s>0; i++) { System.arraycopy( (long[]) bufferArrayList.get(i), 0, resultArray, array_offset, (s<pageSize) ? s : pageSize); //(i == (bufferArrayList.size() - 1)) ? size - ((size>>exp)<<exp) : pageSize); //(i == (bufferArrayList.size() - 1)) ? (size & r) : pageSize); s = s - pageSize; array_offset += pageSize; } return resultArray; } return null; } /** * Return the upper 32 bit of the long at the index. * @return int * @param index int */ public int upper32At(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >>exp); int offset = index & r; return (int) ((((long[]) bufferArrayList.get(pageNum))[offset] & (0xffffffffL << 32)) >> 32); } /** * set teh size of long buffer to zero, capacity * untouched so long buffer can be reused without * any unnecessary and additional allocation * */ public void clear(){ size = 0; } }
12,438
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
EOFExceptionHuge.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/EOFExceptionHuge.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; /** * Signals the End of File exception during parsing (not the one in java.io). * It is adapted to support extended VTD (256 max file size) */ public class EOFExceptionHuge extends ParseExceptionHuge { /** * EOFException constructor comment. */ public EOFExceptionHuge() { super(); } /** * EOFException constructor comment. * @param s java.lang.String */ public EOFExceptionHuge(String s) { super(s); } }
1,271
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
VTDNavHuge.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/VTDNavHuge.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * * this class is created to update VTDNavHuge's implementation with * a more thread safe version */ package com.ximpleware.extended; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; //import com.ximpleware.extended.parser.UTF8Char; import com.ximpleware.BookMark; import com.ximpleware.NavException; import com.ximpleware.VTDNav; import com.ximpleware.extended.parser.*; //import com.ximpleware.NavException; /** * * VTDNavHuge is a cursor-based VTD record navigator supporting extended VTD (256 GB max file size). * The core navigation routines are toElement() and toElementNS() * push() and pop() allows one to save and restore the location of the cursor * String comparsions and primitive data type conversions are done directly from VTD records * without intermediatary string creation. */ public class VTDNavHuge { // Navigation directions public final static int ROOT = 0; public final static int PARENT = 1; public final static int FIRST_CHILD = 2; public final static int LAST_CHILD = 3; public final static int NEXT_SIBLING = 4; public final static int PREV_SIBLING = 5; // Navigation directions public final static int R = 0; public final static int P = 1; public final static int FC = 2; public final static int LC = 3; public final static int NS = 4; public final static int PS = 5; // token type definitions public final static int TOKEN_STARTING_TAG = 0; public final static int TOKEN_ENDING_TAG = 1; public final static int TOKEN_ATTR_NAME = 2; public final static int TOKEN_ATTR_NS = 3; public final static int TOKEN_ATTR_VAL = 4; public final static int TOKEN_CHARACTER_DATA = 5; public final static int TOKEN_COMMENT = 6; public final static int TOKEN_PI_NAME = 7; public final static int TOKEN_PI_VAL = 8; public final static int TOKEN_DEC_ATTR_NAME = 9; public final static int TOKEN_DEC_ATTR_VAL = 10; public final static int TOKEN_CDATA_VAL = 11; public final static int TOKEN_DTD_VAL = 12; public final static int TOKEN_DOCUMENT =13; // encoding format definition here public final static int FORMAT_UTF8 = 2; public final static int FORMAT_ASCII = 0; public final static int FORMAT_ISO_8859_1 = 1; public final static int FORMAT_ISO_8859_2 = 3; public final static int FORMAT_ISO_8859_3 = 4; public final static int FORMAT_ISO_8859_4 = 5; public final static int FORMAT_ISO_8859_5 = 6; public final static int FORMAT_ISO_8859_6 = 7; public final static int FORMAT_ISO_8859_7 = 8; public final static int FORMAT_ISO_8859_8 = 9; public final static int FORMAT_ISO_8859_9 = 10; public final static int FORMAT_ISO_8859_10 = 11; public final static int FORMAT_ISO_8859_11 = 12; public final static int FORMAT_ISO_8859_12 = 13; public final static int FORMAT_ISO_8859_13 = 14; public final static int FORMAT_ISO_8859_14 = 15; public final static int FORMAT_ISO_8859_15 = 16; public final static int FORMAT_ISO_8859_16 = 17; public final static int FORMAT_WIN_1250 = 18; public final static int FORMAT_WIN_1251 = 19; public final static int FORMAT_WIN_1252 = 20; public final static int FORMAT_WIN_1253 = 21; public final static int FORMAT_WIN_1254 = 22; public final static int FORMAT_WIN_1255 = 23; public final static int FORMAT_WIN_1256 = 24; public final static int FORMAT_WIN_1257 = 25; public final static int FORMAT_WIN_1258 = 26; public final static int FORMAT_UTF_16LE = 64; public final static int FORMAT_UTF_16BE = 63; // masks for obtaining various fields from a VTD token 16-bit long protected final static long MASK_TOKEN_FULL_LEN = 0x007fffc000000000L; private final static long MASK_TOKEN_PRE_LEN = 0x007f000000000000L; private final static long MASK_TOKEN_QN_LEN = 0x0000ffc000000000L; private final static long MASK_TOKEN_OFFSET = 0x0000003fffffffffL; private final static long MASK_TOKEN_TYPE = 0xf000000000000000L; private final static long MASK_TOKEN_DEPTH = 0x0f80000000000000L; // tri-state variable for namespace lookup //private final static long MASK_TOKEN_NS_MARK = 0x00000000c0000000L; protected int rootIndex; // where the root element is at protected int nestingLevel; protected int[] context; // main navigation tracker aka context object protected boolean atTerminal; // this variable is to make vn compatible with // xpath's data model // location cache part protected int l2upper; protected int l2lower; protected int l3upper; protected int l3lower; protected int l2index; protected int l3index; protected int l1index; // containers protected ILongBuffer vtdBuffer; protected ILongBuffer l1Buffer; protected ILongBuffer l2Buffer; protected IIntBuffer l3Buffer; protected IByteBuffer XMLDoc; //private int recentNS; // most recently visited NS node, experiment for now // Hierarchical representation is an array of integers addressing elements tokens private ContextBuffer contextStack; protected ContextBuffer contextStack2;// this is reserved for XPath protected int LN; // record txt and attrbute for XPath eval purposes // the document encoding protected int encoding; //protected boolean writeOffsetAdjustment; // for string to token comparison //protected int currentOffset; //protected int currentOffset2; // whether the navigation is namespace enabled or not. protected boolean ns; // intermediate buffer for push and pop purposes protected int[] stackTemp; protected long docOffset; // length of the document protected long docLen; protected int vtdSize; //vtd record count /** * Initialize the VTD navigation object. * @param RootIndex int * @param maxDepth int * @param encoding int * @param NS boolean * @param x byte[] * @param vtd com.ximpleware.extended.ILongBuffer * @param l1 com.ximpleware.extended.ILongBuffer * @param l2 com.ximpleware.extended.ILongBuffer * @param l3 com.ximpleware.extended.IIntBuffer * @param so int starting offset of the document(in byte) * @param length int length of the document (in byte) */ protected VTDNavHuge( int RootIndex, int enc, boolean NS, int depth, IByteBuffer x, ILongBuffer vtd, ILongBuffer l1, ILongBuffer l2, IIntBuffer l3, long so, // start offset of the starting offset(in byte) long length) // lengnth of the XML document (in byte)) { // initialize all buffers if (l1 == null || l2 == null || l3 == null || vtd == null || x == null || depth < 0 || RootIndex < 0 //|| encoding <= FORMAT_UTF8 //|| encoding >= FORMAT_ISO_8859_1 || so < 0 || length < 0) { throw new IllegalArgumentException(); } l1Buffer = l1; l2Buffer = l2; l3Buffer = l3; vtdBuffer = vtd; XMLDoc = x; encoding = enc; //System.out.println("encoding " + encoding); rootIndex = RootIndex; nestingLevel = depth + 1; ns = NS; // namespace aware or not //if (ns == false) // MASK_TOKEN_OFFSET = 0x000000007fffffffL; // this allows xml size to be 2GB //else // if there is no namespace // MASK_TOKEN_OFFSET = 0x000000003fffffffL; atTerminal = false; //this variable will only change value during XPath eval // initialize the context object this.context = new int[nestingLevel]; //depth value is the first entry in the context because root is singular. context[0] = 0; //set the value to zero for (int i = 1; i < nestingLevel; i++) { context[i] = -1; } //currentOffset = 0; //contextStack = new ContextBuffer(1024, nestingLevel + 7); contextStack = new ContextBuffer(10, nestingLevel + 9); contextStack2 = new ContextBuffer(10, nestingLevel+9); stackTemp = new int[nestingLevel + 9]; // initial state of LC variables l1index = l2index = l3index = -1; l2lower = l3lower = -1; l2upper = l3upper = -1; docOffset = so; docLen = length; //System.out.println("offset " + offset + " length " + length); //printL2Buffer(); vtdSize = vtd.size(); //writeOffsetAdjustment = false; //recentNS = -1; } /** * Return the attribute count of the element at the cursor position. * when ns is false, ns tokens are considered attributes; * otherwise, ns tokens are not considered attributes * @return int */ public int getAttrCount() { if (context[0]==-1)return 0; int count = 0; int index = getCurrentIndex() + 1; while (index < vtdSize) { int type = getTokenType(index); if (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_VAL || type == TOKEN_ATTR_NS) { if (type == TOKEN_ATTR_NAME || (!ns && (type == TOKEN_ATTR_NS))) { count++; } } else break; index++; } return count; } /** * Get the token index of the attribute value given an attribute name. * @return int (-1 if no such attribute name exists) * @param an java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD etc can be generated by another * machine from a load-balancer. * @exception IllegalArguementException if an is null */ public int getAttrVal(String an) throws NavExceptionHuge { //int size = vtdBuffer.size(); if (context[0]==-1) return -1; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; int type; if (index<vtdSize) type= getTokenType(index); else return -1; if (ns == false) { while ((type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (matchRawTokenString(index, an)) { // ns node visible only ns is disabled return index + 1; } index += 2; if (index >= vtdSize) break; type = getTokenType(index); } } else { while ((type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (type == TOKEN_ATTR_NAME && matchRawTokenString( index, an)) { // ns node visible only ns is disabled return index + 1; } index += 2; if (index>=vtdSize) break; type = getTokenType(index); } } return -1; } /** * Get the token index of the attribute value of given URL and local name. * If ns is not enabled, the lookup will return -1, indicating a no-found. * Also namespace nodes are invisible using this method. * One can't use * to indicate any name space because * is ambiguous!! * @return int (-1 if no matching attribute found) * @param URL java.lang.String (Name space URL) * @param ln java.lang.String (local name) * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD etc can be generated by another * machine from a load-balancer. * @exception IllegalArguementException if s is null */ public int getAttrValNS(String URL, String ln) throws NavExceptionHuge { if (ns == false) return -1; if (URL == null) return getAttrVal(ln); int size = vtdBuffer.size(); int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; // point to the token next to the element tag int type; if (index<vtdSize) type = getTokenType(index); else return -1; while (index < size && (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { int i = getTokenLength(index); long offset = getTokenOffset(index); int preLen = (i >> 16) & 0xffff; int fullLen = i & 0xffff; if (preLen != 0 // attribute name without a prefix is not bound to any namespaces && matchRawTokenString( offset + preLen + 1, fullLen - preLen - 1, ln) && resolveNS(URL, offset, preLen)) { return index + 1; } index += 2; if (index>=vtdSize) break; type = getTokenType(index); } return -1; } private long handle_utf8(long temp, long offset) throws NavExceptionHuge { int c, d, a; long val; switch (UTF8Char.byteCount((int)temp & 0xff)) { case 2: c = 0x1f; d = 6; a = 1; break; case 3: c = 0x0f; d = 12; a = 2; break; case 4: c = 0x07; d = 18; a = 3; break; case 5: c = 0x03; d = 24; a = 4; break; case 6: c = 0x01; d = 30; a = 5; break; default: throw new NavExceptionHuge("UTF 8 encoding error: should never happen"); } val = (temp & c) << d; int i = a - 1; while (i >= 0) { temp = XMLDoc.byteAt(offset + a - i); if ((temp & 0xc0) != 0x80) throw new NavExceptionHuge( "UTF 8 encoding error: should never happen"); val = val | ((temp & 0x3f) << ((i << 2) + (i << 1))); i--; } //currentOffset += a + 1; return val | (((long)(a+1))<<32); } private long handle_utf16le(long offset) throws NavExceptionHuge { // implement UTF-16LE to UCS4 conversion int val, temp = (XMLDoc.byteAt((offset << 1) + 1 ) & 0xff) << 8 | (XMLDoc.byteAt(offset << 1) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // check for low surrogate if (temp == '\r') { if (XMLDoc.byteAt((offset << 1) + 2) == '\n' && XMLDoc.byteAt((offset << 1) + 3) == 0) { return '\n' | (2L<<32) ; } else { return '\n' | (1L<<32); } } return temp | (1L<<32); } else { if (temp<0xd800 || temp>0xdbff) throw new NavExceptionHuge("UTF 16 LE encoding error: should never happen"); val = temp; temp = (XMLDoc.byteAt((offset << 1) + 3)&0xff) << 8 | (XMLDoc.byteAt((offset << 1) + 2) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be high surrogate throw new NavExceptionHuge("UTF 16 LE encoding error: should never happen"); } val = ((temp - 0xd800)<<10) + (val - 0xdc00) + 0x10000; return val | (2L<<32); } //System.out.println("UTF 16 LE unimplemented for now"); } private long handle_utf16be(long offset) throws NavExceptionHuge{ long val; int temp = ((XMLDoc.byteAt(offset << 1) & 0xff) << 8) |(XMLDoc.byteAt((offset << 1) + 1)& 0xff); if ((temp < 0xd800) || (temp > 0xdfff)) { // not a high surrogate if (temp == '\r') { if (XMLDoc.byteAt((offset << 1) + 3) == '\n' && XMLDoc.byteAt((offset << 1) + 2) == 0) { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } //currentOffset++; return temp| (1L<<32); } else { if (temp<0xd800 || temp>0xdbff) throw new NavExceptionHuge("UTF 16 BE encoding error: should never happen"); val = temp; temp = ((XMLDoc.byteAt((offset << 1) + 2) & 0xff) << 8) | (XMLDoc.byteAt((offset << 1 )+ 3) & 0xff); if (temp < 0xdc00 || temp > 0xdfff) { // has to be a low surrogate here throw new NavExceptionHuge("UTF 16 BE encoding error: should never happen"); } val = ((temp - 0xd800) << 10) + (val - 0xdc00) + 0x10000; //currentOffset += 2; return val | (2L<<32); } } private long getChar4OtherEncoding(long offset) throws NavExceptionHuge{ if (encoding <= FORMAT_WIN_1258){ int temp = decode(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return temp|(1L<<32); } throw new NavExceptionHuge("Unknown Encoding"); } /** * This method decodes the underlying byte array into corresponding UCS2 char representation . * It doesn't resolves built-in entity and character references. * Length will never be zero * Creation date: (11/21/03 6:26:17 PM) * @return int * @exception com.ximpleware.extended.NavExceptionHuge The exception is thrown if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine, e.g. from a load-balancer. */ private long getChar(long offset) throws NavExceptionHuge { long temp = 0; //int a, c, d; //int val; //int ch; //int inc; //a = c = d = val = 0; switch (encoding) { case FORMAT_ASCII : // ascii is compatible with UTF-8, the offset value is bytes temp = XMLDoc.byteAt(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return temp|(1L<<32); case FORMAT_ISO_8859_1 : temp = XMLDoc.byteAt(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return (temp & 0xff)|(1L<<32); case FORMAT_UTF8 : temp = XMLDoc.byteAt(offset); if (temp>=0){ if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } //currentOffset++; return temp|(1L<<32); } return handle_utf8(temp,offset); case FORMAT_UTF_16BE : return handle_utf16be(offset); case FORMAT_UTF_16LE : return handle_utf16le(offset); default : return getChar4OtherEncoding(offset); //throw new NavExceptionHuge("Unknown Encoding"); } } /* the exact same copy of getChar except it operates on currentOffset2 * this is needed to compare VTD tokens directly */ /** * This method decodes the underlying byte array into corresponding UCS2 char representation . * Also it resolves built-in entity and character references. * @return int * @exception com.ximpleware.extended.NavExceptionHuge The exception is thrown if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine from a load-balancer. */ private long getCharResolved(long offset) throws NavExceptionHuge { int ch = 0; int val = 0; long inc =2; long l = getChar(offset); ch = (int)l; if (ch != '&') return l; // let us handle references here //currentOffset++; offset++; ch = getCharUnit(offset); offset++; switch (ch) { case '#' : ch = getCharUnit(offset); if (ch == 'x') { while (true) { offset++; inc++; ch = getCharUnit(offset); if (ch >= '0' && ch <= '9') { val = (val << 4) + (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { val = (val << 4) + (ch - 'a' + 10); } else if (ch >= 'A' && ch <= 'F') { val = (val << 4) + (ch - 'A' + 10); } else if (ch == ';') { inc++; break; } else throw new NavExceptionHuge("Illegal char in a char reference"); } } else { while (true) { ch = getCharUnit(offset); offset++; inc++; if (ch >= '0' && ch <= '9') { val = val * 10 + (ch - '0'); } else if (ch == ';') { break; } else throw new NavExceptionHuge("Illegal char in char reference"); } } break; case 'a' : ch = getCharUnit(offset); if (ch == 'm') { if (getCharUnit(offset + 1) == 'p' && getCharUnit(offset + 2) == ';') { inc = 5; val = '&'; } else throw new NavExceptionHuge("illegal builtin reference"); } else if (ch == 'p') { if (getCharUnit(offset + 1) == 'o' && getCharUnit(offset + 2) == 's' && getCharUnit(offset + 3) == ';') { inc = 6; val = '\''; } else throw new NavExceptionHuge("illegal builtin reference"); } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'q' : if (getCharUnit(offset) == 'u' && getCharUnit(offset + 1) == 'o' && getCharUnit(offset + 2) == 't' && getCharUnit(offset + 3) ==';') { inc = 6; val = '\"'; } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'l' : if (getCharUnit(offset) == 't' && getCharUnit(offset + 1) == ';') { //offset += 2; inc = 4; val = '<'; } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'g' : if (getCharUnit(offset) == 't' && getCharUnit(offset + 1) == ';') { inc = 4; val = '>'; } else throw new NavExceptionHuge("illegal builtin reference"); break; default : throw new NavExceptionHuge("Invalid entity char"); } //currentOffset++; return val | (inc << 32); } /* the exact same copy of getCharResolved except it operates on currentOffset2 * this is needed to compare VTD tokens directly */ /* private int getCharResolved2() throws NavExceptionHuge { int ch = 0; int val = 0; ch = getChar2(); if (ch != '&') return ch; // let us handle references here //currentOffset++; ch = getCharUnit(currentOffset2); currentOffset2++; switch (ch) { case '#' : ch = getCharUnit(currentOffset2); if (ch == 'x') { while (true) { currentOffset2++; ch = getCharUnit(currentOffset2); if (ch >= '0' && ch <= '9') { val = (val << 4) + (ch - '0'); } else if (ch >= 'a' && ch <= 'f') { val = (val << 4) + (ch - 'a' + 10); } else if (ch >= 'A' && ch <= 'F') { val = (val << 4) + (ch - 'A' + 10); } else if (ch == ';') { currentOffset2++; break; } else throw new NavExceptionHuge("Illegal char in a char reference"); } } else { while (true) { ch = getCharUnit(currentOffset2); if (ch >= '0' && ch <= '9') { val = val * 10 + (ch - '0'); } else if (ch == ';') { currentOffset2++; break; } else throw new NavExceptionHuge("Illegal char in char reference"); currentOffset2++; } } break; case 'a' : ch = getCharUnit(currentOffset2); if (ch == 'm') { if (getCharUnit(currentOffset2 + 1) == 'p' && getCharUnit(currentOffset2 + 2) == ';') { currentOffset2 += 3; val = '&'; } else throw new NavExceptionHuge("illegal builtin reference"); } else if (ch == 'p') { if (getCharUnit(currentOffset2 + 1) == 'o' && getCharUnit(currentOffset2 + 2) == 's' && getCharUnit(currentOffset2 + 3) == ';') { currentOffset2 += 4; val = '\''; } else throw new NavExceptionHuge("illegal builtin reference"); } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'q' : if (getCharUnit(currentOffset2) == 'u' && getCharUnit(currentOffset2 + 1) == 'o' && getCharUnit(currentOffset2 + 2) == 't' && getCharUnit(currentOffset2 + 3) == ';') { currentOffset2 += 4; val = '\"'; } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'l' : if (getCharUnit(currentOffset2) == 't' && getCharUnit(currentOffset2 + 1) == ';') { currentOffset2 += 2; val = '<'; } else throw new NavExceptionHuge("illegal builtin reference"); break; case 'g' : if (getCharUnit(currentOffset2) == 't' && getCharUnit(currentOffset2 + 1) == ';') { currentOffset2 += 2; val = '>'; } else throw new NavExceptionHuge("illegal builtin reference"); break; default : throw new NavExceptionHuge("Invalid entity char"); } //currentOffset++; return val; }*/ private int decode(long offset){ byte ch = XMLDoc.byteAt(offset); switch(encoding){ case FORMAT_ISO_8859_2: return ISO8859_2.decode(ch); case FORMAT_ISO_8859_3: return ISO8859_3.decode(ch); case FORMAT_ISO_8859_4: return ISO8859_4.decode(ch); case FORMAT_ISO_8859_5: return ISO8859_5.decode(ch); case FORMAT_ISO_8859_6: return ISO8859_6.decode(ch); case FORMAT_ISO_8859_7: return ISO8859_7.decode(ch); case FORMAT_ISO_8859_8: return ISO8859_8.decode(ch); case FORMAT_ISO_8859_9: return ISO8859_9.decode(ch); case FORMAT_ISO_8859_10: return ISO8859_10.decode(ch); case FORMAT_ISO_8859_11: return ISO8859_11.decode(ch); case FORMAT_ISO_8859_13: return ISO8859_13.decode(ch); case FORMAT_ISO_8859_14: return ISO8859_14.decode(ch); case FORMAT_ISO_8859_15: return ISO8859_15.decode(ch); case FORMAT_WIN_1250: return WIN1250.decode(ch); case FORMAT_WIN_1251: return WIN1251.decode(ch); case FORMAT_WIN_1252: return WIN1252.decode(ch); case FORMAT_WIN_1253: return WIN1253.decode(ch); case FORMAT_WIN_1254: return WIN1254.decode(ch); case FORMAT_WIN_1255: return WIN1255.decode(ch); case FORMAT_WIN_1256: return WIN1256.decode(ch); case FORMAT_WIN_1257: return WIN1257.decode(ch); default: return WIN1258.decode(ch); } } /** * Get the next char unit which gets decoded automatically * @return int */ private int getCharUnit(long offset) { return (encoding <= 2) ? XMLDoc.byteAt(offset) & 0xff : (encoding <= FORMAT_WIN_1258) ? decode(offset):(encoding == FORMAT_UTF_16BE) ? (XMLDoc.byteAt(offset << 1) << 8 | XMLDoc.byteAt((offset << 1) + 1)) : (XMLDoc.byteAt((offset << 1) + 1) << 8 | XMLDoc.byteAt(offset << 1)); } /** * Get the depth (>=0) of the current element. * Creation date: (11/16/03 6:58:22 PM) * @return int */ final public int getCurrentDepth() { return context[0]; } /** * Get the index value of the current element. * Creation date: (11/16/03 6:40:25 PM) * @return int */ final public int getCurrentIndex() { if (atTerminal) return LN; switch(context[0]){ case -1: return 0; case 0: return rootIndex; default: return context[context[0]]; } //return (context[0] == 0) ? rootIndex : context[context[0]]; } // this one is used in iterAttr() in autoPilot final protected int getCurrentIndex2(){ switch(context[0]){ case -1: return 0; case 0: return rootIndex; default: return context[context[0]]; } } /** * Get the encoding of the XML document. * @return int */ final public int getEncoding() { return encoding; } /** * Get the maximum nesting depth of the XML document (>0). * max depth is nestingLevel -1 * @return int */ final public int getNestingLevel() { return nestingLevel; } /** * * @return */ final protected long getOffsetAfterHead(){ int i = getCurrentIndex(); if (getTokenType(i)!=VTDNavHuge.TOKEN_STARTING_TAG){ return -1; } int j=i+1; while (j<vtdSize && (getTokenType(j)==VTDNavHuge.TOKEN_ATTR_NAME || getTokenType(j)==VTDNavHuge.TOKEN_ATTR_NS)){ j += 2; } long offset; // this is character offset if (i+1==j) { offset = getTokenOffset(i)+getTokenLength(i); }else { offset = getTokenOffset(j-1)+getTokenLength(j-1)+1; } while(getCharUnit(offset)!='>'){ offset++; } if (getCharUnit(offset-1)=='/') return -1; else return offset+1; } /** * Get root index value , which is the index val of document element * @return int */ final public int getRootIndex() { return rootIndex; } /** * This method returns of the token index of the type character data or CDATA. * Notice that it is intended to support data orient XML (not mixed-content XML). * return the index of the text token, or -1 if none exists. * @return int */ public int getText() { if (context[0]==-1) return -1; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1; int depth = getCurrentDepth(); int type; if (index<vtdSize) type = getTokenType(index); else return -1; while (true) { if (type == TOKEN_CHARACTER_DATA || type == TOKEN_CDATA_VAL) { if (depth == getTokenDepth(index)) return index; else return -1; } else if (type == TOKEN_ATTR_NS || type == TOKEN_ATTR_NAME) { index += 2; // assuming a single token for attr val } else if ( type == TOKEN_PI_NAME || type == TOKEN_PI_VAL || type == TOKEN_COMMENT) { if (depth == getTokenDepth(index)) { index += 1; } else return -1; } else return -1; if (index >= vtdSize) break; type = getTokenType(index); } return -1; } /** * Get total number of VTD tokens for the current XML document. * @return int */ final public int getTokenCount() { return vtdSize; } /** * Get the depth value of a token (>=0). * @return int * @param index int */ final public int getTokenDepth(int index) { int i = (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_DEPTH) >> 55); if (i != 31) return i; return -1; } /** * Get the token length at the given index value * please refer to VTD spec for more details * Length is in terms of the UTF char unit * For prefixed tokens, it is the qualified name length. * When ns is not enabled, return the full name length for attribute name and element name * When ns is enabled, return an int with upper 16 bit for prefix length, lower 16 bit for qname length * @return int * @param index int */ public int getTokenLength(int index) { int type = getTokenType(index); int depth; //int val; int len = 0; long l; long temp=0; switch (type) { case TOKEN_ATTR_NAME : case TOKEN_ATTR_NS : case TOKEN_STARTING_TAG : l = vtdBuffer.longAt(index); return (ns == false) ? (int) ((l & MASK_TOKEN_QN_LEN) >> 38) : ((int) ((l & MASK_TOKEN_QN_LEN) >> 38) | ((int) ((l & MASK_TOKEN_PRE_LEN) >> 32))); case TOKEN_CHARACTER_DATA: case TOKEN_CDATA_VAL: case TOKEN_COMMENT: // make sure this is total length depth = getTokenDepth(index); do{ len = len + (int) ((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN) >> 38); temp = getTokenOffset(index)+(int) ((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN) >> 38); index++; } while(index < vtdSize && depth == getTokenDepth(index) && type == getTokenType(index) && temp == getTokenOffset(index)); //if (int k=0) return len; default : return (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_FULL_LEN) >> 38); } } /** * Get the starting offset of the token at the given index. * @return int * @param index int */ final public long getTokenOffset(int index) { //return (context[0] != 0) // ? (int) (vtdBuffer.longAt(context[context[0]]) & MASK_TOKEN_OFFSET) // : (int) (vtdBuffer.longAt(rootIndex) & MASK_TOKEN_OFFSET); return (vtdBuffer.longAt(index) & MASK_TOKEN_OFFSET); } /** Get the XML document * @return IByteBuffer */ final public IByteBuffer getXML() { return XMLDoc; } /** * Get the token type of the token at the given index value. * Creation date: (11/16/03 6:41:51 PM) * @return int * @param index int */ final public int getTokenType(int index) { return (int) ((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf; } /** * Test whether current element has an attribute with the matching name. * "*" will match any attribute name, therefore is a test whether there is any attribute at all * if namespace is disabled, this function will not distinguish between ns declaration and attribute * otherwise, ns tokens are invisible * Creation date: (11/16/03 5:50:26 PM) * @return boolean (true if such an attribute exists) * @param an java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD etc can be generated by another * machine from a load-balancer. * @exception IllegalArguementException if an is null */ final public boolean hasAttr(String an) throws NavExceptionHuge { return getAttrVal(an)!=-1; } /** * Test whether the current element has an attribute with * matching namespace URL and localname. * If ns is false, return false immediately * @return boolean * @param URL java.lang.String (namespace URL) * @param ln java.lang.String (localname ) * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. * @exception IllegalArguementException if ln is null */ final public boolean hasAttrNS(String URL, String ln) throws NavExceptionHuge { return (getAttrValNS(URL, ln) != -1); } /** * Test the token type, to see if it is a starting tag. * @return boolean * @param index int */ private final boolean isElement(int index) { return (((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf) == TOKEN_STARTING_TAG; } /** * Test the token type, to see if it is a starting tag * or document token (introduced in 1.0). * @return boolean * @param index int */ private final boolean isElementOrDocument(int index){ long i =(((vtdBuffer.longAt(index) & MASK_TOKEN_TYPE) >> 60) & 0xf); return (i==TOKEN_STARTING_TAG||i==TOKEN_DOCUMENT); } /** * Test whether ch is a white space character or not. * @return boolean * @param ch int */ final private boolean isWS(int ch) { return (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r'); } /** * This function is called by selectElement_P in autoPilot * @param en element Name * @param a context of current position * @param special whether the test type is node() * @return boolean * @throws NavExceptionHuge */ protected boolean iterate_preceding(String en, int[] a, boolean special) throws NavExceptionHuge { int index = getCurrentIndex() - 1; int t,d; //int depth = getTokenDepth(index); //int size = vtdBuffer.size(); while (index > 0) { if (isElementOrDocument(index)) { int depth = getTokenDepth(index); context[0] = depth; //context[depth]=index; if (depth>0){ context[depth] = index; t = index -1; for (int i=depth-1;i>0;i--){ if (context[i]>index || context[i] == -1){ while(t>0){ d = getTokenDepth(t); if ( d == i && isElement(t)){ context[i] = t; break; } t--; } }else break; } } //dumpContext(); if (index!= a[depth] && (special || matchElement(en))) { resolveLC(); return true; } } index--; } return false; } /** * This function is called by selectElementNS_P in autoPilot * @param URL * @param ln * @return boolean * @throws NavExceptionHuge */ protected boolean iterate_precedingNS(String URL, String ln, int[] a ) throws NavExceptionHuge { int index = getCurrentIndex() - 1; int t,d; //int depth = getTokenDepth(index); //int size = vtdBuffer.size(); while (index > 0 ) { if (isElementOrDocument(index)) { int depth = getTokenDepth(index); context[0] = depth; //context[depth]=index; if (depth>0){ context[depth] = index; t = index -1; for (int i=depth-1;i>0;i--){ if (context[i]>index || context[i]==-1){ while(t>0){ d = getTokenDepth(t); if ( d == i && isElement(t)){ context[i] = t; break; } t--; } }else break; } } //dumpContext(); if (index != a[depth] && matchElementNS(URL,ln)) { resolveLC(); return true; } } index--; } return false; } /** * This function is called by selectElement_F in autoPilot * * @param en ElementName * @param special whether it is a node() * @return boolean * @throws NavExceptionHuge */ protected boolean iterate_following(String en, boolean special) throws NavExceptionHuge{ int index = getCurrentIndex() + 1; //int size = vtdBuffer.size(); while (index < vtdSize) { if (isElementOrDocument(index)) { int depth = getTokenDepth(index); context[0] = depth; if (depth>0) context[depth] = index; if (special || matchElement(en)) { resolveLC(); return true; } } index++; } return false; } /** * This function is called by selectElementNS_F in autoPilot * @param URL * @param ln * @return boolean * @throws NavExceptionHuge */ protected boolean iterate_followingNS(String URL, String ln) throws NavExceptionHuge{ int index = getCurrentIndex() + 1; //int size = vtdBuffer.size(); while (index < vtdSize) { if (isElementOrDocument(index)) { int depth = getTokenDepth(index); context[0] = depth; if (depth>0) context[depth] = index; if (matchElementNS(URL,ln)) { resolveLC(); return true; } } index++; } return false; } /** * This method is similar to getElementByName in DOM except it doesn't * return the nodeset, instead it iterates over those nodes. Notice that this method * is called by the "iterate" method in the Autopilot class. * "*" will match any element * Creation date: (12/2/03 2:31:20 PM) * @return boolean * @param dp int (The depth of the starting position before iterating) * @param en java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception is signaled if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because VTD records can be generated by another * machine from a load-balancer. * null element name allowed represent node()in XPath; */ protected boolean iterate(int dp, String en, boolean special) throws NavExceptionHuge { // the navigation doesn't rely on LC // get the current depth int index = getCurrentIndex() + 1; int tokenType; //int size = vtdBuffer.size(); while (index < vtdSize) { tokenType = getTokenType(index); if (tokenType==VTDNavHuge.TOKEN_ATTR_NAME || tokenType == VTDNavHuge.TOKEN_ATTR_NS){ index = index+2; continue; } if (isElementOrDocument(index)) { int depth = getTokenDepth(index); if (depth > dp) { context[0] = depth; if (depth>0) context[depth] = index; if (special || matchElement(en)) { if (dp< 4) resolveLC(); return true; } } else { return false; } } index++; } return false; } /** * This method is similar to getElementByName in DOM except it doesn't * return the nodeset, instead it iterates over those nodes . * When URL is "*" it will match any namespace * if ns is false, return false immediately * @return boolean * @param dp int (The depth of the starting position before iterating) * @param URL java.lang.String * @param ln java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because VTD records can be generated by another * machine from a load-balancer.. * @exception IllegalArguementException if ln is null * example * * int depth = nv.getCurrentDepth() * while(iterateNS(depth, "www.url.com","node_name")){ * push(); // store the current position * //move position safely * pop(); // load the position * } */ final protected boolean iterateNS(int dp, String URL, String ln) throws NavExceptionHuge { if (ns == false) return false; int tokenType; int index = getCurrentIndex() + 1; while (index < vtdSize) { tokenType = getTokenType(index); if(tokenType==VTDNavHuge.TOKEN_ATTR_NAME || tokenType == VTDNavHuge.TOKEN_ATTR_NS){ index = index+2; continue; } if (isElementOrDocument(index)) { int depth = getTokenDepth(index); if (depth > dp) { context[0] = depth; if (depth>0) context[depth] = index; if (matchElementNS(URL, ln)) { if (dp < 4) resolveLC(); return true; } } else { return false; } } index++; } return false; } /** * Test if the current element matches the given name. * Creation date: (11/26/03 2:09:43 PM) * @return boolean * @param en java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge If the underlying raw char representation has errors. */ final public boolean matchElement(String en) throws NavExceptionHuge { if (en.equals("*") && context[0]!=-1) return true; if (context[0]==-1) return false; return matchRawTokenString( (context[0] == 0) ? rootIndex : context[context[0]], en); } /** * Test whether the current element matches the given namespace URL and localname. * URL, when set to "*", matches any namespace (including null), when set to null, defines a "always-no-match" * ln is the localname that, when set to *, matches any localname * @return boolean * @param URL java.lang.String * @param ln java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When there is any encoding conversion error or unknown entity. * @exception java.lang.IllegalArgumentException if ln == null */ public boolean matchElementNS(String URL, String ln) throws NavExceptionHuge { if (context[0]==-1) return false; int i = getTokenLength((context[0] != 0) ? context[context[0]] : rootIndex); long offset = getTokenOffset((context[0] != 0) ? context[context[0]] : rootIndex); int preLen = (i >> 16) & 0xffff; int fullLen = i & 0xffff; if (ln.equals("*") || ((preLen != 0) ? matchRawTokenString( offset + preLen + 1, fullLen - preLen - 1, ln) : matchRawTokenString( offset, fullLen, ln))) { // no prefix, search for xmlns if (((URL != null) ? URL.equals("*") : false) || (resolveNS(URL, offset, preLen) == true)) return true; } return false; } final private boolean matchRawTokenString(long offset, int len, String s) throws NavExceptionHuge{ return compareRawTokenString(offset, len, s)==0; } protected int compareTokenString(long offset, int len, String s) throws NavExceptionHuge { int i, l; long l1; //this.currentOffset = offset; long endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { l1 = getCharResolved(offset); int i1 = s.charAt(i); if (i1 < (int) l1) return 1; if (i1 > (int) l1) return -1; offset += (int) (l1 >> 32); } if (i == l && offset < endOffset) return 1; if (i < l && offset == endOffset) return -1; return 0; } /** * Test whether a given token contains s. notie that this function * directly operates on the byte content of the token to avoid string creation * @param index * @param s * @return * @throws NavExceptionHuge */ final public boolean contains(int index, String s) throws NavExceptionHuge{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); long offset = getTokenOffset(index); long l1; int i,l; long endOffset = offset + len; boolean b = (type == TOKEN_ATTR_VAL || type == TOKEN_CHARACTER_DATA); // System.out.print("currentOffset :" + currentOffset); long gOffset = offset; l = s.length(); if (l> len) return false; //System.out.println(s); while( offset<endOffset){ gOffset = offset; if (endOffset-gOffset< l) return false; for (i = 0; i < l && gOffset < endOffset; i++) { if (b) l1 = getCharResolved(gOffset); else l1 = getChar(gOffset); int i1 = s.charAt(i); gOffset += (int) (l1 >> 32); if (i ==0) offset = gOffset; if (i1 != (int) l1) break; } if (i==l) return true; } return false; } /** * Lexicographically compare a string against a token with given * offset and len, entities doesn't get resolved. * @return int (0 if they are equal, 1 if greater, else -1) * * @param offset int * @param len int * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ protected int compareRawTokenString(long offset, int len, String s) throws NavExceptionHuge { int i, l; long l1; //this.currentOffset = offset; long endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { l1 = getChar(offset); int i1 = s.charAt(i); if (i1 < (int) l1 ) return 1; if (i1 > (int) l1) return -1; offset += (int) (l1 >> 32); } if (i == l && offset < endOffset) return 1; if (i<l && offset == endOffset) return -1; return 0; } /** * <em>New in 2.0</em> * Compare the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets compared against * This method has to take care of the underlying encoding conversion * but it <em> doesn't </em> resolve entity reference in the underlying document * The behavior is the same as calling toRawString on index, then compare to s * @param index * @param s * @return the result of lexical comparison * @exception NavExceptionHuge * */ final public int compareRawTokenString(int index, String s) throws NavExceptionHuge { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid calling getChar() everytime return compareRawTokenString(getTokenOffset(index), len, s); } /** * Match the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched against * This method has to take care of the underlying encoding conversion * but it <em> doesn't </em> resolve entity reference in the underlying document * @return boolean * @param index int (index into the VTD token buffer) * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. **/ final public boolean matchRawTokenString(int index, String s) throws NavExceptionHuge { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid calling getChar() everytime return compareRawTokenString(getTokenOffset(index), len, s)==0; } /** * Match a string with a token represented by a long (upper 32 len, lower 32 offset). * @return boolean * @param l long * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. * */ /*final private boolean matchRawTokenString(long l, String s) throws NavExceptionHuge { int len = (int) ((l & MASK_TOKEN_FULL_LEN) >> 37); // a little hardcode is always bad //currentOffset = (int) l; return compareRawTokenString((int)l, len, s)==0; }*/ /** * Match a string against a token with given offset and len, entities get resolved properly. * Creation date: (11/24/03 1:37:42 PM) * @return boolean * @param offset int * @param len int * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. * @exception IllegalArguementException if s is null */ /*final private boolean matchTokenString(long offset, int len, String s) throws NavExceptionHuge { return compareTokenString(offset,len,s)==0; }*/ /** * <em>New in 2.0</em> * Compare the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched against * This method has to take care of the underlying encoding conversion * as well as entity reference comparison * @param index * @param s * @return int * @throws NavExceptionHuge * */ public int compareTokenString(int index, String s) throws NavExceptionHuge{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid calling getChar() everytime return compareTokenString(getTokenOffset(index), len, s); } /** * Match the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched against * This method has to take care of the underlying encoding conversion * as well as entity reference comparison * @return boolean * @param index int * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. **/ final public boolean matchTokenString(int index, String s) throws NavExceptionHuge { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid calling getChar() everytime return compareTokenString(getTokenOffset(index), len, s)==0; } /** * Match a string against a "non-extractive" token represented by a long (upper 32 len, lower 32 offset). * @return boolean * @param l long * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. * */ /*final private boolean matchTokenString(long l, String s) throws NavExceptionHuge { int len = (int) (l >> 37) & 0xffff; //currentOffset = (int) l; return compareTokenString((int) l, len, s)==0; }*/ /** * Convert a vtd token into a double. * Creation date: (12/8/03 2:28:31 PM) * @return double * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ public double parseDouble(int index) throws NavExceptionHuge { //if (matchTokenString() long offset = getTokenOffset(index); long l=0; long end = offset + getTokenLength(index); int t = getTokenType(index); boolean b = (t==VTDNavHuge.TOKEN_CHARACTER_DATA )|| (t==VTDNavHuge.TOKEN_ATTR_VAL); boolean expneg = false; int ch; //past the last one by one { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } while (offset < end) { // trim leading whitespaces if (!isWS(ch)) break; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (offset > end) // all whitespace return Double.NaN; boolean neg = (ch == '-'); if (ch == '-' || ch == '+'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //get another one if it is sign. } //left part of decimal double left = 0; while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; left = left * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32);; } //right part of decimal double right = 0; double scale = 1; if (ch == '.') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; right = right * 10 + dig; scale *= 10; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } } //exponent long exp = 0; if (ch == 'E' || ch == 'e') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); expneg = (ch == '-'); //sign for exp if (ch == '+' || ch == '-'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //skip the +/- sign } long cur = offset; //remember the indx, used to find a invalid number like 1.23E while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; exp = exp * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (cur == offset) return Double.NaN; //found a invalid number like 1.23E //if (expneg) // exp = (-exp); } //anything left must be space while (offset <= end) { if (!isWS(ch)) return Double.NaN; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } double v = (double) left; if (right != 0) v += ((double) right) / (double) scale; if (exp != 0) v = (expneg)? v /(Math.pow(10,exp)): v*Math.pow(10,exp); return ((neg) ? (-v) : v); } /** * Convert a vtd token into a float. * we assume token type to be attr val or character data * Creation date: (12/8/03 2:28:18 PM) * @return float * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ public float parseFloat(int index) throws NavExceptionHuge { long offset = getTokenOffset(index); long end = offset + getTokenLength(index); long l; //past the last one by one int t = getTokenType(index); boolean b = (t==VTDNavHuge.TOKEN_CHARACTER_DATA )|| (t==VTDNavHuge.TOKEN_ATTR_VAL); int ch ; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { // trim leading whitespaces if (!isWS(ch)) break; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (offset > end) // all whitespace throw new NavExceptionHuge("Empty string"); boolean neg = (ch == '-'); if (ch == '-' || ch == '+'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //get another one if it is sign. } //left part of decimal long left = 0; while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; left = left * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } //right part of decimal long right = 0; long scale = 1; if (ch == '.') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; right = right * 10 + dig; scale *= 10; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } } //exponent long exp = 0; if (ch == 'E' || ch == 'e') { l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); boolean expneg = (ch == '-'); //sign for exp if (ch == '+' || ch == '-'){ l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); //skip the +/- sign } long cur = offset; //remember the indx, used to find a invalid number like 1.23E while (offset <= end) { //must be <= since we get the next one at last. int dig = Character.digit((char) ch, 10); //only consider decimal if (dig < 0) break; exp = exp * 10 + dig; l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } if (cur == offset) return Float.NaN; //found a invalid number like 1.23E if (expneg) exp = (-exp); } //anything left must be space while (offset <= end) { if (!isWS(ch)) throw new NavExceptionHuge(toString(index)); l = b? getCharResolved(offset):getChar(offset); ch = (int)l; offset += (int)(l>>32); } double v = (double) left; if (right != 0) v += ((double) right) / (double) scale; if (exp != 0) v = v * Math.pow(10, exp); float f = (float) v; //try to handle overflow/underflow if (v >= (double)Float.MAX_VALUE) f = Float.MAX_VALUE; else if (v <= (double)Float.MIN_VALUE) f = Float.MIN_VALUE; if (neg) f = -f; return f; } /** * Convert a vtd token into an int. * This method will automatically strip off the leading and trailing * we assume token type to be attr val or character data * zero, unlike Integer.parseInt(int index) * * Creation date: (12/8/03 2:32:22 PM) * @return int * @param index int * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ public int parseInt(int index) throws NavExceptionHuge { return parseInt(index, 10); } /** * Convert a vtd token into an int, with the given radix. * we assume token type to be attr val or character data * the first char can be either '+' or '-' * Creation date: (12/16/03 1:21:20 PM) * @return int * @param index int * @param radix int * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ protected int parseInt(int index, int radix) throws NavExceptionHuge { if (radix < 2 || radix > 36) throw new NumberFormatException( "radix " + radix + " out of valid range"); int t = getTokenType(index); boolean b = (t==VTDNavHuge.TOKEN_CHARACTER_DATA )|| (t==VTDNavHuge.TOKEN_ATTR_VAL); long offset = getTokenOffset(index); long endOffset = offset + getTokenLength(index); int c; long l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); // trim leading whitespaces while ((c == ' ' || c == '\n' || c == '\t' || c == '\r') && (offset <= endOffset)){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset > endOffset) // all whitespace throw new NumberFormatException(" empty string"); boolean neg = (c == '-'); if (neg || c == '+') { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); //skip sign } long result = 0; //long pos = 1; while (offset <= endOffset) { int digit = Character.digit((char) c, radix); if (digit < 0) break; //Note: for binary we can simply shift to left to improve performance result = result * radix + digit; //pos *= radix; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (result > Integer.MAX_VALUE) throw new NumberFormatException("Overflow: " + toString(index)); // take care of the trailing while (offset <= endOffset && isWS(c)) { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset == (endOffset + 1)) return (int) ((neg) ? (-result) : result); else throw new NumberFormatException(toString(index)); } /** * Convert a vtd token into a long. * we assume token type to be attr val or character data * Creation date: (12/8/03 2:32:59 PM) * @return long * @param index int * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ public long parseLong(int index) throws NavExceptionHuge { return parseLong(index, 10); } /** * Convert a vtd token into a long, with the given radix. * the first char can be either '+' or '-', leading and trailing will be stripped * we assume token type to be attr val or character data * Creation date: (12/17/03 1:51:06 PM) * @return long * @param index int * @param radix int * @exception com.ximpleware.extended.NavExceptionHuge The exception if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. */ protected long parseLong(int index, int radix) throws NavExceptionHuge { if (radix < 2 || radix > 36) throw new NumberFormatException( "radix " + radix + " out of valid range"); int t = getTokenType(index); boolean b = (t==VTDNavHuge.TOKEN_CHARACTER_DATA )|| (t==VTDNavHuge.TOKEN_ATTR_VAL); long offset = getTokenOffset(index); long endOffset = offset + getTokenLength(index); int c; long l; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); // trim leading whitespaces while ((c == ' ' || c == '\n' || c == '\t' || c == '\r') && (offset <= endOffset)){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset > endOffset) // all whitespace throw new NumberFormatException(" empty string"); boolean neg = (c == '-'); if (neg || c == '+'){ l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);//skip sign } long result = 0; //long pos = 1; while (offset <= endOffset) { int digit = Character.digit((char) c, radix); if (digit < 0) break; //Note: for binary we can simply shift to left to improve performance result = result * radix + digit; //pos *= radix; l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);; } if (result > Long.MAX_VALUE) throw new NumberFormatException("Overflow: " + toString(index)); // take care of the trailing while (offset <= endOffset && isWS(c)) { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); } if (offset == (endOffset + 1)) return (long) ((neg) ? (-result) : result); else throw new NumberFormatException(toString(index)); } /** * Load the context info from ContextBuffer. * Info saved including LC and current state of the context * @return boolean * */ final public boolean pop() { boolean b = contextStack.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l2lower = stackTemp[nestingLevel + 3]; l2upper = stackTemp[nestingLevel + 4]; l3lower = stackTemp[nestingLevel + 5]; l3upper = stackTemp[nestingLevel + 6]; atTerminal = (stackTemp[nestingLevel + 7] == 1); LN = stackTemp[nestingLevel+8]; return true; } /** * Load the context info from contextStack2. * This method is dedicated for XPath evaluation. * @return status of pop2 */ final protected boolean pop2(){ boolean b = contextStack2.load(stackTemp); if (b == false) return false; for (int i = 0; i < nestingLevel; i++) { context[i] = stackTemp[i]; } l1index = stackTemp[nestingLevel]; l2index = stackTemp[nestingLevel + 1]; l3index = stackTemp[nestingLevel + 2]; l2lower = stackTemp[nestingLevel + 3]; l2upper = stackTemp[nestingLevel + 4]; l3lower = stackTemp[nestingLevel + 5]; l3upper = stackTemp[nestingLevel + 6]; atTerminal = (stackTemp[nestingLevel + 7] == 1); LN = stackTemp[nestingLevel+8]; return true; } /** * Store the context info into the ContextBuffer. * Info saved including LC and current state of the context * Creation date: (11/16/03 7:00:27 PM) */ final public void push() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l2lower; stackTemp[nestingLevel + 4] = l2upper; stackTemp[nestingLevel + 5] = l3lower; stackTemp[nestingLevel + 6] = l3upper; if (atTerminal) stackTemp[nestingLevel + 7] =1; else stackTemp[nestingLevel + 7] =0; stackTemp[nestingLevel+8] = LN; contextStack.store(stackTemp); } /** * Store the context info into the contextStack2. * This method is reserved for XPath Evaluation * */ final protected void push2() { for (int i = 0; i < nestingLevel; i++) { stackTemp[i] = context[i]; } stackTemp[nestingLevel] = l1index; stackTemp[nestingLevel + 1] = l2index; stackTemp[nestingLevel + 2] = l3index; stackTemp[nestingLevel + 3] = l2lower; stackTemp[nestingLevel + 4] = l2upper; stackTemp[nestingLevel + 5] = l3lower; stackTemp[nestingLevel + 6] = l3upper; if (atTerminal) stackTemp[nestingLevel + 7] =1; else stackTemp[nestingLevel + 7] =0; stackTemp[nestingLevel+8] = LN; contextStack2.store(stackTemp); } /** * clear the contextStack2 after XPath evaluation * * */ final protected void clearStack2(){ contextStack2.clear(); } /** * Sync level 1 location cache */ private void resolveLC_l1(){ if (l1index < 0 || l1index >= l1Buffer.size() || context[1] != l1Buffer.upper32At(l1index)) { if (l1index >= l1Buffer.size() || l1index < 0) { l1index = 0; } if (l1index+1<l1Buffer.size() && context[1] != l1Buffer.upper32At(l1index+1)) { int init_guess = (int) (l1Buffer.size() * ((float) context[1] / vtdBuffer .size())); if (l1Buffer.upper32At(init_guess) > context[1]) { while (l1Buffer.upper32At(init_guess) != context[1]) { init_guess--; } } else if (l1Buffer.upper32At(init_guess) < context[1]) { while (l1Buffer.upper32At(init_guess) != context[1]) { init_guess++; } } l1index = init_guess; } else{ if (context[1]>=l1Buffer.upper32At(l1index)){ while(context[1]!=l1Buffer.upper32At(l1index) && l1index < l1Buffer.size()){ l1index++; } } else{ while(context[1]!=l1Buffer.upper32At(l1index) && l1index >=0){ l1index--; } } } } } /** * Sync Level 2 location cache */ private void resolveLC_l2(){ int temp = l1Buffer.lower32At(l1index); if (l2lower != temp) { l2lower = temp; // l2lower shouldn't be -1 !!!! l2lower and l2upper always get // resolved simultaneously l2index = l2lower; l2upper = l2Buffer.size() - 1; for (int i = l1index + 1; i < l1Buffer.size(); i++) { temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } } // intelligent guess again ?? if (l2index < 0 || l2index >= l2Buffer.size() || context[2] != l2Buffer.upper32At(l2index)) { if (l2index >= l2Buffer.size() || l2index<0) l2index = l2lower; if (l2index+1< l2Buffer.size()&& context[2] == l2Buffer.upper32At(l2index + 1)) l2index = l2index + 1; else if (l2upper - l2lower >= 16) { int init_guess = l2lower + (int) ((l2upper - l2lower) * ((float) context[2] - l2Buffer .upper32At(l2lower)) / (l2Buffer .upper32At(l2upper) - l2Buffer .upper32At(l2lower))); if (l2Buffer.upper32At(init_guess) > context[2]) { while (context[2] != l2Buffer.upper32At(init_guess)) init_guess--; } else if (l2Buffer.upper32At(init_guess) < context[2]) { while (context[2] != l2Buffer.upper32At(init_guess)) init_guess++; } l2index = init_guess; } else if (context[2]<l2Buffer.upper32At(l2index)){ while ( context[2] != l2Buffer.upper32At(l2index)) { l2index--; } } else { while(context[2]!=l2Buffer.upper32At(l2index)) l2index++; } } } /** * Sync L3 location Cache */ private void resolveLC_l3(){ int temp = l2Buffer.lower32At(l2index); if (l3lower != temp) { //l3lower and l3upper are always together l3lower = temp; // l3lower shouldn't be -1 l3index = l3lower; l3upper = l3Buffer.size() - 1; for (int i = l2index + 1; i < l2Buffer.size(); i++) { temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } } if (l3index < 0 || l3index >= l3Buffer.size() || context[3] != l3Buffer.intAt(l3index)) { if (l3index >= l3Buffer.size() || l3index <0) l3index = l3lower; if (l3index+1 < l3Buffer.size() && context[3] == l3Buffer.intAt(l3index + 1)) l3index = l3index + 1; else if (l3upper - l3lower >= 16) { int init_guess = l3lower + (int) ((l3upper - l3lower) * ((float) (context[3] - l3Buffer .intAt(l3lower)) / (l3Buffer.intAt(l3upper) - l3Buffer .intAt(l3lower)))); if (l3Buffer.intAt(init_guess) > context[3]) { while (context[3] != l3Buffer.intAt(init_guess)) init_guess--; } else if (l3Buffer.intAt(init_guess) < context[3]) { while (context[3] != l3Buffer.intAt(init_guess)) init_guess++; } l3index = init_guess; } else if (context[3]<l3Buffer.intAt(l3index)){ while (context[3] != l3Buffer.intAt(l3index)) { l3index--; } } else { while (context[3] != l3Buffer.intAt(l3index)) { l3index++; } } } } /** * Sync up the current context with location cache. * This operation includes finding out l1index, l2index, * l3index and restores upper and lower bound info * To improve efficieny this method employs some heuristic search algorithm. * The result is that it is quite close to direct access. * Creation date: (11/16/03 7:44:53 PM) * @return int The index of the NS URL */ private void resolveLC() { if (context[0]<=0) return; resolveLC_l1(); if (context[0] == 1) return; resolveLC_l2(); if (context[0] == 2) return; resolveLC_l3(); } /** * Test whether the URL is defined in the scope. Null is allowed to * indicate the name space is undefined. Creation date: (11/16/03 7:54:01 * PM) * * @param URL * java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge * When there is any encoding conversion error or unknown * entity. */ final protected int lookupNS() throws NavExceptionHuge { if (context[0]==-1) throw new NavExceptionHuge("Can't lookup NS for document node"); int i = getTokenLength((context[0] != 0) ? context[context[0]] : rootIndex); long offset = getTokenOffset((context[0] != 0) ? context[context[0]] : rootIndex); int preLen = (i >> 16) & 0xffff; return lookupNS(offset, preLen); //return resolveNS(URL, offset, preLen); } /** * This function returns the VTD record index of the namespace * that matches the prefix of cursor element * @param URL * @return int * */ protected int lookupNS(long offset, int len){ long l; boolean hasNS = false; int size = vtdBuffer.size(); int type; // look for a match in the current hiearchy and return true for (int i = context[0]; i >= 0; i--) { int s = (i != 0) ? context[i] : rootIndex; { int k = s + 1; if (k>=size) break; type = getTokenType(k); while ( (type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS)) { if (type == TOKEN_ATTR_NS) { // Get the token length hasNS = true; int temp = getTokenLength(k); int preLen = ((temp >> 16) & 0xffff); int fullLen = temp & 0xffff; long os = getTokenOffset(k); // xmlns found if (temp == 5 && len == 0) { l = vtdBuffer.longAt(s); hasNS = false; /*vtdBuffer.modifyEntry( s, l | 0x00000000c0000000L);*/ return k+1; } else if ((fullLen - preLen - 1) == len) { // prefix length identical to local part of ns declaration boolean a = true; for (int j = 0; j < len; j++) { if (getCharUnit(os + preLen + 1 + j) != getCharUnit(offset + j)) { a = false; break; } } if (a == true) { //l = vtdBuffer.longAt(s); //hasNS = false; //vtdBuffer.modifyEntry( // s, // l | 0x00000000c0000000L); return k+1; } } } //return (URL != null) ? true : false; k += 2; if (k>=size) break; type = getTokenType(k); } /*l = vtdBuffer.longAt(s); if (hasNS) { hasNS = false; //vtdBuffer.modifyEntry(s, l | 0x00000000c0000000L); } else { //vtdBuffer.modifyEntry(s, l | 0x0000000080000000L); }*/ //break; } } return 0; //return -1; } private boolean resolveNS(String URL, long offset, int len) throws NavExceptionHuge { int result = lookupNS(offset, len); switch(result){ case 0: if (URL == null){ return true; } else { return false; } default: if (URL == null) return false; else { return matchTokenString(result, URL); } } } /** * A generic navigation method. * Move the current to the element according to the direction constants * If no such element, no position change and return false. * Creation date: (12/2/03 1:43:50 PM) * Legal direction constants are *<pre> ROOT 0 </pre> *<pre> PARENT 1 </pre> *<pre> FIRST_CHILD 2 </pre> *<pre> LAST_CHILD 3 </pre> *<pre> NEXT_SIBLING 4 </pre> *<pre> PREV_SIBLING 5 </pre> * @return boolean * @param direction int * @exception com.ximpleware.extended.NavExceptionHuge When direction value is illegal. */ public boolean toElement(int direction) throws NavExceptionHuge { int size; switch (direction) { case ROOT : // to document element! if (context[0] != 0) { /*for (int i = 1; i <= context[0]; i++) { context[i] = 0xffffffff; }*/ context[0] = 0; } atTerminal = false; l1index = l2index = l3index = -1; return true; case PARENT : if (atTerminal == true){ atTerminal = false; return true; } if (context[0] > 0) { //context[context[0]] = context[context[0] + 1] = 0xffffffff; context[context[0]] = -1; context[0]--; return true; }else if (context[0]==0){ context[0]=-1; //to be compatible with XPath Data model return true; } else { return false; } case FIRST_CHILD : case LAST_CHILD : if (atTerminal) return false; switch (context[0]) { case -1: context[0] = 0; return true; case 0 : if (l1Buffer.size() > 0) { context[0] = 1; l1index = (direction == FIRST_CHILD) ? 0 : (l1Buffer.size() - 1); context[1] = l1Buffer.upper32At(l1index); //(int) (vtdToken >> 32); return true; } else return false; case 1 : l2lower = l1Buffer.lower32At(l1index); if (l2lower == -1) { return false; } context[0] = 2; l2upper = l2Buffer.size() - 1; size = l1Buffer.size(); for (int i = l1index + 1; i < size; i++) { int temp = l1Buffer.lower32At(i); if (temp != 0xffffffff) { l2upper = temp - 1; break; } } //System.out.println(" l2 upper: " + l2upper + " l2 lower : " + l2lower); l2index = (direction == FIRST_CHILD) ? l2lower : l2upper; context[2] = l2Buffer.upper32At(l2index); return true; case 2 : l3lower = l2Buffer.lower32At(l2index); if (l3lower == -1) { return false; } context[0] = 3; l3upper = l3Buffer.size() - 1; size = l2Buffer.size(); for (int i = l2index + 1; i < size; i++) { int temp = l2Buffer.lower32At(i); if (temp != 0xffffffff) { l3upper = temp - 1; break; } } //System.out.println(" l3 upper : " + l3upper + " l3 lower : " + l3lower); l3index = (direction == FIRST_CHILD) ? l3lower : l3upper; context[3] = l3Buffer.intAt(l3index); return true; default : if (direction == FIRST_CHILD) { size = vtdBuffer.size(); int index = context[context[0]] + 1; while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 55); if (depth <= context[0]) { return false; } else if (depth == (context[0] + 1)) { context[0] += 1; context[context[0]] = index; return true; } } index++; } // what condition return false; } else { int index = context[context[0]] + 1; int last_index = -1; size = vtdBuffer.size(); while (index < size) { long temp = vtdBuffer.longAt(index); int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 55); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { if (depth <= context[0]) { break; } else if (depth == (context[0] + 1)) { last_index = index; } } index++; } if (last_index == -1) { return false; } else { context[0] += 1; context[context[0]] = last_index; return true; } } } case NEXT_SIBLING : case PREV_SIBLING : if(atTerminal)return false; switch (context[0]) { case -1: case 0 : return false; case 1 : if (direction == NEXT_SIBLING) { if (l1index + 1 >= l1Buffer.size()) { return false; } l1index++; // global incremental } else { if (l1index - 1 < 0) { return false; } l1index--; // global incremental } context[1] = l1Buffer.upper32At(l1index); return true; case 2 : if (direction == NEXT_SIBLING) { if (l2index + 1 > l2upper) { return false; } l2index++; } else { if (l2index - 1 < l2lower) { return false; } l2index--; } context[2] = l2Buffer.upper32At(l2index); return true; case 3 : if (direction == NEXT_SIBLING) { if (l3index + 1 > l3upper) { return false; } l3index++; } else { if (l3index - 1 < l3lower) { return false; } l3index--; } context[3] = l3Buffer.intAt(l3index); return true; default : //int index = context[context[0]] + 1; if (direction == NEXT_SIBLING) { int index = context[context[0]] + 1; size = vtdBuffer.size(); while (index < size) { long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 55); if (depth < context[0]) { return false; } else if (depth == (context[0])) { context[context[0]] = index; return true; } } index++; } return false; } else { int index = context[context[0]] - 1; while (index > context[context[0] - 1]) { // scan backforward long temp = vtdBuffer.longAt(index); int token_type = (int) ((MASK_TOKEN_TYPE & temp) >> 60) & 0xf; if (token_type == TOKEN_STARTING_TAG) { int depth = (int) ((MASK_TOKEN_DEPTH & temp) >> 55); /*if (depth < context[0]) { return false; } else */ if (depth == (context[0])) { context[context[0]] = index; return true; } } index--; } // what condition return false; } } default : throw new NavExceptionHuge("illegal navigation options"); } } /** * A generic navigation method. * Move the current to the element according to the direction constants and the element name * If no such element, no position change and return false. * "*" matches any element * Creation date: (12/2/03 1:43:50 PM) * Legal direction constants are <br> * <pre> ROOT 0 </pre> * <pre> PARENT 1 </pre> * <pre> FIRST_CHILD 2 </pre> * <pre> LAST_CHILD 3 </pre> * <pre> NEXT_SIBLING 4 </pre> * <pre> PREV_SIBLING 5 </pre> * <br> * for ROOT and PARENT, element name will be ignored. * @return boolean * @param direction int * @param en String * @exception com.ximpleware.extended.NavExceptionHuge When direction value is illegal. Or there are errors * in underlying byte representation of the document * @exception IllegalArguementException if en is null */ public boolean toElement(int direction, String en) throws NavExceptionHuge { //int size; int temp; int d; int val=0; if (en == null) throw new IllegalArgumentException(" Element name can't be null "); if (en.equals("*")) return toElement(direction); switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElement(en) == false) { if (toElement(NEXT_SIBLING, en) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElement(en) == false) { if (toElement(PREV_SIBLING, en) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal)return false; d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } temp = context[d]; // store the current position while (toElement(NEXT_SIBLING)) { if (matchElement(en)) { return true; } } switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; case PREV_SIBLING : if (atTerminal) return false; d = context[0]; switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } temp = context[d]; // store the current position while (toElement(PREV_SIBLING)) { if (matchElement(en)) { return true; } } switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; default : throw new NavExceptionHuge("illegal navigation options"); } } /** * A generic navigation method with namespace support. * Move the current to the element according to the direction constants and the prefix and local names * If no such element, no position change and return false. * URL * matches any namespace, including undefined namespaces * a null URL means hte namespace prefix is undefined for the element * ln * matches any localname * Creation date: (12/2/03 1:43:50 PM) * Legal direction constants are<br> * <pre> ROOT 0 </pre> * <pre> PARENT 1 </pre> * <pre> FIRST_CHILD 2 </pre> * <pre> LAST_CHILD 3 </pre> * <pre> NEXT_SIBLING 4 </pre> * <pre> PREV_SIBLING 5 </pre> * <br> * for ROOT and PARENT, element name will be ignored. * If not ns enabled, return false immediately with no position change. * @return boolean * @param direction int * @param URL String * @param ln String * @exception com.ximpleware.extended.NavExceptionHuge When direction value is illegal. Or there are errors * in underlying byte representation of the document */ public boolean toElementNS(int direction, String URL, String ln) throws NavExceptionHuge { //int size; int temp; int val=0; int d; // temp location if (ns == false) return false; switch (direction) { case ROOT : return toElement(ROOT); case PARENT : return toElement(PARENT); case FIRST_CHILD : if (atTerminal)return false; if (toElement(FIRST_CHILD) == false) return false; // check current element name if (matchElementNS(URL, ln) == false) { if (toElementNS(NEXT_SIBLING, URL, ln) == true) return true; else { //toParentElement(); //context[context[0]] = 0xffffffff; context[0]--; return false; } } else return true; case LAST_CHILD : if (atTerminal)return false; if (toElement(LAST_CHILD) == false) return false; if (matchElementNS(URL, ln) == false) { if (toElementNS(PREV_SIBLING, URL, ln) == true) return true; else { //context[context[0]] = 0xffffffff; context[0]--; //toParentElement(); return false; } } else return true; case NEXT_SIBLING : if (atTerminal)return false; d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } //if (d == 0) // return false; while (toElement(NEXT_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; case PREV_SIBLING : if (atTerminal)return false; d = context[0]; temp = context[d]; // store the current position switch(d) { case -1: case 0: return false; case 1: val = l1index; break; case 2: val = l2index; break; case 3: val = l3index; break; default: } //if (d == 0) // return false; while (toElement(PREV_SIBLING)) { if (matchElementNS(URL, ln)) { return true; } } switch(d) { case 1: l1index = val; break; case 2: l2index = val; break; case 3: l3index = val; break; default: } context[d] = temp; return false; default : throw new NavExceptionHuge("illegal navigation options"); } } /** * This method normalizes a token into a string in a way that resembles DOM. * The leading and trailing white space characters will be stripped. * The entity and character references will be resolved * Multiple whitespaces char will be collapsed into one. * Whitespaces via entities will nonetheless be preserved. * Creation date: (12/8/03 1:57:10 PM) * @return java.lang.String * @param index int * @exception NavExceptionHuge When the encoding has errors */ public String toNormalizedString(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); long l; int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); if (len == 0) return ""; long offset = getTokenOffset(index); long endOffset = len + offset - 1; // point to the last character StringBuffer sb = new StringBuffer(len); int ch; // trim off the leading whitespaces while (true) { long temp = offset; l = getChar(offset); ch = (int)l; offset += (int)(l>>32); if (!isWS(ch)) { offset = temp; break; } } boolean d = false; while (offset <= endOffset) { l = getCharResolved(offset); ch = (int)l; offset += (int)(l>>32); if (isWS(ch) && getCharUnit(offset - 1) != ';') { d = true; } else { if (d == false) sb.append((char) ch); // java only supports 16 bit unicode else { sb.append(' '); sb.append((char) ch); d = false; } } } return sb.toString(); } /** * Convert a token at the given index to a String, (built-in entity and char references not resolved) * (entities and char references not expanded). * Creation date: (11/16/03 7:28:49 PM) * @return java.lang.String * @param index int * @exception NavExceptionHuge When the encoding has errors */ public String toRawString(int index) throws NavExceptionHuge { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); return toRawString(offset, len); } protected String toRawString(long os, int len) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); sb.append((char)l); } return sb.toString(); } /* @param index * @return * @throws NavException */ final public String toRawStringLowerCase(int index) throws NavExceptionHuge { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); return toRawStringLowerCase(offset, len); } /** * * @param index * @return * @throws NavException */ final public String toRawStringUpperCase(int index) throws NavExceptionHuge { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); return toRawStringUpperCase(offset, len); } final protected String toRawStringLowerCase(long os, int len) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } return sb.toString(); } final protected String toRawStringUpperCase(long os, int len) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } return sb.toString(); } /** * Convert a token at the given index to a String, (entities and char references resolved). * An attribute name or an element name will get the UCS2 string of qualified name * Creation date: (11/16/03 7:27:19 PM) * @return java.lang.String * @param index * @exception NavExceptionHuge */ public String toString(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); int len; //long l; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); return toString(offset, len); } protected String toString(long os, int len) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); sb.append((char)l); } return sb.toString(); } /** * This method matches two VTD tokens of VTDNav objects * @param i1 * @param vn2 * @param i2 * @return boolean true if two tokens are lexically identical * */ final public boolean matchTokens(int i1, VTDNavHuge vn2, int i2) throws NavExceptionHuge{ return compareTokens(i1,vn2,i2)==0; } /** * Set the value of atTerminal * This function only gets called in XPath eval * when a step calls for @* or child::text() * @param b */ final protected void setAtTerminal(boolean b){ atTerminal = b; } /** * Get the value of atTerminal * This function only gets called in XPath eval * @return boolean */ final protected boolean getAtTerminal(){ return atTerminal; } /** * This is for debugging purpose * @param fib */ public void sampleState(FastIntBuffer fib){ // for(int i=0;i<context.) // context[i] = -1; // fib.append(context); if (context[0]>=1) fib.append(l1index); if (context[0]>=2){ fib.append(l2index); fib.append(l2lower); fib.append(l2upper); } if (context[0]>=3){ fib.append(l3index); fib.append(l3lower); fib.append(l3upper); } } final public int getStringLength(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type != TOKEN_CHARACTER_DATA && type != TOKEN_ATTR_VAL) return getRawStringLength(index); int len = 0, len1 = 0; len = getTokenLength(index); long offset = getTokenOffset(index); long endOffset = offset + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int) (l >> 32); len1++; } return len1; } final public int getRawStringLength(int index) throws NavExceptionHuge { int type = getTokenType(index); int len = 0, len1 = 0; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); long endOffset = offset + len; long l; while (offset < endOffset) { l = getChar(offset); offset += (int) (l >> 32); len1++; } return len1; } /** * This method compares two VTD tokens of VTDNav * objects The behavior of this method is like compare the strings * corresponds to i1 and i2, meaning for text or attribute val, entities * will be converted into the corresponding char * * @param i1 * @param vn2 * @param i2 * @return -1,0, or 1 * @throws NavExceptionHuge * */ public int compareTokens(int i1, VTDNavHuge vn2, int i2) throws NavExceptionHuge{ int t1, t2; int ch1, ch2; long endOffset1, endOffset2; long l; if ( i1 ==i2 && this == vn2) return 0; t1 = this.getTokenType(i1); t2 = vn2.getTokenType(i2); long offset1 = this.getTokenOffset(i1); long offset2 = vn2.getTokenOffset(i2); int len1 = (t1 == TOKEN_STARTING_TAG || t1 == TOKEN_ATTR_NAME || t1 == TOKEN_ATTR_NS) ? getTokenLength(i1) & 0xffff : getTokenLength(i1); int len2 = (t2 == TOKEN_STARTING_TAG || t2 == TOKEN_ATTR_NAME || t2 == TOKEN_ATTR_NS) ? vn2.getTokenLength(i2) & 0xffff : vn2.getTokenLength(i2); endOffset1 = len1+offset1; endOffset2 = len2+ offset2; for(;offset1<endOffset1&& offset2< endOffset2;){ if(t1 == VTDNavHuge.TOKEN_CHARACTER_DATA || t1== VTDNavHuge.TOKEN_ATTR_VAL){ l = this.getCharResolved(offset1); } else { l = this.getChar(offset1); } ch1 = (int)l; offset1 += (int)(l>>32); if(t2 == VTDNavHuge.TOKEN_CHARACTER_DATA || t2== VTDNavHuge.TOKEN_ATTR_VAL){ l = vn2.getCharResolved(offset2); } else { l = vn2.getChar(offset2); } ch2 = (int)l; offset2 += (int)(l>>32); if (ch1 > ch2) return 1; if (ch1 < ch2) return -1; } if (offset1 == endOffset1 && offset2 < endOffset2) return -1; else if (offset1 < endOffset1 && offset2 == endOffset2) return 1; else return 0; } /** * Test the start of token content at index i matches the content * of s, notice that this is to save the string allocation cost of * using String's built-in startsWidth * @param index * @param s * @return * @throws NavExceptionHuge */ final public boolean startsWith(int index, String s) throws NavExceptionHuge{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); long offset = getTokenOffset(index); long l1; int i,l; long endOffset = offset + len; boolean b = (type == TOKEN_CHARACTER_DATA || type == TOKEN_ATTR_VAL); // System.out.print("currentOffset :" + currentOffset); l = s.length(); if (l> len) return false; //System.out.println(s); for (i = 0; i < l && offset < endOffset; i++) { if (b) l1 = getCharResolved(offset); else l1 = getChar(offset); int i1 = s.charAt(i); if (i1 != (int) l1) return false; offset += (int) (l1 >> 32); } return true; } /** * Test the end of token content at index i matches the content * of s, notice that this is to save the string allocation cost of * using String's built-in endsWidth * @param i * @return */ final public boolean endsWith(int index, String s) throws NavExceptionHuge{ int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); long offset = getTokenOffset(index); long l1; int i,l,i2; boolean b = (type == TOKEN_CHARACTER_DATA || type == TOKEN_ATTR_VAL); //int endOffset = offset + len; // System.out.print("currentOffset :" + currentOffset); l = s.length(); i2 = getStringLength(index); if (l> len || l> i2) return false; i2 = i2 - l; // calculate the # of chars to be skipped // eat away first several chars for (i = 0; i < i2; i++) { if (b) l1 = getCharResolved(offset); else l1 = getChar(offset); offset += (int) (l1 >> 32); } //System.out.println(s); for (i = 0; i < l; i++) { if (b) l1 = getCharResolved(offset); else l1 = getChar(offset); int i1 = s.charAt(i); if (i1 != (int) l1) return false; offset += (int) (l1 >> 32); } return true; } /** * Convert a token at the given index to a String and any upper case * character will be converted to lower case, (entities and char * references resolved). An attribute name or an element name will get the * UCS2 string of qualified name * @param index * @return * @throws NavExceptionHuge */ public String toStringLowerCase(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringLowerCase(index); int len; len = getTokenLength(index); long offset = getTokenOffset(index); return toStringLowerCase(offset, len); } /** * Convert the byte content segment (in terms of offset and length) to * String, upper case characters are converted to lower case * * @param os * the offset of the segment * @param len * the length of the segment * @return the corresponding string value * @throws NavExceptionHuge * */ final protected String toStringLowerCase(long os, int len) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>64 && (int)l<91) sb.append((char)(l+32)); else sb.append((char)l); } return sb.toString(); } /** * Convert a token at the given index to a String and any lower case * character will be converted to upper case, (entities and char * references resolved). An attribute name or an element name will get the * UCS2 string of qualified name * @param index * @return * @throws NavExceptionHuge */ public String toStringUpperCase(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringUpperCase(index); int len; len = getTokenLength(index); long offset = getTokenOffset(index); return toStringUpperCase(offset, len); } /** * Convert the byte content segment (in terms of offset and length) to * String, lower case characters are converted to upper case * * @param os * the offset of the segment * @param len * the length of the segment * @return the corresponding string value * @throws NavExceptionHuge * */ final protected String toStringUpperCase(long os, int len ) throws NavExceptionHuge{ StringBuffer sb = new StringBuffer(len); long offset = os; long endOffset = os + len; long l; while (offset < endOffset) { l = getCharResolved(offset); offset += (int)(l>>32); if ((int)l>96 && (int)l<123) sb.append((char)(l-32)); else sb.append((char)l); } return sb.toString(); } /** * Return the offset (64-bit) and length (64-bit) of an element * fragment * @return a long[2], result[0]=offset, result[1]=length * @throws NavExceptionHuge */ public long[] getElementFragment() throws NavExceptionHuge { // a little scanning is needed // has next sibling case // if not long[] result = new long[2]; int depth = getCurrentDepth(); // document length and offset returned if depth == -1 if (depth == -1){ int i=vtdBuffer.lower32At(0); if (i==0){ result[0] = docOffset; result[1] = docLen; //return ((long)docLen)<<32| docOffset; } else { result[0] = 32; result[1] = docLen-32; //return ((long)(docLen-32))| 32; } return result; } long so = getTokenOffset(getCurrentIndex2()) - 1; long length = 0; // for an element with next sibling if (toElement(NEXT_SIBLING)) { int temp = getCurrentIndex(); // rewind while (getTokenDepth(temp) < depth) { temp--; } //temp++; long so2 = getTokenOffset(temp) - 1; // look for the first '>' while (getCharUnit(so2) != '>') { so2--; } length = so2 - so + 1; toElement(PREV_SIBLING); if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else { result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } // for root element if (depth == 0) { int temp = vtdBuffer.size() - 1; boolean b = false; long so2 = 0; while (getTokenDepth(temp) == -1) { temp--; // backward scan b = true; } if (b == false) so2 = (encoding <= FORMAT_WIN_1258 ) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; else so2 = getTokenOffset(temp + 1); while (getCharUnit(so2) != '>') { so2--; } length = so2 - so + 1; if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else{ result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } // for a non-root element with no next sibling int temp = getCurrentIndex() + 1; int size = vtdBuffer.size(); // temp is not the last entry in VTD buffer if (temp < size) { while (temp < size && getTokenDepth(temp) >= depth) { temp++; } if (temp != size) { int d = depth - getTokenDepth(temp) + ((getTokenType(temp) == TOKEN_STARTING_TAG) ? 1 : 0); long so2 = getTokenOffset(temp) - 1; int i = 0; // scan backward while (i < d) { if (getCharUnit(so2) == '>') i++; so2--; } length = so2 - so + 2; if (encoding <= FORMAT_WIN_1258){ result[0]=so; result[1]=length; //return ((long) length) << 32 | so; } else{ result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } /* * int so2 = getTokenOffset(temp - 1) - 1; int d = depth - * getTokenDepth(temp - 1); int i = 0; while (i < d) { if * (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + * 2; if (encoding < 3) return ((long) length) < < 32 | so; else * return ((long) length) < < 33 | (so < < 1); */ } // temp is the last entry // scan forward search for /> or </cc> long so2 = (encoding <= FORMAT_WIN_1258) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; int d; d = depth + 1; int i = 0; while (i < d) { if (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + 2; if (encoding <= FORMAT_WIN_1258){ result[0]=so; result[1]=length; //return ((long) length) << 32 | so; } else{ result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } /** * Get content fragment returns a long[2] encoding the offset and length of the byte segment of * the content of current element, which is the byte segment between the starting tag and * ending tag, null is returned if the current element is an empty element * * @return long[2] whose upper 64 bite is length, lower 64 bit is offset */ public long[] getContentFragment() throws NavExceptionHuge{ // a little scanning is needed // has next sibling case // if not long[] result = new long[2]; int depth = getCurrentDepth(); // document length and offset returned if depth == -1 if (depth == -1){ int i=vtdBuffer.lower32At(0); if (i==0){ result[0]= docOffset; result[1]= docLen; //return ((long)docLen)<<32| docOffset; } else{ result[0]= 32; result[1]= docLen-32; //return ((long)(docLen-32))| 32; } return result; } long so = getOffsetAfterHead(); if (so==-1) return null; long length = 0; // for an element with next sibling if (toElement(NEXT_SIBLING)) { int temp = getCurrentIndex(); // rewind while (getTokenDepth(temp) < depth) { temp--; } //temp++; long so2 = getTokenOffset(temp) - 1; // look for the first '>' while (getCharUnit(so2) != '>') { so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; toElement(PREV_SIBLING); if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else{ result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } // for root element if (depth == 0) { int temp = vtdBuffer.size() - 1; boolean b = false; long so2 = 0; while (getTokenDepth(temp) == -1) { temp--; // backward scan b = true; } if (b == false) so2 = (encoding <= FORMAT_WIN_1258 ) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; else so2 = getTokenOffset(temp + 1); while (getCharUnit(so2) != '>') { so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else { result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } // for a non-root element with no next sibling int temp = getCurrentIndex() + 1; int size = vtdBuffer.size(); // temp is not the last entry in VTD buffer if (temp < size) { while (temp < size && getTokenDepth(temp) >= depth) { temp++; } if (temp != size) { int d = depth - getTokenDepth(temp) + ((getTokenType(temp) == TOKEN_STARTING_TAG) ? 1 : 0); long so2 = getTokenOffset(temp) - 1; int i = 0; // scan backward while (i < d) { if (getCharUnit(so2) == '>') i++; so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else{ result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } /* * int so2 = getTokenOffset(temp - 1) - 1; int d = depth - * getTokenDepth(temp - 1); int i = 0; while (i < d) { if * (getCharUnit(so2) == '>') { i++; } so2--; } length = so2 - so + * 2; if (encoding < 3) return ((long) length) < < 32 | so; else * return ((long) length) < < 33 | (so < < 1); */ } // temp is the last entry // scan forward search for /> or </cc> long so2 = (encoding <= FORMAT_WIN_1258) ? (docOffset + docLen - 1) : ((docOffset + docLen) >> 1) - 1; int d; d = depth + 1; int i = 0; while (i < d) { if (getCharUnit(so2) == '>') { i++; } so2--; } while (getCharUnit(so2) != '/') { so2--; } while (getCharUnit(so2) != '<') { so2--; } length = so2 - so; if (encoding <= FORMAT_WIN_1258){ result[0]= so; result[1]= length; //return ((long) length) << 32 | so; } else { result[0]=so<<1; result[1]=length<<1; //return ((long) length) << 33 | (so << 1); } return result; } public ElementFragmentNsHuge getElementFragmentNs() throws NavExceptionHuge{ if (this.ns == false) throw new NavExceptionHuge("getElementFragmentNS can only be called when parsing is ns enabled"); FastIntBuffer fib = new FastIntBuffer(3); // init size 8 //fill the fib with integer // first get the list of name space nodes int[] ia = context; int d =ia[0]; // -1 for document node, 0 for root element; int c = getCurrentIndex2(); int len = (c == 0 || c == rootIndex )? 0: (getTokenLength(c) & 0xffff); // get the length of qualified node // put the neighboring ATTR_NS nodes into the array // and record the total # of them int i = 0; int count=0; if (d > 0){ // depth > 0 every node except document and root element int k=getCurrentIndex2()+1; if (k<this.vtdSize){ while(k<this.vtdSize){ int type = this.getTokenType(k); if (type==VTDNavHuge.TOKEN_ATTR_NAME || type==VTDNavHuge.TOKEN_ATTR_NS) if (type == VTDNavHuge.TOKEN_ATTR_NS){ fib.append(k); //System.out.println(" ns name ==>" + toString(k)); } k+=2; //type = this.getTokenType(k); } } count = fib.size(); d--; while (d >= 0) { // then search for ns node in the vinicity of the ancestor nodes if (d > 0) { // starting point k = ia[d]+1; } else { // starting point k = this.rootIndex+1; } if (k<this.vtdSize){ while (k < this.vtdSize) { int type = this.getTokenType(k); if (type == VTDNavHuge.TOKEN_ATTR_NAME || type == VTDNavHuge.TOKEN_ATTR_NS) { boolean unique = true; if (type == VTDNavHuge.TOKEN_ATTR_NS) { for (int z = 0; z < fib.size(); z++) { //System.out.println("fib size ==> // "+fib.size()); //if (fib.size()==4); if (matchTokens(fib.intAt(z), this, k)) { unique = false; break; } } if (unique) fib.append(k); } } k += 2; // type = this.getTokenType(k); } } d--; } // System.out.println("count ===> "+count); // then restore the name space node by shifting the array int newSz= fib.size()-count; for (i= 0; i<newSz; i++ ){ fib.modifyEntry(i,fib.intAt(i+count)); } fib.resize(newSz); } long[] l = getElementFragment(); //return new ElementFragmentNsHuge(this,l,fib,(long)len); return new ElementFragmentNsHuge(this, l, fib, len); } /** * Duplicate the VTDNavHuge instance with shared XML, VTD and LC buffers * This method may be useful for parallel XPath evaluation * The node Position is at root element * @return a VTDNavHuge instance * */ final public VTDNavHuge duplicateNav(){ return new VTDNavHuge(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen ); } /** * Clone the VTDNav instance to get with shared XML, VTD and LC buffers * The node position is also copied from the original instance * @return */ final public VTDNavHuge cloneNav(){ VTDNavHuge vn = new VTDNavHuge(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen ); vn.atTerminal = this.atTerminal; vn.LN = this.LN; if (this.context[0]!=-1) System.arraycopy(this.context, 0, vn.context, 0, this.context[0] ); else vn.context[0]=-1; vn.l1index = l1index; if (getCurrentDepth()>1){ vn.l2index = this.l2index; vn.l2upper = l2upper; vn.l2lower = l2lower; } if (getCurrentDepth() > 2) { vn.l3lower = l3lower; vn.l3index = l3index; vn.l3upper = l3upper; } return vn; } /** * Return the byte offset and length of up to i sibling fragments. If * there is a i+1 sibling element, the cursor element would * move to it; otherwise, there is no cursor movement. If the cursor isn't * positioned at an element (due to XPath evaluation), then -1 will be * returned * @param i number of silbing elements including the cursor element * @return a long[2] encoding byte offset (lower 64 bits), length ( * upper 64 bits) of those fragments * @throws NavExceptionHuge */ public long[] getSiblingElementFragments(int i) throws NavExceptionHuge{ if (i<=0) throw new IllegalArgumentException(" # of sibling can be less or equal to 0"); // get starting char offset if(atTerminal==true) return null; // so is the char offset long so = getTokenOffset(getCurrentIndex())-1; // char offset to byte offset conversion if (encoding>=FORMAT_UTF_16BE) so = so<<1; BookMarkHuge bmh = new BookMarkHuge(this); bmh.recordCursorPosition(); while(i>1 && toElement(VTDNav.NEXT_SIBLING)){ i--; } long[] l= getElementFragment(); long len = l[0]+l[1]-so; if (i==1 && toElement(VTDNav.NEXT_SIBLING)){ }else bmh.setCursorPosition(); l[0] = so; l[1]=len; return l; } }
128,649
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
BinaryExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/BinaryExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; import com.ximpleware.extended.xpath.Expr; /** * The parser.java uses this class to contruct the corresponding * AST for XPath expression when there are two operands and one * operator * */ public class BinaryExpr extends Expr { public final static int ADD = 0; public final static int SUB = 1; public final static int MULT = 2; public final static int DIV = 3; public final static int MOD = 4; public final static int OR = 5; public final static int AND = 6; public final static int EQ = 7; public final static int NE = 8; public final static int LE = 9; public final static int GE = 10; public final static int LT = 11; public final static int GT = 12; //public final static int UNION = 13; public final static int BUF_SZ_EXP = 7; protected int op; boolean isNumerical; boolean isBoolean; protected Expr left; protected Expr right; protected FastIntBuffer fib1; /** * constructor * @param l * @param o * @param r */ public BinaryExpr ( Expr l, int o, Expr r) { op = o; left = l; right = r; fib1 = null; switch(op){ case ADD: case SUB: case MULT: case DIV: case MOD: isNumerical = true; isBoolean = false; break; case OR : case AND: case EQ: case NE: case LE: case GE: case LT: case GT: isNumerical = false; isBoolean = true; default: } } public String toString(){ String os; switch(op){ case ADD: os = " + "; break; case SUB: os = " - "; break; case MULT: os = " * "; break; case DIV: os = " / "; break; case MOD: os = " mod "; break; case OR : os = " or ";break; case AND: os = " and "; break; case EQ: os = " = "; break; case NE: os = " != "; break; case LE: os = " <= "; break; case GE: os = " >= "; break; case LT: os = " < "; break; default: os = " > "; break; } return "("+ left + os + right+")"; } public boolean evalBoolean(VTDNavHuge vn){ /*int i,i1=0, s1, s2; int stackSize; Expr e1, e2; int t; boolean b = false;*/ switch(op){ case OR: return left.evalBoolean(vn) || right.evalBoolean(vn); case AND:return left.evalBoolean(vn) && right.evalBoolean(vn); case EQ: case NE: case LE: case GE: case LT: case GT: return computeComp(op,vn); default: double dval = evalNumber(vn); if (dval ==-0.0 || dval ==+0.0 || Double.isNaN(dval)) return false; return true; } } public double evalNumber(VTDNavHuge vn){ switch(op){ case ADD: return left.evalNumber(vn) + right.evalNumber(vn); case SUB: return left.evalNumber(vn) - right.evalNumber(vn); case MULT:return left.evalNumber(vn) * right.evalNumber(vn); case DIV: return left.evalNumber(vn) / right.evalNumber(vn); case MOD: return left.evalNumber(vn) % right.evalNumber(vn); default : if (evalBoolean(vn) == true) return 1; return 0; } } public int evalNodeSet(VTDNavHuge vn) throws XPathEvalExceptionHuge { throw new XPathEvalExceptionHuge("BinaryExpr can't eval to a node set!"); } public String evalString(VTDNavHuge vn){ if(isNumerical()){ double d = evalNumber(vn); if (d==(long)d){ return ""+(long)d; } else return ""+d; } else { boolean b = evalBoolean(vn); if (b) return "true"; else return "false"; } } public void reset(VTDNavHuge vn){left.reset(vn); right.reset(vn);}; public boolean isNodeSet(){ return false; } public boolean isNumerical(){ return isNumerical; } public boolean isString(){ return false; } public boolean isBoolean(){ return isBoolean; } // to support computation of context size // needs to add // public boolean needContextSize(); // public boolean SetContextSize(int contextSize); //If both objects to be compared are node-sets, then //the comparison will be true if and only if there is //a node in the first node-set and a node in the second //node-set such that the result of performing the comparison //on the string-values of the two nodes is true. If one //object to be compared is a node-set and the other is a //number, then the comparison will be true if and only if //there is a node in the node-set such that the result of //performing the comparison on the number to be compared and on //the result of converting the string-value of that node to a //number using the number function is true. If one object to be //compared is a node-set and the other is a string, then the //comparison will be true if and only if there is a node in //the node-set such that the result of performing the comparison //on the string-value of the node and the other string is true. //If one object to be compared is a node-set and the other is a boolean, //then the comparison will be true if and only if the result of //performing the comparison on the boolean and on the result of //converting the node-set to a boolean using the boolean function is true. //When neither object to be compared is a node-set and the operator //is = or !=, then the objects are compared by converting them to a //common type as follows and then comparing them. If at least one object //to be compared is a boolean, then each object to be compared is //converted to a boolean as if by applying the boolean function. //Otherwise, if at least one object to be compared is a number, then //each object to be compared is converted to a number as if by applying //the number function. Otherwise, both objects to be compared are //converted to strings as if by applying the string function. The = //comparison will be true if and only if the objects are equal; the //!= comparison will be true if and only if the objects are not equal. //Numbers are compared for equality according to IEEE 754 [IEEE 754]. Two //booleans are equal if either both are true or both are false. Two strings //are equal if and only if they consist of the same sequence of UCS characters. private boolean computeComp(int op, VTDNavHuge vn){ //int i, t, i1 = 0, stackSize, s1, s2; String st1, st2; if (left.isNodeSet() && right.isNodeSet()) { return compNodeSetNodeSet(left, right, vn, op); } else { if (left.isNumerical() && right.isNodeSet()){ return compNumericalNodeSet(left, right, vn, op); } if (left.isNodeSet() && right.isNumerical()) { return compNodeSetNumerical(left, right, vn, op); } if (left.isString() && right.isNodeSet()){ return compStringNodeSet(left, right, vn, op); } if (left.isNodeSet() && right.isString()) { return compNodeSetString(left, right, vn, op); } } if (op==EQ || op==NE){ if (left.isBoolean() || right.isBoolean()) { if (op == EQ) return left.evalBoolean(vn) == right.evalBoolean(vn); else return left.evalBoolean(vn) != right.evalBoolean(vn); } if (left.isNumerical() || right.isNumerical()) { if (op == EQ) return left.evalNumber(vn) == right.evalNumber(vn); else return left.evalNumber(vn) != right.evalNumber(vn); } st1 = left.evalString(vn); st2 = right.evalString(vn); /*if (st1 == null || st2 == null) if (op == EQ) return false; else return true;*/ return (op == EQ) ? (st1.equals(st2)) : (!st1.equals(st2)); } return compNumbers(left.evalNumber(vn),right.evalNumber(vn),op); } public boolean requireContextSize(){ return left.requireContextSize() || right.requireContextSize(); } public void setContextSize(int size){ left.setContextSize(size); right.setContextSize(size); } public void setPosition(int pos){ left.setPosition(pos); right.setPosition(pos); } // this function computes the case where one expr is a node set, the other is a string private boolean compNodeSetString(Expr left, Expr right, VTDNavHuge vn,int op){ int i, i1 = 0, stackSize; String s; try { s = right.evalString(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); // if (i1==-1 && s.length()==0) //return true; if (i1 != -1) { boolean b = compareVString1(i1,vn,s,op); if (b){ left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return b; } } } vn.contextStack2.size = stackSize; vn.pop2(); left.reset(vn); return false; //compareEmptyNodeSet(op, s); } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } private boolean compareEmptyNodeSet(int op, String s){ if (op == NE ){ if (s.length()==0) { return false; } else return true; }else{ if (s.length()==0) { return true; } else return false; } } private boolean compStringNodeSet(Expr left, Expr right, VTDNavHuge vn,int op){ int i, i1 = 0, stackSize; String s; try { s = left.evalString(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1){ boolean b = compareVString2(i1,vn,s,op); if (b){ right.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return b; } } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return false;//compareEmptyNodeSet(op, s); } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } private boolean compNumbers(double d1, double d2, int op) { switch (op) { case LE: return d1 <= d2; case GE: return d1 >= d2; case LT: return d1 < d2; case GT: return d1 > d2; } return false; } // this function computes the boolean when one expression is node set // the other is numerical private boolean compNumericalNodeSet(Expr left, Expr right, VTDNavHuge vn, int op ){ int i, i1 = 0, stackSize; double d; try { d = left.evalNumber(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1!=-1 && compareVNumber1(i1,vn,d,op)){ right.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return true; } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return false; } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } private boolean compNodeSetNumerical(Expr left, Expr right, VTDNavHuge vn, int op ){ int i,i1 = 0, stackSize; double d; try { d = right.evalNumber(vn); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1!=-1 && compareVNumber2(i1,vn,d,op)){ left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); return true; } } vn.contextStack2.size = stackSize; vn.pop2(); left.reset(vn); return false; } catch (Exception e) { throw new RuntimeException("Undefined behavior"); } } private int getStringVal(VTDNavHuge vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNavHuge.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNavHuge.TOKEN_ATTR_NAME || t == VTDNavHuge.TOKEN_ATTR_NS) return i+1; else return i; } private boolean compareVNumber1(int k, VTDNavHuge vn, double d, int op) throws NavExceptionHuge { double d1 = vn.parseDouble(k); switch (op){ case EQ: return d == d1; case NE: return d != d1; case GE: return d >= d1; case LE: return d <= d1; case GT: return d > d1; default: return d < d1; } } private boolean compareVString1(int k, VTDNavHuge vn, String s, int op) throws NavExceptionHuge { int i = vn.compareTokenString(k, s); switch (i) { case -1: if (op == NE || op == LT || op == LE) { return true; } break; case 0: if (op == EQ || op == LE || op == GE) { return true; } break; case 1: if (op == NE || op == GE || op == GT) { return true; } } return false; } private boolean compareVString2(int k, VTDNavHuge vn, String s, int op) throws NavExceptionHuge { int i = vn.compareTokenString(k, s); switch(i){ case -1: if (op== NE || op == GT || op == GE){ return true; } break; case 0: if (op==EQ || op == LE || op == GE ){ return true; } break; case 1: if (op == NE || op==LE || op == LT ){ return true; } } return false; } private boolean compareVNumber2(int k, VTDNavHuge vn, double d, int op) throws NavExceptionHuge { double d1 = vn.parseDouble(k); switch (op){ case EQ: return d1 == d; case NE: return d1 != d; case GE: return d1 >= d; case LE: return d1 <= d; case GT: return d1 > d; default: return d1 < d; } } private boolean compareVV(int k, VTDNavHuge vn, int j,int op) throws NavExceptionHuge { int i = vn.compareTokens(k, vn, j); switch(i){ case 1: if (op == NE || op==GE || op == GT ){ return true; } break; case 0: if (op==EQ || op == LE || op == GE ){ return true; } break; case -1: if (op== NE || op == LT || op == LE){ return true; } } return false; } // this method compare node set with another node set private boolean compNodeSetNodeSet(Expr left, Expr right, VTDNavHuge vn, int op){ int i,i1,stackSize,s1; try { if (fib1 == null) fib1 = new FastIntBuffer(BUF_SZ_EXP); vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1) fib1.append(i1); } left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn,i); if (i1 != -1){ s1 = fib1.size(); for (int k = 0; k < s1; k++) { boolean b = compareVV(fib1.intAt(k),vn,i1,op); if (b){ fib1.clear(); vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return true; } } } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); fib1.clear(); return false; } catch (Exception e) { fib1.clear(); throw new RuntimeException("Undefined behavior"); } } public int adjust(int n){ int i = left.adjust(n); int j = right.adjust(n); if (i>j)return i; else return j; } }
18,620
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
FuncExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/FuncExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; //import com.ximpleware.VTDNav; import com.ximpleware.extended.xpath.Alist; import com.ximpleware.extended.xpath.Expr; import com.ximpleware.extended.xpath.FuncName; import com.ximpleware.extended.xpath.UnsupportedException; /** * FuncExpr implements the function expression defined * in XPath spec * */ public class FuncExpr extends Expr{ public Alist argumentList; public int opCode; boolean isNumerical; boolean isBoolean; boolean isString; int contextSize; //double d; int position; int a; int argCount(){ Alist temp = argumentList; int count = 0; while(temp!=null){ count++; temp = temp.next; } return count; } public FuncExpr(int oc , Alist list){ a = 0; opCode = oc; argumentList = list; isBoolean = false; isString = false; position = 0; //isNodeSet = false; isNumerical = false; switch(opCode){ case FuncName.LAST: isNumerical = true;break; case FuncName.POSITION: isNumerical = true;break; case FuncName.COUNT: isNumerical = true;break; case FuncName.LOCAL_NAME: isString = true; break; case FuncName.NAMESPACE_URI: isString = true; break; case FuncName.NAME: isString = true; break; case FuncName.STRING: isString = true; break; case FuncName.CONCAT: isString = true; break; case FuncName.STARTS_WITH: isBoolean= true;break; case FuncName.CONTAINS: isBoolean= true;break; case FuncName.SUBSTRING_BEFORE: isString = true; break; case FuncName.SUBSTRING_AFTER: isString = true; break; case FuncName.SUBSTRING: isString = true; break; case FuncName.STRING_LENGTH: isNumerical = true;break; case FuncName.NORMALIZE_SPACE: isString = true; break; case FuncName.TRANSLATE: isString = true;break; case FuncName.BOOLEAN: isBoolean =true;break; case FuncName.NOT: isBoolean =true;break; case FuncName.TRUE: isBoolean = true;break; case FuncName.FALSE: isBoolean = true;break; case FuncName.LANG: isBoolean = true;break; case FuncName.NUMBER: isNumerical = true;break; case FuncName.SUM: isNumerical = true;break; case FuncName.FLOOR: isNumerical = true;break; case FuncName.CEILING: isNumerical = true;break; case FuncName.ROUND: isNumerical = true;break; case FuncName.ABS: isNumerical = true;break; case FuncName.ROUND_HALF_TO_EVEN : isNumerical = true;break; case FuncName.ROUND_HALF_TO_ODD: isNumerical = true;break; case FuncName.CODE_POINTS_TO_STRING: isString = true; break; case FuncName.COMPARE: isBoolean= true;break; case FuncName.UPPER_CASE: isString = true; break; case FuncName.LOWER_CASE: isString = true; break; case FuncName.ENDS_WITH: isBoolean= true;break; case FuncName.QNAME: isString = true; break; case FuncName.LOCAL_NAME_FROM_QNAME: isString = true; break; case FuncName.NAMESPACE_URI_FROM_QNAME: isString = true; break; case FuncName.NAMESPACE_URI_FOR_PREFIX: isString = true; break; case FuncName.RESOLVE_QNAME: isString = true; break; case FuncName.IRI_TO_URI: isString = true; break; case FuncName.ESCAPE_HTML_URI: isString = true; break; default: isString = true; break; } } public String toString(){ if (argumentList == null) return fname()+" ("+")"; return fname()+" ("+argumentList +")"; } private String getLocalName(VTDNavHuge vn){ if (argCount()== 0){ try{ int index = vn.getCurrentIndex(); int type = vn.getTokenType(index); if (vn.ns && (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME)) { long offset = vn.getTokenOffset(index); int length = vn.getTokenLength(index); if (length < 0x10000) return vn.toRawString(index); else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0) return vn.toRawString(offset + preLen+1, QLen - preLen - 1); else { return vn.toRawString(offset, QLen); } } } else return ""; }catch(NavExceptionHuge e){ return ""; // this will almost never occur } } else if (argCount() == 1){ int a = -1; vn.push2(); try{ a = argumentList.e.evalNodeSet(vn); argumentList.e.reset(vn); vn.pop2(); }catch(Exception e){ argumentList.e.reset(vn); vn.pop2(); } if (a == -1 || vn.ns == false) return ""; int type = vn.getTokenType(a); if (type!=VTDNavHuge.TOKEN_STARTING_TAG && type!= VTDNavHuge.TOKEN_ATTR_NAME) return ""; try { long offset = vn.getTokenOffset(a); int length = vn.getTokenLength(a); if (length < 0x10000) return vn.toRawString(a); else { int preLen = length >> 16; int QLen = length & 0xffff; if (preLen != 0) return vn.toRawString(offset + preLen+1, QLen - preLen - 1); else { return vn.toRawString(offset, QLen); } } } catch (NavExceptionHuge e) { return ""; // this will almost never occur } } else throw new IllegalArgumentException ("local-name()'s argument count is invalid"); } private String getNameSpaceURI(VTDNavHuge vn){ if (argCount()==0){ try{ int i = vn.getCurrentIndex(); int type = vn.getTokenType(i); if (vn.ns && (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME)) { int a = vn.lookupNS(); if (a == 0) return ""; else return vn.toString(a); } return ""; }catch (Exception e){ return ""; } }else if (argCount()==1){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } String s=""; // return a; try { if (a == -1 || vn.ns == false) ; else { int type = vn.getTokenType(a); if (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME) s= vn.toString(vn.lookupNS()); } } catch (Exception e){} ; vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return s; }else throw new IllegalArgumentException ("namespace-uri()'s argument count is invalid"); } private String getName(VTDNavHuge vn){ int a; if (argCount()==0){ a = vn.getCurrentIndex(); int type = vn.getTokenType(a); if (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME){ try{ return vn.toString(a); }catch(Exception e){ return ""; } } else return ""; } else if (argCount() == 1){ a = evalFirstArgumentListNodeSet2(vn); try { if (a == -1 || vn.ns == false) return ""; else { int type = vn.getTokenType(a); if (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME) return vn.toString(a); return ""; } } catch (Exception e) { } return ""; }else throw new IllegalArgumentException ("name()'s argument count is invalid"); } // ISO 639 // http://www.loc.gov/standards/iso639-2/php/English_list.php // below are defined two-letter words // // ab , aa , af, ak, sq, am, ar, an, hy, as, av, ae, ay, az, bm // ba , eu , be, bn, bh, bi, nb, bs, br, bg, my, es, ca, km, ch // ce , ny , zh, za, cu, cv, kw, co, cr, hr, cs, da, dv, dv, nl // dz , en , eo, et, ee, fo, fj, fi, nl, fr, ff, gd, gl, lg, ka // de , ki , el, kl, gn, gu, ht, ha, he, hz, hi, ho, hu, is, io // ig , id , ia, ie, iu, ik, ga, it, ja, jv, kl, kn, kr, ks, kk // ki , rw , ky, kv, kg, ko, kj, ku, kj, ky, lo, la, lv, lb, li // ln , lt , lu, lb, mk, mg, ms, ml, dv, mt, gv, mi, mr, mh, mo // mn , na , nv, nv, nd, nr, ng, ne, nd, se, no, nb, nn, ii, nn, // ie , oc , oj, cu, or, om, os, pi, pa, ps, fa, pl, pt, oc, pa, // ps , qu , ro, rm, rn, ru, sm, sa, sc, gd, sr, sn, ii, si, sk, // sl , so , st, nr, es, su, sw, ss, sv, tl, ty, tg, ta, tt, te, // th , bo , ti, to, ts, tn, tr, tk, tw, ug, uk, ur, ug, uz, ca, // ve , vi , vo, wa, cy, fy, wo, xh, yi, yo, za, zu private boolean lang(VTDNavHuge vn, String s){ // check the length of s boolean b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i!=-1){ b = vn.matchTokenString(i,s); break; } vn.toElement(VTDNavHuge.P); } } catch (NavExceptionHuge e) { } vn.pop2(); return b; } private boolean startsWith(VTDNavHuge vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ //boolean b = false; int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return "".startsWith(s2); else{ try{ return vn.startsWith(a, s2); }catch(Exception e){ } return false; } } String s1 = argumentList.e.evalString(vn); return s1.startsWith(s2); } private boolean contains(VTDNavHuge vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return false; try { return vn.contains(a, s2); }catch (Exception e){ return false; } } String s1 = argumentList.e.evalString(vn); //return s1.contains(s2); return s1.indexOf(s2)!=-1; //return (s1.i)) } private String subString(VTDNavHuge vn){ if (argCount()== 2){ String s = argumentList.e.evalString(vn); double d1 = Math.floor(argumentList.next.e.evalNumber(vn)+0.5d); if (d1!=d1 || d1>s.length()) return ""; return s.substring(Math.max((int)(d1-1),0)); } else if (argCount() == 3){ String s = argumentList.e.evalString(vn); double d1 = Math.floor(argumentList.next.e.evalNumber(vn) + 0.5d); double d2 = Math .floor(argumentList.next.next.e.evalNumber(vn) + 0.5d); //int i1 = Math.max(0, (int) d1 - 1); if ((d1 + d2) != (d1 + d2) || d1 > s.length()) return ""; return s.substring(Math.max(0, (int) d1 - 1), Math.min(s.length(), (int) (d1 - 1) + (int) d2)); //(int) argumentList.next.next.e.evalNumber(vn)-1); } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String subStringBefore(VTDNavHuge vn){ if (argCount()==2){ String s1 = argumentList.e.evalString(vn); String s2 = argumentList.next.e.evalString(vn); int len1 = s1.length(); int len2 = s2.length(); for (int i=0;i<len1;i++){ if (s1.regionMatches(i,s2,0,len2)) return s1.substring(0,i); } return ""; } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String subStringAfter(VTDNavHuge vn){ if (argCount()==2){ String s1 = argumentList.e.evalString(vn); String s2 = argumentList.next.e.evalString(vn); int len1 = s1.length(); int len2 = s2.length(); for (int i=0;i<len1;i++){ if (s1.regionMatches(i,s2,0,len2)) return s1.substring(i+len2); } return ""; } throw new IllegalArgumentException ("substring()'s argument count is invalid"); } private String translate(VTDNavHuge vn) { int numArg = argCount(); if (numArg == 3) { String resultStr = argumentList.e.evalString(vn); String indexStr = argumentList.next.e.evalString(vn); if(resultStr == null || resultStr.length() == 0 || indexStr == null || indexStr.length() == 0) return resultStr; String replace = argumentList.next.next.e.evalString(vn); StringBuilder usedCharStr = new StringBuilder(); int lenRep = (replace != null)?replace.length() : 0; for(int i = 0;i< indexStr.length(); i++) { char idxChar = indexStr.charAt(i); if(usedCharStr.indexOf(String.valueOf(idxChar)) < 0) { if(i < lenRep) { resultStr = resultStr.replace(idxChar, replace.charAt(i)); } else { resultStr = resultStr.replaceAll(String.valueOf(idxChar), ""); } usedCharStr.append(idxChar); } } return resultStr; } else { throw new IllegalArgumentException("Argument count for translate() is invalid. Expected: 3; Actual: " + numArg); } } private String normalizeSpace(VTDNavHuge vn){ if (argCount()== 0){ String s =null; try{ if (vn.atTerminal){ int ttype = vn.getTokenType(vn.LN); if (ttype == VTDNavHuge.TOKEN_CDATA_VAL ) s= vn.toRawString(vn.LN); else if (ttype == VTDNavHuge.TOKEN_ATTR_NAME || ttype == VTDNavHuge.TOKEN_ATTR_NS){ s = vn.toNormalizedString(vn.LN+1); } else s= vn.toNormalizedString(vn.LN); }else { s= vn.toNormalizedString(vn.getCurrentIndex()); } return s; } catch(NavExceptionHuge e){ return ""; // this will almost never occur } } else if (argCount() == 1){ String s=""; if (argumentList.e.isNodeSet()){ //boolean b = false; int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else { try{ s = vn.toNormalizedString(a); } catch (Exception e){ } return s; } } else { s = argumentList.e.evalString(vn); return normalize(s); } } throw new IllegalArgumentException ("normalize-space()'s argument count is invalid"); //return null; } private String normalize(String s){ int len = s.length(); StringBuffer sb = new StringBuffer(len); int i=0; // strip off leading ws for(i=0;i<len;i++){ if (isWS(s.charAt(i))){ }else{ break; } } while(i<len){ char c = s.charAt(i); if (!isWS(c)){ sb.append(c); i++; } else { while(i<len){ c = s.charAt(i); if (isWS(c)) i++; else break; } if (i<len) sb.append(' '); } } return sb.toString(); } private boolean isWS(char c){ if (c==' ' || c=='\t' || c=='\r'||c=='\n') return true; return false; } private String concat(VTDNavHuge vn){ StringBuffer sb = new StringBuffer(); if (argCount()>=2){ Alist temp = argumentList; while(temp!=null){ sb.append(temp.e.evalString(vn)); temp = temp.next; } return sb.toString(); } else throw new IllegalArgumentException ("concat()'s argument count is invalid"); } private String getString(VTDNavHuge vn){ if (argCount()== 0) try{ if (vn.atTerminal){ if (vn.getTokenType(vn.LN) == VTDNavHuge.TOKEN_CDATA_VAL ) return vn.toRawString(vn.LN); return vn.toString(vn.LN); } return vn.toString(vn.getCurrentIndex()); } catch(NavExceptionHuge e){ return ""; // this will almost never occur } else if (argCount() == 1){ return argumentList.e.evalString(vn); } else throw new IllegalArgumentException ("String()'s argument count is invalid"); } public String evalString(VTDNavHuge vn) throws UnsupportedException{ //int d=0; switch(opCode){ case FuncName.CONCAT: return concat(vn); //throw new UnsupportedException("Some functions are not supported"); case FuncName.LOCAL_NAME: return getLocalName(vn); case FuncName.NAMESPACE_URI: return getNameSpaceURI(vn); case FuncName.NAME: return getName(vn); case FuncName.STRING: return getString(vn); case FuncName.SUBSTRING_BEFORE: return subStringBefore(vn); case FuncName.SUBSTRING_AFTER: return subStringAfter(vn); case FuncName.SUBSTRING: return subString(vn); case FuncName.TRANSLATE: return translate(vn); case FuncName.NORMALIZE_SPACE: return normalizeSpace(vn); //case FuncName.LANG: return lang(vn) case FuncName.CODE_POINTS_TO_STRING: throw new com.ximpleware.extended.xpath.UnsupportedException("not yet implemented"); case FuncName.UPPER_CASE:return upperCase(vn); case FuncName.LOWER_CASE:return lowerCase(vn); case FuncName.QNAME: case FuncName.LOCAL_NAME_FROM_QNAME: case FuncName.NAMESPACE_URI_FROM_QNAME: case FuncName.NAMESPACE_URI_FOR_PREFIX: case FuncName.RESOLVE_QNAME: case FuncName.IRI_TO_URI: case FuncName.ESCAPE_HTML_URI: case FuncName.ENCODE_FOR_URI: throw new com.ximpleware.extended.xpath.UnsupportedException("not yet implemented"); default: if (isBoolean()){ if (evalBoolean(vn)== true) return "true"; else return "false"; } else { return ""+ evalNumber(vn); } } } public double evalNumber(VTDNavHuge vn){ int ac = 0; switch(opCode){ case FuncName.LAST: if (argCount()!=0 ) throw new IllegalArgumentException ("floor()'s argument count is invalid"); return contextSize; case FuncName.POSITION: if (argCount()!=0 ) throw new IllegalArgumentException ("position()'s argument count is invalid"); return position; case FuncName.COUNT: return count(vn); case FuncName.NUMBER: if (argCount()!=1) throw new IllegalArgumentException ("number()'s argument count is invalid"); return argumentList.e.evalNumber(vn); case FuncName.SUM: return sum(vn); case FuncName.FLOOR: if (argCount()!=1 ) throw new IllegalArgumentException("floor()'s argument count is invalid"); return Math.floor(argumentList.e.evalNumber(vn)); case FuncName.CEILING: if (argCount()!=1 ) throw new IllegalArgumentException("ceiling()'s argument count is invalid"); return Math.ceil(argumentList.e.evalNumber(vn)); case FuncName.STRING_LENGTH: ac = argCount(); if (ac == 0){ try{ if (vn.atTerminal == true){ int type = vn.getTokenType(vn.LN); if (type == VTDNavHuge.TOKEN_ATTR_NAME || type == VTDNavHuge.TOKEN_ATTR_NS){ return vn.getStringLength(vn.LN+1); } else { return vn.getStringLength(vn.LN); } }else { int i = vn.getText(); if (i==-1) return 0; else return vn.getStringLength(i); } }catch (NavExceptionHuge e){ return 0; } } else if (ac == 1){ return argumentList.e.evalString(vn).length(); } else { throw new IllegalArgumentException("string-length()'s argument count is invalid"); } case FuncName.ROUND: if (argCount()!=1 ) throw new IllegalArgumentException("round()'s argument count is invalid"); return Math.floor(argumentList.e.evalNumber(vn))+0.5d; case FuncName.ABS: if (argCount() != 1) throw new IllegalArgumentException( "abs()'s argument count is invalid"); return Math.abs(argumentList.e.evalNumber(vn)); case FuncName.ROUND_HALF_TO_EVEN : case FuncName.ROUND_HALF_TO_ODD: throw new com.ximpleware.extended.xpath.UnsupportedException("not yet implemented"); default: if (isBoolean){ if (evalBoolean(vn)) return 1; else return 0; }else { try { double dval = Double.parseDouble(evalString(vn)); return dval; }catch (NumberFormatException e){ return Double.NaN; } } } } public int evalNodeSet(VTDNavHuge vn) throws XPathEvalExceptionHuge{ throw new XPathEvalExceptionHuge(" Function Expr can't eval to node set "); } public boolean evalBoolean(VTDNavHuge vn){ switch(opCode){ case FuncName.STARTS_WITH: if (argCount()!=2){ throw new IllegalArgumentException("starts-with()'s argument count is invalid"); } return startsWith(vn); case FuncName.CONTAINS: if (argCount()!=2){ throw new IllegalArgumentException("contains()'s argument count is invalid"); } return contains(vn); case FuncName.TRUE: if (argCount()!=0){ throw new IllegalArgumentException("true() doesn't take any argument"); } return true; case FuncName.FALSE:if (argCount()!=0){ throw new IllegalArgumentException("false() doesn't take any argument"); } return false; case FuncName.BOOLEAN: if (argCount()!=1){ throw new IllegalArgumentException("boolean() doesn't take any argument"); } return argumentList.e.evalBoolean(vn); case FuncName.NOT: if (argCount()!=1){ throw new IllegalArgumentException("not() doesn't take any argument"); } return !argumentList.e.evalBoolean(vn); case FuncName.LANG: if (argCount()!=1){ throw new IllegalArgumentException("lang()'s argument count is invalid"); } return lang(vn,argumentList.e.evalString(vn)); case FuncName.COMPARE:throw new com.ximpleware.extended.xpath.UnsupportedException("not yet implemented"); case FuncName.ENDS_WITH: if (argCount()!=2){ throw new IllegalArgumentException("starts-with()'s argument count is invalid"); } return endsWith(vn); default: if (isNumerical()){ double d = evalNumber(vn); if (d==0 || d!=d) return false; return true; }else{ return evalString(vn).length()!=0; } } } public void reset(VTDNavHuge vn){ a = 0; //contextSize = 0; if (argumentList!=null) argumentList.reset(vn); } public String fname(){ switch(opCode){ case FuncName.LAST: return "last"; case FuncName.POSITION: return "position"; case FuncName.COUNT: return "count"; case FuncName.LOCAL_NAME: return "local-name"; case FuncName.NAMESPACE_URI: return "namespace-uri"; case FuncName.NAME: return "name"; case FuncName.STRING: return "string"; case FuncName.CONCAT: return "concat"; case FuncName.STARTS_WITH: return "starts-with"; case FuncName.CONTAINS: return "contains"; case FuncName.SUBSTRING_BEFORE: return "substring-before"; case FuncName.SUBSTRING_AFTER: return "substring-after"; case FuncName.SUBSTRING: return "substring"; case FuncName.STRING_LENGTH: return "string-length"; case FuncName.NORMALIZE_SPACE: return "normalize-space"; case FuncName.TRANSLATE: return "translate"; case FuncName.BOOLEAN: return "boolean"; case FuncName.NOT: return "not"; case FuncName.TRUE: return "true"; case FuncName.FALSE: return "false"; case FuncName.LANG: return "lang"; case FuncName.NUMBER: return "number"; case FuncName.SUM: return "sum"; case FuncName.FLOOR: return "floor"; case FuncName.CEILING: return "ceiling"; case FuncName.ROUND: return "round"; case FuncName.ABS: return "abs"; case FuncName.ROUND_HALF_TO_EVEN : return "round-half-to-even"; case FuncName.ROUND_HALF_TO_ODD: return "round-half-to-odd"; case FuncName.CODE_POINTS_TO_STRING: return "code-points-to-string"; case FuncName.COMPARE: return "compare"; case FuncName.UPPER_CASE: return "upper-case"; case FuncName.LOWER_CASE: return "lower-case"; case FuncName.ENDS_WITH: return "ends-with"; case FuncName.QNAME: return "qname"; case FuncName.LOCAL_NAME_FROM_QNAME: return "local-name-from-QName"; case FuncName.NAMESPACE_URI_FROM_QNAME: return "namespace-uri-from-QName"; case FuncName.NAMESPACE_URI_FOR_PREFIX: return "namespace-uri-for-prefix"; case FuncName.RESOLVE_QNAME: return "resolve-QName"; case FuncName.IRI_TO_URI: return "iri-to-uri"; case FuncName.ESCAPE_HTML_URI: return "escape-html-uri"; default: return "encode-for-uri"; } } public boolean isNodeSet(){ return false; } public boolean isNumerical(){ return isNumerical; } public boolean isString(){ return isString; } public boolean isBoolean(){ return isBoolean; } private int count(VTDNavHuge vn){ int a = -1; if (argCount()!=1 || argumentList.e.isNodeSet()==false) throw new IllegalArgumentException ("Count()'s argument count is invalid"); vn.push2(); try{ a = 0; argumentList.e.adjust(vn.getTokenCount()); while(argumentList.e.evalNodeSet(vn)!=-1){ a ++; } argumentList.e.reset(vn); vn.pop2(); }catch(Exception e){ argumentList.e.reset(vn); vn.pop2(); } return a; } private double sum(VTDNavHuge vn){ double d=0; if (argCount() != 1 || argumentList.e.isNodeSet() == false) throw new IllegalArgumentException("sum()'s argument count is invalid"); vn.push2(); try { a = 0; int i1; while ((a =argumentList.e.evalNodeSet(vn)) != -1) { int t = vn.getTokenType(a); if (t == VTDNavHuge.TOKEN_STARTING_TAG){ i1 = vn.getText(); if (i1!=-1) d += vn.parseDouble(i1); if (Double.isNaN(d)) break; } else if (t == VTDNavHuge.TOKEN_ATTR_NAME || t == VTDNavHuge.TOKEN_ATTR_NS){ d += vn.parseDouble(a+1); if (Double.isNaN(d)) break; } else if (t == VTDNavHuge.TOKEN_CHARACTER_DATA || t == VTDNavHuge.TOKEN_CDATA_VAL){ d += vn.parseDouble(a); if (Double.isNaN(d)) break; } // fib1.append(i); } argumentList.e.reset(vn); vn.pop2(); return d; } catch (Exception e) { argumentList.e.reset(vn); vn.pop2(); return Double.NaN; } } // to support computer context size // needs to add public boolean requireContextSize(){ if (opCode == FuncName.LAST) return true; else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ if (temp.e.requireContextSize()){ return true; } temp = temp.next; } } return false; } public void setContextSize(int size){ if (opCode == FuncName.LAST){ contextSize = size; //System.out.println("contextSize: "+size); } else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ temp.e.setContextSize(size); temp = temp.next; } } } public void setPosition(int pos){ if (opCode == FuncName.POSITION){ position = pos; //System.out.println("PO: "+size); } else { Alist temp = argumentList; //boolean b = false; while(temp!=null){ temp.e.setPosition(pos); temp = temp.next; } } } public int adjust(int n){ int i = 0; switch(opCode){ case FuncName.COUNT: case FuncName.SUM: i = argumentList.e.adjust(n); break; default: } return i; } private int evalFirstArgumentListNodeSet(VTDNavHuge vn){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); if (a != -1) { if (vn.getTokenType(a) == VTDNavHuge.TOKEN_ATTR_NAME) { a++; } if (vn.getTokenType(a) == VTDNavHuge.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; } private int evalFirstArgumentListNodeSet2(VTDNavHuge vn){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; } private String upperCase(VTDNavHuge vn){ if (argCount()==1){ if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else{ try{ return vn.toStringUpperCase(a); }catch(Exception e){ } return ""; } }else { return (argumentList.e.evalString(vn)).toUpperCase(); } }else throw new IllegalArgumentException ("upperCase()'s argument count is invalid"); } private String lowerCase(VTDNavHuge vn){ if (argCount()==1){ if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return ""; else{ try{ return vn.toStringLowerCase(a); }catch(Exception e){ } return ""; } }else { return (argumentList.e.evalString(vn)).toLowerCase(); } }else throw new IllegalArgumentException ("lowerCase()'s argument count is invalid"); } private boolean endsWith(VTDNavHuge vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return "".startsWith(s2); else{ try{ return vn.endsWith(a, s2); }catch(Exception e){ } return false; } } String s1 = argumentList.e.evalString(vn); return s1.endsWith(s2); } }
34,678
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
UnionExpr.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/UnionExpr.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; import com.ximpleware.extended.xpath.*; public class UnionExpr extends Expr { public intHash ih; public Expr e; public UnionExpr next; UnionExpr current; int state; public UnionExpr(Expr e1) { e = e1; next = null; current = this; ih = null; state = 0; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalBoolean(com.ximpleware.VTDNav) */ public boolean evalBoolean(VTDNavHuge vn) { if (e.isNodeSet()==false) return e.evalBoolean(vn); else { boolean a = false; vn.push2(); // record teh stack size int size = vn.contextStack2.size; try { a = (evalNodeSet(vn) != -1); } catch (Exception e) { } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; } } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalNumber(com.ximpleware.VTDNav) */ public double evalNumber(VTDNavHuge vn) { if (e.isNodeSet()==false) return e.evalNumber(vn); int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { if (vn.getTokenType(a) == VTDNavHuge.TOKEN_ATTR_NAME) { a++; } else if (vn.getTokenType(a) == VTDNavHuge.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); try { if (a != -1) return vn.parseDouble(a); } catch (NavExceptionHuge e) { } return Double.NaN; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalNodeSet(com.ximpleware.VTDNav) */ public int evalNodeSet(VTDNavHuge vn) throws XPathEvalExceptionHuge, NavExceptionHuge { int a; if (this.next == null) { return e.evalNodeSet(vn); } else { while (true) { switch (state) { case 0: if (ih==null) ih = new intHash(); if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; } else state = 3; break; case 1: while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; case 2: current = current.next; if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } vn.pop2(); break; } else state = 3; break; case 3: return -1; default: throw new XPathEvalExceptionHuge( "Invalid state evaluating UnionExpr"); } } } /* * default: throw new XPathEvalException( "Invalid state evaluating * PathExpr"); */ } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalString(com.ximpleware.VTDNav) */ public String evalString(VTDNavHuge vn) { if (e.isNodeSet()==false){ return e.evalString(vn); } vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = evalNodeSet(vn); if (a != -1) { if (vn.getTokenType(a) == VTDNavHuge.TOKEN_ATTR_NAME) { a++; } if (vn.getTokenType(a) == VTDNavHuge.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); try { if (a != -1) return vn.toString(a); } catch (NavExceptionHuge e) { } return ""; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#reset(com.ximpleware.VTDNav) */ public void reset(VTDNavHuge vn) { // travese el list and reset every expression e.reset(vn); current = this; UnionExpr tmp = this.next; while (tmp != null) { tmp.e.reset(vn); tmp = tmp.next; } if (ih != null) ih.reset(); state = 0; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ public String toString() { // TODO Auto-generated method stub if (this.next == null) return this.e.toString(); else return this.e.toString() + " | " + this.next.toString(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isNumerical() */ public boolean isNumerical() { // TODO Auto-generated method stub return e.isNumerical(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isNodeSet() */ public boolean isNodeSet() { // TODO Auto-generated method stub return e.isNodeSet(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isString() */ public boolean isString() { // TODO Auto-generated method stub return e.isString(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#isBoolean() */ public boolean isBoolean() { // TODO Auto-generated method stub return e.isBoolean(); } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#requireContextSize() */ public boolean requireContextSize() { // boolean b = false; UnionExpr tmp = this; while (tmp != null) { if (tmp.e.requireContextSize()== true){ return true; } tmp = tmp.next; } return false; } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#setContextSize(int) */ public void setContextSize(int size) { current = this; current.e.setContextSize(size); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.setContextSize(size); tmp = tmp.next; } } /* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#setPosition(int) */ public void setPosition(int pos) { current = this; current.e.setPosition(pos); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.setPosition(pos); tmp = tmp.next; } } public boolean isUnique(int i) { return ih.isUnique(i); } public int adjust(int n){ int i = e.adjust(n); if (ih!=null && i==ih.e) {} else ih = new intHash(i); UnionExpr tmp = this.next; while (tmp != null) { tmp.e.adjust(n); tmp = tmp.next; } return i; } }
9,397
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z
intHash.java
/FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/net.heartsome.xml/src/com/ximpleware/extended/intHash.java
/* * Copyright (C) 2002-2012 XimpleWare, [email protected] * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.ximpleware.extended; /** * * This is the implementation of a hash table for integers * It is used by various XPath expressions to check for uniqueness * of a node */ class intHash { private int mask1 = 0x7ff; //2048 private int mask2 = 0xfffff800; private int pageSizeE = 4; // 32 * 4 bytes protected FastIntBuffer[] storage; private int hashWidth = 1<<11; private int maxDepth; protected int e; /** * Test whether the input i is unique; * if not, insert into the hash table and return false * otherwise, return true */ public boolean isUnique(int i){ int temp = i & mask1; if (temp>maxDepth){ maxDepth = temp; } if (storage[temp]==null) { storage[temp]= new FastIntBuffer(pageSizeE); storage[temp].append(i); return true; } else{ int size = storage[temp].size(); for (int j=0;j<size;j++){ if (i == storage[temp].intAt(j)){ return false; } } storage[temp].append(i); return true; } } /** * Clear all entries in the hash table * This method sets the size of member FastIntBuffer * to zero */ public void reset(){ for (int i=0;i<=maxDepth;i++){ if (storage[i]!=null){ storage[i].clear(); } } } /** * Constructor * */ public intHash(){ hashWidth = 1<<0; mask1 = (hashWidth) -1; mask2 = (~mask1) & 0xffffffff; storage = new FastIntBuffer[hashWidth]; e=0; } public intHash(int hashWidthExpo){ e=hashWidthExpo; hashWidth = 1<<hashWidthExpo; mask1 = (hashWidth) -1; mask2 = (~mask1) & 0xffffffff; storage = new FastIntBuffer[hashWidth]; } public static void main(String[] args) { intHash a = new intHash(6); for(int i=0;i<667;i++) System.out.println("" + i + " " + a.isUnique(i)); for(int i=0;i<667;i++) System.out.println("" + i + " " + a.isUnique(i)); } public static int determineHashWidth(int i){ if (i<(1<<8)) return 3; if (i<(1<<9)) return 4; if (i<(1<<10)) return 5; if (i<(1<<11)) return 6; if (i<(1<<12)) return 7; if (i<(1<<13)) return 8; if (i<(1<<14)) return 9; if (i<(1<<15)) return 10; if (i<(1<<16)) return 11; if (i<(1<<17)) return 12; if (i<(1<<18)) return 13; if (i<(1<<19)) return 14; if (i<(1<<20)) return 15; if (i<(1<<21)) return 16; if (i<(1<<22)) return 17; if (i<(1<<23)) return 18; if (i<(1<<25)) return 19; if (i<(1<<27)) return 20; if (i<(1<<29)) return 21; return 22; } }
4,012
Java
.java
heartsome/translationstudio8
83
45
18
2014-06-03T17:56:15Z
2020-10-13T06:46:15Z