1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 package org.apache.openoffice.ooxml.parser.type;
23 
24 import org.apache.openoffice.ooxml.parser.NameMap;
25 
26 public class BlobParser implements ISimpleTypeParser
27 {
BlobParser(final String[] aLine)28     public BlobParser(final String[] aLine)
29     {
30         switch(aLine[5])
31         {
32             case "B":
33                 meType = Type.Base64Binary;
34                 break;
35             case "H":
36                 meType = Type.HexBinary;
37                 break;
38             default:
39                 throw new RuntimeException();
40         }
41         switch(aLine[6])
42         {
43             case "L":
44                 mnLengthRestriction = Integer.parseInt(aLine[7]);
45                 break;
46             case "N":
47                 mnLengthRestriction = null;
48                 break;
49             default:
50                 throw new RuntimeException();
51         }
52     }
53 
54 
55 
56 
57     @Override
Parse( final String sRawValue, final NameMap aAttributeValueMap)58     public Object Parse (
59         final String sRawValue,
60         final NameMap aAttributeValueMap)
61     {
62         if (mnLengthRestriction != null)
63             if (sRawValue.length()/2 != mnLengthRestriction)
64                 return null;
65         /*
66                 throw new RuntimeException(
67                     String.format(
68                         "length restriction (=%d) is violated, actual length is %d",
69                         mnLengthRestriction,
70                         sRawValue.length()));
71           */
72         switch(meType)
73         {
74             case Base64Binary:
75                 throw new RuntimeException("not yet implemented");
76 
77             case HexBinary:
78                 try
79                 {
80                     return Integer.parseInt(sRawValue, 16);
81                 }
82                 catch (NumberFormatException aException)
83                 {
84                     return null;
85                 }
86 
87             default:
88                 throw new RuntimeException();
89         }
90     }
91 
92 
93 
94 
95     enum Type
96     {
97         Base64Binary,
98         HexBinary
99     };
100     private final Type meType;
101     private final Integer mnLengthRestriction;
102 }
103