You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LinkTable.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.model;
  16. import java.util.ArrayList;
  17. import java.util.Iterator;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.apache.poi.hssf.record.CRNCountRecord;
  21. import org.apache.poi.hssf.record.CRNRecord;
  22. import org.apache.poi.hssf.record.CountryRecord;
  23. import org.apache.poi.hssf.record.ExternSheetRecord;
  24. import org.apache.poi.hssf.record.ExternalNameRecord;
  25. import org.apache.poi.hssf.record.NameCommentRecord;
  26. import org.apache.poi.hssf.record.NameRecord;
  27. import org.apache.poi.hssf.record.Record;
  28. import org.apache.poi.hssf.record.SupBookRecord;
  29. import org.apache.poi.ss.formula.ptg.Area3DPtg;
  30. import org.apache.poi.ss.formula.ptg.ErrPtg;
  31. import org.apache.poi.ss.formula.ptg.NameXPtg;
  32. import org.apache.poi.ss.formula.ptg.Ptg;
  33. import org.apache.poi.ss.formula.ptg.Ref3DPtg;
  34. /**
  35. * Link Table (OOO pdf reference: 4.10.3 ) <p/>
  36. *
  37. * The main data of all types of references is stored in the Link Table inside the Workbook Globals
  38. * Substream (4.2.5). The Link Table itself is optional and occurs only if there are any
  39. * references in the document.
  40. * <p/>
  41. *
  42. * In BIFF8 the Link Table consists of
  43. * <ul>
  44. * <li>zero or more EXTERNALBOOK Blocks<p/>
  45. * each consisting of
  46. * <ul>
  47. * <li>exactly one EXTERNALBOOK (0x01AE) record</li>
  48. * <li>zero or more EXTERNALNAME (0x0023) records</li>
  49. * <li>zero or more CRN Blocks<p/>
  50. * each consisting of
  51. * <ul>
  52. * <li>exactly one XCT (0x0059)record</li>
  53. * <li>zero or more CRN (0x005A) records (documentation says one or more)</li>
  54. * </ul>
  55. * </li>
  56. * </ul>
  57. * </li>
  58. * <li>zero or one EXTERNSHEET (0x0017) record</li>
  59. * <li>zero or more DEFINEDNAME (0x0018) records</li>
  60. * </ul>
  61. */
  62. final class LinkTable {
  63. // TODO make this class into a record aggregate
  64. private static final class CRNBlock {
  65. private final CRNCountRecord _countRecord;
  66. private final CRNRecord[] _crns;
  67. public CRNBlock(RecordStream rs) {
  68. _countRecord = (CRNCountRecord) rs.getNext();
  69. int nCRNs = _countRecord.getNumberOfCRNs();
  70. CRNRecord[] crns = new CRNRecord[nCRNs];
  71. for (int i = 0; i < crns.length; i++) {
  72. crns[i] = (CRNRecord) rs.getNext();
  73. }
  74. _crns = crns;
  75. }
  76. public CRNRecord[] getCrns() {
  77. return _crns.clone();
  78. }
  79. }
  80. private static final class ExternalBookBlock {
  81. private final SupBookRecord _externalBookRecord;
  82. private ExternalNameRecord[] _externalNameRecords;
  83. private final CRNBlock[] _crnBlocks;
  84. public ExternalBookBlock(RecordStream rs) {
  85. _externalBookRecord = (SupBookRecord) rs.getNext();
  86. List<Object> temp = new ArrayList<Object>();
  87. while(rs.peekNextClass() == ExternalNameRecord.class) {
  88. temp.add(rs.getNext());
  89. }
  90. _externalNameRecords = new ExternalNameRecord[temp.size()];
  91. temp.toArray(_externalNameRecords);
  92. temp.clear();
  93. while(rs.peekNextClass() == CRNCountRecord.class) {
  94. temp.add(new CRNBlock(rs));
  95. }
  96. _crnBlocks = new CRNBlock[temp.size()];
  97. temp.toArray(_crnBlocks);
  98. }
  99. /**
  100. * Create a new block for internal references. It is called when constructing a new LinkTable.
  101. *
  102. * @see org.apache.poi.hssf.model.LinkTable#LinkTable(int, WorkbookRecordList)
  103. */
  104. public ExternalBookBlock(int numberOfSheets) {
  105. _externalBookRecord = SupBookRecord.createInternalReferences((short)numberOfSheets);
  106. _externalNameRecords = new ExternalNameRecord[0];
  107. _crnBlocks = new CRNBlock[0];
  108. }
  109. /**
  110. * Create a new block for registering add-in functions
  111. *
  112. * @see org.apache.poi.hssf.model.LinkTable#addNameXPtg(String)
  113. */
  114. public ExternalBookBlock() {
  115. _externalBookRecord = SupBookRecord.createAddInFunctions();
  116. _externalNameRecords = new ExternalNameRecord[0];
  117. _crnBlocks = new CRNBlock[0];
  118. }
  119. public SupBookRecord getExternalBookRecord() {
  120. return _externalBookRecord;
  121. }
  122. public String getNameText(int definedNameIndex) {
  123. return _externalNameRecords[definedNameIndex].getText();
  124. }
  125. public int getNameIx(int definedNameIndex) {
  126. return _externalNameRecords[definedNameIndex].getIx();
  127. }
  128. /**
  129. * Performs case-insensitive search
  130. * @return -1 if not found
  131. */
  132. public int getIndexOfName(String name) {
  133. for (int i = 0; i < _externalNameRecords.length; i++) {
  134. if(_externalNameRecords[i].getText().equalsIgnoreCase(name)) {
  135. return i;
  136. }
  137. }
  138. return -1;
  139. }
  140. public int getNumberOfNames() {
  141. return _externalNameRecords.length;
  142. }
  143. public int addExternalName(ExternalNameRecord rec){
  144. ExternalNameRecord[] tmp = new ExternalNameRecord[_externalNameRecords.length + 1];
  145. System.arraycopy(_externalNameRecords, 0, tmp, 0, _externalNameRecords.length);
  146. tmp[tmp.length - 1] = rec;
  147. _externalNameRecords = tmp;
  148. return _externalNameRecords.length - 1;
  149. }
  150. }
  151. private ExternalBookBlock[] _externalBookBlocks;
  152. private final ExternSheetRecord _externSheetRecord;
  153. private final List<NameRecord> _definedNames;
  154. private final int _recordCount;
  155. private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this
  156. public LinkTable(List<Record> inputList, int startIndex, WorkbookRecordList workbookRecordList, Map<String, NameCommentRecord> commentRecords) {
  157. _workbookRecordList = workbookRecordList;
  158. RecordStream rs = new RecordStream(inputList, startIndex);
  159. List<ExternalBookBlock> temp = new ArrayList<ExternalBookBlock>();
  160. while(rs.peekNextClass() == SupBookRecord.class) {
  161. temp.add(new ExternalBookBlock(rs));
  162. }
  163. _externalBookBlocks = new ExternalBookBlock[temp.size()];
  164. temp.toArray(_externalBookBlocks);
  165. temp.clear();
  166. if (_externalBookBlocks.length > 0) {
  167. // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
  168. if (rs.peekNextClass() != ExternSheetRecord.class) {
  169. // not quite - if written by google docs
  170. _externSheetRecord = null;
  171. } else {
  172. _externSheetRecord = readExtSheetRecord(rs);
  173. }
  174. } else {
  175. _externSheetRecord = null;
  176. }
  177. _definedNames = new ArrayList<NameRecord>();
  178. // collect zero or more DEFINEDNAMEs id=0x18,
  179. // with their comments if present
  180. while(true) {
  181. Class nextClass = rs.peekNextClass();
  182. if (nextClass == NameRecord.class) {
  183. NameRecord nr = (NameRecord)rs.getNext();
  184. _definedNames.add(nr);
  185. }
  186. else if (nextClass == NameCommentRecord.class) {
  187. NameCommentRecord ncr = (NameCommentRecord)rs.getNext();
  188. commentRecords.put(ncr.getNameText(), ncr);
  189. }
  190. else {
  191. break;
  192. }
  193. }
  194. _recordCount = rs.getCountRead();
  195. _workbookRecordList.getRecords().addAll(inputList.subList(startIndex, startIndex + _recordCount));
  196. }
  197. private static ExternSheetRecord readExtSheetRecord(RecordStream rs) {
  198. List<ExternSheetRecord> temp = new ArrayList<ExternSheetRecord>(2);
  199. while(rs.peekNextClass() == ExternSheetRecord.class) {
  200. temp.add((ExternSheetRecord) rs.getNext());
  201. }
  202. int nItems = temp.size();
  203. if (nItems < 1) {
  204. throw new RuntimeException("Expected an EXTERNSHEET record but got ("
  205. + rs.peekNextClass().getName() + ")");
  206. }
  207. if (nItems == 1) {
  208. // this is the normal case. There should be just one ExternSheetRecord
  209. return temp.get(0);
  210. }
  211. // Some apps generate multiple ExternSheetRecords (see bug 45698).
  212. // It seems like the best thing to do might be to combine these into one
  213. ExternSheetRecord[] esrs = new ExternSheetRecord[nItems];
  214. temp.toArray(esrs);
  215. return ExternSheetRecord.combine(esrs);
  216. }
  217. public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList) {
  218. _workbookRecordList = workbookRecordList;
  219. _definedNames = new ArrayList<NameRecord>();
  220. _externalBookBlocks = new ExternalBookBlock[] {
  221. new ExternalBookBlock(numberOfSheets),
  222. };
  223. _externSheetRecord = new ExternSheetRecord();
  224. _recordCount = 2;
  225. // tell _workbookRecordList about the 2 new records
  226. SupBookRecord supbook = _externalBookBlocks[0].getExternalBookRecord();
  227. int idx = findFirstRecordLocBySid(CountryRecord.sid);
  228. if(idx < 0) {
  229. throw new RuntimeException("CountryRecord not found");
  230. }
  231. _workbookRecordList.add(idx+1, _externSheetRecord);
  232. _workbookRecordList.add(idx+1, supbook);
  233. }
  234. /**
  235. * TODO - would not be required if calling code used RecordStream or similar
  236. */
  237. public int getRecordCount() {
  238. return _recordCount;
  239. }
  240. /**
  241. * @param builtInCode a BUILTIN_~ constant from {@link NameRecord}
  242. * @param sheetNumber 1-based sheet number
  243. */
  244. public NameRecord getSpecificBuiltinRecord(byte builtInCode, int sheetNumber) {
  245. Iterator iterator = _definedNames.iterator();
  246. while (iterator.hasNext()) {
  247. NameRecord record = ( NameRecord ) iterator.next();
  248. //print areas are one based
  249. if (record.getBuiltInName() == builtInCode && record.getSheetNumber() == sheetNumber) {
  250. return record;
  251. }
  252. }
  253. return null;
  254. }
  255. public void removeBuiltinRecord(byte name, int sheetIndex) {
  256. //the name array is smaller so searching through it should be faster than
  257. //using the findFirstXXXX methods
  258. NameRecord record = getSpecificBuiltinRecord(name, sheetIndex);
  259. if (record != null) {
  260. _definedNames.remove(record);
  261. }
  262. // TODO - do we need "Workbook.records.remove(...);" similar to that in Workbook.removeName(int namenum) {}?
  263. }
  264. public int getNumNames() {
  265. return _definedNames.size();
  266. }
  267. public NameRecord getNameRecord(int index) {
  268. return _definedNames.get(index);
  269. }
  270. public void addName(NameRecord name) {
  271. _definedNames.add(name);
  272. // TODO - this is messy
  273. // Not the most efficient way but the other way was causing too many bugs
  274. int idx = findFirstRecordLocBySid(ExternSheetRecord.sid);
  275. if (idx == -1) idx = findFirstRecordLocBySid(SupBookRecord.sid);
  276. if (idx == -1) idx = findFirstRecordLocBySid(CountryRecord.sid);
  277. int countNames = _definedNames.size();
  278. _workbookRecordList.add(idx+countNames, name);
  279. }
  280. public void removeName(int namenum) {
  281. _definedNames.remove(namenum);
  282. }
  283. /**
  284. * checks if the given name is already included in the linkTable
  285. */
  286. public boolean nameAlreadyExists(NameRecord name)
  287. {
  288. // Check to ensure no other names have the same case-insensitive name
  289. for ( int i = getNumNames()-1; i >=0; i-- ) {
  290. NameRecord rec = getNameRecord(i);
  291. if (rec != name) {
  292. if (isDuplicatedNames(name, rec))
  293. return true;
  294. }
  295. }
  296. return false;
  297. }
  298. private static boolean isDuplicatedNames(NameRecord firstName, NameRecord lastName) {
  299. return lastName.getNameText().equalsIgnoreCase(firstName.getNameText())
  300. && isSameSheetNames(firstName, lastName);
  301. }
  302. private static boolean isSameSheetNames(NameRecord firstName, NameRecord lastName) {
  303. return lastName.getSheetNumber() == firstName.getSheetNumber();
  304. }
  305. public String[] getExternalBookAndSheetName(int extRefIndex) {
  306. int ebIx = _externSheetRecord.getExtbookIndexFromRefIndex(extRefIndex);
  307. SupBookRecord ebr = _externalBookBlocks[ebIx].getExternalBookRecord();
  308. if (!ebr.isExternalReferences()) {
  309. return null;
  310. }
  311. // Sheet name only applies if not a global reference
  312. int shIx = _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex);
  313. String usSheetName = null;
  314. if(shIx >= 0) {
  315. usSheetName = ebr.getSheetNames()[shIx];
  316. }
  317. return new String[] {
  318. ebr.getURL(),
  319. usSheetName,
  320. };
  321. }
  322. public int getExternalSheetIndex(String workbookName, String sheetName) {
  323. SupBookRecord ebrTarget = null;
  324. int externalBookIndex = -1;
  325. for (int i=0; i<_externalBookBlocks.length; i++) {
  326. SupBookRecord ebr = _externalBookBlocks[i].getExternalBookRecord();
  327. if (!ebr.isExternalReferences()) {
  328. continue;
  329. }
  330. if (workbookName.equals(ebr.getURL())) { // not sure if 'equals()' works when url has a directory
  331. ebrTarget = ebr;
  332. externalBookIndex = i;
  333. break;
  334. }
  335. }
  336. if (ebrTarget == null) {
  337. throw new RuntimeException("No external workbook with name '" + workbookName + "'");
  338. }
  339. int sheetIndex = getSheetIndex(ebrTarget.getSheetNames(), sheetName);
  340. int result = _externSheetRecord.getRefIxForSheet(externalBookIndex, sheetIndex);
  341. if (result < 0) {
  342. throw new RuntimeException("ExternSheetRecord does not contain combination ("
  343. + externalBookIndex + ", " + sheetIndex + ")");
  344. }
  345. return result;
  346. }
  347. private static int getSheetIndex(String[] sheetNames, String sheetName) {
  348. for (int i = 0; i < sheetNames.length; i++) {
  349. if (sheetNames[i].equals(sheetName)) {
  350. return i;
  351. }
  352. }
  353. throw new RuntimeException("External workbook does not contain sheet '" + sheetName + "'");
  354. }
  355. /**
  356. * @param extRefIndex as from a {@link Ref3DPtg} or {@link Area3DPtg}
  357. * @return -1 if the reference is to an external book
  358. */
  359. public int getIndexToInternalSheet(int extRefIndex) {
  360. return _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex);
  361. }
  362. public void updateIndexToInternalSheet(int extRefIndex, int offset) {
  363. _externSheetRecord.adjustIndex(extRefIndex, offset);
  364. }
  365. public int getSheetIndexFromExternSheetIndex(int extRefIndex) {
  366. if (extRefIndex >= _externSheetRecord.getNumOfRefs() || extRefIndex < 0) {
  367. return -1;
  368. }
  369. return _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex);
  370. }
  371. public int checkExternSheet(int sheetIndex) {
  372. int thisWbIndex = -1; // this is probably always zero
  373. for (int i=0; i<_externalBookBlocks.length; i++) {
  374. SupBookRecord ebr = _externalBookBlocks[i].getExternalBookRecord();
  375. if (ebr.isInternalReferences()) {
  376. thisWbIndex = i;
  377. break;
  378. }
  379. }
  380. if (thisWbIndex < 0) {
  381. throw new RuntimeException("Could not find 'internal references' EXTERNALBOOK");
  382. }
  383. //Trying to find reference to this sheet
  384. int i = _externSheetRecord.getRefIxForSheet(thisWbIndex, sheetIndex);
  385. if (i>=0) {
  386. return i;
  387. }
  388. //We haven't found reference to this sheet
  389. return _externSheetRecord.addRef(thisWbIndex, sheetIndex, sheetIndex);
  390. }
  391. /**
  392. * copied from Workbook
  393. */
  394. private int findFirstRecordLocBySid(short sid) {
  395. int index = 0;
  396. for (Iterator iterator = _workbookRecordList.iterator(); iterator.hasNext(); ) {
  397. Record record = ( Record ) iterator.next();
  398. if (record.getSid() == sid) {
  399. return index;
  400. }
  401. index ++;
  402. }
  403. return -1;
  404. }
  405. public String resolveNameXText(int refIndex, int definedNameIndex) {
  406. int extBookIndex = _externSheetRecord.getExtbookIndexFromRefIndex(refIndex);
  407. return _externalBookBlocks[extBookIndex].getNameText(definedNameIndex);
  408. }
  409. public int resolveNameXIx(int refIndex, int definedNameIndex) {
  410. int extBookIndex = _externSheetRecord.getExtbookIndexFromRefIndex(refIndex);
  411. return _externalBookBlocks[extBookIndex].getNameIx(definedNameIndex);
  412. }
  413. public NameXPtg getNameXPtg(String name) {
  414. // first find any external book block that contains the name:
  415. for (int i = 0; i < _externalBookBlocks.length; i++) {
  416. int definedNameIndex = _externalBookBlocks[i].getIndexOfName(name);
  417. if (definedNameIndex < 0) {
  418. continue;
  419. }
  420. // found it.
  421. int sheetRefIndex = findRefIndexFromExtBookIndex(i);
  422. if (sheetRefIndex >= 0) {
  423. return new NameXPtg(sheetRefIndex, definedNameIndex);
  424. }
  425. }
  426. return null;
  427. }
  428. /**
  429. * Register an external name in this workbook
  430. *
  431. * @param name the name to register
  432. * @return a NameXPtg describing this name
  433. */
  434. public NameXPtg addNameXPtg(String name) {
  435. int extBlockIndex = -1;
  436. ExternalBookBlock extBlock = null;
  437. // find ExternalBlock for Add-In functions and remember its index
  438. for (int i = 0; i < _externalBookBlocks.length; i++) {
  439. SupBookRecord ebr = _externalBookBlocks[i].getExternalBookRecord();
  440. if (ebr.isAddInFunctions()) {
  441. extBlock = _externalBookBlocks[i];
  442. extBlockIndex = i;
  443. break;
  444. }
  445. }
  446. // An ExternalBlock for Add-In functions was not found. Create a new one.
  447. if (extBlock == null) {
  448. extBlock = new ExternalBookBlock();
  449. ExternalBookBlock[] tmp = new ExternalBookBlock[_externalBookBlocks.length + 1];
  450. System.arraycopy(_externalBookBlocks, 0, tmp, 0, _externalBookBlocks.length);
  451. tmp[tmp.length - 1] = extBlock;
  452. _externalBookBlocks = tmp;
  453. extBlockIndex = _externalBookBlocks.length - 1;
  454. // add the created SupBookRecord before ExternSheetRecord
  455. int idx = findFirstRecordLocBySid(ExternSheetRecord.sid);
  456. _workbookRecordList.add(idx, extBlock.getExternalBookRecord());
  457. // register the SupBookRecord in the ExternSheetRecord
  458. // -2 means that the scope of this name is Workbook and the reference applies to the entire workbook.
  459. _externSheetRecord.addRef(_externalBookBlocks.length - 1, -2, -2);
  460. }
  461. // create a ExternalNameRecord that will describe this name
  462. ExternalNameRecord extNameRecord = new ExternalNameRecord();
  463. extNameRecord.setText(name);
  464. // The docs don't explain why Excel set the formula to #REF!
  465. extNameRecord.setParsedExpression(new Ptg[]{ErrPtg.REF_INVALID});
  466. int nameIndex = extBlock.addExternalName(extNameRecord);
  467. int supLinkIndex = 0;
  468. // find the posistion of the Add-In SupBookRecord in the workbook stream,
  469. // the created ExternalNameRecord will be appended to it
  470. for (Iterator<Record> iterator = _workbookRecordList.iterator(); iterator.hasNext(); supLinkIndex++) {
  471. Record record = iterator.next();
  472. if (record instanceof SupBookRecord) {
  473. if (((SupBookRecord) record).isAddInFunctions()) break;
  474. }
  475. }
  476. int numberOfNames = extBlock.getNumberOfNames();
  477. // a new name is inserted in the end of the SupBookRecord, after the last name
  478. _workbookRecordList.add(supLinkIndex + numberOfNames, extNameRecord);
  479. int ix = _externSheetRecord.getRefIxForSheet(extBlockIndex, -2 /* the scope is workbook*/);
  480. return new NameXPtg(ix, nameIndex);
  481. }
  482. private int findRefIndexFromExtBookIndex(int extBookIndex) {
  483. return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex);
  484. }
  485. /**
  486. * Changes an external referenced file to another file.
  487. * A formular in Excel which refers a cell in another file is saved in two parts:
  488. * The referenced file is stored in an reference table. the row/cell information is saved separate.
  489. * This method invokation will only change the reference in the lookup-table itself.
  490. * @param oldUrl The old URL to search for and which is to be replaced
  491. * @param newUrl The URL replacement
  492. * @return true if the oldUrl was found and replaced with newUrl. Otherwise false
  493. */
  494. public boolean changeExternalReference(String oldUrl, String newUrl) {
  495. for(ExternalBookBlock ex : _externalBookBlocks) {
  496. SupBookRecord externalRecord = ex.getExternalBookRecord();
  497. if (externalRecord.isExternalReferences()
  498. && externalRecord.getURL().equals(oldUrl)) {
  499. externalRecord.setURL(newUrl);
  500. return true;
  501. }
  502. }
  503. return false;
  504. }
  505. }