Initial commit
This commit is contained in:
parent
e90c4d3e38
commit
261d3aefc0
@ -537,7 +537,8 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
lvRuleHistory.setAdapter(ruleHistoryListViewAdapter);
|
||||
|
||||
ruleHistoryListViewAdapter.notifyDataSetChanged();
|
||||
} catch (NullPointerException e)
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -47,6 +51,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -70,6 +75,9 @@ import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import static com.jens.automation2.AutomationService.NOTIFICATION_CHANNEL_ID;
|
||||
import static com.jens.automation2.AutomationService.channelName;
|
||||
@ -928,4 +936,40 @@ public class Miscellaneous extends Service
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Element getXmlTree(String inputString) throws SAXException, IOException, ParserConfigurationException
|
||||
{
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
// Create a Document from a file or stream
|
||||
/*
|
||||
StringBuilder xmlStringBuilder = new StringBuilder();
|
||||
xmlStringBuilder.append("<?xml version="1.0"?> <class> </class>");
|
||||
ByteArrayInputStream input = new ByteArrayInputStream(xmlStringBuilder.toString().getBytes("UTF-8"));
|
||||
*/
|
||||
// Document doc = builder.parse(input);
|
||||
Document doc = builder.parse(new InputSource(new StringReader(inputString)));
|
||||
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
return rootElement;
|
||||
/*
|
||||
// Examine attributes
|
||||
|
||||
//returns specific attribute
|
||||
root.getAttribute("attributeName");
|
||||
|
||||
//returns a Map (table) of names/values
|
||||
root.getAttributes();
|
||||
|
||||
// Examine sub-elements
|
||||
|
||||
//returns a list of subelements of specified name
|
||||
root.getElementsByTagName("subelementName");
|
||||
|
||||
//returns a list of all child nodes
|
||||
root.getChildNodes();
|
||||
*/
|
||||
}
|
||||
}
|
55
app/src/main/java/com/jens/automation2/News.java
Normal file
55
app/src/main/java/com/jens/automation2/News.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class News
|
||||
{
|
||||
String headline;
|
||||
String text;
|
||||
Calendar publishDate;
|
||||
|
||||
public static ArrayList<News> extractNewsFromString()
|
||||
{
|
||||
String result =
|
||||
Miscellaneous.messageBox(title, text, ActivityMainScreen.getActivityMainScreenInstance());
|
||||
|
||||
Element homeControlRootElement = Miscellaneous.getXmlTree(inventoryString);
|
||||
if(homeControlRootElement.getAttribute("protocolVersion").equals(String.valueOf(requiredProtocolVersion)))
|
||||
{
|
||||
FullDataModel.getInstance().houseList = new ArrayList<HouseTemplate>();
|
||||
// FullDataModel.getInstance().roomList = new ArrayList<RoomTemplate>();
|
||||
FullDataModel.getInstance().nodeList = new ArrayList<NodeTemplate>();
|
||||
// FullDataModel.getInstance().deviceList = new ArrayList<DeviceTemplate>();
|
||||
FullDataModel.getInstance().commandsList = new ArrayList<CommandTemplate>();
|
||||
FullDataModel.getInstance().deviceGroupList = new ArrayList<DeviceGroupTemplate>();
|
||||
// FullDataModel.getInstance().sensorList = new ArrayList<SensorTemplate>();
|
||||
FullDataModel.getInstance().ruleList = new ArrayList<RuleTemplate>();
|
||||
FullDataModel.getInstance().userList = new ArrayList<UserTemplate>();
|
||||
FullDataModel.getInstance().userDeviceList = new ArrayList<UserDeviceTemplate>();
|
||||
|
||||
NodeList responseElements = homeControlRootElement.getElementsByTagName("response");
|
||||
Node responseElement = responseElements.item(0);
|
||||
|
||||
NodeList nodeElementsHouses = homeControlRootElement.getElementsByTagName("houses");
|
||||
for(int i = 0; i < nodeElementsHouses.getLength(); i++)
|
||||
{
|
||||
if(nodeElementsHouses.item(i).getNodeType() == Node.ELEMENT_NODE && (nodeElementsHouses.item(i).getParentNode().isSameNode(homeControlRootElement) | nodeElementsHouses.item(i).getParentNode().isSameNode(responseElement)))
|
||||
{
|
||||
NodeList nodeElementsHousesInd = nodeElementsHouses.item(i).getChildNodes();
|
||||
for(int j = 0; j < nodeElementsHousesInd.getLength(); j++)
|
||||
{
|
||||
Element houseElement = (Element) nodeElementsHousesInd.item(j);
|
||||
HouseTemplate house = HouseTemplate.fromXmlStringStatic(Diverse.xmlToString(houseElement, true, false));
|
||||
FullDataModel.getInstance().houseList.add(house);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user