Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/admin/Syndicator.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  
17  
18  package com.obinary.cms.admin;
19  
20  
21  import com.obinary.cms.beans.SubscriberInfo;
22  import com.obinary.cms.core.Content;
23  import com.obinary.cms.core.MetaData;
24  import com.obinary.cms.util.Resource;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.jcr.RepositoryException;
28  import java.util.Enumeration;
29  import java.util.Iterator;
30  import java.net.URL;
31  import java.net.URLConnection;
32  
33  
34  /**
35   * User: sameercharles
36   * Date: Sep 28, 2003
37   * Time: 11:20:59 AM
38   * @author Sameer Charles
39   * @version 1.0
40   */
41  
42  
43  public class Syndicator {
44  
45  
46      private static final int ACTIVATE = 1;
47      private static final int DE_ACTIVATE = 2;
48  
49  
50      private HttpServletRequest request;
51      private String parent;
52      private String path;
53      private boolean recursive;
54  
55  
56  
57  
58      public Syndicator(HttpServletRequest request) {
59          this.request = request;
60      }
61  
62  
63  
64      /**
65       *
66       * @param parent
67       * @param path
68       * @param recursive
69       * @throws Exception
70       * */
71      public synchronized void activate(String parent, String path, boolean recursive) throws Exception {
72          this.parent = parent;
73          this.path = path;
74          this.recursive = recursive;
75          Enumeration en = SubscriberInfo.getList();
76          while (en.hasMoreElements()) {
77              SubscriberInfo si = (SubscriberInfo)en.nextElement();
78              String handle = getActivationURL(si.getProtocol()+"://"+si.getAddress());
79              URL url = new URL(handle);
80              URLConnection urlConnection = url.openConnection();
81              urlConnection.setRequestProperty("Authorization",Authenticator.getCredentials(this.request));
82              urlConnection.getContent();
83          }
84          updateActivationDetails();
85      }
86  
87  
88  
89      /**
90       *
91       * @param path , to deactivate
92       */
93      public synchronized void deActivate(String path) throws Exception {
94          this.path = path;
95          Enumeration en = SubscriberInfo.getList();
96          while (en.hasMoreElements()) {
97              SubscriberInfo si = (SubscriberInfo)en.nextElement();
98              String handle = getActivationURL(si.getProtocol()+"://"+si.getAddress());
99              handle = si.getProtocol()+"://"+si.getAddress()+"/ActivationHandler?page="+this.path+"&action=deactivate";
100             URL url = new URL(handle);
101             URLConnection urlConnection = url.openConnection();
102             urlConnection.setRequestProperty("Authorization",Authenticator.getCredentials(this.request));
103             urlConnection.getContent();
104         }
105         updateDeActivationDetails();
106     }
107 
108 
109 
110     /**
111      *
112      * @return activation handle
113      */
114     private String getActivationURL(String subscriber) {
115         String handle;
116         if (this.recursive)
117             handle = subscriber+"/ActivationHandler?page="+this.path+"&parent="+this.parent+"&action=activate&recursive=true";
118         else
119             handle = subscriber+"/ActivationHandler?page="+this.path+"&parent="+this.parent+"&action=activate&recursive=false";
120         return handle;
121     }
122 
123 
124 
125     /**
126      */
127     private void updateActivationDetails()  throws RepositoryException {
128         Content page = Resource.getHierarchyManager(this.request).getPage(this.path);
129         updateMetaData(page,Syndicator.ACTIVATE);
130         if (this.recursive)
131             this.updateTree(page,Syndicator.ACTIVATE);
132     }
133 
134 
135 
136     /**
137      */
138     private void updateDeActivationDetails()  throws RepositoryException {
139         Content page = Resource.getHierarchyManager(this.request).getPage(this.path);
140         updateMetaData(page,Syndicator.DE_ACTIVATE);
141         this.updateTree(page,Syndicator.DE_ACTIVATE);
142     }
143 
144 
145 
146     /**
147      * @param startPage
148      */
149     private void updateTree(Content startPage, int type) {
150         Iterator children = startPage.getChildren().iterator();
151         while (children.hasNext()) {
152             Content aPage = (Content)children.next();
153             updateMetaData(aPage,type);
154             if (aPage.hasChildren())
155                 updateTree(aPage,type);
156         }
157     }
158 
159 
160 
161     /**
162      * @param page
163      */
164     private void updateMetaData(Content page, int type) {
165         try {
166             MetaData md = page.getMetaData(MetaData.ACTIVATION_INFO);
167             if (type == Syndicator.ACTIVATE)
168                 md.setActivated();
169             else
170                 md.setUnActivated();
171             md.setActivatorId(Authenticator.getUserId(this.request));
172             md.setLastActivationActionDate();
173             md = null;
174         } catch (RepositoryException re) {}
175     }
176 
177 
178 
179 
180 
181 }