/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.hwpf.sprm; import org.apache.logging.log4j.Logger; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.TableCellDescriptor; import org.apache.poi.hwpf.usermodel.TableProperties; import org.apache.poi.logging.PoiLogManager; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @Internal public final class TableSprmUncompressor extends SprmUncompressor { private static final Logger LOG = PoiLogManager.getLogger(TableSprmUncompressor.class); public TableSprmUncompressor() { } public static TableProperties uncompressTAP( SprmBuffer sprmBuffer ) { TableProperties tableProperties; if (sprmBuffer == null) { throw new IllegalArgumentException("Cannot process TableProperties with an empty SprmBuffer"); } SprmOperation sprmOperation = sprmBuffer.findSprm( (short) 0xd608 ); if ( sprmOperation != null ) { byte[] grpprl = sprmOperation.getGrpprl(); int offset = sprmOperation.getGrpprlOffset(); short itcMac = grpprl[offset]; tableProperties = new TableProperties( itcMac ); } else { LOG.atWarn().log("Some table rows didn't specify number of columns in SPRMs"); tableProperties = new TableProperties( (short) 1 ); } for ( SprmIterator iterator = sprmBuffer.iterator(); iterator.hasNext(); ) { SprmOperation sprm = iterator.next(); /* * TAPXs are actually PAPXs so we have to make sure we are only * trying to uncompress the right type of sprm. */ if ( sprm.getType() == SprmOperation.TYPE_TAP ) { try { unCompressTAPOperation( tableProperties, sprm ); } catch ( ArrayIndexOutOfBoundsException ex ) { LOG.atError().withThrowable(ex).log("Unable to apply {}", sprm); } } } return tableProperties; } /** * Used to uncompress a table property. Performs an operation defined * by a sprm stored in a tapx. * * @param newTAP The TableProperties object to perform the operation on. * @param sprm The operation to perform. */ static void unCompressTAPOperation (TableProperties newTAP, SprmOperation sprm) { switch (sprm.getOperation()) { case 0: newTAP.setJc ((short) sprm.getOperand()); break; case 0x01: { short[] rgdxaCenter = newTAP.getRgdxaCenter (); short itcMac = newTAP.getItcMac (); int adjust = sprm.getOperand() - (rgdxaCenter[0] + newTAP.getDxaGapHalf ()); for (int x = 0; x < itcMac; x++) { rgdxaCenter[x] += (short) adjust; } break; } case 0x02: { short[] rgdxaCenter = newTAP.getRgdxaCenter (); if (rgdxaCenter != null) { int adjust = newTAP.getDxaGapHalf () - sprm.getOperand(); rgdxaCenter[0] += (short) adjust; } newTAP.setDxaGapHalf (sprm.getOperand()); break; } case 0x03: newTAP.setFCantSplit (getFlag(sprm.getOperand())); break; case 0x04: newTAP.setFTableHeader (getFlag (sprm.getOperand())); break; case 0x05: { byte[] buf = sprm.getGrpprl(); int offset = sprm.getGrpprlOffset(); newTAP.setBrcTop(new BorderCode(buf, offset)); offset += BorderCode.SIZE; newTAP.setBrcLeft(new BorderCode(buf, offset)); offset += BorderCode.SIZE; newTAP.setBrcBottom(new BorderCode(buf, offset)); offset += BorderCode.SIZE; newTAP.setBrcRight(new BorderCode(buf, offset)); offset += BorderCode.SIZE; newTAP.setBrcHorizontal(new BorderCode(buf, offset)); offset += BorderCode.SIZE; newTAP.setBrcVertical(new BorderCode(buf, offset)); break; } case 0x06: //obsolete, used in word 1.x break; case 0x07: newTAP.setDyaRowHeight (sprm.getOperand()); break; case 0x08: { byte[] grpprl = sprm.getGrpprl(); int offset = sprm.getGrpprlOffset(); short itcMac = grpprl[offset]; short[] rgdxaCenter = new short[itcMac + 1]; TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac]; //I use varParam[0] and newTAP._itcMac interchangably newTAP.setItcMac (itcMac); newTAP.setRgdxaCenter (rgdxaCenter); newTAP.setRgtc (rgtc); // get the rgdxaCenters for (int x = 0; x < itcMac; x++) { rgdxaCenter[x] = LittleEndian.getShort (grpprl, offset + (1 + (x * 2))); } // only try to get the TC entries if they exist... int endOfSprm = offset+sprm.size()-6; // -2 bytes for sprm - 2 for size short - 2 to correct offsets being 0 based int startOfTCs = offset + (1 + (itcMac + 1) * 2); boolean hasTCs = startOfTCs < endOfSprm; for (int x = 0; x < itcMac; x++) { // Sometimes, the grpprl does not contain data at every offset. I have no idea why this happens. if(hasTCs && offset + (1 + ( (itcMac + 1) * 2) + (x * 20)) < grpprl.length) rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl, offset + (1 + ( (itcMac + 1) * 2) + (x * 20))); else rgtc[x] = new TableCellDescriptor(); } rgdxaCenter[itcMac] = LittleEndian.getShort (grpprl, offset + (1 + (itcMac * 2))); break; } case 0x09: /** @todo handle cell shading*/ break; case 0x0a: /** @todo handle word defined table styles*/
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>jQuery UI Datepicker - Dates in other months</title>
	<link rel="stylesheet" href="../../themes/base/all.css">
	<script src="../../external/jquery/jquery.js"></script>
	<script src="../../ui/core.js"></script>
	<script src="../../ui/widget.js"></script>
	<script src="../../ui/datepicker.js"></script>
	<link rel="stylesheet" href="../demos.css">
	<script>
	$(function() {
		$( "#datepicker" ).datepicker({
			showOtherMonths: true,
			selectOtherMonths: true
		});
	});
	</script>
</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>

<div class="demo-description">
<p>The datepicker can show dates that come from other than the main month
	being displayed. These other dates can also be made selectable.</p>
</div>
</body>
</html>