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.

PackagingURIHelper.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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.openxml4j.opc;
  16. import java.net.URI;
  17. import java.net.URISyntaxException;
  18. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  19. import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
  20. /**
  21. * Helper for part and pack URI.
  22. *
  23. * @author Julien Chable, CDubet, Kim Ung
  24. * @version 0.1
  25. */
  26. public final class PackagingURIHelper {
  27. /**
  28. * Package root URI.
  29. */
  30. private static URI packageRootUri;
  31. /**
  32. * Extension name of a relationship part.
  33. */
  34. public static final String RELATIONSHIP_PART_EXTENSION_NAME;
  35. /**
  36. * Segment name of a relationship part.
  37. */
  38. public static final String RELATIONSHIP_PART_SEGMENT_NAME;
  39. /**
  40. * Segment name of the package properties folder.
  41. */
  42. public static final String PACKAGE_PROPERTIES_SEGMENT_NAME;
  43. /**
  44. * Core package properties art name.
  45. */
  46. public static final String PACKAGE_CORE_PROPERTIES_NAME;
  47. /**
  48. * Forward slash URI separator.
  49. */
  50. public static final char FORWARD_SLASH_CHAR;
  51. /**
  52. * Forward slash URI separator.
  53. */
  54. public static final String FORWARD_SLASH_STRING;
  55. /**
  56. * Package relationships part URI
  57. */
  58. public static final URI PACKAGE_RELATIONSHIPS_ROOT_URI;
  59. /**
  60. * Package relationships part name.
  61. */
  62. public static final PackagePartName PACKAGE_RELATIONSHIPS_ROOT_PART_NAME;
  63. /**
  64. * Core properties part URI.
  65. */
  66. public static final URI CORE_PROPERTIES_URI;
  67. /**
  68. * Core properties partname.
  69. */
  70. public static final PackagePartName CORE_PROPERTIES_PART_NAME;
  71. /**
  72. * Root package URI.
  73. */
  74. public static final URI PACKAGE_ROOT_URI;
  75. /**
  76. * Root package part name.
  77. */
  78. public static final PackagePartName PACKAGE_ROOT_PART_NAME;
  79. /* Static initialization */
  80. static {
  81. RELATIONSHIP_PART_SEGMENT_NAME = "_rels";
  82. RELATIONSHIP_PART_EXTENSION_NAME = ".rels";
  83. FORWARD_SLASH_CHAR = '/';
  84. FORWARD_SLASH_STRING = "/";
  85. PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps";
  86. PACKAGE_CORE_PROPERTIES_NAME = "core.xml";
  87. // Make URI
  88. URI uriPACKAGE_ROOT_URI = null;
  89. URI uriPACKAGE_RELATIONSHIPS_ROOT_URI = null;
  90. URI uriPACKAGE_PROPERTIES_URI = null;
  91. try {
  92. uriPACKAGE_ROOT_URI = new URI("/");
  93. uriPACKAGE_RELATIONSHIPS_ROOT_URI = new URI(FORWARD_SLASH_CHAR
  94. + RELATIONSHIP_PART_SEGMENT_NAME + FORWARD_SLASH_CHAR
  95. + RELATIONSHIP_PART_EXTENSION_NAME);
  96. packageRootUri = new URI("/");
  97. uriPACKAGE_PROPERTIES_URI = new URI(FORWARD_SLASH_CHAR
  98. + PACKAGE_PROPERTIES_SEGMENT_NAME + FORWARD_SLASH_CHAR
  99. + PACKAGE_CORE_PROPERTIES_NAME);
  100. } catch (URISyntaxException e) {
  101. // Should never happen in production as all data are fixed
  102. }
  103. PACKAGE_ROOT_URI = uriPACKAGE_ROOT_URI;
  104. PACKAGE_RELATIONSHIPS_ROOT_URI = uriPACKAGE_RELATIONSHIPS_ROOT_URI;
  105. CORE_PROPERTIES_URI = uriPACKAGE_PROPERTIES_URI;
  106. // Make part name from previous URI
  107. PackagePartName tmpPACKAGE_ROOT_PART_NAME = null;
  108. PackagePartName tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME = null;
  109. PackagePartName tmpCORE_PROPERTIES_URI = null;
  110. try {
  111. tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME = createPartName(PACKAGE_RELATIONSHIPS_ROOT_URI);
  112. tmpCORE_PROPERTIES_URI = createPartName(CORE_PROPERTIES_URI);
  113. tmpPACKAGE_ROOT_PART_NAME = new PackagePartName(PACKAGE_ROOT_URI,
  114. false);
  115. } catch (InvalidFormatException e) {
  116. // Should never happen in production as all data are fixed
  117. }
  118. PACKAGE_RELATIONSHIPS_ROOT_PART_NAME = tmpPACKAGE_RELATIONSHIPS_ROOT_PART_NAME;
  119. CORE_PROPERTIES_PART_NAME = tmpCORE_PROPERTIES_URI;
  120. PACKAGE_ROOT_PART_NAME = tmpPACKAGE_ROOT_PART_NAME;
  121. }
  122. /**
  123. * Gets the URI for the package root.
  124. *
  125. * @return URI of the package root.
  126. */
  127. public static URI getPackageRootUri() {
  128. return packageRootUri;
  129. }
  130. /**
  131. * Know if the specified URI is a relationship part name.
  132. *
  133. * @param partUri
  134. * URI to check.
  135. * @return <i>true</i> if the URI <i>false</i>.
  136. */
  137. public static boolean isRelationshipPartURI(URI partUri) {
  138. if (partUri == null)
  139. throw new IllegalArgumentException("partUri");
  140. return partUri.getPath().matches(
  141. ".*" + RELATIONSHIP_PART_SEGMENT_NAME + ".*"
  142. + RELATIONSHIP_PART_EXTENSION_NAME + "$");
  143. }
  144. /**
  145. * Get file name from the specified URI.
  146. */
  147. public static String getFilename(URI uri) {
  148. if (uri != null) {
  149. String path = uri.getPath();
  150. int len = path.length();
  151. int num2 = len;
  152. while (--num2 >= 0) {
  153. char ch1 = path.charAt(num2);
  154. if (ch1 == PackagingURIHelper.FORWARD_SLASH_CHAR)
  155. return path.substring(num2 + 1, len);
  156. }
  157. }
  158. return "";
  159. }
  160. /**
  161. * Get the file name without the trailing extension.
  162. */
  163. public static String getFilenameWithoutExtension(URI uri) {
  164. String filename = getFilename(uri);
  165. int dotIndex = filename.lastIndexOf(".");
  166. if (dotIndex == -1)
  167. return filename;
  168. return filename.substring(0, dotIndex);
  169. }
  170. /**
  171. * Get the directory path from the specified URI.
  172. */
  173. public static URI getPath(URI uri) {
  174. if (uri != null) {
  175. String path = uri.getPath();
  176. int len = path.length();
  177. int num2 = len;
  178. while (--num2 >= 0) {
  179. char ch1 = path.charAt(num2);
  180. if (ch1 == PackagingURIHelper.FORWARD_SLASH_CHAR) {
  181. try {
  182. return new URI(path.substring(0, num2));
  183. } catch (URISyntaxException e) {
  184. return null;
  185. }
  186. }
  187. }
  188. }
  189. return null;
  190. }
  191. /**
  192. * Combine two URIs.
  193. *
  194. * @param prefix the prefix URI
  195. * @param suffix the suffix URI
  196. *
  197. * @return the combined URI
  198. */
  199. public static URI combine(URI prefix, URI suffix) {
  200. URI retUri = null;
  201. try {
  202. retUri = new URI(combine(prefix.getPath(), suffix.getPath()));
  203. } catch (URISyntaxException e) {
  204. throw new IllegalArgumentException(
  205. "Prefix and suffix can't be combine !");
  206. }
  207. return retUri;
  208. }
  209. /**
  210. * Combine a string URI with a prefix and a suffix.
  211. */
  212. public static String combine(String prefix, String suffix) {
  213. if (!prefix.endsWith("" + FORWARD_SLASH_CHAR)
  214. && !suffix.startsWith("" + FORWARD_SLASH_CHAR))
  215. return prefix + FORWARD_SLASH_CHAR + suffix;
  216. else if ((!prefix.endsWith("" + FORWARD_SLASH_CHAR)
  217. && suffix.startsWith("" + FORWARD_SLASH_CHAR) || (prefix
  218. .endsWith("" + FORWARD_SLASH_CHAR) && !suffix.startsWith(""
  219. + FORWARD_SLASH_CHAR))))
  220. return prefix + suffix;
  221. else
  222. return "";
  223. }
  224. /**
  225. * Fully relativize the source part URI against the target part URI.
  226. *
  227. * @param sourceURI
  228. * The source part URI.
  229. * @param targetURI
  230. * The target part URI.
  231. * @param msCompatible if true then remove leading slash from the relativized URI.
  232. * This flag violates [M1.4]: A part name shall start with a forward slash ('/') character, but
  233. * allows generating URIs compatible with MS Office and OpenOffice.
  234. * @return A fully relativize part name URI ('word/media/image1.gif',
  235. * '/word/document.xml' => 'media/image1.gif') else
  236. * <code>null</code>.
  237. */
  238. public static URI relativizeURI(URI sourceURI, URI targetURI, boolean msCompatible) {
  239. StringBuilder retVal = new StringBuilder();
  240. String[] segmentsSource = sourceURI.getPath().split("/", -1);
  241. String[] segmentsTarget = targetURI.getPath().split("/", -1);
  242. // If the source URI is empty
  243. if (segmentsSource.length == 0) {
  244. throw new IllegalArgumentException(
  245. "Can't relativize an empty source URI !");
  246. }
  247. // If target URI is empty
  248. if (segmentsTarget.length == 0) {
  249. throw new IllegalArgumentException(
  250. "Can't relativize an empty target URI !");
  251. }
  252. // If the source is the root, then the relativized
  253. // form must actually be an absolute URI
  254. if(sourceURI.toString().equals("/")) {
  255. String path = targetURI.getPath();
  256. if(msCompatible && path.charAt(0) == '/') {
  257. try {
  258. targetURI = new URI(path.substring(1));
  259. } catch (Exception e) {
  260. System.err.println(e);
  261. return null;
  262. }
  263. }
  264. return targetURI;
  265. }
  266. // Relativize the source URI against the target URI.
  267. // First up, figure out how many steps along we can go
  268. // and still have them be the same
  269. int segmentsTheSame = 0;
  270. for (int i = 0; i < segmentsSource.length && i < segmentsTarget.length; i++) {
  271. if (segmentsSource[i].equals(segmentsTarget[i])) {
  272. // Match so far, good
  273. segmentsTheSame++;
  274. } else {
  275. break;
  276. }
  277. }
  278. // If we didn't have a good match or at least except a first empty element
  279. if ((segmentsTheSame == 0 || segmentsTheSame == 1) &&
  280. segmentsSource[0].equals("") && segmentsTarget[0].equals("")) {
  281. for (int i = 0; i < segmentsSource.length - 2; i++) {
  282. retVal.append("../");
  283. }
  284. for (int i = 0; i < segmentsTarget.length; i++) {
  285. if (segmentsTarget[i].equals(""))
  286. continue;
  287. retVal.append(segmentsTarget[i]);
  288. if (i != segmentsTarget.length - 1)
  289. retVal.append("/");
  290. }
  291. try {
  292. return new URI(retVal.toString());
  293. } catch (Exception e) {
  294. System.err.println(e);
  295. return null;
  296. }
  297. }
  298. // Special case for where the two are the same
  299. if (segmentsTheSame == segmentsSource.length
  300. && segmentsTheSame == segmentsTarget.length) {
  301. retVal.append("");
  302. } else {
  303. // Matched for so long, but no more
  304. // Do we need to go up a directory or two from
  305. // the source to get here?
  306. // (If it's all the way up, then don't bother!)
  307. if (segmentsTheSame == 1) {
  308. retVal.append("/");
  309. } else {
  310. for (int j = segmentsTheSame; j < segmentsSource.length - 1; j++) {
  311. retVal.append("../");
  312. }
  313. }
  314. // Now go from here on down
  315. for (int j = segmentsTheSame; j < segmentsTarget.length; j++) {
  316. if (retVal.length() > 0
  317. && retVal.charAt(retVal.length() - 1) != '/') {
  318. retVal.append("/");
  319. }
  320. retVal.append(segmentsTarget[j]);
  321. }
  322. }
  323. try {
  324. return new URI(retVal.toString());
  325. } catch (Exception e) {
  326. System.err.println(e);
  327. return null;
  328. }
  329. }
  330. /**
  331. * Fully relativize the source part URI against the target part URI.
  332. *
  333. * @param sourceURI
  334. * The source part URI.
  335. * @param targetURI
  336. * The target part URI.
  337. * @return A fully relativize part name URI ('word/media/image1.gif',
  338. * '/word/document.xml' => 'media/image1.gif') else
  339. * <code>null</code>.
  340. */
  341. public static URI relativizeURI(URI sourceURI, URI targetURI) {
  342. return relativizeURI(sourceURI, targetURI, false);
  343. }
  344. /**
  345. * Resolve a source uri against a target.
  346. *
  347. * @param sourcePartUri
  348. * The source URI.
  349. * @param targetUri
  350. * The target URI.
  351. * @return The resolved URI.
  352. */
  353. public static URI resolvePartUri(URI sourcePartUri, URI targetUri) {
  354. if (sourcePartUri == null || sourcePartUri.isAbsolute()) {
  355. throw new IllegalArgumentException("sourcePartUri invalid - "
  356. + sourcePartUri);
  357. }
  358. if (targetUri == null || targetUri.isAbsolute()) {
  359. throw new IllegalArgumentException("targetUri invalid - "
  360. + targetUri);
  361. }
  362. return sourcePartUri.resolve(targetUri);
  363. }
  364. /**
  365. * Get URI from a string path.
  366. */
  367. public static URI getURIFromPath(String path) {
  368. URI retUri = null;
  369. try {
  370. retUri = new URI(path);
  371. } catch (URISyntaxException e) {
  372. throw new IllegalArgumentException("path");
  373. }
  374. return retUri;
  375. }
  376. /**
  377. * Get the source part URI from a specified relationships part.
  378. *
  379. * @param relationshipPartUri
  380. * The relationship part use to retrieve the source part.
  381. * @return The source part URI from the specified relationships part.
  382. */
  383. public static URI getSourcePartUriFromRelationshipPartUri(
  384. URI relationshipPartUri) {
  385. if (relationshipPartUri == null)
  386. throw new IllegalArgumentException(
  387. "Must not be null");
  388. if (!isRelationshipPartURI(relationshipPartUri))
  389. throw new IllegalArgumentException(
  390. "Must be a relationship part");
  391. if (relationshipPartUri.compareTo(PACKAGE_RELATIONSHIPS_ROOT_URI) == 0)
  392. return PACKAGE_ROOT_URI;
  393. String filename = relationshipPartUri.getPath();
  394. String filenameWithoutExtension = getFilenameWithoutExtension(relationshipPartUri);
  395. filename = filename
  396. .substring(0, ((filename.length() - filenameWithoutExtension
  397. .length()) - RELATIONSHIP_PART_EXTENSION_NAME.length()));
  398. filename = filename.substring(0, filename.length()
  399. - RELATIONSHIP_PART_SEGMENT_NAME.length() - 1);
  400. filename = combine(filename, filenameWithoutExtension);
  401. return getURIFromPath(filename);
  402. }
  403. /**
  404. * Create an OPC compliant part name by throwing an exception if the URI is
  405. * not valid.
  406. *
  407. * @param partUri
  408. * The part name URI to validate.
  409. * @return A valid part name object, else <code>null</code>.
  410. * @throws InvalidFormatException
  411. * Throws if the specified URI is not OPC compliant.
  412. */
  413. public static PackagePartName createPartName(URI partUri)
  414. throws InvalidFormatException {
  415. if (partUri == null)
  416. throw new IllegalArgumentException("partName");
  417. return new PackagePartName(partUri, true);
  418. }
  419. /**
  420. * Create an OPC compliant part name.
  421. *
  422. * @param partName
  423. * The part name to validate.
  424. * @return The correspondant part name if valid, else <code>null</code>.
  425. * @throws InvalidFormatException
  426. * Throws if the specified part name is not OPC compliant.
  427. * @see #createPartName(URI)
  428. */
  429. public static PackagePartName createPartName(String partName)
  430. throws InvalidFormatException {
  431. URI partNameURI;
  432. try {
  433. partNameURI = new URI(resolvePartName(partName));
  434. } catch (URISyntaxException e) {
  435. throw new InvalidFormatException(e.getMessage());
  436. }
  437. return createPartName(partNameURI);
  438. }
  439. /**
  440. * Create an OPC compliant part name by resolving it using a base part.
  441. *
  442. * @param partName
  443. * The part name to validate.
  444. * @param relativePart
  445. * The relative base part.
  446. * @return The correspondant part name if valid, else <code>null</code>.
  447. * @throws InvalidFormatException
  448. * Throws if the specified part name is not OPC compliant.
  449. * @see #createPartName(URI)
  450. */
  451. public static PackagePartName createPartName(String partName,
  452. PackagePart relativePart) throws InvalidFormatException {
  453. URI newPartNameURI;
  454. try {
  455. newPartNameURI = resolvePartUri(
  456. relativePart.getPartName().getURI(), new URI(partName));
  457. } catch (URISyntaxException e) {
  458. throw new InvalidFormatException(e.getMessage());
  459. }
  460. return createPartName(newPartNameURI);
  461. }
  462. /**
  463. * Create an OPC compliant part name by resolving it using a base part.
  464. *
  465. * @param partName
  466. * The part name URI to validate.
  467. * @param relativePart
  468. * The relative base part.
  469. * @return The correspondant part name if valid, else <code>null</code>.
  470. * @throws InvalidFormatException
  471. * Throws if the specified part name is not OPC compliant.
  472. * @see #createPartName(URI)
  473. */
  474. public static PackagePartName createPartName(URI partName,
  475. PackagePart relativePart) throws InvalidFormatException {
  476. URI newPartNameURI = resolvePartUri(
  477. relativePart.getPartName().getURI(), partName);
  478. return createPartName(newPartNameURI);
  479. }
  480. /**
  481. * Validate a part URI by returning a boolean.
  482. * ([M1.1],[M1.3],[M1.4],[M1.5],[M1.6])
  483. *
  484. * (OPC Specifications 8.1.1 Part names) :
  485. *
  486. * Part Name Syntax
  487. *
  488. * The part name grammar is defined as follows:
  489. *
  490. * <i>part_name = 1*( "/" segment )
  491. *
  492. * segment = 1*( pchar )</i>
  493. *
  494. *
  495. * (pchar is defined in RFC 3986)
  496. *
  497. * @param partUri
  498. * The URI to validate.
  499. * @return <b>true</b> if the URI is valid to the OPC Specifications, else
  500. * <b>false</b>
  501. *
  502. * @see #createPartName(URI)
  503. */
  504. public static boolean isValidPartName(URI partUri) {
  505. if (partUri == null)
  506. throw new IllegalArgumentException("partUri");
  507. try {
  508. createPartName(partUri);
  509. return true;
  510. } catch (Exception e) {
  511. return false;
  512. }
  513. }
  514. /**
  515. * Decode a URI by converting all percent encoded character into a String
  516. * character.
  517. *
  518. * @param uri
  519. * The URI to decode.
  520. * @return The specified URI in a String with converted percent encoded
  521. * characters.
  522. */
  523. public static String decodeURI(URI uri) {
  524. StringBuffer retVal = new StringBuffer();
  525. String uriStr = uri.toASCIIString();
  526. char c;
  527. for (int i = 0; i < uriStr.length(); ++i) {
  528. c = uriStr.charAt(i);
  529. if (c == '%') {
  530. // We certainly found an encoded character, check for length
  531. // now ( '%' HEXDIGIT HEXDIGIT)
  532. if (((uriStr.length() - i) < 2)) {
  533. throw new IllegalArgumentException("The uri " + uriStr
  534. + " contain invalid encoded character !");
  535. }
  536. // Decode the encoded character
  537. char decodedChar = (char) Integer.parseInt(uriStr.substring(
  538. i + 1, i + 3), 16);
  539. retVal.append(decodedChar);
  540. i += 2;
  541. continue;
  542. }
  543. retVal.append(c);
  544. }
  545. return retVal.toString();
  546. }
  547. /**
  548. * Build a part name where the relationship should be stored ((ex
  549. * /word/document.xml -> /word/_rels/document.xml.rels)
  550. *
  551. * @param partName
  552. * Source part URI
  553. * @return the full path (as URI) of the relation file
  554. * @throws InvalidOperationException
  555. * Throws if the specified URI is a relationshp part.
  556. */
  557. public static PackagePartName getRelationshipPartName(
  558. PackagePartName partName) {
  559. if (partName == null)
  560. throw new IllegalArgumentException("partName");
  561. if (PackagingURIHelper.PACKAGE_ROOT_URI.getPath().equals(
  562. partName.getURI().getPath()) )
  563. return PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME;
  564. if (partName.isRelationshipPartURI())
  565. throw new InvalidOperationException("Can't be a relationship part");
  566. String fullPath = partName.getURI().getPath();
  567. String filename = getFilename(partName.getURI());
  568. fullPath = fullPath.substring(0, fullPath.length() - filename.length());
  569. fullPath = combine(fullPath,
  570. PackagingURIHelper.RELATIONSHIP_PART_SEGMENT_NAME);
  571. fullPath = combine(fullPath, filename);
  572. fullPath = fullPath
  573. + PackagingURIHelper.RELATIONSHIP_PART_EXTENSION_NAME;
  574. PackagePartName retPartName;
  575. try {
  576. retPartName = createPartName(fullPath);
  577. } catch (InvalidFormatException e) {
  578. // Should never happen in production as all data are fixed but in
  579. // case of return null:
  580. return null;
  581. }
  582. return retPartName;
  583. }
  584. /**
  585. * If part name is not a valid URI, it is resolved as follows:
  586. * <p>
  587. * 1. Percent-encode each open bracket ([) and close bracket (]).</li>
  588. * 2. Percent-encode each percent (%) character that is not followed by a hexadecimal notation of an octet value.</li>
  589. * 3. Un-percent-encode each percent-encoded unreserved character.
  590. * 4. Un-percent-encode each forward slash (/) and back slash (\).
  591. * 5. Convert all back slashes to forward slashes.
  592. * 6. If present in a segment containing non-dot (?.?) characters, remove trailing dot (?.?) characters from each segment.
  593. * 7. Replace each occurrence of multiple consecutive forward slashes (/) with a single forward slash.
  594. * 8. If a single trailing forward slash (/) is present, remove that trailing forward slash.
  595. * 9. Remove complete segments that consist of three or more dots.
  596. * 10. Resolve the relative reference against the base URI of the part holding the Unicode string, as it is defined
  597. * in ?5.2 of RFC 3986. The path component of the resulting absolute URI is the part name.
  598. *</p>
  599. *
  600. * @param partName the name to resolve
  601. * @return the resolved part name that should be OK to construct a URI
  602. *
  603. * TODO YK: for now this method does only (5). Finish the rest.
  604. */
  605. public static String resolvePartName(String partName){
  606. return partName.replace('\\', '/');
  607. }
  608. }