001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.repository.metadata.jcr; 017 018import javax.jcr.Node; 019import javax.jcr.RepositoryException; 020 021import org.apache.jackrabbit.JcrConstants; 022import org.apache.jackrabbit.util.Text; 023 024import org.ametys.plugins.repository.AmetysRepositoryException; 025import org.ametys.plugins.repository.metadata.ModifiableFile; 026 027/** 028 * Java binding of a nt:file JCR Node.<p> 029 * {@link Text#escapeIllegalJcrChars(String)} is used for 030 * escaping invalid JCR characters or character sequences. 031 * @deprecated org.ametys.cms.data.RichText new class doesn't use folder anymore 032 */ 033@Deprecated 034public class JCRFile implements ModifiableFile 035{ 036 private Node _node; 037 038 /** 039 * Constructor 040 * @param node the nt:file Node 041 */ 042 public JCRFile(Node node) 043 { 044 _node = node; 045 } 046 047 /** 048 * Retrieves the underlying node. 049 * @return the underlying node. 050 */ 051 public Node getNode() 052 { 053 return _node; 054 } 055 056 @Override 057 public String getName() throws AmetysRepositoryException 058 { 059 try 060 { 061 return Text.unescapeIllegalJcrChars(_node.getName()); 062 } 063 catch (RepositoryException e) 064 { 065 throw new AmetysRepositoryException(e); 066 } 067 } 068 069 public JCRResource getResource() throws AmetysRepositoryException 070 { 071 try 072 { 073 Node resourceNode = null; 074 075 if (_node.hasNode(JcrConstants.JCR_CONTENT)) 076 { 077 // Already exists 078 resourceNode = _node.getNode(JcrConstants.JCR_CONTENT); 079 } 080 else 081 { 082 resourceNode = _node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); 083 } 084 085 return new JCRResource(resourceNode); 086 } 087 catch (RepositoryException e) 088 { 089 throw new AmetysRepositoryException(e); 090 } 091 } 092}