001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.pd;
031:
032: import java.net.MalformedURLException;
033: import java.net.URL;
034:
035: import de.intarsys.pdf.cos.COSName;
036: import de.intarsys.pdf.cos.COSObject;
037: import de.intarsys.pdf.cos.COSRuntimeException;
038: import de.intarsys.pdf.cos.COSString;
039:
040: public class PDFileSpecificationURL extends PDFileSpecification {
041: // todo 2 review url attribute
042:
043: /**
044: * The meta class implementation
045: */
046: static public class MetaClass extends PDFileSpecification.MetaClass {
047: protected MetaClass(Class instanceClass) {
048: super (instanceClass);
049: }
050: }
051:
052: /** The meta class instance */
053: static public final MetaClass META = new MetaClass(MetaClass.class
054: .getDeclaringClass());
055:
056: private URL url = null;
057:
058: protected PDFileSpecificationURL(COSObject object) {
059: super (object);
060: }
061:
062: public void setURL(URL newURL) {
063: this .url = newURL;
064: if (newURL == null) {
065: setFieldString(DK_F, null);
066: } else {
067: setFieldString(DK_F, url.toString());
068: }
069: }
070:
071: public URL getURL() {
072: return url;
073: }
074:
075: static public PDFileSpecificationURL createNew(URL url) {
076: PDFileSpecificationURL result = (PDFileSpecificationURL) META
077: .createNew();
078: result.setURL(url);
079: return result;
080: }
081:
082: /**
083: * provide some hook for initialization after creation based on a cos object
084: */
085: protected void initializeFromCos() {
086: super .initializeFromCos();
087: setFileSystem(CN_FS_URL);
088: COSString fileString = cosGetField(DK_F).asString();
089: if (fileString != null) {
090: try {
091: setURL(new URL(fileString.stringValue()));
092: } catch (MalformedURLException e) {
093: cosGetObject()
094: .handleException(
095: new COSRuntimeException(
096: "error parsing URL", e));
097: }
098: }
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see de.intarsys.pdf.pd.PDFileSpecification#initializeFromScratch()
105: */
106: protected void initializeFromScratch() {
107: super .initializeFromScratch();
108: setFileSystem((COSName) CN_FS_URL.copyShallow());
109: }
110: }
|