forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ItemRegistry, ItemUIRegistry and ChartProvider support fo…
…r the compatibility layer. This fixes openhab#146. Signed-off-by: Kai Kreuzer <[email protected]> (github: @kaikreuzer)
- Loading branch information
1 parent
791e777
commit 60c3b88
Showing
33 changed files
with
2,216 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
bundles/core/org.openhab.core.compat1x/OSGI-INF/chartproviderfactory.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.openhab.core.compat1x.chartproviderfactory" immediate="true" > | ||
<implementation class="org.openhab.ui.chart.internal.ChartProviderFactory"/> | ||
<reference bind="addChartProvider" cardinality="0..n" interface="org.openhab.ui.chart.ChartProvider" name="ChartProvider" policy="dynamic" unbind="removeChartProvider"/> | ||
</scr:component> |
9 changes: 9 additions & 0 deletions
9
bundles/core/org.openhab.core.compat1x/OSGI-INF/itemuiregistry.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.openhab.core.compat1x.itemuiregistry"> | ||
<implementation class="org.openhab.core.items.internal.ItemUIRegistryDelegate"/> | ||
<service> | ||
<provide interface="org.openhab.core.items.ItemRegistry"/> | ||
<provide interface="org.openhab.ui.items.ItemUIRegistry"/> | ||
</service> | ||
<reference bind="setItemUIRegistry" cardinality="1..1" interface="org.eclipse.smarthome.ui.items.ItemUIRegistry" name="ItemUIRegistry" policy="static" unbind="unsetItemUIRegistry"/> | ||
</scr:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
...b.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
package org.openhab.core.items.internal; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.emf.common.util.EList; | ||
import org.eclipse.smarthome.core.common.registry.RegistryChangeListener; | ||
import org.openhab.core.compat1x.internal.ItemMapper; | ||
import org.openhab.core.items.Item; | ||
import org.openhab.core.items.ItemNotFoundException; | ||
import org.openhab.core.items.ItemNotUniqueException; | ||
import org.openhab.core.items.ItemRegistryChangeListener; | ||
import org.openhab.core.types.State; | ||
import org.openhab.model.sitemap.LinkableWidget; | ||
import org.openhab.model.sitemap.Sitemap; | ||
import org.openhab.model.sitemap.Widget; | ||
import org.openhab.ui.items.ItemUIRegistry; | ||
|
||
public class ItemUIRegistryDelegate implements ItemUIRegistry, RegistryChangeListener<org.eclipse.smarthome.core.items.Item> { | ||
|
||
private org.eclipse.smarthome.ui.items.ItemUIRegistry itemUIRegistry; | ||
private Set<ItemRegistryChangeListener> listeners = new HashSet<>(); | ||
|
||
protected void setItemUIRegistry(org.eclipse.smarthome.ui.items.ItemUIRegistry itemUIRegistry) { | ||
this.itemUIRegistry = itemUIRegistry; | ||
itemUIRegistry.addRegistryChangeListener(this); | ||
} | ||
|
||
protected void unsetItemUIRegistry(org.eclipse.smarthome.core.items.ItemRegistry itemUIRegistry) { | ||
this.itemUIRegistry = null; | ||
} | ||
|
||
@Override | ||
public Item getItem(String name) throws ItemNotFoundException { | ||
org.eclipse.smarthome.core.items.Item eshItem = itemUIRegistry.get(name); | ||
return ItemMapper.mapToOpenHABItem(eshItem); | ||
} | ||
|
||
@Override | ||
public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException { | ||
org.eclipse.smarthome.core.items.Item eshItem; | ||
try { | ||
eshItem = itemUIRegistry.getItemByPattern(name); | ||
} catch (org.eclipse.smarthome.core.items.ItemNotFoundException e) { | ||
throw new ItemNotFoundException(name); | ||
} catch (org.eclipse.smarthome.core.items.ItemNotUniqueException e) { | ||
throw new ItemNotUniqueException(name, null); | ||
} | ||
return ItemMapper.mapToOpenHABItem(eshItem); | ||
} | ||
|
||
@Override | ||
public Collection<Item> getItems() { | ||
Collection<org.eclipse.smarthome.core.items.Item> eshItems = itemUIRegistry.getItems(); | ||
Collection<Item> ohItems = new HashSet<Item>(eshItems.size()); | ||
|
||
for(org.eclipse.smarthome.core.items.Item eshItem : eshItems) { | ||
ohItems.add(ItemMapper.mapToOpenHABItem(eshItem)); | ||
} | ||
return ohItems; | ||
} | ||
|
||
@Override | ||
public Collection<Item> getItems(String pattern) { | ||
Collection<org.eclipse.smarthome.core.items.Item> eshItems = itemUIRegistry.getItems(pattern); | ||
Collection<Item> ohItems = new HashSet<Item>(eshItems.size()); | ||
|
||
for(org.eclipse.smarthome.core.items.Item eshItem : eshItems) { | ||
ohItems.add(ItemMapper.mapToOpenHABItem(eshItem)); | ||
} | ||
return ohItems; | ||
} | ||
|
||
@Override | ||
public boolean isValidItemName(String itemName) { | ||
return itemUIRegistry.isValidItemName(itemName); | ||
} | ||
|
||
@Override | ||
public void addItemRegistryChangeListener(ItemRegistryChangeListener listener) { | ||
this.listeners.add(listener); | ||
} | ||
|
||
@Override | ||
public void removeItemRegistryChangeListener(ItemRegistryChangeListener listener) { | ||
this.listeners.remove(listener); | ||
} | ||
|
||
@Override | ||
public void added(org.eclipse.smarthome.core.items.Item element) { | ||
Item ohItem = ItemMapper.mapToOpenHABItem(element); | ||
for(ItemRegistryChangeListener listener : listeners) { | ||
listener.itemAdded(ohItem); | ||
} | ||
} | ||
|
||
@Override | ||
public void removed(org.eclipse.smarthome.core.items.Item element) { | ||
Item ohItem = ItemMapper.mapToOpenHABItem(element); | ||
for(ItemRegistryChangeListener listener : listeners) { | ||
listener.itemRemoved(ohItem); | ||
} | ||
} | ||
|
||
@Override | ||
public void updated(org.eclipse.smarthome.core.items.Item oldElement, org.eclipse.smarthome.core.items.Item element) { | ||
Item ohItem = ItemMapper.mapToOpenHABItem(element); | ||
for(ItemRegistryChangeListener listener : listeners) { | ||
listener.itemRemoved(ohItem); | ||
listener.itemAdded(ohItem); | ||
} | ||
} | ||
|
||
@Override | ||
public String getIcon(String itemName) { | ||
return itemUIRegistry.getIcon(itemName); | ||
} | ||
|
||
@Override | ||
public String getLabel(String itemName) { | ||
return itemUIRegistry.getLabel(itemName); | ||
} | ||
|
||
@Override | ||
public Widget getDefaultWidget(Class<? extends Item> itemType, String itemName) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Widget getWidget(String itemName) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getLabel(Widget w) { | ||
return itemUIRegistry.getLabel(w.getItem()); | ||
} | ||
|
||
@Override | ||
public String getIcon(Widget w) { | ||
return itemUIRegistry.getIcon(w.getItem()); | ||
} | ||
|
||
@Override | ||
public State getState(Widget w) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Widget getWidget(Sitemap sitemap, String id) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getWidgetId(Widget w) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public EList<Widget> getChildren(LinkableWidget w) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean iconExists(String icon) { | ||
return itemUIRegistry.iconExists(icon); | ||
} | ||
|
||
@Override | ||
public String getLabelColor(Widget w) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getValueColor(Widget w) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean getVisiblity(Widget w) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public State getItemState(String itemName) { | ||
try { | ||
return getItem(itemName).getState(); | ||
} catch (ItemNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...re/org.openhab.core.compat1x/src/main/java/org/openhab/io/net/http/SecureHttpContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2010-2014, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.io.net.http; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.osgi.service.http.HttpContext; | ||
|
||
|
||
/** | ||
* Implementation of {@link HttpContext} which adds Basic-Authentication | ||
* functionality to openHAB. | ||
* | ||
* @author Thomas.Eichstaedt-Engelen | ||
* @since 0.9.0 | ||
*/ | ||
public class SecureHttpContext implements HttpContext { | ||
|
||
private HttpContext defaultContext = null; | ||
|
||
public SecureHttpContext() { | ||
} | ||
|
||
public SecureHttpContext(HttpContext defaultContext, final String realm) { | ||
this.defaultContext = defaultContext; | ||
} | ||
|
||
|
||
/** | ||
* <p>@{inheritDoc}</p> | ||
* <p>Delegates to <code>defaultContext.getMimeType()</code> | ||
*/ | ||
public String getMimeType(String name) { | ||
return this.defaultContext.getMimeType(name); | ||
} | ||
|
||
/** | ||
* <p>@{inheritDoc}</p> | ||
* <p>Delegates to <code>defaultContext.getResource()</code> | ||
*/ | ||
public URL getResource(String name) { | ||
return this.defaultContext.getResource(name); | ||
} | ||
|
||
@Override | ||
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.